20 #include <sys/types.h> 36 struct stonith_action_s {
45 void (*done_cb) (GPid
pid, gint status,
const char *output, gpointer user_data);
46 void (*fork_cb) (GPid
pid, gpointer user_data);
51 time_t initial_start_time;
53 int remaining_timeout;
63 typedef struct stonith_private_s {
67 GHashTable *stonith_op_callback_table;
76 typedef struct stonith_notify_client_s {
85 typedef struct stonith_callback_client_s {
89 gboolean only_success;
90 gboolean allow_timeout_updates;
95 struct notify_blob_s {
107 typedef int (*
stonith_op_t) (
const char *, int,
const char *, xmlNode *,
108 xmlNode *, xmlNode *, xmlNode **, xmlNode **);
113 static int stonith_send_command(
stonith_t *stonith,
const char *op,
114 xmlNode *
data, xmlNode **output_data,
115 int call_options,
int timeout);
117 static void stonith_connection_destroy(gpointer user_data);
118 static void stonith_send_notification(gpointer
data, gpointer user_data);
135 }
else if (!strcmp(namespace_s,
"redhat")
136 || !strcmp(namespace_s,
"stonith-ng")) {
139 }
else if (!strcmp(namespace_s,
"internal")) {
142 }
else if (!strcmp(namespace_s,
"heartbeat")) {
158 switch (st_namespace) {
165 return "unsupported";
187 #if HAVE_STONITH_STONITH_H 193 crm_err(
"Unknown fence agent: %s", agent);
226 private->notify_refcnt++;
227 g_list_foreach(private->notify_list, func, user_data);
228 private->notify_refcnt--;
229 if ((private->notify_refcnt == 0) &&
230 private->notify_deletes) {
231 GList *list_item =
private->notify_list;
233 private->notify_deletes = FALSE;
234 while (list_item != NULL)
237 GList *next = g_list_next(list_item);
239 if (list_client->delete) {
241 private->notify_list =
242 g_list_delete_link(private->notify_list, list_item);
250 stonith_connection_destroy(gpointer user_data)
254 struct notify_blob_s blob;
256 crm_trace(
"Sending destroyed notification");
257 blob.stonith = stonith;
262 native->source = NULL;
264 free(native->token); native->token = NULL;
269 foreach_notify_entry(native, stonith_send_notification, &blob);
276 const char *rsc_provides)
281 #if HAVE_STONITH_STONITH_H 286 hash2field((gpointer)
"plugin", (gpointer) agent, args);
287 agent =
"fence_legacy";
301 for (; params; params = params->
next) {
309 stonith_api_register_device(
stonith_t *
st,
int call_options,
310 const char *
id,
const char *
namespace,
const char *agent,
314 xmlNode *
data = NULL;
317 agent, params, NULL);
326 stonith_api_remove_device(
stonith_t *
st,
int call_options,
const char *
name)
329 xmlNode *
data = NULL;
341 stonith_api_remove_level_full(
stonith_t *
st,
int options,
342 const char *node,
const char *pattern,
343 const char *attr,
const char *value,
int level)
346 xmlNode *
data = NULL;
348 CRM_CHECK(node || pattern || (attr && value),
return -EINVAL);
356 }
else if (pattern) {
372 stonith_api_remove_level(
stonith_t *
st,
int options,
const char *node,
int level)
374 return stonith_api_remove_level_full(
st, options, node,
375 NULL, NULL, NULL, level);
395 const char *attr,
const char *value,
402 CRM_CHECK(node || pattern || (attr && value),
return NULL);
414 }
else if (pattern) {
424 for (; device_list; device_list = device_list->
next) {
435 stonith_api_register_level_full(
stonith_t *
st,
int options,
const char *node,
437 const char *attr,
const char *value,
452 stonith_api_register_level(
stonith_t *
st,
int options,
const char *node,
int level,
455 return stonith_api_register_level_full(
st, options, node, NULL, NULL, NULL,
460 append_arg(
const char *key,
const char *value, GHashTable **args)
466 if (strstr(key,
"pcmk_")) {
475 *args = crm_str_table_new();
479 crm_trace(
"Appending: %s=%s", key, value);
480 g_hash_table_replace(*args, strdup(key), strdup(value));
484 append_config_arg(gpointer key, gpointer value, gpointer user_data)
491 append_arg(key, value, user_data);
497 make_args(
const char *agent,
const char *
action,
const char *victim,
498 uint32_t victim_nodeid, GHashTable * device_args,
499 GHashTable * port_map,
const char *host_arg)
502 GHashTable *arg_list = NULL;
503 const char *value = NULL;
507 snprintf(buffer,
sizeof(buffer),
"pcmk_%s_action",
action);
509 value = g_hash_table_lookup(device_args, buffer);
512 crm_debug(
"Substituting action '%s' for requested operation '%s'", value,
action);
517 if (victim && device_args) {
518 const char *alias = victim;
521 if (port_map && g_hash_table_lookup(port_map, victim)) {
522 alias = g_hash_table_lookup(port_map, victim);
528 append_arg(
"nodename", victim, &arg_list);
530 char nodeid_str[33] = { 0, };
531 if (snprintf(nodeid_str, 33,
"%u", (
unsigned int)victim_nodeid)) {
532 crm_info(
"For stonith action (%s) for victim %s, adding nodeid (%s) to parameters",
533 action, victim, nodeid_str);
534 append_arg(
"nodeid", nodeid_str, &arg_list);
542 }
else if (param == NULL) {
544 if (host_arg == NULL) {
551 value = g_hash_table_lookup(device_args, param);
557 value = g_hash_table_lookup(device_args, param);
562 crm_debug(
"Performing '%s' action targeting '%s' as '%s=%s'",
action, victim, param,
564 append_arg(param, alias, &arg_list);
569 g_hash_table_foreach(device_args, append_config_arg, &arg_list);
587 g_hash_table_destroy(
action->args);
623 *error_output = NULL;
629 if (output &&
action->output) {
633 if (error_output &&
action->error) {
634 *error_output =
action->error;
640 #define FAILURE_MAX_RETRIES 2 645 uint32_t victim_nodeid,
646 int timeout, GHashTable * device_args,
647 GHashTable * port_map,
const char *host_arg)
652 action->args = make_args(agent, _action, victim, victim_nodeid,
653 device_args, port_map, host_arg);
654 crm_debug(
"Preparing '%s' action for %s using agent %s",
655 _action, (victim? victim :
"no target"), agent);
656 action->agent = strdup(agent);
657 action->action = strdup(_action);
659 action->victim = strdup(victim);
666 const char *value = NULL;
668 snprintf(buffer,
sizeof(buffer),
"pcmk_%s_retries", _action);
669 value = g_hash_table_lookup(device_args, buffer);
672 action->max_retries = atoi(value);
682 int diff = time(NULL) -
action->initial_start_time;
685 crm_info(
"Attempted to execute agent %s (%s) the maximum number of times (%d) allowed",
687 action->remaining_timeout = 0;
693 action->remaining_timeout = 0;
695 return action->remaining_timeout ? TRUE : FALSE;
702 if (svc_action->
rc > 0) {
712 }
else if (strstr(svc_action->
stderr_data,
"imed out")) {
716 }
else if (strstr(svc_action->
stderr_data,
"Unrecognised action")) {
731 action->rc = svc_action_to_errno(svc_action);
737 svc_action->
params = NULL;
739 crm_debug(
"Child process %d performing action '%s' exited with rc %d",
745 int rc = internal_stonith_action_execute(
action);
755 action->svc_action = NULL;
765 action->svc_action = svc_action;
771 crm_trace(
"Child process %d performing action '%s' successfully forked",
781 static int stonith_sequence = 0;
785 action->initial_start_time = time(NULL);
790 crm_info(
"Attempt %d to execute %s (%s). remaining timeout is %d",
807 svc_action->
sequence = stonith_sequence++;
810 svc_action->
flags = pcmk__set_flags_as(__func__, __LINE__,
812 svc_action->
id, svc_action->
flags,
814 "SVC_ACTION_NON_BLOCKED");
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;
882 action->fork_cb = fork_cb;
885 return internal_stonith_action_execute(
action);
905 rc = internal_stonith_action_execute(
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_with_delay(
stonith_t * stonith,
int call_options,
const char *node,
1080 xmlNode *
data = NULL;
1096 stonith_api_fence(
stonith_t * stonith,
int call_options,
const char *node,
const char *
action,
1099 return stonith_api_fence_with_delay(stonith, call_options, node,
action,
1104 stonith_api_confirm(
stonith_t * stonith,
int call_options,
const char *
target)
1107 return stonith_api_fence(stonith, call_options,
target,
"off", 0, 0);
1111 stonith_api_history(
stonith_t * stonith,
int call_options,
const char *node,
1115 xmlNode *
data = NULL;
1116 xmlNode *output = NULL;
1136 for (op = pcmk__xml_first_child(reply); op != NULL;
1137 op = pcmk__xml_next(op)) {
1139 long long completed;
1169 for (hp = history; hp; hp_old = hp, hp = hp->
next, free(hp_old)) {
1179 stonithlib_GCompareFunc(gconstpointer a, gconstpointer b)
1185 if (a_client->delete || b_client->delete) {
1189 CRM_CHECK(a_client->event != NULL && b_client->event != NULL,
return 0);
1190 rc = strcmp(a_client->event, b_client->event);
1192 if (a_client->notify == NULL || b_client->notify == NULL) {
1195 }
else if (a_client->notify == b_client->notify) {
1198 }
else if (((
long)a_client->notify) < ((
long)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);
1203 crm_err(
"callbacks for %s are not equal: %p vs. %p",
1204 a_client->event, a_client->notify, b_client->notify);
1224 crm_trace(
"Sending call options: %.8lx, %d", (
long)call_options, call_options);
1235 stonith_destroy_op_callback(gpointer
data)
1239 if (blob->timer && blob->timer->ref > 0) {
1240 g_source_remove(blob->timer->ref);
1247 stonith_api_signoff(
stonith_t * stonith)
1251 crm_debug(
"Disconnecting from the fencer");
1253 if (native->source != NULL) {
1256 native->source = NULL;
1259 }
else if (native->ipc) {
1268 free(native->token); native->token = NULL;
1274 stonith_api_del_callback(
stonith_t * stonith,
int call_id,
bool all_callbacks)
1278 if (all_callbacks) {
1279 private->op_callback = NULL;
1280 g_hash_table_destroy(private->stonith_op_callback_table);
1281 private->stonith_op_callback_table = g_hash_table_new_full(g_direct_hash, g_direct_equal,
1283 stonith_destroy_op_callback);
1285 }
else if (call_id == 0) {
1286 private->op_callback = NULL;
1289 g_hash_table_remove(private->stonith_op_callback_table, GINT_TO_POINTER(call_id));
1295 invoke_callback(
stonith_t *
st,
int call_id,
int rc,
void *userdata,
1300 data.call_id = call_id;
1302 data.userdata = userdata;
1308 stonith_perform_callback(
stonith_t * stonith, xmlNode * msg,
int call_id,
int rc)
1319 local_blob.id = NULL;
1320 local_blob.callback = NULL;
1321 local_blob.user_data = NULL;
1322 local_blob.only_success = FALSE;
1331 blob = g_hash_table_lookup(private->stonith_op_callback_table, GINT_TO_POINTER(call_id));
1337 stonith_api_del_callback(stonith, call_id, FALSE);
1340 crm_trace(
"No callback found for call %d", call_id);
1341 local_blob.callback = NULL;
1344 if (local_blob.callback != NULL && (
rc ==
pcmk_ok || local_blob.only_success == FALSE)) {
1345 crm_trace(
"Invoking callback %s for call %d",
crm_str(local_blob.id), call_id);
1346 invoke_callback(stonith, call_id,
rc, local_blob.user_data, local_blob.callback);
1348 }
else if (private->op_callback == NULL &&
rc !=
pcmk_ok) {
1353 if (private->op_callback != NULL) {
1354 crm_trace(
"Invoking global callback for call %d", call_id);
1355 invoke_callback(stonith, call_id,
rc, NULL, private->op_callback);
1361 stonith_async_timeout_handler(gpointer
data)
1378 struct timer_rec_s *async_timer = callback->timer;
1385 async_timer = calloc(1,
sizeof(
struct timer_rec_s));
1386 callback->timer = async_timer;
1395 if (async_timer->
ref) {
1396 g_source_remove(async_timer->
ref);
1399 g_timeout_add(async_timer->
timeout, stonith_async_timeout_handler, async_timer);
1408 callback = g_hash_table_lookup(private->stonith_op_callback_table, GINT_TO_POINTER(
call_id));
1409 if (!callback || !callback->allow_timeout_updates) {
1417 stonith_dispatch_internal(
const char *buffer, ssize_t length, gpointer userdata)
1419 const char *
type = NULL;
1420 struct notify_blob_s blob;
1430 if (blob.xml == NULL) {
1431 crm_warn(
"Received malformed message from fencer: %s", buffer);
1440 stonith_perform_callback(
st, blob.xml, 0, 0);
1443 foreach_notify_entry(
private, stonith_send_notification, &blob);
1451 update_callback_timeout(call_id,
timeout,
st);
1462 stonith_api_signon(
stonith_t * stonith,
const char *
name,
int *stonith_fd)
1466 const char *display_name =
name?
name :
"client";
1469 .
dispatch = stonith_dispatch_internal,
1470 .destroy = stonith_connection_destroy
1473 CRM_CHECK(stonith != NULL,
return -EINVAL);
1478 crm_debug(
"Attempting fencer connection by %s with%s mainloop",
1479 display_name, (stonith_fd?
"out" :
""));
1488 }
else if (native->ipc) {
1501 if (native->ipc == NULL) {
1504 xmlNode *reply = NULL;
1513 crm_debug(
"Couldn't register with the fencer: %s " 1517 }
else if (reply == NULL) {
1518 crm_debug(
"Couldn't register with the fencer: no reply");
1526 crm_debug(
"Couldn't register with the fencer: invalid reply type '%s'",
1527 (msg_type? msg_type :
"(missing)"));
1531 }
else if (native->token == NULL) {
1532 crm_debug(
"Couldn't register with the fencer: no token in reply");
1537 #if HAVE_MSGFROMIPC_TIMEOUT 1540 crm_debug(
"Connection to fencer by %s succeeded (registration token: %s)",
1541 display_name, native->token);
1551 crm_debug(
"Connection attempt to fencer by %s failed: %s " 1559 stonith_set_notification(
stonith_t * stonith,
const char *callback,
int enabled)
1576 crm_perror(LOG_DEBUG,
"Couldn't register for fencing notifications: %d",
rc);
1588 stonith_api_add_notification(
stonith_t * stonith,
const char *event,
1591 GList *list_item = NULL;
1596 crm_trace(
"Adding callback for %s events (%d)", event, g_list_length(private->notify_list));
1599 new_client->event = event;
1600 new_client->notify = callback;
1602 list_item = g_list_find_custom(private->notify_list, new_client, stonithlib_GCompareFunc);
1604 if (list_item != NULL) {
1605 crm_warn(
"Callback already present");
1610 private->notify_list = g_list_append(private->notify_list, new_client);
1612 stonith_set_notification(stonith, event, 1);
1614 crm_trace(
"Callback added (%d)", g_list_length(private->notify_list));
1620 stonith_api_del_notification(
stonith_t * stonith,
const char *event)
1622 GList *list_item = NULL;
1626 crm_debug(
"Removing callback for %s events", event);
1630 new_client->event = event;
1631 new_client->notify = NULL;
1633 list_item = g_list_find_custom(private->notify_list, new_client, stonithlib_GCompareFunc);
1635 stonith_set_notification(stonith, event, 0);
1637 if (list_item != NULL) {
1640 if (private->notify_refcnt) {
1641 list_client->delete = TRUE;
1642 private->notify_deletes = TRUE;
1644 private->notify_list = g_list_remove(private->notify_list, list_client);
1658 stonith_api_add_callback(
stonith_t * stonith,
int call_id,
int timeout,
int options,
1659 void *user_data,
const char *callback_name,
1665 CRM_CHECK(stonith != NULL,
return -EINVAL);
1670 private->op_callback = callback;
1672 }
else if (call_id < 0) {
1675 invoke_callback(stonith, call_id, call_id, user_data, callback);
1683 blob->id = callback_name;
1685 blob->user_data = user_data;
1686 blob->callback = callback;
1690 set_callback_timeout(blob, stonith, call_id,
timeout);
1693 g_hash_table_insert(private->stonith_op_callback_table, GINT_TO_POINTER(call_id), blob);
1694 crm_trace(
"Added callback to %s for call %d", callback_name, call_id);
1700 stonith_dump_pending_op(gpointer key, gpointer value, gpointer user_data)
1702 int call = GPOINTER_TO_INT(key);
1713 if (private->stonith_op_callback_table == NULL) {
1716 return g_hash_table_foreach(private->stonith_op_callback_table, stonith_dump_pending_op, NULL);
1739 xml_to_event(xmlNode * msg)
1763 crm_err(
"No data for %s event", ntype);
1789 stonith_send_notification(gpointer
data, gpointer user_data)
1791 struct notify_blob_s *blob = user_data;
1794 const char *
event = NULL;
1796 if (blob->xml == NULL) {
1797 crm_warn(
"Skipping callback - NULL message");
1803 if (entry == NULL) {
1804 crm_warn(
"Skipping callback - NULL callback client");
1807 }
else if (entry->delete) {
1808 crm_trace(
"Skipping callback - marked for deletion");
1811 }
else if (entry->notify == NULL) {
1812 crm_warn(
"Skipping callback - NULL callback");
1816 crm_trace(
"Skipping callback - event mismatch %p/%s vs. %s", entry, entry->event, event);
1820 st_event = xml_to_event(blob->xml);
1822 crm_trace(
"Invoking callback for %p/%s event...", entry, event);
1823 entry->notify(blob->stonith, st_event);
1826 event_free(st_event);
1844 stonith_send_command(
stonith_t * stonith,
const char *op, xmlNode *
data, xmlNode ** output_data,
1845 int call_options,
int timeout)
1850 xmlNode *op_msg = NULL;
1851 xmlNode *op_reply = NULL;
1857 if (output_data != NULL) {
1858 *output_data = NULL;
1875 if (op_msg == NULL) {
1898 1000 * (
timeout + 60), &op_reply);
1919 if (reply_id == stonith->
call_id) {
1920 crm_trace(
"Synchronous reply %d received", reply_id);
1930 *output_data = op_reply;
1934 }
else if (reply_id <= 0) {
1935 crm_err(
"Received bad reply: No id set");
1941 crm_err(
"Received bad reply: %d (wanted %d)", reply_id, stonith->
call_id);
1949 crm_err(
"Fencer disconnected");
1950 free(native->token); native->token = NULL;
1962 gboolean stay_connected = TRUE;
1973 stonith_dispatch_internal(msg, strlen(msg),
st);
1978 stay_connected = FALSE;
1982 return stay_connected;
1993 crm_trace(
"Disconnecting %p first", stonith);
2000 crm_trace(
"Removing %d callbacks", g_hash_table_size(private->stonith_op_callback_table));
2001 g_hash_table_destroy(private->stonith_op_callback_table);
2003 crm_trace(
"Destroying %d notification clients", g_list_length(private->notify_list));
2004 g_list_free_full(private->notify_list, free);
2007 free(stonith->
cmds);
2027 stonith_api_validate(
stonith_t *
st,
int call_options,
const char *rsc_id,
2028 const char *namespace_s,
const char *agent,
2030 char **error_output)
2043 const char *
target =
"node1";
2044 const char *host_arg = NULL;
2046 GHashTable *params_table = crm_str_table_new();
2049 for (; params; params = params->
next) {
2051 host_arg = params->
value;
2056 && strcmp(params->
key,
"provides")
2057 && strcmp(params->
key,
"stonith-timeout")) {
2058 g_hash_table_insert(params_table, strdup(params->
key),
2059 strdup(params->
value));
2063 #if SUPPORT_CIBSECRETS 2066 crm_warn(
"Could not replace secret parameters for validation of %s: %s",
2076 *error_output = NULL;
2082 params_table, host_arg,
timeout,
2083 output, error_output);
2086 #if HAVE_STONITH_STONITH_H 2089 params_table,
timeout, output,
2098 "Agent %s not found or does not support validation",
2102 g_hash_table_destroy(params_table);
2112 new_stonith = calloc(1,
sizeof(
stonith_t));
2113 if (new_stonith == NULL) {
2118 if (
private == NULL) {
2124 private->stonith_op_callback_table = g_hash_table_new_full(g_direct_hash, g_direct_equal,
2125 NULL, stonith_destroy_op_callback);
2126 private->notify_list = NULL;
2127 private->notify_refcnt = 0;
2128 private->notify_deletes = FALSE;
2134 if (new_stonith->
cmds == NULL) {
2141 new_stonith->
cmds->
free = stonith_api_free;
2145 new_stonith->
cmds->
list = stonith_api_list;
2147 new_stonith->
cmds->
status = stonith_api_status;
2148 new_stonith->
cmds->
fence = stonith_api_fence;
2154 new_stonith->
cmds->
metadata = stonith_api_device_metadata;
2156 new_stonith->
cmds->
query = stonith_api_query;
2190 for (
int attempt = 1; attempt <= max_attempts; attempt++) {
2194 }
else if (attempt < max_attempts) {
2195 crm_notice(
"Fencer connection attempt %d of %d failed (retrying in 2s): %s " 2213 p->
key = strdup(key);
2216 p->
value = strdup(value);
2220 while (end && end->
next) {
2251 #define api_log_open() openlog("stonith-api", LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON) 2252 #define api_log(level, fmt, args...) syslog(level, "%s: "fmt, __func__, args) 2259 const char *
action = off?
"off" :
"reboot";
2263 api_log(LOG_ERR,
"API initialization failed, could not kick (%s) node %u/%s",
2270 api_log(LOG_ERR,
"Connection failed, could not kick (%s) node %u/%s : %s (%d)",
2278 if ((
uname == NULL) && (nodeid > 0)) {
2285 api_log(LOG_ERR,
"Could not kick (%s) node %u/%s : %s (%d)",
2305 api_log(LOG_ERR,
"Could not retrieve fence history for %u/%s: " 2306 "API initialization failed", nodeid,
uname);
2321 if ((
uname == NULL) && (nodeid > 0)) {
2327 for (hp = history; hp; hp = hp->
next) {
2335 }
else if (hp->state ==
st_done) {
2337 if (hp->completed > when) {
2338 when = hp->completed;
2346 api_log(LOG_INFO,
"Found %d entries for %u/%s: %d in progress, %d completed", entries, nodeid,
uname, progress, completed);
2355 api_log(LOG_INFO,
"Node %u/%s last kicked at: %ld", nodeid,
uname, (
long int)when);
2368 if (agent == NULL) {
2374 crm_err(
"Could not list fence agents: API memory allocation failed");
2379 for (dIter = devices; dIter != NULL; dIter = dIter->
next) {
2396 }
else if (!strcmp(
action,
"on")) {
2398 }
else if (!strcmp(
action,
"off")) {
2399 return "turning off";
2414 parse_list_line(
const char *line,
int len, GList **output)
2417 size_t entry_start = 0;
2423 if (strstr(line,
"invalid") || strstr(line,
"variable")) {
2424 crm_debug(
"Skipping list output line: %s", line);
2429 for (i = 0; i <= len; i++) {
2431 if (isspace(line[i]) || (line[i] ==
',') || (line[i] ==
';')
2432 || (line[i] ==
'\0')) {
2438 if (i == entry_start) {
2440 entry_start = i + 1;
2444 entry = calloc(i - entry_start + 1,
sizeof(
char));
2451 rc = sscanf(line + entry_start,
"%[a-zA-Z0-9_-.]", entry);
2453 crm_warn(
"Could not parse list output entry: %s " 2454 CRM_XS " entry_start=%d position=%d",
2455 line + entry_start, entry_start, i);
2471 *output = g_list_append(*output, entry);
2473 entry_start = i + 1;
2502 GList *targets = NULL;
2504 if (target_spec != NULL) {
2505 size_t out_len = strlen(target_spec);
2506 size_t line_start = 0;
2508 for (
size_t i = 0; i <= out_len; ++i) {
2509 if ((target_spec[i] ==
'\n') || (target_spec[i] ==
'\0')
2510 || ((target_spec[i] ==
'\\') && (target_spec[i + 1] ==
'n'))) {
2513 int len = i - line_start;
2516 char *line =
strndup(target_spec + line_start, len);
2519 parse_list_line(line, len, &targets);
2522 if (target_spec[i] ==
'\\') {
2542 gboolean ret = FALSE;
2545 if (prev_hp == event) {
2549 if ((prev_hp->state ==
st_done) &&
2553 (event->
completed < prev_hp->completed)) {
2575 for (hp = history; hp; ) {
2579 if ((!
new) || (hp->completed > new->completed)) {
2585 if ((!np->next) || (hp->completed > np->next->completed)) {
2605 while (last_pending->
next) {
2606 last_pending = last_pending->
next;
2609 last_pending->
next =
new;
2621 if (matching_fn(hp, user_data)) {
2638 return history->
state == GPOINTER_TO_INT(user_data);
2644 return history->
state != GPOINTER_TO_INT(user_data);
2663 xmlXPathObjectPtr xpath = NULL;
2667 CRM_CHECK((device_flags != NULL) && (metadata != NULL),
return);
2670 max = numXpathResults(xpath);
2677 for (lpc = 0; lpc < max; lpc++) {
2678 const char *parameter = NULL;
2682 if (match == NULL) {
#define CRM_CHECK(expr, failure_action)
#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.
#define crm_notice(fmt, args...)
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
const char * pcmk_strerror(int rc)
void pcmk__add_separated_word(char **list, size_t *len, const char *word, const char *separator)
void services_action_free(svc_action_t *op)
void stonith__device_parameter_flags(uint32_t *device_flags, const char *device_name, xmlNode *metadata)
#define PCMK__FENCE_BINDIR
void hash2field(gpointer key, gpointer value, gpointer user_data)
Set XML attribute based on hash table entry.
int stonith__rhcs_metadata(const char *agent, int timeout, char **output)
Execute RHCS-compatible agent's meta-data action.
bool stonith__event_state_neq(stonith_history_t *history, void *user_data)
bool pcmk__strcase_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
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)
#define stonith__set_device_flags(device_flags, device_id, flags_to_set)
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)
bool stonith__event_state_eq(stonith_history_t *history, void *user_data)
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)
int pcmk__substitute_secrets(const char *rsc_id, GHashTable *params)
#define XML_TAG_FENCING_LEVEL
const char * stonith_action_str(const char *action)
Turn stonith action into a more readable string.
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 *))
gboolean stonith__later_succeeded(stonith_history_t *event, stonith_history_t *top_history)
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)
#define F_STONITH_NOTIFY_DEACTIVATE
const char * pcmk_rc_str(int rc)
Get a user-friendly description of a return code.
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 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.
#define STONITH_OP_LEVEL_DEL
char * strndup(const char *str, size_t len)
#define STONITH_OP_DEVICE_ADD
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)
int stonith_api_connect_retry(stonith_t *st, const char *name, int max_attempts)
Make a blocking connection attempt to the fencer.
#define STONITH_ATTR_HOSTARG
bool stonith_dispatch(stonith_t *st)
#define crm_debug(fmt, args...)
stonith_history_t * stonith__first_matching_event(stonith_history_t *history, bool(*matching_fn)(stonith_history_t *, void *), void *user_data)
#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)
int(* metadata)(stonith_t *st, int options, const char *device, const char *provider, char **output, int timeout)
Get the metadata documentation for a resource.
#define XML_ATTR_STONITH_DEVICES
int(* register_device)(stonith_t *st, int options, const char *id, const char *provider, const char *agent, stonith_key_value_t *params)
Register a stonith device with the local stonith daemon.
GList * stonith__parse_targets(const char *target_spec)
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 asynchronous call.
#define stonith__set_call_options(st_call_opts, call_for, flags_to_set)
#define crm_log_xml_debug(xml, text)
bool stonith_agent_exists(const char *agent, int timeout)
#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
int(* list_agents)(stonith_t *stonith, int call_options, const char *provider, stonith_key_value_t **devices, int timeout)
Retrieve a list of installed stonith agents.
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
stonith_history_t * stonith__sort_history(stonith_history_t *history)
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)
void log_action(unsigned int log_level, const char *pre_text, pe_action_t *action, gboolean details)
#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...)
Send a system error message to both the log and stderr.
#define pcmk__set_ipc_flags(ipc_flags, ipc_name, flags_to_set)
crm_ipc_t * mainloop_get_ipc_client(mainloop_io_t *client)
#define crm_err(fmt, args...)
#define G_PRIORITY_MEDIUM
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)
Send an IPC XML message.
stonith_t * stonith_api_new(void)
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)
crm_ipc_t * crm_ipc_new(const char *name, size_t max_size)
Create a new (legacy) object for using Pacemaker daemon IPC.
bool stonith__agent_is_lha(const char *agent)
Determine namespace of a fence agent.
bool stonith__event_state_pending(stonith_history_t *history, void *user_data)
#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)
bool pcmk__starts_with(const char *str, const char *prefix)
Check whether a string starts with a certain sequence.
#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)
#define F_STONITH_NOTIFY_ACTIVATE
void freeXpathObject(xmlXPathObjectPtr xpathObj)
void crm_ipc_close(crm_ipc_t *client)
#define F_STONITH_CALLDATA
CRM_TRACE_INIT_DATA(stonith)
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
#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