20 #include <sys/types.h>
33 #if SUPPORT_CIBSECRETS
39 struct stonith_action_s {
48 void (*done_cb) (GPid
pid, gint status,
const char *output, gpointer user_data);
49 void (*fork_cb) (GPid
pid, gpointer user_data);
54 time_t initial_start_time;
56 int remaining_timeout;
66 typedef struct stonith_private_s {
70 GHashTable *stonith_op_callback_table;
79 typedef struct stonith_notify_client_s {
88 typedef struct stonith_callback_client_s {
92 gboolean only_success;
93 gboolean allow_timeout_updates;
98 struct notify_blob_s {
110 typedef int (*
stonith_op_t) (
const char *, int,
const char *, xmlNode *,
111 xmlNode *, xmlNode *, xmlNode **, xmlNode **);
116 static int stonith_send_command(
stonith_t *stonith,
const char *op,
117 xmlNode *
data, xmlNode **output_data,
118 int call_options,
int timeout);
120 static void stonith_connection_destroy(gpointer user_data);
121 static void stonith_send_notification(gpointer
data, gpointer user_data);
135 if ((namespace_s == NULL) || !strcmp(namespace_s,
"any")) {
138 }
else if (!strcmp(namespace_s,
"redhat")
139 || !strcmp(namespace_s,
"stonith-ng")) {
142 }
else if (!strcmp(namespace_s,
"internal")) {
145 }
else if (!strcmp(namespace_s,
"heartbeat")) {
161 switch (st_namespace) {
168 return "unsupported";
190 #if HAVE_STONITH_STONITH_H
196 crm_err(
"Unknown fence agent: %s", agent);
203 if (action->output) {
229 private->notify_refcnt++;
230 g_list_foreach(private->notify_list, func, user_data);
231 private->notify_refcnt--;
232 if ((private->notify_refcnt == 0) &&
233 private->notify_deletes) {
234 GList *list_item =
private->notify_list;
236 private->notify_deletes = FALSE;
237 while (list_item != NULL)
240 GList *next = g_list_next(list_item);
242 if (list_client->delete) {
244 private->notify_list =
245 g_list_delete_link(private->notify_list, list_item);
253 stonith_connection_destroy(gpointer user_data)
257 struct notify_blob_s blob;
259 crm_trace(
"Sending destroyed notification");
260 blob.stonith = stonith;
265 native->source = NULL;
267 free(native->token); native->token = NULL;
272 foreach_notify_entry(native, stonith_send_notification, &blob);
279 const char *rsc_provides)
284 #if HAVE_STONITH_STONITH_H
289 hash2field((gpointer)
"plugin", (gpointer) agent, args);
290 agent =
"fence_legacy";
304 for (; params; params = params->
next) {
312 stonith_api_register_device(
stonith_t * st,
int call_options,
313 const char *
id,
const char *
namespace,
const char *agent,
317 xmlNode *
data = NULL;
320 agent, params, NULL);
329 stonith_api_remove_device(
stonith_t * st,
int call_options,
const char *name)
332 xmlNode *
data = NULL;
344 stonith_api_remove_level_full(
stonith_t *st,
int options,
345 const char *node,
const char *pattern,
346 const char *attr,
const char *value,
int level)
349 xmlNode *
data = NULL;
351 CRM_CHECK(node || pattern || (attr && value),
return -EINVAL);
359 }
else if (pattern) {
375 stonith_api_remove_level(
stonith_t * st,
int options,
const char *node,
int level)
377 return stonith_api_remove_level_full(st, options, node,
378 NULL, NULL, NULL, level);
398 const char *attr,
const char *value,
405 CRM_CHECK(node || pattern || (attr && value),
return NULL);
417 }
else if (pattern) {
425 for (; device_list; device_list = device_list->
next) {
427 int adding = strlen(device_list->
value);
432 crm_trace(
"Adding %s (%dc) at offset %d", device_list->
value, adding, len);
433 list = realloc_safe(list, len + adding + 1);
435 crm_perror(LOG_CRIT,
"Could not create device list");
439 sprintf(list + len,
"%s%s", len?
",":
"", device_list->
value);
450 stonith_api_register_level_full(
stonith_t * st,
int options,
const char *node,
452 const char *attr,
const char *value,
467 stonith_api_register_level(
stonith_t * st,
int options,
const char *node,
int level,
470 return stonith_api_register_level_full(st, options, node, NULL, NULL, NULL,
475 append_arg(
const char *key,
const char *value, GHashTable **args)
481 if (strstr(key,
"pcmk_")) {
490 *args = crm_str_table_new();
494 crm_trace(
"Appending: %s=%s", key, value);
495 g_hash_table_replace(*args, strdup(key), strdup(value));
499 append_config_arg(gpointer key, gpointer value, gpointer user_data)
506 append_arg(key, value, user_data);
512 make_args(
const char *agent,
const char *action,
const char *victim, uint32_t victim_nodeid, GHashTable * device_args,
513 GHashTable * port_map)
516 GHashTable *arg_list = NULL;
517 const char *value = NULL;
521 snprintf(buffer,
sizeof(buffer),
"pcmk_%s_action", action);
523 value = g_hash_table_lookup(device_args, buffer);
526 crm_debug(
"Substituting action '%s' for requested operation '%s'", value, action);
531 if (victim && device_args) {
532 const char *alias = victim;
535 if (port_map && g_hash_table_lookup(port_map, victim)) {
536 alias = g_hash_table_lookup(port_map, victim);
542 append_arg(
"nodename", victim, &arg_list);
544 char nodeid_str[33] = { 0, };
545 if (snprintf(nodeid_str, 33,
"%u", (
unsigned int)victim_nodeid)) {
546 crm_info(
"For stonith action (%s) for victim %s, adding nodeid (%s) to parameters",
547 action, victim, nodeid_str);
548 append_arg(
"nodeid", nodeid_str, &arg_list);
556 }
else if (param == NULL) {
558 value = g_hash_table_lookup(device_args, param);
564 value = g_hash_table_lookup(device_args, param);
568 if (value == NULL ||
safe_str_eq(value,
"dynamic")) {
569 crm_debug(
"Performing '%s' action targeting '%s' as '%s=%s'", action, victim, param,
571 append_arg(param, alias, &arg_list);
576 g_hash_table_foreach(device_args, append_config_arg, &arg_list);
594 g_hash_table_destroy(action->args);
596 free(action->action);
597 free(action->victim);
598 if (action->svc_action) {
601 free(action->output);
630 *error_output = NULL;
632 if (action != NULL) {
636 if (output && action->output) {
637 *output = action->output;
638 action->output = NULL;
640 if (error_output && action->error) {
641 *error_output = action->error;
642 action->error = NULL;
647 #define FAILURE_MAX_RETRIES 2
652 uint32_t victim_nodeid,
653 int timeout, GHashTable * device_args, GHashTable * port_map)
658 action->args = make_args(agent, _action, victim, victim_nodeid, device_args, port_map);
659 crm_debug(
"Preparing '%s' action for %s using agent %s",
660 _action, (victim? victim :
"no target"), agent);
661 action->agent = strdup(agent);
662 action->action = strdup(_action);
664 action->victim = strdup(victim);
666 action->timeout = action->remaining_timeout = timeout;
671 const char *value = NULL;
673 snprintf(buffer,
sizeof(buffer),
"pcmk_%s_retries", _action);
674 value = g_hash_table_lookup(device_args, buffer);
677 action->max_retries = atoi(value);
687 int diff = time(NULL) - action->initial_start_time;
689 if (action->tries >= action->max_retries) {
690 crm_info(
"Attempted to execute agent %s (%s) the maximum number of times (%d) allowed",
691 action->agent, action->action, action->max_retries);
692 action->remaining_timeout = 0;
693 }
else if ((action->rc != -
ETIME) && diff < (action->timeout * 0.7)) {
696 action->remaining_timeout = action->timeout - diff;
698 action->remaining_timeout = 0;
700 return action->remaining_timeout ? TRUE : FALSE;
707 if (svc_action->
rc > 0) {
717 }
else if (strstr(svc_action->
stderr_data,
"imed out")) {
721 }
else if (strstr(svc_action->
stderr_data,
"Unrecognised action")) {
736 action->rc = svc_action_to_errno(svc_action);
742 svc_action->
params = NULL;
744 crm_debug(
"Child process %d performing action '%s' exited with rc %d",
745 action->pid, action->action, svc_action->
rc);
749 if (action->rc !=
pcmk_ok && update_remaining_timeout(action)) {
750 int rc = internal_stonith_action_execute(action);
756 if (action->done_cb) {
757 action->done_cb(action->pid, action->rc, action->output, action->userdata);
760 action->svc_action = NULL;
769 action->pid = svc_action->
pid;
770 action->svc_action = svc_action;
772 if (action->fork_cb) {
773 (action->fork_cb) (svc_action->
pid, action->userdata);
776 crm_trace(
"Child process %d performing action '%s' successfully forked",
777 action->pid, action->action);
786 static int stonith_sequence = 0;
789 if (!action->tries) {
790 action->initial_start_time = time(NULL);
794 if (action->tries > 1) {
795 crm_info(
"Attempt %d to execute %s (%s). remaining timeout is %d",
796 action->tries, action->agent, action->action, action->remaining_timeout);
800 if (action->args == NULL || action->agent == NULL)
806 svc_action->
timeout = 1000 * action->remaining_timeout;
809 action->action, action->tries);
810 svc_action->
agent = strdup(action->agent);
811 svc_action->
sequence = stonith_sequence++;
812 svc_action->
params = action->args;
813 svc_action->
cb_data = (
void *) action;
818 free(action->output);
819 action->output = NULL;
821 action->error = NULL;
828 &stonith_action_async_done,
829 &stonith_action_async_forked) == FALSE) {
840 action->
rc = svc_action_to_errno(svc_action);
846 action->rc = -ECONNABORTED;
850 svc_action->
params = NULL;
872 void (*done) (GPid
pid,
int rc,
const char *output,
874 void (*fork_cb) (GPid
pid, gpointer user_data))
880 action->userdata = userdata;
881 action->done_cb = done;
882 action->fork_cb = fork_cb;
885 return internal_stonith_action_execute(action);
901 CRM_CHECK(action != NULL,
return -EINVAL);
905 rc = internal_stonith_action_execute(action);
906 }
while ((rc !=
pcmk_ok) && update_remaining_timeout(action));
912 stonith_api_device_list(
stonith_t * stonith,
int call_options,
const char *
namespace,
918 if (devices == NULL) {
919 crm_err(
"Parameter error: stonith_api_device_list");
923 #if HAVE_STONITH_STONITH_H
939 stonith_api_device_metadata(
stonith_t * stonith,
int call_options,
const char *agent,
940 const char *
namespace,
char **output,
int timeout)
948 crm_trace(
"Looking up metadata for %s agent %s",
955 #if HAVE_STONITH_STONITH_H
961 crm_err(
"Can't get fence agent '%s' meta-data: No such agent",
969 stonith_api_query(
stonith_t * stonith,
int call_options,
const char *target,
972 int rc = 0, lpc = 0, max = 0;
974 xmlNode *
data = NULL;
975 xmlNode *output = NULL;
976 xmlXPathObjectPtr xpathObj = NULL;
978 CRM_CHECK(devices != NULL,
return -EINVAL);
992 max = numXpathResults(xpathObj);
994 for (lpc = 0; lpc < max; lpc++) {
999 xmlChar *match_path = xmlGetNodePath(match);
1001 crm_info(
"%s[%d] = %s",
"//@agent", lpc, match_path);
1019 const char *action,
const char *victim,
int timeout, xmlNode ** output)
1022 xmlNode *
data = NULL;
1037 stonith_api_list(
stonith_t * stonith,
int call_options,
const char *
id,
char **list_info,
1041 xmlNode *output = NULL;
1043 rc = stonith_api_call(stonith, call_options,
id,
"list", NULL, timeout, &output);
1045 if (output && list_info) {
1046 const char *list_str;
1051 *list_info = strdup(list_str);
1063 stonith_api_monitor(
stonith_t * stonith,
int call_options,
const char *
id,
int timeout)
1065 return stonith_api_call(stonith, call_options,
id,
"monitor", NULL, timeout, NULL);
1069 stonith_api_status(
stonith_t * stonith,
int call_options,
const char *
id,
const char *port,
1072 return stonith_api_call(stonith, call_options,
id,
"status", port, timeout, NULL);
1076 stonith_api_fence(
stonith_t * stonith,
int call_options,
const char *node,
const char *action,
1077 int timeout,
int tolerance)
1080 xmlNode *
data = NULL;
1095 stonith_api_confirm(
stonith_t * stonith,
int call_options,
const char *target)
1097 return stonith_api_fence(stonith, call_options |
st_opt_manual_ack, target,
"off", 0, 0);
1101 stonith_api_history(
stonith_t * stonith,
int call_options,
const char *node,
1105 xmlNode *
data = NULL;
1106 xmlNode *output = NULL;
1124 for (op = __xml_first_child(reply); op != NULL; op = __xml_next(op)) {
1156 for (hp = history; hp; hp_old = hp, hp = hp->
next, free(hp_old)) {
1175 stonithlib_GCompareFunc(gconstpointer a, gconstpointer b)
1181 if (a_client->delete || b_client->delete) {
1185 CRM_CHECK(a_client->event != NULL && b_client->event != NULL,
return 0);
1186 rc = strcmp(a_client->event, b_client->event);
1188 if (a_client->notify == NULL || b_client->notify == NULL) {
1191 }
else if (a_client->notify == b_client->notify) {
1194 }
else if (((
long)a_client->notify) < ((
long)b_client->notify)) {
1195 crm_err(
"callbacks for %s are not equal: %p vs. %p",
1196 a_client->event, a_client->notify, b_client->notify);
1199 crm_err(
"callbacks for %s are not equal: %p vs. %p",
1200 a_client->event, a_client->notify, b_client->notify);
1220 crm_trace(
"Sending call options: %.8lx, %d", (
long)call_options, call_options);
1231 stonith_destroy_op_callback(gpointer
data)
1235 if (blob->timer && blob->timer->ref > 0) {
1236 g_source_remove(blob->timer->ref);
1243 stonith_api_signoff(
stonith_t * stonith)
1247 crm_debug(
"Disconnecting from the fencer");
1249 if (native->source != NULL) {
1252 native->source = NULL;
1255 }
else if (native->ipc) {
1264 free(native->token); native->token = NULL;
1270 stonith_api_del_callback(
stonith_t * stonith,
int call_id,
bool all_callbacks)
1274 if (all_callbacks) {
1275 private->op_callback = NULL;
1276 g_hash_table_destroy(private->stonith_op_callback_table);
1277 private->stonith_op_callback_table = g_hash_table_new_full(g_direct_hash, g_direct_equal,
1279 stonith_destroy_op_callback);
1281 }
else if (call_id == 0) {
1282 private->op_callback = NULL;
1285 g_hash_table_remove(private->stonith_op_callback_table, GINT_TO_POINTER(call_id));
1291 invoke_callback(
stonith_t * st,
int call_id,
int rc,
void *userdata,
1296 data.call_id = call_id;
1298 data.userdata = userdata;
1300 callback(st, &
data);
1304 stonith_perform_callback(
stonith_t * stonith, xmlNode * msg,
int call_id,
int rc)
1315 local_blob.id = NULL;
1316 local_blob.callback = NULL;
1317 local_blob.user_data = NULL;
1318 local_blob.only_success = FALSE;
1327 blob = g_hash_table_lookup(private->stonith_op_callback_table, GINT_TO_POINTER(call_id));
1333 stonith_api_del_callback(stonith, call_id, FALSE);
1336 crm_trace(
"No callback found for call %d", call_id);
1337 local_blob.callback = NULL;
1340 if (local_blob.callback != NULL && (rc ==
pcmk_ok || local_blob.only_success == FALSE)) {
1341 crm_trace(
"Invoking callback %s for call %d",
crm_str(local_blob.id), call_id);
1342 invoke_callback(stonith, call_id, rc, local_blob.user_data, local_blob.callback);
1344 }
else if (private->op_callback == NULL && rc !=
pcmk_ok) {
1349 if (private->op_callback != NULL) {
1350 crm_trace(
"Invoking global callback for call %d", call_id);
1351 invoke_callback(stonith, call_id, rc, NULL, private->op_callback);
1357 stonith_async_timeout_handler(gpointer
data)
1374 struct timer_rec_s *async_timer = callback->timer;
1381 async_timer = calloc(1,
sizeof(
struct timer_rec_s));
1382 callback->timer = async_timer;
1391 if (async_timer->
ref) {
1392 g_source_remove(async_timer->
ref);
1395 g_timeout_add(async_timer->
timeout, stonith_async_timeout_handler, async_timer);
1404 callback = g_hash_table_lookup(private->stonith_op_callback_table, GINT_TO_POINTER(
call_id));
1405 if (!callback || !callback->allow_timeout_updates) {
1413 stonith_dispatch_internal(
const char *buffer, ssize_t length, gpointer userdata)
1415 const char *
type = NULL;
1416 struct notify_blob_s blob;
1422 private = st->st_private;
1426 if (blob.xml == NULL) {
1427 crm_warn(
"Received malformed message from fencer: %s", buffer);
1436 stonith_perform_callback(st, blob.xml, 0, 0);
1439 foreach_notify_entry(
private, stonith_send_notification, &blob);
1447 update_callback_timeout(call_id, timeout, st);
1458 stonith_api_signon(
stonith_t * stonith,
const char *name,
int *stonith_fd)
1462 const char *display_name = name? name :
"client";
1465 .
dispatch = stonith_dispatch_internal,
1466 .destroy = stonith_connection_destroy
1469 CRM_CHECK(stonith != NULL,
return -EINVAL);
1474 crm_debug(
"Attempting fencer connection by %s with%s mainloop",
1475 display_name, (stonith_fd?
"out" :
""));
1484 }
else if (native->ipc) {
1497 if (native->ipc == NULL) {
1500 xmlNode *reply = NULL;
1509 crm_debug(
"Couldn't register with the fencer: %s "
1513 }
else if (reply == NULL) {
1514 crm_debug(
"Couldn't register with the fencer: no reply");
1522 crm_debug(
"Couldn't register with the fencer: invalid reply type '%s'",
1523 (msg_type? msg_type :
"(missing)"));
1527 }
else if (native->token == NULL) {
1528 crm_debug(
"Couldn't register with the fencer: no token in reply");
1533 #if HAVE_MSGFROMIPC_TIMEOUT
1536 crm_debug(
"Connection to fencer by %s succeeded (registration token: %s)",
1537 display_name, native->token);
1547 crm_debug(
"Connection attempt to fencer by %s failed: %s "
1555 stonith_set_notification(
stonith_t * stonith,
const char *callback,
int enabled)
1572 crm_perror(LOG_DEBUG,
"Couldn't register for fencing notifications: %d", rc);
1584 stonith_api_add_notification(
stonith_t * stonith,
const char *event,
1587 GList *list_item = NULL;
1592 crm_trace(
"Adding callback for %s events (%d)", event, g_list_length(private->notify_list));
1595 new_client->event = event;
1596 new_client->notify = callback;
1598 list_item = g_list_find_custom(private->notify_list, new_client, stonithlib_GCompareFunc);
1600 if (list_item != NULL) {
1601 crm_warn(
"Callback already present");
1606 private->notify_list = g_list_append(private->notify_list, new_client);
1608 stonith_set_notification(stonith, event, 1);
1610 crm_trace(
"Callback added (%d)", g_list_length(private->notify_list));
1616 stonith_api_del_notification(
stonith_t * stonith,
const char *event)
1618 GList *list_item = NULL;
1622 crm_debug(
"Removing callback for %s events", event);
1626 new_client->event = event;
1627 new_client->notify = NULL;
1629 list_item = g_list_find_custom(private->notify_list, new_client, stonithlib_GCompareFunc);
1631 stonith_set_notification(stonith, event, 0);
1633 if (list_item != NULL) {
1636 if (private->notify_refcnt) {
1637 list_client->delete = TRUE;
1638 private->notify_deletes = TRUE;
1640 private->notify_list = g_list_remove(private->notify_list, list_client);
1654 stonith_api_add_callback(
stonith_t * stonith,
int call_id,
int timeout,
int options,
1655 void *user_data,
const char *callback_name,
1661 CRM_CHECK(stonith != NULL,
return -EINVAL);
1666 private->op_callback = callback;
1668 }
else if (call_id < 0) {
1671 invoke_callback(stonith, call_id, call_id, user_data, callback);
1679 blob->id = callback_name;
1681 blob->user_data = user_data;
1682 blob->callback = callback;
1686 set_callback_timeout(blob, stonith, call_id, timeout);
1689 g_hash_table_insert(private->stonith_op_callback_table, GINT_TO_POINTER(call_id), blob);
1690 crm_trace(
"Added callback to %s for call %d", callback_name, call_id);
1696 stonith_dump_pending_op(gpointer key, gpointer value, gpointer user_data)
1698 int call = GPOINTER_TO_INT(key);
1709 if (private->stonith_op_callback_table == NULL) {
1712 return g_hash_table_foreach(private->stonith_op_callback_table, stonith_dump_pending_op, NULL);
1735 xml_to_event(xmlNode * msg)
1759 crm_err(
"No data for %s event", ntype);
1785 stonith_send_notification(gpointer
data, gpointer user_data)
1787 struct notify_blob_s *blob = user_data;
1790 const char *
event = NULL;
1792 if (blob->xml == NULL) {
1793 crm_warn(
"Skipping callback - NULL message");
1799 if (entry == NULL) {
1800 crm_warn(
"Skipping callback - NULL callback client");
1803 }
else if (entry->delete) {
1804 crm_trace(
"Skipping callback - marked for deletion");
1807 }
else if (entry->notify == NULL) {
1808 crm_warn(
"Skipping callback - NULL callback");
1812 crm_trace(
"Skipping callback - event mismatch %p/%s vs. %s", entry, entry->event, event);
1816 st_event = xml_to_event(blob->xml);
1818 crm_trace(
"Invoking callback for %p/%s event...", entry, event);
1819 entry->notify(blob->stonith, st_event);
1822 event_free(st_event);
1840 stonith_send_command(
stonith_t * stonith,
const char *op, xmlNode *
data, xmlNode ** output_data,
1841 int call_options,
int timeout)
1846 xmlNode *op_msg = NULL;
1847 xmlNode *op_reply = NULL;
1853 if (output_data != NULL) {
1854 *output_data = NULL;
1871 if (op_msg == NULL) {
1876 crm_trace(
"Sending %s message to fencer with timeout %ds", op, timeout);
1885 1000 * (timeout + 60), &op_reply);
1890 crm_perror(LOG_ERR,
"Couldn't perform %s operation (timeout=%ds): %d", op, timeout, rc);
1906 if (reply_id == stonith->
call_id) {
1907 crm_trace(
"Synchronous reply %d received", reply_id);
1917 *output_data = op_reply;
1921 }
else if (reply_id <= 0) {
1922 crm_err(
"Received bad reply: No id set");
1928 crm_err(
"Received bad reply: %d (wanted %d)", reply_id, stonith->
call_id);
1936 crm_err(
"Fencer disconnected");
1937 free(native->token); native->token = NULL;
1949 gboolean stay_connected = TRUE;
1960 stonith_dispatch_internal(msg, strlen(msg), st);
1965 stay_connected = FALSE;
1969 return stay_connected;
1980 crm_trace(
"Disconnecting %p first", stonith);
1987 crm_trace(
"Removing %d callbacks", g_hash_table_size(private->stonith_op_callback_table));
1988 g_hash_table_destroy(private->stonith_op_callback_table);
1990 crm_trace(
"Destroying %d notification clients", g_list_length(private->notify_list));
1991 g_list_free_full(private->notify_list, free);
1994 free(stonith->
cmds);
2014 stonith_api_validate(
stonith_t *st,
int call_options,
const char *rsc_id,
2015 const char *namespace_s,
const char *agent,
2017 char **error_output)
2030 const char *target =
"node1";
2032 GHashTable *params_table = crm_str_table_new();
2035 for (; params; params = params->
next) {
2039 && strcmp(params->
key,
"provides")
2040 && strcmp(params->
key,
"stonith-timeout")) {
2041 g_hash_table_insert(params_table, strdup(params->
key),
2042 strdup(params->
value));
2046 #if SUPPORT_CIBSECRETS
2049 crm_warn(
"Could not replace secret parameters for validation of %s: %s",
2058 *error_output = NULL;
2064 params_table, timeout, output,
2068 #if HAVE_STONITH_STONITH_H
2071 params_table, timeout, output,
2080 "Agent %s not found or does not support validation",
2084 g_hash_table_destroy(params_table);
2094 new_stonith = calloc(1,
sizeof(
stonith_t));
2095 if (new_stonith == NULL) {
2100 if (
private == NULL) {
2106 private->stonith_op_callback_table = g_hash_table_new_full(g_direct_hash, g_direct_equal,
2107 NULL, stonith_destroy_op_callback);
2108 private->notify_list = NULL;
2109 private->notify_refcnt = 0;
2110 private->notify_deletes = FALSE;
2116 if (new_stonith->
cmds == NULL) {
2123 new_stonith->
cmds->
free = stonith_api_free;
2127 new_stonith->
cmds->
list = stonith_api_list;
2129 new_stonith->
cmds->
status = stonith_api_status;
2130 new_stonith->
cmds->
fence = stonith_api_fence;
2135 new_stonith->
cmds->
metadata = stonith_api_device_metadata;
2137 new_stonith->
cmds->
query = stonith_api_query;
2171 for (
int attempt = 1; attempt <= max_attempts; attempt++) {
2175 }
else if (attempt < max_attempts) {
2176 crm_notice(
"Fencer connection attempt %d of %d failed (retrying in 2s): %s "
2194 p->
key = strdup(key);
2197 p->
value = strdup(value);
2201 while (end && end->
next) {
2232 #define api_log_open() openlog("stonith-api", LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON)
2233 #define api_log(level, fmt, args...) syslog(level, "%s: "fmt, __FUNCTION__, args)
2240 const char *action = off?
"off" :
"reboot";
2244 api_log(LOG_ERR,
"API initialization failed, could not kick (%s) node %u/%s",
2245 action, nodeid,
uname);
2251 api_log(LOG_ERR,
"Connection failed, could not kick (%s) node %u/%s : %s (%d)",
2257 if (
uname != NULL) {
2258 name = strdup(
uname);
2259 }
else if (nodeid > 0) {
2261 name = crm_itoa(nodeid);
2263 rc = st->
cmds->
fence(st, opts, name, action, timeout, 0);
2267 api_log(LOG_ERR,
"Could not kick (%s) node %u/%s : %s (%d)",
2270 api_log(LOG_NOTICE,
"Node %u/%s kicked: %s", nodeid,
uname, action);
2287 api_log(LOG_ERR,
"Could not retrieve fence history for %u/%s: "
2288 "API initialization failed", nodeid,
uname);
2302 if (
uname != NULL) {
2303 name = strdup(
uname);
2304 }
else if (nodeid > 0) {
2306 name = crm_itoa(nodeid);
2308 rc = st->
cmds->
history(st, opts, name, &history, 120);
2311 for (hp = history; hp; hp = hp->
next) {
2319 }
else if (hp->state ==
st_done) {
2321 if (hp->completed > when) {
2322 when = hp->completed;
2330 api_log(LOG_INFO,
"Found %d entries for %u/%s: %d in progress, %d completed", entries, nodeid,
uname, progress, completed);
2339 api_log(LOG_INFO,
"Node %u/%s last kicked at: %ld", nodeid,
uname, (
long int)when);
2352 if (agent == NULL) {
2358 crm_err(
"Could not list fence agents: API memory allocation failed");
2363 for (dIter = devices; dIter != NULL; dIter = dIter->
next) {
2378 if (action == NULL) {
2380 }
else if (!strcmp(action,
"on")) {
2382 }
else if (!strcmp(action,
"off")) {
2383 return "turning off";
2398 parse_list_line(
const char *line,
int len, GList **output)
2401 size_t entry_start = 0;
2407 if (strstr(line,
"invalid") || strstr(line,
"variable")) {
2408 crm_debug(
"Skipping list output line: %s", line);
2413 for (i = 0; i <= len; i++) {
2415 if (isspace(line[i]) || (line[i] ==
',') || (line[i] ==
';')
2416 || (line[i] ==
'\0')) {
2422 if (i == entry_start) {
2424 entry_start = i + 1;
2428 entry = calloc(i - entry_start + 1,
sizeof(
char));
2435 rc = sscanf(line + entry_start,
"%[a-zA-Z0-9_-.]", entry);
2437 crm_warn(
"Could not parse list output entry: %s "
2438 CRM_XS " entry_start=%d position=%d",
2439 line + entry_start, entry_start, i);
2455 *output = g_list_append(*output, entry);
2457 entry_start = i + 1;
2486 GList *targets = NULL;
2488 if (target_spec != NULL) {
2489 size_t out_len = strlen(target_spec);
2490 size_t line_start = 0;
2492 for (
size_t i = 0; i <= out_len; ++i) {
2493 if ((target_spec[i] ==
'\n') || (target_spec[i] ==
'\0')
2494 || ((target_spec[i] ==
'\\') && (target_spec[i + 1] ==
'n'))) {
2497 int len = i - line_start;
2500 char *line =
strndup(target_spec + line_start, len);
2503 parse_list_line(line, len, &targets);
2506 if (target_spec[i] ==
'\\') {
2526 gboolean ret = FALSE;
2529 if (prev_hp == event) {
2533 if ((prev_hp->state ==
st_done) &&
2537 (event->
completed < prev_hp->completed)) {
2559 for (hp = history; hp; ) {
2563 if ((!
new) || (hp->completed > new->completed)) {
2569 if ((!np->next) || (hp->completed > np->next->completed)) {
2589 while (last_pending->
next) {
2590 last_pending = last_pending->
next;
2593 last_pending->
next =
new;