28 #include <sys/types.h> 41 #if SUPPORT_CIBSECRETS 47 struct stonith_action_s {
56 void (*done_cb) (GPid
pid, gint status,
const char *output, gpointer user_data);
57 void (*fork_cb) (GPid
pid, gpointer user_data);
62 time_t initial_start_time;
64 int remaining_timeout;
74 typedef struct stonith_private_s {
78 GHashTable *stonith_op_callback_table;
87 typedef struct stonith_notify_client_s {
96 typedef struct stonith_callback_client_s {
100 gboolean only_success;
101 gboolean allow_timeout_updates;
106 struct notify_blob_s {
118 typedef int (*
stonith_op_t) (
const char *, int,
const char *, xmlNode *,
119 xmlNode *, xmlNode *, xmlNode **, xmlNode **);
127 xmlNode ** output_data,
int call_options,
int timeout);
129 static void stonith_connection_destroy(gpointer user_data);
130 static void stonith_send_notification(gpointer
data, gpointer user_data);
144 if ((namespace_s == NULL) || !strcmp(namespace_s,
"any")) {
147 }
else if (!strcmp(namespace_s,
"redhat")
148 || !strcmp(namespace_s,
"stonith-ng")) {
151 }
else if (!strcmp(namespace_s,
"internal")) {
154 }
else if (!strcmp(namespace_s,
"heartbeat")) {
170 switch (st_namespace) {
177 return "unsupported";
199 #if HAVE_STONITH_STONITH_H 205 crm_err(
"Unknown fence agent: %s", agent);
212 if (action->output) {
238 private->notify_refcnt++;
239 g_list_foreach(private->notify_list, func, user_data);
240 private->notify_refcnt--;
241 if ((private->notify_refcnt == 0) &&
242 private->notify_deletes) {
243 GList *list_item =
private->notify_list;
245 private->notify_deletes = FALSE;
246 while (list_item != NULL)
249 GList *next = g_list_next(list_item);
251 if (list_client->delete) {
253 private->notify_list =
254 g_list_delete_link(private->notify_list, list_item);
262 stonith_connection_destroy(gpointer user_data)
266 struct notify_blob_s blob;
268 crm_trace(
"Sending destroyed notification");
269 blob.stonith = stonith;
274 native->source = NULL;
276 free(native->token); native->token = NULL;
281 foreach_notify_entry(native, stonith_send_notification, &blob);
288 const char *rsc_provides)
293 #if HAVE_STONITH_STONITH_H 298 hash2field((gpointer)
"plugin", (gpointer) agent, args);
299 agent =
"fence_legacy";
313 for (; params; params = params->
next) {
321 stonith_api_register_device(
stonith_t * st,
int call_options,
322 const char *
id,
const char *
namespace,
const char *agent,
326 xmlNode *
data = NULL;
329 agent, params, NULL);
338 stonith_api_remove_device(
stonith_t * st,
int call_options,
const char *name)
341 xmlNode *
data = NULL;
353 stonith_api_remove_level_full(
stonith_t *st,
int options,
354 const char *node,
const char *pattern,
355 const char *attr,
const char *value,
int level)
358 xmlNode *
data = NULL;
360 CRM_CHECK(node || pattern || (attr && value),
return -EINVAL);
368 }
else if (pattern) {
384 stonith_api_remove_level(
stonith_t * st,
int options,
const char *node,
int level)
386 return stonith_api_remove_level_full(st, options, node,
387 NULL, NULL, NULL, level);
407 const char *attr,
const char *value,
414 CRM_CHECK(node || pattern || (attr && value),
return NULL);
426 }
else if (pattern) {
434 for (; device_list; device_list = device_list->
next) {
436 int adding = strlen(device_list->
value);
441 crm_trace(
"Adding %s (%dc) at offset %d", device_list->
value, adding, len);
442 list = realloc_safe(list, len + adding + 1);
444 crm_perror(LOG_CRIT,
"Could not create device list");
448 sprintf(list + len,
"%s%s", len?
",":
"", device_list->
value);
459 stonith_api_register_level_full(
stonith_t * st,
int options,
const char *node,
461 const char *attr,
const char *value,
476 stonith_api_register_level(
stonith_t * st,
int options,
const char *node,
int level,
479 return stonith_api_register_level_full(st, options, node, NULL, NULL, NULL,
484 append_arg(
const char *key,
const char *value, GHashTable **args)
490 if (strstr(key,
"pcmk_")) {
499 *args = crm_str_table_new();
503 crm_trace(
"Appending: %s=%s", key, value);
504 g_hash_table_replace(*args, strdup(key), strdup(value));
508 append_config_arg(gpointer key, gpointer value, gpointer user_data)
515 append_arg(key, value, user_data);
521 append_host_specific_args(
const char *victim,
const char *map, GHashTable * params, GHashTable **args)
524 int last = 0, lpc = 0, max = 0;
528 crm_debug(
"Using default arg map: port=uname");
529 append_arg(
"port", victim, args);
534 crm_debug(
"Processing arg map: %s", map);
535 for (; lpc < max + 1; lpc++) {
536 if (isalpha(map[lpc])) {
539 }
else if (map[lpc] ==
'=' || map[lpc] ==
':') {
541 name = calloc(1, 1 + lpc - last);
542 memcpy(name, map + last, lpc - last);
546 }
else if (map[lpc] == 0 || map[lpc] ==
',' || isspace(map[lpc])) {
548 const char *value = NULL;
550 param = calloc(1, 1 + lpc - last);
551 memcpy(param, map + last, lpc - last);
556 crm_err(
"Misparsed '%s', found '%s' without a name", map, param);
566 value = g_hash_table_lookup(params, key);
571 crm_debug(
"Setting '%s'='%s' (%s) for %s", name, value, param, victim);
572 append_arg(name, value, args);
575 crm_err(
"No node attribute '%s' for '%s'", name, victim);
585 }
else if (isspace(map[lpc])) {
593 make_args(
const char *agent,
const char *action,
const char *victim,
594 uint32_t victim_nodeid, GHashTable * device_args,
595 GHashTable * port_map,
const char *host_arg)
598 GHashTable *arg_list = NULL;
599 const char *value = NULL;
603 snprintf(buffer,
sizeof(buffer),
"pcmk_%s_action", action);
605 value = g_hash_table_lookup(device_args, buffer);
608 if (value == NULL && device_args) {
610 snprintf(buffer,
sizeof(buffer),
"pcmk_%s_cmd", action);
611 value = g_hash_table_lookup(device_args, buffer);
614 if (value == NULL && device_args &&
safe_str_eq(action,
"off")) {
616 value = g_hash_table_lookup(device_args,
"pcmk_poweroff_action");
620 crm_info(
"Substituting action '%s' for requested operation '%s'", value, action);
625 if (victim && device_args) {
626 const char *alias = victim;
629 if (port_map && g_hash_table_lookup(port_map, victim)) {
630 alias = g_hash_table_lookup(port_map, victim);
636 append_arg(
"nodename", victim, &arg_list);
638 char nodeid_str[33] = { 0, };
639 if (snprintf(nodeid_str, 33,
"%u", (
unsigned int)victim_nodeid)) {
640 crm_info(
"For stonith action (%s) for victim %s, adding nodeid (%s) to parameters",
641 action, victim, nodeid_str);
642 append_arg(
"nodeid", nodeid_str, &arg_list);
650 }
else if (param == NULL) {
657 if (host_arg == NULL) {
664 value = g_hash_table_lookup(device_args, param);
667 append_host_specific_args(alias, map, device_args, &arg_list);
675 value = g_hash_table_lookup(device_args, param);
679 if (value == NULL ||
safe_str_eq(value,
"dynamic")) {
680 crm_debug(
"Performing '%s' action targeting '%s' as '%s=%s'", action, victim, param,
682 append_arg(param, alias, &arg_list);
687 g_hash_table_foreach(device_args, append_config_arg, &arg_list);
705 g_hash_table_destroy(action->args);
707 free(action->action);
708 free(action->victim);
709 if (action->svc_action) {
712 free(action->output);
741 *error_output = NULL;
743 if (action != NULL) {
747 if (output && action->output) {
748 *output = action->output;
749 action->output = NULL;
751 if (error_output && action->error) {
752 *error_output = action->error;
753 action->error = NULL;
758 #define FAILURE_MAX_RETRIES 2 764 int timeout, GHashTable * device_args,
765 GHashTable * port_map,
const char *host_arg)
770 action->args = make_args(agent, _action, victim, victim_nodeid,
771 device_args, port_map, host_arg);
772 crm_debug(
"Preparing '%s' action for %s using agent %s",
773 _action, (victim? victim :
"no target"), agent);
774 action->agent = strdup(agent);
775 action->action = strdup(_action);
777 action->victim = strdup(victim);
779 action->timeout = action->remaining_timeout = timeout;
784 const char *value = NULL;
786 snprintf(buffer,
sizeof(buffer),
"pcmk_%s_retries", _action);
787 value = g_hash_table_lookup(device_args, buffer);
790 action->max_retries = atoi(value);
800 int diff = time(NULL) - action->initial_start_time;
802 if (action->tries >= action->max_retries) {
803 crm_info(
"Attempted to execute agent %s (%s) the maximum number of times (%d) allowed",
804 action->agent, action->action, action->max_retries);
805 action->remaining_timeout = 0;
806 }
else if ((action->rc != -
ETIME) && diff < (action->timeout * 0.7)) {
809 action->remaining_timeout = action->timeout - diff;
811 action->remaining_timeout = 0;
813 return action->remaining_timeout ? TRUE : FALSE;
820 if (svc_action->
rc > 0) {
830 }
else if (strstr(svc_action->
stderr_data,
"imed out")) {
834 }
else if (strstr(svc_action->
stderr_data,
"Unrecognised action")) {
849 action->rc = svc_action_to_errno(svc_action);
855 svc_action->
params = NULL;
857 crm_debug(
"Child process %d performing action '%s' exited with rc %d",
858 action->pid, action->action, svc_action->
rc);
860 log_action(action, action->pid);
862 if (action->rc !=
pcmk_ok && update_remaining_timeout(action)) {
863 int rc = internal_stonith_action_execute(action);
869 if (action->done_cb) {
870 action->done_cb(action->pid, action->rc, action->output, action->userdata);
873 action->svc_action = NULL;
882 action->pid = svc_action->
pid;
883 action->svc_action = svc_action;
885 if (action->fork_cb) {
886 (action->fork_cb) (svc_action->
pid, action->userdata);
889 crm_trace(
"Child process %d performing action '%s' successfully forked",
890 action->pid, action->action);
899 static int stonith_sequence = 0;
902 if (!action->tries) {
903 action->initial_start_time = time(NULL);
907 if (action->tries > 1) {
908 crm_info(
"Attempt %d to execute %s (%s). remaining timeout is %d",
909 action->tries, action->agent, action->action, action->remaining_timeout);
913 if (action->args == NULL || action->agent == NULL)
919 svc_action->
timeout = 1000 * action->remaining_timeout;
922 action->action, action->tries);
923 svc_action->
agent = strdup(action->agent);
924 svc_action->
sequence = stonith_sequence++;
925 svc_action->
params = action->args;
926 svc_action->
cb_data = (
void *) action;
931 free(action->output);
932 action->output = NULL;
934 action->error = NULL;
941 &stonith_action_async_done,
942 &stonith_action_async_forked) == FALSE) {
953 action->
rc = svc_action_to_errno(svc_action);
959 action->rc = -ECONNABORTED;
963 svc_action->
params = NULL;
985 void (*done) (GPid
pid,
int rc,
const char *output,
987 void (*fork_cb) (GPid pid, gpointer user_data))
993 action->userdata = userdata;
994 action->done_cb = done;
995 action->fork_cb = fork_cb;
998 return internal_stonith_action_execute(action);
1014 CRM_CHECK(action != NULL,
return -EINVAL);
1018 rc = internal_stonith_action_execute(action);
1019 }
while ((rc !=
pcmk_ok) && update_remaining_timeout(action));
1025 stonith_api_device_list(
stonith_t * stonith,
int call_options,
const char *
namespace,
1031 if (devices == NULL) {
1032 crm_err(
"Parameter error: stonith_api_device_list");
1036 #if HAVE_STONITH_STONITH_H 1052 stonith_api_device_metadata(
stonith_t * stonith,
int call_options,
const char *agent,
1053 const char *
namespace,
char **output,
int timeout)
1061 crm_trace(
"Looking up metadata for %s agent %s",
1068 #if HAVE_STONITH_STONITH_H 1076 "Agent %s not found or does not support meta-data",
1084 stonith_api_query(
stonith_t * stonith,
int call_options,
const char *target,
1087 int rc = 0, lpc = 0, max = 0;
1089 xmlNode *
data = NULL;
1090 xmlNode *output = NULL;
1091 xmlXPathObjectPtr xpathObj = NULL;
1093 CRM_CHECK(devices != NULL,
return -EINVAL);
1107 max = numXpathResults(xpathObj);
1109 for (lpc = 0; lpc < max; lpc++) {
1114 xmlChar *match_path = xmlGetNodePath(match);
1116 crm_info(
"%s[%d] = %s",
"//@agent", lpc, match_path);
1134 const char *action,
const char *victim,
int timeout, xmlNode ** output)
1137 xmlNode *
data = NULL;
1152 stonith_api_list(
stonith_t * stonith,
int call_options,
const char *
id,
char **list_info,
1156 xmlNode *output = NULL;
1158 rc = stonith_api_call(stonith, call_options,
id,
"list", NULL, timeout, &output);
1160 if (output && list_info) {
1161 const char *list_str;
1166 *list_info = strdup(list_str);
1178 stonith_api_monitor(
stonith_t * stonith,
int call_options,
const char *
id,
int timeout)
1180 return stonith_api_call(stonith, call_options,
id,
"monitor", NULL, timeout, NULL);
1184 stonith_api_status(
stonith_t * stonith,
int call_options,
const char *
id,
const char *port,
1187 return stonith_api_call(stonith, call_options,
id,
"status", port, timeout, NULL);
1191 stonith_api_fence_with_delay(
stonith_t * stonith,
int call_options,
const char *node,
1192 const char *action,
int timeout,
int tolerance,
int delay)
1195 xmlNode *
data = NULL;
1211 stonith_api_fence(
stonith_t * stonith,
int call_options,
const char *node,
const char *action,
1212 int timeout,
int tolerance)
1214 return stonith_api_fence_with_delay(stonith, call_options, node, action,
1215 timeout, tolerance, 0);
1219 stonith_api_confirm(
stonith_t * stonith,
int call_options,
const char *target)
1221 return stonith_api_fence(stonith, call_options |
st_opt_manual_ack, target,
"off", 0, 0);
1225 stonith_api_history(
stonith_t * stonith,
int call_options,
const char *node,
1229 xmlNode *
data = NULL;
1230 xmlNode *output = NULL;
1248 for (op = __xml_first_child(reply); op != NULL; op = __xml_next(op)) {
1278 for (hp = history; hp; hp_old = hp, hp = hp->
next, free(hp_old)) {
1297 stonithlib_GCompareFunc(gconstpointer a, gconstpointer b)
1303 if (a_client->delete || b_client->delete) {
1307 CRM_CHECK(a_client->event != NULL && b_client->event != NULL,
return 0);
1308 rc = strcmp(a_client->event, b_client->event);
1310 if (a_client->notify == NULL || b_client->notify == NULL) {
1313 }
else if (a_client->notify == b_client->notify) {
1316 }
else if (((
long)a_client->notify) < ((
long)b_client->notify)) {
1317 crm_err(
"callbacks for %s are not equal: %p vs. %p",
1318 a_client->event, a_client->notify, b_client->notify);
1321 crm_err(
"callbacks for %s are not equal: %p vs. %p",
1322 a_client->event, a_client->notify, b_client->notify);
1342 crm_trace(
"Sending call options: %.8lx, %d", (
long)call_options, call_options);
1353 stonith_destroy_op_callback(gpointer
data)
1357 if (blob->timer && blob->timer->ref > 0) {
1358 g_source_remove(blob->timer->ref);
1365 stonith_api_signoff(
stonith_t * stonith)
1369 crm_debug(
"Signing out of the STONITH Service");
1371 if (native->source != NULL) {
1374 native->source = NULL;
1377 }
else if (native->ipc) {
1386 free(native->token); native->token = NULL;
1392 stonith_api_signon(
stonith_t * stonith,
const char *name,
int *stonith_fd)
1399 .destroy = stonith_connection_destroy
1402 crm_trace(
"Connecting command channel");
1411 }
else if (native->ipc) {
1412 crm_perror(LOG_ERR,
"Connection to STONITH manager failed");
1423 if (native->ipc == NULL) {
1424 crm_debug(
"Could not connect to the Stonith API");
1429 xmlNode *reply = NULL;
1438 crm_perror(LOG_DEBUG,
"Couldn't complete registration with the fencing API: %d", rc);
1441 }
else if (reply == NULL) {
1442 crm_err(
"Did not receive registration reply");
1450 crm_err(
"Invalid registration message: %s", msg_type);
1454 }
else if (tmp_ticket == NULL) {
1455 crm_err(
"No registration token provided");
1460 crm_trace(
"Obtained registration token: %s", tmp_ticket);
1461 native->token = strdup(tmp_ticket);
1471 #if HAVE_MSGFROMIPC_TIMEOUT 1474 crm_debug(
"Connection to STONITH successful");
1484 stonith_set_notification(
stonith_t * stonith,
const char *callback,
int enabled)
1501 crm_perror(LOG_DEBUG,
"Couldn't register for fencing notifications: %d", rc);
1513 stonith_api_add_notification(
stonith_t * stonith,
const char *event,
1516 GList *list_item = NULL;
1521 crm_trace(
"Adding callback for %s events (%d)", event, g_list_length(private->notify_list));
1524 new_client->event = event;
1525 new_client->notify = callback;
1527 list_item = g_list_find_custom(private->notify_list, new_client, stonithlib_GCompareFunc);
1529 if (list_item != NULL) {
1530 crm_warn(
"Callback already present");
1535 private->notify_list = g_list_append(private->notify_list, new_client);
1537 stonith_set_notification(stonith, event, 1);
1539 crm_trace(
"Callback added (%d)", g_list_length(private->notify_list));
1545 stonith_api_del_notification(
stonith_t * stonith,
const char *event)
1547 GList *list_item = NULL;
1551 crm_debug(
"Removing callback for %s events", event);
1555 new_client->event = event;
1556 new_client->notify = NULL;
1558 list_item = g_list_find_custom(private->notify_list, new_client, stonithlib_GCompareFunc);
1560 stonith_set_notification(stonith, event, 0);
1562 if (list_item != NULL) {
1565 if (private->notify_refcnt) {
1566 list_client->delete = TRUE;
1567 private->notify_deletes = TRUE;
1569 private->notify_list = g_list_remove(private->notify_list, list_client);
1583 stonith_async_timeout_handler(gpointer data)
1600 struct timer_rec_s *async_timer = callback->timer;
1607 async_timer = calloc(1,
sizeof(
struct timer_rec_s));
1608 callback->timer = async_timer;
1616 async_timer->
timeout = (timeout + 60) * 1000;
1617 if (async_timer->
ref) {
1618 g_source_remove(async_timer->
ref);
1621 g_timeout_add(async_timer->
timeout, stonith_async_timeout_handler, async_timer);
1625 update_callback_timeout(
int call_id,
int timeout,
stonith_t * st)
1630 callback = g_hash_table_lookup(private->stonith_op_callback_table, GINT_TO_POINTER(call_id));
1631 if (!callback || !callback->allow_timeout_updates) {
1635 set_callback_timeout(callback, st, call_id, timeout);
1639 invoke_callback(
stonith_t * st,
int call_id,
int rc,
void *userdata,
1648 callback(st, &data);
1652 stonith_api_add_callback(
stonith_t * stonith,
int call_id,
int timeout,
int options,
1653 void *user_data,
const char *callback_name,
1659 CRM_CHECK(stonith != NULL,
return -EINVAL);
1664 private->op_callback = callback;
1666 }
else if (call_id < 0) {
1669 invoke_callback(stonith, call_id, call_id, user_data, callback);
1677 blob->id = callback_name;
1679 blob->user_data = user_data;
1680 blob->callback = callback;
1684 set_callback_timeout(blob, stonith, call_id, timeout);
1687 g_hash_table_insert(private->stonith_op_callback_table, GINT_TO_POINTER(call_id), blob);
1688 crm_trace(
"Added callback to %s for call %d", callback_name, call_id);
1694 stonith_api_del_callback(
stonith_t * stonith,
int call_id,
bool all_callbacks)
1698 if (all_callbacks) {
1699 private->op_callback = NULL;
1700 g_hash_table_destroy(private->stonith_op_callback_table);
1701 private->stonith_op_callback_table = g_hash_table_new_full(g_direct_hash, g_direct_equal,
1703 stonith_destroy_op_callback);
1705 }
else if (call_id == 0) {
1706 private->op_callback = NULL;
1709 g_hash_table_remove(private->stonith_op_callback_table, GINT_TO_POINTER(call_id));
1715 stonith_dump_pending_op(gpointer key, gpointer value, gpointer user_data)
1717 int call = GPOINTER_TO_INT(key);
1728 if (private->stonith_op_callback_table == NULL) {
1731 return g_hash_table_foreach(private->stonith_op_callback_table, stonith_dump_pending_op, NULL);
1746 local_blob.id = NULL;
1747 local_blob.callback = NULL;
1748 local_blob.user_data = NULL;
1749 local_blob.only_success = FALSE;
1758 blob = g_hash_table_lookup(private->stonith_op_callback_table, GINT_TO_POINTER(call_id));
1764 stonith_api_del_callback(stonith, call_id, FALSE);
1767 crm_trace(
"No callback found for call %d", call_id);
1768 local_blob.callback = NULL;
1771 if (local_blob.callback != NULL && (rc ==
pcmk_ok || local_blob.only_success == FALSE)) {
1772 crm_trace(
"Invoking callback %s for call %d",
crm_str(local_blob.id), call_id);
1773 invoke_callback(stonith, call_id, rc, local_blob.user_data, local_blob.callback);
1775 }
else if (private->op_callback == NULL && rc !=
pcmk_ok) {
1780 if (private->op_callback != NULL) {
1781 crm_trace(
"Invoking global callback for call %d", call_id);
1782 invoke_callback(stonith, call_id, rc, NULL, private->op_callback);
1807 xml_to_event(xmlNode * msg)
1831 crm_err(
"No data for %s event", ntype);
1857 stonith_send_notification(gpointer data, gpointer user_data)
1859 struct notify_blob_s *blob = user_data;
1862 const char *
event = NULL;
1864 if (blob->xml == NULL) {
1865 crm_warn(
"Skipping callback - NULL message");
1871 if (entry == NULL) {
1872 crm_warn(
"Skipping callback - NULL callback client");
1875 }
else if (entry->delete) {
1876 crm_trace(
"Skipping callback - marked for deletion");
1879 }
else if (entry->notify == NULL) {
1880 crm_warn(
"Skipping callback - NULL callback");
1884 crm_trace(
"Skipping callback - event mismatch %p/%s vs. %s", entry, entry->event, event);
1888 st_event = xml_to_event(blob->xml);
1890 crm_trace(
"Invoking callback for %p/%s event...", entry, event);
1891 entry->notify(blob->stonith, st_event);
1894 event_free(st_event);
1899 int call_options,
int timeout)
1905 xmlNode *op_msg = NULL;
1906 xmlNode *op_reply = NULL;
1914 if (output_data != NULL) {
1915 *output_data = NULL;
1919 crm_err(
"No operation specified");
1939 if (op_msg == NULL) {
1944 crm_trace(
"Sending %s message to STONITH service, Timeout: %ds", op, timeout);
1954 rc =
crm_ipc_send(native->ipc, op_msg, ipc_flags, 1000 * (timeout + 60), &op_reply);
1958 crm_perror(LOG_ERR,
"Couldn't perform %s operation (timeout=%ds): %d", op, timeout, rc);
1965 if (!(call_options & st_opt_sync_call)) {
1976 if (reply_id == stonith->
call_id) {
1977 crm_trace(
"Synchronous reply %d received", reply_id);
1987 *output_data = op_reply;
1991 }
else if (reply_id <= 0) {
1992 crm_err(
"Received bad reply: No id set");
1998 crm_err(
"Received bad reply: %d (wanted %d)", reply_id, stonith->
call_id);
2006 crm_err(
"STONITH disconnected");
2007 free(native->token); native->token = NULL;
2019 gboolean stay_connected = TRUE;
2035 stay_connected = FALSE;
2039 return stay_connected;
2045 const char *
type = NULL;
2046 struct notify_blob_s blob;
2052 private = st->private;
2056 if (blob.xml == NULL) {
2057 crm_warn(
"Received a NULL msg from STONITH service: %s.", buffer);
2063 crm_trace(
"Activating %s callbacks...", type);
2069 foreach_notify_entry(
private, stonith_send_notification, &blob);
2077 update_callback_timeout(call_id, timeout, st);
2079 crm_err(
"Unknown message type: %s", type);
2095 crm_trace(
"Disconnecting %p first", stonith);
2102 crm_trace(
"Removing %d callbacks", g_hash_table_size(private->stonith_op_callback_table));
2103 g_hash_table_destroy(private->stonith_op_callback_table);
2105 crm_trace(
"Destroying %d notification clients", g_list_length(private->notify_list));
2106 g_list_free_full(private->notify_list, free);
2109 free(stonith->
cmds);
2129 stonith_api_validate(
stonith_t *st,
int call_options,
const char *rsc_id,
2130 const char *namespace_s,
const char *agent,
2132 char **error_output)
2145 const char *target =
"node1";
2146 const char *host_arg = NULL;
2148 GHashTable *params_table = crm_str_table_new();
2151 for (; params; params = params->
next) {
2153 host_arg = params->
value;
2158 && strcmp(params->
key,
"provides")
2159 && strcmp(params->
key,
"stonith-timeout")) {
2160 g_hash_table_insert(params_table, strdup(params->
key),
2161 strdup(params->
value));
2165 #if SUPPORT_CIBSECRETS 2168 crm_warn(
"Could not replace secret parameters for validation of %s: %s",
2177 *error_output = NULL;
2183 params_table, host_arg, timeout,
2184 output, error_output);
2187 #if HAVE_STONITH_STONITH_H 2190 params_table, timeout, output,
2199 "Agent %s not found or does not support validation",
2203 g_hash_table_destroy(params_table);
2213 new_stonith = calloc(1,
sizeof(
stonith_t));
2215 new_stonith->
private =
private;
2217 private->stonith_op_callback_table = g_hash_table_new_full(g_direct_hash, g_direct_equal,
2218 NULL, stonith_destroy_op_callback);
2219 private->notify_list = NULL;
2220 private->notify_refcnt = 0;
2221 private->notify_deletes = FALSE;
2229 new_stonith->
cmds->
free = stonith_api_free;
2233 new_stonith->
cmds->
list = stonith_api_list;
2235 new_stonith->
cmds->
status = stonith_api_status;
2236 new_stonith->
cmds->
fence = stonith_api_fence;
2242 new_stonith->
cmds->
metadata = stonith_api_device_metadata;
2244 new_stonith->
cmds->
query = stonith_api_query;
2271 p->
key = strdup(key);
2274 p->
value = strdup(value);
2278 while (end && end->
next) {
2309 #define api_log_open() openlog("stonith-api", LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON) 2310 #define api_log(level, fmt, args...) syslog(level, "%s: "fmt, __FUNCTION__, args) 2316 const char *action =
"reboot";
2327 api_log(LOG_ERR,
"Connection failed, could not kick (%s) node %u/%s : %s (%d)", action, nodeid, uname,
pcmk_strerror(rc), rc);
2331 if (uname != NULL) {
2332 name = strdup(uname);
2334 }
else if (nodeid > 0) {
2344 rc = st->
cmds->
fence(st, opts, name, action, timeout, 0);
2346 api_log(LOG_ERR,
"Could not kick (%s) node %u/%s : %s (%d)", action, nodeid, uname,
pcmk_strerror(rc), rc);
2348 api_log(LOG_NOTICE,
"Node %u/%s kicked: %s ", nodeid, uname, action);
2380 if (uname != NULL) {
2381 name = strdup(uname);
2383 }
else if (nodeid > 0) {
2393 rc = st->
cmds->
history(st, opts, name, &history, 120);
2395 for (hp = history; hp; hp = hp->
next) {
2403 }
else if (hp->state ==
st_done) {
2405 if (hp->completed > when) {
2406 when = hp->completed;
2414 api_log(LOG_INFO,
"Found %d entries for %u/%s: %d in progress, %d completed", entries, nodeid, uname, progress, completed);
2416 api_log(LOG_ERR,
"Could not retrieve fence history for %u/%s: %s (%d)", nodeid, uname,
pcmk_strerror(rc), rc);
2426 api_log(LOG_INFO,
"Node %u/%s last kicked at: %ld", nodeid, uname, (
long int)when);
2435 xmlXPathObjectPtr xpath = NULL;
2438 long long flags = 0;
2443 max = numXpathResults(xpath);
2450 for (lpc = 0; lpc < max; lpc++) {
2451 const char *parameter = NULL;
2455 if (match == NULL) {
#define CRM_CHECK(expr, failure_action)
int stonith_send_command(stonith_t *stonith, const char *op, xmlNode *data, xmlNode **output_data, int call_options, int timeout)
#define XML_ATTR_STONITH_TARGET_ATTRIBUTE
struct stonith_action_s stonith_action_t
void stonith_history_free(stonith_history_t *history)
#define F_STONITH_REMOTE_OP_ID
struct stonith_history_s * next
bool crm_ipc_connect(crm_ipc_t *client)
Establish an IPC connection to a Pacemaker component.
int(* register_level_full)(stonith_t *st, int options, const char *node, const char *pattern, const char *attr, const char *value, int level, stonith_key_value_t *device_list)
Register fencing level for specific node, node regex or attribute.
#define F_STONITH_CLIENTID
gboolean safe_str_neq(const char *a, const char *b)
void services_action_free(svc_action_t *op)
void hash2field(gpointer key, gpointer value, gpointer user_data)
Set XML attribute based on hash table entry.
int(* register_device)(stonith_t *st, int options, const char *id, const char *namespace, const char *agent, stonith_key_value_t *params)
Register a stonith device with the local stonith daemon.
int stonith__rhcs_metadata(const char *agent, int timeout, char **output)
Execute RHCS-compatible agent's meta-data action.
int(* list_agents)(stonith_t *stonith, int call_options, const char *namespace, stonith_key_value_t **devices, int timeout)
Retrieve a list of installed stonith agents.
stonith_key_value_t * stonith_key_value_add(stonith_key_value_t *head, const char *key, const char *value)
void stonith_dump_pending_callbacks(stonith_t *stonith)
#define crm_log_output(level, prefix, output)
int crm_ipc_get_fd(crm_ipc_t *client)
const char * pcmk_strerror(int rc)
int(* query)(stonith_t *st, int options, const char *node, stonith_key_value_t **devices, int timeout)
Retrieve a list of registered stonith devices.
xmlNode * create_device_registration_xml(const char *id, enum stonith_namespace namespace, const char *agent, stonith_key_value_t *params, const char *rsc_provides)
int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off)
#define F_STONITH_CALLBACK_TOKEN
int stonith__lha_validate(stonith_t *st, int call_options, const char *target, const char *agent, GHashTable *params, int timeout, char **output, char **error_output)
#define F_STONITH_CLIENTNAME
const char * crm_xml_add_int(xmlNode *node, const char *name, int value)
Create an XML attribute with specified name and integer value.
xmlNode * stonith_create_op(int call_id, const char *token, const char *op, xmlNode *data, int call_options)
#define XML_TAG_FENCING_LEVEL
struct stonith_key_value_s * next
struct mainloop_io_s mainloop_io_t
svc_action_t * services_action_create_generic(const char *exec, const char *args[])
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
gboolean services_action_async_fork_notify(svc_action_t *op, void(*action_callback)(svc_action_t *), void(*action_fork_callback)(svc_action_t *))
int(* register_level)(stonith_t *st, int options, const char *node, int level, stonith_key_value_t *device_list)
Register a fencing level containing the fencing devices to be used at that level for a specific node...
void stonith_key_value_freeall(stonith_key_value_t *head, int keys, int values)
#define F_STONITH_TIMEOUT
int stonith__lha_metadata(const char *agent, int timeout, char **output)
void stonith__destroy_action(stonith_action_t *action)
#define T_STONITH_TIMEOUT_VALUE
#define CRM_LOG_ASSERT(expr)
long crm_ipc_read(crm_ipc_t *client)
int stonith_dispatch_internal(const char *buffer, ssize_t length, gpointer userdata)
#define F_STONITH_NOTIFY_DEACTIVATE
void stonith__action_result(stonith_action_t *action, int *rc, char **output, char **error_output)
int crm_element_value_int(const xmlNode *data, const char *name, int *dest)
Retrieve the integer value of an XML attribute.
int(* remove_callback)(stonith_t *st, int call_id, bool all_callbacks)
Remove a registered callback for a given call id.
xmlNode * get_xpath_object(const char *xpath, xmlNode *xml_obj, int error_level)
int stonith__execute(stonith_action_t *action)
Wrappers for and extensions to glib mainloop.
bool crm_starts_with(const char *str, const char *prefix)
Check whether a string starts with a certain sequence.
#define STONITH_OP_LEVEL_DEL
#define STONITH_OP_DEVICE_ADD
char * crm_meta_name(const char *field)
xmlNode * string2xml(const char *input)
const char * crm_ipc_buffer(crm_ipc_t *client)
const char * stonith_namespace2text(enum stonith_namespace st_namespace)
Get agent namespace name.
int stonith__list_lha_agents(stonith_key_value_t **devices)
time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress)
int(* free)(stonith_t *st)
Destroy the stonith api structure.
enum svc_action_flags flags
#define XML_ATTR_STONITH_TARGET_PATTERN
xmlNode * create_level_registration_xml(const char *node, const char *pattern, const char *attr, const char *value, int level, stonith_key_value_t *device_list)
#define crm_warn(fmt, args...)
bool stonith__agent_is_rhcs(const char *agent)
#define set_bit(word, bit)
#define STONITH_ATTR_HOSTARG
bool stonith_dispatch(stonith_t *st)
#define crm_debug(fmt, args...)
#define STONITH_OP_LEVEL_ADD
struct crm_ipc_s crm_ipc_t
char * crm_element_value_copy(const xmlNode *data, const char *name)
Retrieve a copy of the value of an XML attribute.
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
gboolean services_action_sync(svc_action_t *op)
#define XML_ATTR_STONITH_DEVICES
int(* status)(stonith_t *st, int options, const char *id, const char *port, int timeout)
Check to see if a local stonith device's port is reachable.
enum stonith_namespace stonith_text2namespace(const char *namespace_s)
Get agent namespace by name.
#define crm_trace(fmt, args...)
#define XML_ATTR_STONITH_INDEX
int(* fence)(stonith_t *st, int options, const char *node, const char *action, int timeout, int tolerance)
Issue a fencing action against a node.
int(* register_callback)(stonith_t *st, int call_id, int timeout, int options, void *userdata, const char *callback_name, void(*callback)(stonith_t *st, stonith_callback_data_t *data))
Register a callback to receive the result of an async call id.
#define crm_log_xml_debug(xml, text)
#define XML_ATTR_STONITH_TARGET
Wrappers for and extensions to libxml2.
xmlNode * create_xml_node(xmlNode *parent, const char *name)
#define crm_log_xml_warn(xml, text)
int(* disconnect)(stonith_t *st)
Disconnect from the local stonith daemon.
int stonith__rhcs_validate(stonith_t *st, int call_options, const char *target, const char *agent, GHashTable *params, const char *host_arg, int timeout, char **output, char **error_output)
int(* stonith_op_t)(const char *, int, const char *, xmlNode *, xmlNode *, xmlNode *, xmlNode **, xmlNode **)
enum stonith_namespace stonith_get_namespace(const char *agent, const char *namespace_s)
Determine namespace of a fence agent.
#define T_STONITH_NOTIFY_DISCONNECT
const char * get_stonith_provider(const char *agent, const char *provider)
Deprecated (use stonith_get_namespace() instead)
#define STONITH_OP_DEVICE_DEL
int(* list)(stonith_t *st, int options, const char *id, char **list_output, int timeout)
Retrieve string listing hosts and port assignments from a local stonith device.
void mainloop_del_ipc_client(mainloop_io_t *client)
void crm_ipc_destroy(crm_ipc_t *client)
#define XML_ATTR_STONITH_TARGET_VALUE
struct stonith_notify_client_s stonith_notify_client_t
gboolean add_message_xml(xmlNode *msg, const char *field, xmlNode *xml)
void stonith_api_delete(stonith_t *stonith)
int(* fence_with_delay)(stonith_t *st, int options, const char *node, const char *action, int timeout, int tolerance, int delay)
Issue a fencing action against a node with requested fencing delay.
void free_xml(xmlNode *child)
int(* connect)(stonith_t *st, const char *name, int *stonith_fd)
Connect to the local stonith daemon.
#define api_log(level, fmt, args...)
#define STONITH_ATTR_ACTION_OP
#define STONITH_OP_FENCE_HISTORY
#define F_STONITH_CALLOPTS
int(* remove_device)(stonith_t *st, int options, const char *name)
Remove a registered stonith device with the local stonith daemon.
struct stonith_private_s stonith_private_t
bool crm_ipc_connected(crm_ipc_t *client)
stonith_action_t * stonith_action_create(const char *agent, const char *_action, const char *victim, uint32_t victim_nodeid, int timeout, GHashTable *device_args, GHashTable *port_map, const char *host_arg)
#define PCMK_RESOURCE_CLASS_STONITH
int(* register_notification)(stonith_t *st, const char *event, void(*notify)(stonith_t *st, stonith_event_t *e))
int crm_ipc_ready(crm_ipc_t *client)
Check whether an IPC connection is ready to be read.
int(* monitor)(stonith_t *st, int options, const char *id, int timeout)
Check to see if a local stonith device is reachable.
int(* remove_notification)(stonith_t *st, const char *event)
int replace_secret_params(const char *rsc_id, GHashTable *params)
#define crm_log_xml_err(xml, text)
struct stonith_callback_client_s stonith_callback_client_t
int(* validate)(stonith_t *st, int call_options, const char *rsc_id, const char *namespace_s, const char *agent, stonith_key_value_t *params, int timeout, char **output, char **error_output)
Validate an arbitrary stonith device configuration.
int stonith__list_rhcs_agents(stonith_key_value_t **devices)
#define crm_perror(level, fmt, args...)
Log a system error message.
crm_ipc_t * mainloop_get_ipc_client(mainloop_io_t *client)
#define crm_err(fmt, args...)
#define G_PRIORITY_MEDIUM
void stonith_perform_callback(stonith_t *stonith, xmlNode *msg, int call_id, int rc)
xmlXPathObjectPtr xpath_search(xmlNode *xml_top, const char *path)
int(* remove_level_full)(stonith_t *st, int options, const char *node, const char *pattern, const char *attr, const char *value, int level)
Remove fencing level for specific node, node regex or attribute.
stonith_api_operations_t * cmds
int crm_ipc_send(crm_ipc_t *client, xmlNode *message, enum crm_ipc_flags flags, int32_t ms_timeout, xmlNode **reply)
stonith_t * stonith_api_new(void)
long long stonith__device_parameter_flags(xmlNode *metadata)
int(* remove_level)(stonith_t *st, int options, const char *node, int level)
Remove a fencing level for a specific node.
#define FAILURE_MAX_RETRIES
#define crm_log_xml_notice(xml, text)
xmlNode * getXpathResult(xmlXPathObjectPtr xpathObj, int index)
#define STONITH_ATTR_ARGMAP
crm_ipc_t * crm_ipc_new(const char *name, size_t max_size)
bool stonith__agent_is_lha(const char *agent)
Determine namespace of a fence agent.
#define T_STONITH_NOTIFY_FENCE
int(* confirm)(stonith_t *st, int options, const char *node)
Manually confirm that a node is down.
#define crm_log_xml_trace(xml, text)
#define F_STONITH_OPERATION
mainloop_io_t * mainloop_add_ipc_client(const char *name, int priority, size_t max_size, void *userdata, struct ipc_client_callbacks *callbacks)
char * crm_itoa(int an_int)
#define safe_str_eq(a, b)
int(* metadata)(stonith_t *st, int options, const char *device, const char *namespace, char **output, int timeout)
Get the metadata documentation for a resource.
#define F_STONITH_NOTIFY_ACTIVATE
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
void freeXpathObject(xmlXPathObjectPtr xpathObj)
void crm_ipc_close(crm_ipc_t *client)
#define F_STONITH_CALLDATA
CRM_TRACE_INIT_DATA(stonith)
#define F_STONITH_DELEGATE
#define crm_info(fmt, args...)
int(* history)(stonith_t *st, int options, const char *node, stonith_history_t **output, int timeout)
Retrieve a list of fencing operations that have occurred for a specific node.
int(* dispatch)(const char *buffer, ssize_t length, gpointer userdata)
#define F_STONITH_HISTORY_LIST
int stonith_action_execute_async(stonith_action_t *action, void *userdata, void(*done)(GPid pid, int rc, const char *output, gpointer user_data), void(*fork_cb)(GPid pid, gpointer user_data))
enum crm_ais_msg_types type
#define F_STONITH_TOLERANCE