21 #include <sys/types.h> 41 #include <gnutls/gnutls.h> 42 #include <sys/socket.h> 43 #include <netinet/in.h> 44 #include <netinet/ip.h> 45 #include <arpa/inet.h> 48 #define MAX_TLS_RECV_WAIT 10000 52 static int lrmd_api_disconnect(
lrmd_t * lrmd);
53 static int lrmd_api_is_connected(
lrmd_t * lrmd);
57 static void lrmd_internal_proxy_dispatch(
lrmd_t *lrmd, xmlNode *msg);
61 #define TLS_HANDSHAKE_TIMEOUT 5 63 static void lrmd_tls_disconnect(
lrmd_t * lrmd);
64 static int global_remote_msg_id = 0;
65 static void lrmd_tls_connection_destroy(gpointer userdata);
66 static int add_tls_to_mainloop(
lrmd_t *lrmd,
bool do_api_handshake);
68 typedef struct lrmd_private_s {
79 char *remote_nodename;
92 int expected_late_replies;
93 GList *pending_notify;
100 void (*proxy_callback)(
lrmd_t *lrmd,
void *userdata, xmlNode *msg);
101 void *proxy_callback_userdata;
105 static int process_lrmd_handshake_reply(xmlNode *reply,
lrmd_private_t *native);
106 static void report_async_connection_result(
lrmd_t * lrmd,
int rc);
109 lrmd_list_add(
lrmd_list_t * head,
const char *value)
114 p->
val = strdup(value);
117 while (end && end->
next) {
136 char *val = (
char *)head->
val;
151 p->
key = strdup(key);
152 p->
value = strdup(value);
155 while (end && end->
next) {
202 event->interval_ms = interval_ms;
213 copy->
type =
event->type;
223 copy->
call_id =
event->call_id;
224 copy->
timeout =
event->timeout;
228 copy->
rc =
event->rc;
230 copy->
t_run =
event->t_run;
252 free((
void *) event->
rsc_id);
257 if (event->
params != NULL) {
258 g_hash_table_destroy(event->
params);
264 lrmd_dispatch_internal(gpointer
data, gpointer user_data)
275 if (proxy_session != NULL) {
277 lrmd_internal_proxy_dispatch(lrmd, msg);
279 }
else if (!native->callback) {
281 crm_trace(
"notify event received but client has not set callback");
285 event.remote_nodename = native->remote_nodename;
318 event.t_rcchange = epoch;
322 event.exec_time = QB_MAX(0, exec_time);
326 event.queue_time = QB_MAX(0, queue_time);
348 native->callback(&event);
351 g_hash_table_destroy(event.params);
358 lrmd_ipc_dispatch(
const char *buffer, ssize_t length, gpointer userdata)
363 if (native->callback != NULL) {
366 lrmd_dispatch_internal(msg, lrmd);
373 lrmd_free_xml(gpointer userdata)
379 remote_executor_connected(
lrmd_t * lrmd)
383 return (native->remote->tls_session != NULL);
387 handle_remote_msg(xmlNode *xml,
lrmd_t *lrmd)
390 const char *msg_type = NULL;
394 lrmd_dispatch_internal(xml, lrmd);
398 if (native->expected_late_replies > 0) {
399 native->expected_late_replies--;
405 int rc = process_lrmd_handshake_reply(xml, native);
412 crm_err(
"Got outdated Pacemaker Remote reply %d", reply_id);
427 process_pending_notifies(gpointer userdata)
432 if (native->pending_notify == NULL) {
433 return G_SOURCE_CONTINUE;
436 crm_trace(
"Processing pending notifies");
437 g_list_foreach(native->pending_notify, lrmd_dispatch_internal, lrmd);
438 g_list_free_full(native->pending_notify, lrmd_free_xml);
439 native->pending_notify = NULL;
440 return G_SOURCE_CONTINUE;
453 lrmd_tls_dispatch(gpointer userdata)
460 if (!remote_executor_connected(lrmd)) {
461 crm_trace(
"TLS dispatch triggered after disconnect");
473 crm_info(
"Lost %s executor connection while reading data",
474 (native->remote_nodename? native->remote_nodename :
"local"));
475 lrmd_tls_disconnect(lrmd);
488 handle_remote_msg(xml, lrmd);
499 switch (native->type) {
504 if (native->pending_notify) {
519 crm_err(
"Unsupported executor connection type (bug?): %d",
521 return -EPROTONOSUPPORT;
534 switch (private->type) {
540 lrmd_ipc_dispatch(msg, strlen(msg), lrmd);
545 lrmd_tls_dispatch(lrmd);
548 crm_err(
"Unsupported executor connection type (bug?): %d",
552 if (lrmd_api_is_connected(lrmd) == FALSE) {
561 lrmd_create_op(
const char *token,
const char *op, xmlNode *
data,
int timeout,
564 xmlNode *op_msg = NULL;
580 crm_trace(
"Created executor %s command with call options %.8lx (%d)",
581 op, (
long)options, options);
586 lrmd_ipc_connection_destroy(gpointer userdata)
591 switch (native->type) {
593 crm_info(
"Disconnected from local executor");
596 crm_info(
"Disconnected from remote executor on %s",
597 native->remote_nodename);
600 crm_err(
"Unsupported executor connection type %d (bug?)",
606 native->source = NULL;
608 if (native->callback) {
611 event.remote_nodename = native->remote_nodename;
612 native->callback(&event);
617 lrmd_tls_connection_destroy(gpointer userdata)
622 crm_info(
"TLS connection destroyed");
624 if (native->remote->tls_session) {
625 gnutls_bye(native->remote->tls_session, GNUTLS_SHUT_RDWR);
626 gnutls_deinit(native->remote->tls_session);
627 native->remote->tls_session = NULL;
636 if (native->process_notify) {
638 native->process_notify = NULL;
640 if (native->pending_notify) {
641 g_list_free_full(native->pending_notify, lrmd_free_xml);
642 native->pending_notify = NULL;
644 if (native->handshake_trigger != NULL) {
646 native->handshake_trigger = NULL;
649 free(native->remote->buffer);
650 free(native->remote->start_state);
651 native->remote->buffer = NULL;
652 native->remote->start_state = NULL;
656 if (native->callback) {
660 native->callback(&event);
668 const char *msg_type)
677 read_remote_reply(
lrmd_t *lrmd,
int total_timeout,
int expected_reply_id,
681 time_t start = time(NULL);
682 const char *msg_type = NULL;
684 int remaining_timeout = 0;
693 for (*reply = NULL; *reply == NULL; ) {
696 if (*reply == NULL) {
698 if (remaining_timeout) {
699 remaining_timeout = total_timeout - ((time(NULL) - start) * 1000);
701 remaining_timeout = total_timeout;
703 if (remaining_timeout <= 0) {
713 if (*reply == NULL) {
722 crm_err(
"Empty msg type received while waiting for reply");
728 native->pending_notify = g_list_append(native->pending_notify, *reply);
729 if (native->process_notify) {
736 crm_err(
"Expected a reply, got %s", msg_type);
739 }
else if (reply_id != expected_reply_id) {
740 if (native->expected_late_replies > 0) {
741 native->expected_late_replies--;
743 crm_err(
"Got outdated reply, expected id %d got id %d", expected_reply_id, reply_id);
750 if (native->remote->buffer && native->process_notify) {
759 send_remote_message(
lrmd_t *lrmd, xmlNode *msg)
764 global_remote_msg_id++;
765 if (global_remote_msg_id <= 0) {
766 global_remote_msg_id = 1;
772 crm_err(
"Disconnecting because TLS message could not be sent to " 774 lrmd_tls_disconnect(lrmd);
780 lrmd_tls_send_recv(
lrmd_t * lrmd, xmlNode * msg,
int timeout, xmlNode ** reply)
785 if (!remote_executor_connected(lrmd)) {
789 rc = send_remote_message(lrmd, msg);
794 rc = read_remote_reply(lrmd,
timeout, global_remote_msg_id, &xml);
796 crm_err(
"Disconnecting remote after request %d reply not received: %s " 797 QB_XS
" rc=%d timeout=%dms",
799 lrmd_tls_disconnect(lrmd);
812 lrmd_send_xml(
lrmd_t * lrmd, xmlNode * msg,
int timeout, xmlNode ** reply)
817 switch (native->type) {
822 rc = lrmd_tls_send_recv(lrmd, msg,
timeout, reply);
825 crm_err(
"Unsupported executor connection type (bug?): %d",
827 rc = -EPROTONOSUPPORT;
834 lrmd_send_xml_no_reply(
lrmd_t * lrmd, xmlNode * msg)
839 switch (native->type) {
844 rc = send_remote_message(lrmd, msg);
849 native->expected_late_replies++;
854 crm_err(
"Unsupported executor connection type (bug?): %d",
856 rc = -EPROTONOSUPPORT;
863 lrmd_api_is_connected(
lrmd_t * lrmd)
867 switch (native->type) {
871 return remote_executor_connected(lrmd);
873 crm_err(
"Unsupported executor connection type (bug?): %d",
898 lrmd_send_command(
lrmd_t *lrmd,
const char *op, xmlNode *
data,
899 xmlNode **output_data,
int timeout,
904 xmlNode *op_msg = NULL;
905 xmlNode *op_reply = NULL;
907 if (!lrmd_api_is_connected(lrmd)) {
912 crm_err(
"No operation specified");
917 crm_trace(
"Sending %s op to executor", op);
919 op_msg = lrmd_create_op(native->token, op,
data,
timeout, options);
921 if (op_msg == NULL) {
926 rc = lrmd_send_xml(lrmd, op_msg,
timeout, &op_reply);
928 rc = lrmd_send_xml_no_reply(lrmd, op_msg);
933 crm_perror(LOG_ERR,
"Couldn't perform %s operation (timeout=%d): %d", op,
timeout, rc);
936 }
else if (op_reply == NULL) {
951 *output_data = op_reply;
956 if (lrmd_api_is_connected(lrmd) == FALSE) {
957 crm_err(
"Executor disconnected");
966 lrmd_api_poke_connection(
lrmd_t * lrmd)
1004 lrmd_handshake_hello_msg(
const char *
name,
bool is_proxy)
1022 process_lrmd_handshake_reply(xmlNode *reply,
lrmd_private_t *native)
1029 long long uptime = -1;
1039 native->remote->uptime = uptime;
1042 native->remote->start_state = strdup(start_state);
1046 crm_err(
"Executor protocol version mismatch between client (%s) and server (%s)",
1050 crm_err(
"Invalid registration message: %s", msg_type);
1053 }
else if (tmp_ticket == NULL) {
1054 crm_err(
"No registration token provided");
1058 crm_trace(
"Obtained registration token: %s", tmp_ticket);
1059 native->token = strdup(tmp_ticket);
1068 lrmd_handshake(
lrmd_t * lrmd,
const char *
name)
1072 xmlNode *reply = NULL;
1073 xmlNode *hello = lrmd_handshake_hello_msg(
name, native->proxy_callback != NULL);
1075 rc = lrmd_send_xml(lrmd, hello, -1, &reply);
1078 crm_perror(LOG_DEBUG,
"Couldn't complete registration with the executor API: %d", rc);
1080 }
else if (reply == NULL) {
1081 crm_err(
"Did not receive registration reply");
1084 rc = process_lrmd_handshake_reply(reply, native);
1091 lrmd_api_disconnect(lrmd);
1098 lrmd_handshake_async(
lrmd_t * lrmd,
const char *
name)
1102 xmlNode *hello = lrmd_handshake_hello_msg(
name, native->proxy_callback != NULL);
1104 rc = send_remote_message(lrmd, hello);
1107 native->expected_late_replies++;
1109 lrmd_api_disconnect(lrmd);
1117 lrmd_ipc_connect(
lrmd_t * lrmd,
int *fd)
1124 .destroy = lrmd_ipc_connection_destroy
1127 crm_info(
"Connecting to executor");
1132 if (native->ipc != NULL) {
1147 if (native->ipc == NULL) {
1148 crm_debug(
"Could not connect to the executor API");
1156 copy_gnutls_datum(gnutls_datum_t *dest, gnutls_datum_t *source)
1158 pcmk__assert((dest != NULL) && (source != NULL) && (source->data != NULL));
1160 dest->data = gnutls_malloc(source->size);
1163 memcpy(dest->data, source->data, source->size);
1164 dest->size = source->size;
1168 clear_gnutls_datum(gnutls_datum_t *datum)
1170 gnutls_free(datum->data);
1175 #define KEY_READ_LEN 256 // Chunk size for reading key from file 1179 read_gnutls_key(
const char *location, gnutls_datum_t *key)
1181 FILE *stream = NULL;
1184 if ((location == NULL) || (key == NULL)) {
1188 stream = fopen(location,
"r");
1189 if (stream == NULL) {
1193 key->data = gnutls_malloc(buf_len);
1195 while (!feof(stream)) {
1196 int next = fgetc(stream);
1199 if (!feof(stream)) {
1200 crm_warn(
"Pacemaker Remote key read was partially successful " 1201 "(copy in memory may be corrupted)");
1205 if (key->size == buf_len) {
1207 key->data = gnutls_realloc(key->data, buf_len);
1210 key->data[key->size++] = (
unsigned char) next;
1214 if (key->size == 0) {
1215 clear_gnutls_datum(key);
1223 struct key_cache_s {
1225 const char *location;
1230 key_is_cached(
struct key_cache_s *key_cache)
1232 return key_cache->updated != 0;
1236 key_cache_expired(
struct key_cache_s *key_cache)
1238 return (time(NULL) - key_cache->updated) >= 60;
1242 clear_key_cache(
struct key_cache_s *key_cache)
1244 clear_gnutls_datum(&(key_cache->key));
1245 if ((key_cache->updated != 0) || (key_cache->location != NULL)) {
1246 key_cache->updated = 0;
1247 key_cache->location = NULL;
1248 crm_debug(
"Cleared Pacemaker Remote key cache");
1253 get_cached_key(
struct key_cache_s *key_cache, gnutls_datum_t *key)
1255 copy_gnutls_datum(key, &(key_cache->key));
1256 crm_debug(
"Using cached Pacemaker Remote key from %s",
1257 pcmk__s(key_cache->location,
"unknown location"));
1261 cache_key(
struct key_cache_s *key_cache, gnutls_datum_t *key,
1262 const char *location)
1264 key_cache->updated = time(NULL);
1265 key_cache->location = location;
1266 copy_gnutls_datum(&(key_cache->key), key);
1267 crm_debug(
"Using (and cacheing) Pacemaker Remote key from %s",
1268 pcmk__s(location,
"unknown location"));
1282 get_remote_key(
const char *location, gnutls_datum_t *key)
1284 static struct key_cache_s key_cache = { 0, };
1287 if ((location == NULL) || (key == NULL)) {
1291 if (key_is_cached(&key_cache)) {
1292 if (key_cache_expired(&key_cache)) {
1293 clear_key_cache(&key_cache);
1295 get_cached_key(&key_cache, key);
1300 rc = read_gnutls_key(location, key);
1304 cache_key(&key_cache, key, location);
1325 static const char *env_location = NULL;
1326 static bool need_env =
true;
1336 if (env_location != NULL) {
1337 rc = get_remote_key(env_location, key);
1342 crm_warn(
"Could not read Pacemaker Remote key from %s: %s",
1353 crm_warn(
"Could not read Pacemaker Remote key from default location %s: %s",
1359 report_async_connection_result(
lrmd_t * lrmd,
int rc)
1363 if (native->callback) {
1366 event.remote_nodename = native->remote_nodename;
1367 event.connection_rc = rc;
1368 native->callback(&event);
1373 tls_handshake_failed(
lrmd_t *lrmd,
int tls_rc,
int rc)
1377 crm_warn(
"Disconnecting after TLS handshake with " 1378 "Pacemaker Remote server %s:%d failed: %s",
1379 native->server, native->port,
1380 (rc == EPROTO)? gnutls_strerror(tls_rc) :
pcmk_rc_str(rc));
1383 gnutls_deinit(native->remote->tls_session);
1384 native->remote->tls_session = NULL;
1385 lrmd_tls_connection_destroy(lrmd);
1389 tls_handshake_succeeded(
lrmd_t *lrmd)
1401 crm_info(
"TLS connection to Pacemaker Remote server %s:%d succeeded",
1402 native->server, native->port);
1403 rc = add_tls_to_mainloop(lrmd,
true);
1422 tls_client_handshake(
lrmd_t *lrmd)
1425 int tls_rc = GNUTLS_E_SUCCESS;
1430 tls_handshake_failed(lrmd, tls_rc, rc);
1446 add_tls_to_mainloop(
lrmd_t *lrmd,
bool do_api_handshake)
1452 native->server, native->port);
1456 .destroy = lrmd_tls_connection_destroy,
1460 process_pending_notifies, lrmd);
1470 if (do_api_handshake) {
1471 rc = lrmd_handshake_async(lrmd,
name);
1477 struct handshake_data_s {
1484 try_handshake_cb(gpointer user_data)
1486 struct handshake_data_s *hs = user_data;
1492 int tls_rc = GNUTLS_E_SUCCESS;
1494 if (time(NULL) >= hs->start_time + hs->timeout_sec) {
1497 tls_handshake_failed(lrmd, GNUTLS_E_TIMEDOUT, rc);
1505 tls_handshake_succeeded(lrmd);
1508 }
else if (rc == EAGAIN) {
1513 tls_handshake_failed(lrmd, tls_rc, rc);
1520 lrmd_tcp_connect_cb(
void *userdata,
int rc,
int sock)
1524 int tls_rc = GNUTLS_E_SUCCESS;
1527 native->async_timer = 0;
1530 lrmd_tls_connection_destroy(lrmd);
1531 crm_info(
"Could not connect to Pacemaker Remote at %s:%d: %s " 1533 native->server, native->port,
pcmk_rc_str(rc), rc);
1540 native->sock = sock;
1542 if (native->tls == NULL) {
1543 rc =
pcmk__init_tls(&native->tls,
false, use_cert ? GNUTLS_CRD_CERTIFICATE : GNUTLS_CRD_PSK);
1546 lrmd_tls_connection_destroy(lrmd);
1553 gnutls_datum_t psk_key = { NULL, 0 };
1557 crm_info(
"Could not connect to Pacemaker Remote at %s:%d: %s " 1559 native->server, native->port,
pcmk_rc_str(rc), rc);
1560 lrmd_tls_connection_destroy(lrmd);
1566 gnutls_free(psk_key.data);
1570 if (native->remote->tls_session == NULL) {
1571 lrmd_tls_connection_destroy(lrmd);
1572 report_async_connection_result(lrmd, -EPROTO);
1582 struct handshake_data_s *hs = NULL;
1584 if (native->handshake_trigger != NULL) {
1590 hs->start_time = time(NULL);
1597 tls_handshake_succeeded(lrmd);
1600 tls_handshake_failed(lrmd, tls_rc, rc);
1613 &(native->sock), lrmd, lrmd_tcp_connect_cb);
1615 crm_warn(
"Pacemaker Remote connection to %s:%d failed: %s " 1617 native->server, native->port,
pcmk_rc_str(rc), rc);
1620 native->async_timer = timer_id;
1625 lrmd_tls_connect(
lrmd_t * lrmd,
int *fd)
1633 &(native->sock), NULL, NULL);
1635 crm_warn(
"Pacemaker Remote connection to %s:%d failed: %s " 1637 native->server, native->port,
pcmk_rc_str(rc), rc);
1638 lrmd_tls_connection_destroy(lrmd);
1642 if (native->tls == NULL) {
1643 rc =
pcmk__init_tls(&native->tls,
false, use_cert ? GNUTLS_CRD_CERTIFICATE : GNUTLS_CRD_PSK);
1646 lrmd_tls_connection_destroy(lrmd);
1652 gnutls_datum_t psk_key = { NULL, 0 };
1656 lrmd_tls_connection_destroy(lrmd);
1661 gnutls_free(psk_key.data);
1665 if (native->remote->tls_session == NULL) {
1666 lrmd_tls_connection_destroy(lrmd);
1670 if (tls_client_handshake(lrmd) !=
pcmk_rc_ok) {
1674 crm_info(
"Client TLS connection established with Pacemaker Remote server %s:%d", native->server,
1680 rc = add_tls_to_mainloop(lrmd,
false);
1686 lrmd_api_connect(
lrmd_t * lrmd,
const char *
name,
int *fd)
1691 switch (native->type) {
1693 rc = lrmd_ipc_connect(lrmd, fd);
1696 rc = lrmd_tls_connect(lrmd, fd);
1700 crm_err(
"Unsupported executor connection type (bug?): %d",
1702 rc = -EPROTONOSUPPORT;
1706 rc = lrmd_handshake(lrmd,
name);
1719 CRM_CHECK(native && native->callback,
return -EINVAL);
1721 switch (native->type) {
1725 rc = lrmd_api_connect(lrmd,
name, NULL);
1727 report_async_connection_result(lrmd, rc);
1731 rc = lrmd_tls_connect_async(lrmd,
timeout);
1735 crm_err(
"Unsupported executor connection type (bug?): %d",
1737 rc = -EPROTONOSUPPORT;
1744 lrmd_ipc_disconnect(
lrmd_t * lrmd)
1748 if (native->source != NULL) {
1751 native->source = NULL;
1754 }
else if (native->ipc) {
1765 lrmd_tls_disconnect(
lrmd_t * lrmd)
1769 if (native->remote->tls_session) {
1770 gnutls_bye(native->remote->tls_session, GNUTLS_SHUT_RDWR);
1771 gnutls_deinit(native->remote->tls_session);
1772 native->remote->tls_session = NULL;
1775 if (native->async_timer) {
1776 g_source_remove(native->async_timer);
1777 native->async_timer = 0;
1780 if (native->source != NULL) {
1783 native->source = NULL;
1785 }
else if (native->sock) {
1786 close(native->sock);
1790 if (native->pending_notify) {
1791 g_list_free_full(native->pending_notify, lrmd_free_xml);
1792 native->pending_notify = NULL;
1797 lrmd_api_disconnect(
lrmd_t * lrmd)
1802 switch (native->type) {
1804 crm_debug(
"Disconnecting from local executor");
1805 lrmd_ipc_disconnect(lrmd);
1808 crm_debug(
"Disconnecting from remote executor on %s",
1809 native->remote_nodename);
1810 lrmd_tls_disconnect(lrmd);
1813 crm_err(
"Unsupported executor connection type (bug?): %d",
1815 rc = -EPROTONOSUPPORT;
1818 free(native->token);
1819 native->token = NULL;
1821 free(native->peer_version);
1822 native->peer_version = NULL;
1827 lrmd_api_register_rsc(
lrmd_t * lrmd,
1833 xmlNode *
data = NULL;
1835 if (!
class || !
type || !rsc_id) {
1839 && (provider == NULL)) {
1872 const char *provider,
const char *
type)
1897 free(rsc_info->
type);
1908 xmlNode *output = NULL;
1909 const char *
class = NULL;
1910 const char *provider = NULL;
1911 const char *
type = NULL;
1926 if (!
class || !
type) {
1953 lrmd_api_get_recurring_ops(
lrmd_t *lrmd,
const char *rsc_id,
int timeout_ms,
1956 xmlNode *
data = NULL;
1957 xmlNode *output_xml = NULL;
1960 if (output == NULL) {
1972 timeout_ms, options,
true);
1978 if ((rc !=
pcmk_ok) || (output_xml == NULL)) {
1984 (rsc_xml != NULL) && (rc ==
pcmk_ok);
1988 if (rsc_id == NULL) {
1989 crm_err(
"Could not parse recurring operation information from executor");
2000 if (op_info == NULL) {
2004 op_info->
rsc_id = strdup(rsc_id);
2011 *output = g_list_prepend(*output, op_info);
2024 native->callback = callback;
2032 native->proxy_callback = callback;
2033 native->proxy_callback_userdata = userdata;
2037 lrmd_internal_proxy_dispatch(
lrmd_t *lrmd, xmlNode *msg)
2041 if (native->proxy_callback) {
2043 native->proxy_callback(lrmd, native->proxy_callback_userdata, msg);
2056 return lrmd_send_xml_no_reply(lrmd, msg);
2060 stonith_get_metadata(
const char *provider,
const char *
type,
char **output)
2065 if (stonith_api == NULL) {
2066 crm_err(
"Could not get fence agent meta-data: API memory allocation failed");
2071 provider, output, 0);
2072 if ((rc ==
pcmk_ok) && (*output == NULL)) {
2075 stonith_api->
cmds->
free(stonith_api);
2080 lrmd_api_get_metadata(
lrmd_t *lrmd,
const char *standard,
const char *provider,
2081 const char *
type,
char **output,
2085 output, options, NULL);
2089 lrmd_api_get_metadata_params(
lrmd_t *lrmd,
const char *standard,
2090 const char *provider,
const char *
type,
2095 GHashTable *params_table = NULL;
2097 if (!standard || !
type) {
2104 return stonith_get_metadata(provider,
type, output);
2126 crm_err(
"Failed to retrieve meta-data for %s:%s:%s",
2127 standard, provider,
type);
2132 if (!
action->stdout_data) {
2133 crm_err(
"Failed to receive meta-data for %s:%s:%s",
2134 standard, provider,
type);
2139 *output = strdup(
action->stdout_data);
2146 lrmd_api_exec(
lrmd_t *lrmd,
const char *rsc_id,
const char *
action,
2147 const char *userdata, guint interval_ms,
2165 for (tmp = params; tmp; tmp = tmp->
next) {
2178 lrmd_api_exec_alert(
lrmd_t *lrmd,
const char *alert_id,
const char *alert_path,
2191 for (tmp = params; tmp; tmp = tmp->
next) {
2204 lrmd_api_cancel(
lrmd_t *lrmd,
const char *rsc_id,
const char *
action,
2227 if (stonith_api == NULL) {
2228 crm_err(
"Could not list fence agents: API memory allocation failed");
2232 &stonith_resources, 0);
2233 stonith_api->
cmds->
free(stonith_api);
2235 for (dIter = stonith_resources; dIter; dIter = dIter->
next) {
2238 *resources = lrmd_list_add(*resources, dIter->
value);
2247 lrmd_api_list_agents(
lrmd_t * lrmd,
lrmd_list_t ** resources,
const char *
class,
2248 const char *provider)
2251 int stonith_count = 0;
2257 GList *gIter = NULL;
2260 for (gIter = agents; gIter != NULL; gIter = gIter->next) {
2261 *resources = lrmd_list_add(*resources, (
const char *)gIter->data);
2264 g_list_free_full(agents, free);
2271 if (stonith_count) {
2273 stonith_count = list_stonith_agents(resources);
2274 if (stonith_count > 0) {
2275 rc += stonith_count;
2279 crm_notice(
"No agents found for class %s",
class);
2280 rc = -EPROTONOSUPPORT;
2286 does_provider_have_agent(
const char *agent,
const char *provider,
const char *
class)
2289 GList *agents = NULL;
2290 GList *gIter2 = NULL;
2293 for (gIter2 = agents; gIter2 != NULL; gIter2 = gIter2->next) {
2298 g_list_free_full(agents, free);
2303 lrmd_api_list_ocf_providers(
lrmd_t * lrmd,
const char *agent,
lrmd_list_t ** providers)
2306 char *provider = NULL;
2307 GList *ocf_providers = NULL;
2308 GList *gIter = NULL;
2312 for (gIter = ocf_providers; gIter != NULL; gIter = gIter->next) {
2313 provider = gIter->data;
2314 if (!agent || does_provider_have_agent(agent, provider,
2316 *providers = lrmd_list_add(*providers, (
const char *)gIter->data);
2321 g_list_free_full(ocf_providers, free);
2329 GList *standards = NULL;
2330 GList *gIter = NULL;
2334 for (gIter = standards; gIter != NULL; gIter = gIter->next) {
2335 *supported = lrmd_list_add(*supported, (
const char *)gIter->data);
2339 if (list_stonith_agents(NULL) > 0) {
2344 g_list_free_full(standards, free);
2379 *api = calloc(1,
sizeof(
lrmd_t));
2397 if ((pvt->remote == NULL) || ((*api)->cmds == NULL)) {
2405 (*api)->cmds->connect_async = lrmd_api_connect_async;
2406 (*api)->cmds->is_connected = lrmd_api_is_connected;
2407 (*api)->cmds->poke_connection = lrmd_api_poke_connection;
2408 (*api)->cmds->disconnect = lrmd_api_disconnect;
2409 (*api)->cmds->register_rsc = lrmd_api_register_rsc;
2410 (*api)->cmds->unregister_rsc = lrmd_api_unregister_rsc;
2411 (*api)->cmds->get_rsc_info = lrmd_api_get_rsc_info;
2412 (*api)->cmds->get_recurring_ops = lrmd_api_get_recurring_ops;
2413 (*api)->cmds->set_callback = lrmd_api_set_callback;
2414 (*api)->cmds->get_metadata = lrmd_api_get_metadata;
2415 (*api)->cmds->exec = lrmd_api_exec;
2416 (*api)->cmds->cancel = lrmd_api_cancel;
2417 (*api)->cmds->list_agents = lrmd_api_list_agents;
2418 (*api)->cmds->list_ocf_providers = lrmd_api_list_ocf_providers;
2419 (*api)->cmds->list_standards = lrmd_api_list_standards;
2420 (*api)->cmds->exec_alert = lrmd_api_exec_alert;
2421 (*api)->cmds->get_metadata_params = lrmd_api_get_metadata_params;
2423 if ((nodename == NULL) && (server == NULL)) {
2426 if (nodename == NULL) {
2428 }
else if (server == NULL) {
2432 pvt->remote_nodename = strdup(nodename);
2433 pvt->server = strdup(server);
2434 if ((pvt->remote_nodename == NULL) || (pvt->server == NULL)) {
2440 if (pvt->port == 0) {
2471 if (lrmd->
cmds != NULL) {
2480 free(native->server);
2481 free(native->remote_nodename);
2482 free(native->remote);
2483 free(native->token);
2484 free(native->peer_version);
2490 struct metadata_cb {
2505 struct metadata_cb *metadata_cb = (
struct metadata_cb *)
action->cb_data;
2512 metadata_cb->callback(0, &
result, metadata_cb->user_data);
2537 void (*callback)(
int pid,
2543 struct metadata_cb *metadata_cb = NULL;
2546 CRM_CHECK(callback != NULL,
return EINVAL);
2548 if ((rsc == NULL) || (rsc->
standard == NULL) || (rsc->
type == NULL)) {
2551 "Invalid resource specification");
2552 callback(0, &
result, user_data);
2560 callback, user_data);
2572 callback(0, &
result, user_data);
2579 callback(0, &
result, user_data);
2585 action->cb_data = calloc(1,
sizeof(
struct metadata_cb));
2586 if (
action->cb_data == NULL) {
2590 callback(0, &
result, user_data);
2595 metadata_cb = (
struct metadata_cb *)
action->cb_data;
2596 metadata_cb->callback = callback;
2597 metadata_cb->user_data = user_data;
2618 const char *exit_reason)
2620 if (event == NULL) {
2625 event->op_status = op_status;
2640 if (event == NULL) {
2645 event->exit_reason = NULL;
2647 free((
void *) event->
output);
2648 event->output = NULL;
2666 if (native->remote == NULL) {
2669 return native->remote->uptime;
2678 if (native->remote == NULL) {
2681 return native->remote->start_state;
#define CRM_CHECK(expr, failure_action)
#define LRMD_OP_ALERT_EXEC
xmlNode * pcmk__xml_copy(xmlNode *parent, xmlNode *src)
int lrmd__remote_send_xml(pcmk__remote_t *session, xmlNode *msg, uint32_t id, const char *msg_type)
ocf_exitcode
Exit status codes for resource agents.
xmlNode * pcmk__xe_first_child(const xmlNode *parent, const char *node_name, const char *attr_n, const char *attr_v)
#define crm_notice(fmt, args...)
#define PCMK__XA_LRMD_IPC_SESSION
lrmd_event_data_t * lrmd_copy_event(lrmd_event_data_t *event)
int crm_element_value_ll(const xmlNode *data, const char *name, long long *dest)
Retrieve the long long integer value of an XML attribute.
void services_action_free(svc_action_t *op)
mainloop_io_t * mainloop_add_fd(const char *name, int priority, int fd, void *userdata, struct mainloop_fd_callbacks *callbacks)
int pcmk_rc2legacy(int rc)
int lrmd__metadata_async(const lrmd_rsc_info_t *rsc, void(*callback)(int pid, const pcmk__action_result_t *result, void *user_data), void *user_data)
void pcmk__xe_set_bool_attr(xmlNodePtr node, const char *name, bool value)
enum pcmk_ipc_server type
#define LRMD_OP_RSC_CANCEL
#define PCMK__XE_LRMD_RSC_OP
#define PCMK__XA_LRMD_RSC_OUTPUT
int crm_element_value_epoch(const xmlNode *xml, const char *name, time_t *dest)
Retrieve the seconds-since-epoch value of an XML attribute.
void(* lrmd_event_callback)(lrmd_event_data_t *event)
#define PCMK__XA_LRMD_ALERT_ID
void void pcmk__set_result_output(pcmk__action_result_t *result, char *out, char *err)
#define PCMK_ACTION_META_DATA
struct stonith_key_value_s * next
void lrmd_key_value_freeall(lrmd_key_value_t *head)
struct mainloop_io_s mainloop_io_t
lrmd_event_data_t * lrmd_new_event(const char *rsc_id, const char *task, guint interval_ms)
Create a new lrmd_event_data_t object.
#define PCMK__XE_ATTRIBUTES
void mainloop_set_trigger(crm_trigger_t *source)
#define LRMD_OP_GET_RECURRING
#define PCMK__XA_LRMD_RCCHANGE_TIME
#define MAX_TLS_RECV_WAIT
#define PCMK_RESOURCE_CLASS_OCF
int pcmk__tls_client_try_handshake(pcmk__remote_t *remote, int *gnutls_rc)
#define PCMK__XA_LRMD_REMOTE_MSG_TYPE
#define PCMK__XA_LRMD_PROTOCOL_VERSION
int lrmd_internal_proxy_send(lrmd_t *lrmd, xmlNode *msg)
#define PCMK__XA_LRMD_RSC_ACTION
#define CRM_LOG_ASSERT(expr)
#define PCMK__XA_LRMD_ORIGIN
lrmd_rsc_info_t * lrmd_copy_rsc_info(lrmd_rsc_info_t *rsc_info)
int pcmk__init_tls(pcmk__tls_t **tls, bool server, gnutls_credentials_type_t cred_type)
long crm_ipc_read(crm_ipc_t *client)
gboolean mainloop_destroy_trigger(crm_trigger_t *source)
#define PCMK__XA_LRMD_RSC_EXIT_REASON
const char * pcmk_rc_str(int rc)
Get a user-friendly description of a return code.
void lrmd__set_result(lrmd_event_data_t *event, enum ocf_exitcode rc, int op_status, const char *exit_reason)
void hash2smartfield(gpointer key, gpointer value, gpointer user_data)
Safely add hash table entry to XML as attribute or name-value pair.
const char * pcmk__env_option(const char *option)
Wrappers for and extensions to glib mainloop.
lrmd_t * lrmd_remote_api_new(const char *nodename, const char *server, int port)
Create a new TLS connection to a remote executor.
stonith_t * stonith_api_new(void)
xmlNode * pcmk__xe_create(xmlNode *parent, const char *name)
#define PCMK__XA_LRMD_EXEC_OP_STATUS
const char * crm_ipc_buffer(crm_ipc_t *client)
#define PCMK__XA_LRMD_EXEC_TIME
#define LRMD_OP_RSC_UNREG
int(* list_agents)(stonith_t *stonith, int call_options, const char *namespace_s, stonith_key_value_t **devices, int timeout)
Retrieve a list of installed fence agents.
int pcmk__tls_client_handshake(pcmk__remote_t *remote, int timeout_sec, int *gnutls_rc)
#define PCMK__XE_LRMD_RSC
#define TLS_HANDSHAKE_TIMEOUT
#define PCMK__XE_LRMD_ALERT
#define PCMK__XA_LRMD_CALLOPT
void pcmk__xml_free(xmlNode *xml)
#define DEFAULT_REMOTE_KEY_LOCATION
struct trigger_s crm_trigger_t
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
#define PCMK__XA_LRMD_CLASS
struct lrmd_private_s lrmd_private_t
int pcmk__connect_generic_ipc(crm_ipc_t *ipc)
int(* free)(stonith_t *st)
Destroy a fencer connection.
int(* dispatch)(gpointer userdata)
Dispatch function for mainloop file descriptor with data ready.
#define PCMK_DEFAULT_ACTION_TIMEOUT_MS
Default timeout (in milliseconds) for non-metadata actions.
#define PCMK__UNKNOWN_RESULT
#define crm_warn(fmt, args...)
GHashTable * xml2list(const xmlNode *parent)
Retrieve XML attributes as a hash table.
#define PCMK__XA_LRMD_RSC_ID
#define PCMK__XA_LRMD_ALERT_PATH
#define PCMK__XA_LRMD_TIMEOUT
int crm_element_value_ms(const xmlNode *data, const char *name, guint *dest)
Retrieve the millisecond value of an XML attribute.
#define crm_debug(fmt, args...)
struct crm_ipc_s crm_ipc_t
const char * services__exit_reason(const svc_action_t *action)
int pcmk__remote_ready(const pcmk__remote_t *remote, int timeout_ms)
bool lrmd_dispatch(lrmd_t *lrmd)
Use after lrmd_poll returns 1 to read and dispatch a message.
svc_action_t * services__create_resource_action(const char *name, const char *standard, const char *provider, const char *agent, const char *action, guint interval_ms, int timeout, GHashTable *params, enum svc_action_flags flags)
Create a new resource action.
struct lrmd_list_s * next
gboolean services_action_sync(svc_action_t *op)
#define LRMD_PROTOCOL_VERSION
#define PCMK__XA_NODE_START_STATE
Parameter invalid (inherently)
char * crm_element_value_copy(const xmlNode *data, const char *name)
Retrieve a copy of the value of an XML attribute.
void lrmd_free_op_info(lrmd_op_info_t *op_info)
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
void lrmd_list_freeall(lrmd_list_t *head)
int(* connect)(lrmd_t *lrmd, const char *client_name, int *fd)
Connect to an executor.
#define crm_trace(fmt, args...)
#define PCMK_RESOURCE_CLASS_STONITH
Object for executing external actions.
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
int pcmk__connect_remote(const char *host, int port, int timeout_ms, int *timer_id, int *sock_fd, void *userdata, void(*callback)(void *userdata, int rc, int sock))
#define PCMK__XA_LRMD_RUN_TIME
void pcmk__str_update(char **str, const char *value)
Wrappers for and extensions to libxml2.
#define PCMK__XA_LRMD_RSC_INTERVAL
crm_trigger_t * mainloop_add_trigger(int priority, int(*dispatch)(gpointer user_data), gpointer userdata)
Create a trigger to be used as a mainloop source.
#define LRMD_OP_NEW_CLIENT
#define PCMK__XE_LRMD_CALLDATA
void stonith_key_value_freeall(stonith_key_value_t *kvp, int keys, int values)
int pcmk__remote_send_xml(pcmk__remote_t *remote, const xmlNode *msg)
gnutls_session_t pcmk__new_tls_session(pcmk__tls_t *tls, int csock)
#define PCMK__XA_LRMD_EXEC_RC
lrmd_rsc_info_t * lrmd_new_rsc_info(const char *rsc_id, const char *standard, const char *provider, const char *type)
void mainloop_del_ipc_client(mainloop_io_t *client)
void crm_ipc_destroy(crm_ipc_t *client)
int pcmk_legacy2rc(int legacy_rc)
GList * resources_list_providers(const char *standard)
Get a list of providers.
int lrmd__init_remote_key(gnutls_datum_t *key)
lrmd_t * lrmd_api_new(void)
Create a new connection to the local executor.
int(* get_metadata_params)(lrmd_t *lrmd, const char *standard, const char *provider, const char *agent, char **output, enum lrmd_call_options options, lrmd_key_value_t *params)
Retrieve resource agent metadata synchronously with parameters.
Notify only the client that made the request (rather than all clients)
Execution failed, do not retry anywhere.
#define PCMK__XA_LRMD_TYPE
const char * lrmd__node_start_state(lrmd_t *lrmd)
struct lrmd_key_value_s * next
Client uses TCP with TLS.
void pcmk__free_tls(pcmk__tls_t *tls)
void lrmd_free_rsc_info(lrmd_rsc_info_t *rsc_info)
int(* metadata)(stonith_t *stonith, int call_options, const char *agent, const char *namespace_s, char **output, int timeout_sec)
Retrieve a fence agent's metadata.
CRM_TRACE_INIT_DATA(lrmd)
#define pcmk__str_copy(str)
xmlNode * pcmk__xml_parse(const char *input)
#define PCMK__XE_LRMD_COMMAND
int(* disconnect)(lrmd_t *lrmd)
Disconnect from the executor.
int lrmd__new(lrmd_t **api, const char *nodename, const char *server, int port)
#define PCMK__XA_LRMD_REMOTE_MSG_ID
time_t lrmd__uptime(lrmd_t *lrmd)
Wait for request to be completed before returning.
xmlNode * pcmk__xe_next(const xmlNode *node, const char *element_name)
bool crm_ipc_connected(crm_ipc_t *client)
#define pcmk__assert(expr)
int lrmd_poll(lrmd_t *lrmd, int timeout)
Check whether a message is available on an executor connection.
void lrmd__reset_result(lrmd_event_data_t *event)
int crm_ipc_ready(crm_ipc_t *client)
Check whether an IPC connection is ready to be read.
#define crm_log_xml_err(xml, text)
void lrmd_api_delete(lrmd_t *lrmd)
Destroy executor connection object.
GHashTable * pcmk__strkey_table(GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func)
pcmk__action_result_t result
bool pcmk__x509_enabled(void)
#define crm_perror(level, fmt, args...)
Send a system error message to both the log and stderr.
const char * remote_nodename
lrmd_api_operations_t * cmds
crm_ipc_t * mainloop_get_ipc_client(mainloop_io_t *client)
GList * resources_list_standards(void)
gboolean stonith__watchdog_fencing_enabled_for_node(const char *node)
#define crm_err(fmt, args...)
#define PCMK__XA_LRMD_WATCHDOG
GHashTable * pcmk__str_table_dup(GHashTable *old_table)
enum lrmd_callback_event type
lrmd_key_value_t * lrmd_key_value_add(lrmd_key_value_t *head, const char *key, const char *value)
stonith_api_operations_t * cmds
#define PCMK__XA_LRMD_CLIENTID
void pcmk__tls_add_psk_key(pcmk__tls_t *tls, gnutls_datum_t *key)
#define PCMK__XA_LRMD_RSC_START_DELAY
int pcmk__ipc_fd(crm_ipc_t *ipc, int *fd)
int crm_element_value_int(const xmlNode *data, const char *name, int *dest)
Retrieve the integer value of an XML attribute.
guint pcmk__timeout_ms2s(guint timeout_ms)
#define pcmk__mem_assert(ptr)
#define PCMK__XA_LRMD_QUEUE_TIME
crm_ipc_t * crm_ipc_new(const char *name, size_t max_size)
Create a new (legacy) object for using Pacemaker daemon IPC.
GList * resources_list_agents(const char *standard, const char *provider)
Get a list of resource agents.
#define PCMK__ENV_AUTHKEY_LOCATION
#define PCMK__XA_LRMD_PROVIDER
void lrmd_internal_set_proxy_callback(lrmd_t *lrmd, void *userdata, void(*callback)(lrmd_t *lrmd, void *userdata, xmlNode *msg))
void pcmk__set_result(pcmk__action_result_t *result, int exit_status, enum pcmk_exec_status exec_status, const char *exit_reason)
#define crm_log_xml_trace(xml, text)
uint32_t pcmk_get_ra_caps(const char *standard)
Get capabilities of a resource agent standard.
#define PCMK__XA_LRMD_IS_IPC_PROVIDER
const char * crm_xml_add_ms(xmlNode *node, const char *name, guint ms)
Create an XML attribute with specified name and unsigned value.
int lrmd__validate_remote_settings(lrmd_t *lrmd, GHashTable *hash)
mainloop_io_t * mainloop_add_ipc_client(const char *name, int priority, size_t max_size, void *userdata, struct ipc_client_callbacks *callbacks)
int pcmk__read_remote_message(pcmk__remote_t *remote, int timeout_ms)
#define PCMK__XA_LRMD_CLIENTNAME
void pcmk__tls_check_cert_expiration(gnutls_session_t session)
#define PCMK__XA_LRMD_RSC_DELETED
gboolean services_action_async(svc_action_t *op, void(*action_callback)(svc_action_t *))
Request asynchronous execution of an action.
#define pcmk__assert_alloc(nmemb, size)
void lrmd_free_event(lrmd_event_data_t *event)
Free an executor event.
void pcmk__reset_result(pcmk__action_result_t *result)
#define PCMK__XA_LRMD_RSC_USERDATA_STR
int crm_ipc_send(crm_ipc_t *client, const xmlNode *message, enum crm_ipc_flags flags, int32_t ms_timeout, xmlNode **reply)
Send an IPC XML message.
void crm_ipc_close(crm_ipc_t *client)
#define PCMK__XA_LRMD_CALLID
Execution failed, may be retried.
#define crm_info(fmt, args...)
void pcmk__insert_dup(GHashTable *table, const char *name, const char *value)
xmlNode * pcmk__remote_message_xml(pcmk__remote_t *remote)
int(* dispatch)(const char *buffer, ssize_t length, gpointer userdata)
Dispatch function for an IPC connection used as mainloop source.
int crm_default_remote_port(void)
Get the default remote connection TCP port on this host.
int stonith__metadata_async(const char *agent, int timeout_sec, void(*callback)(int pid, const pcmk__action_result_t *result, void *user_data), void *user_data)
#define PCMK_OPT_STONITH_WATCHDOG_TIMEOUT
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
const char * crm_xml_add_int(xmlNode *node, const char *name, int value)
Create an XML attribute with specified name and integer value.