21 #include <sys/types.h>
37 struct stonith_action_s {
46 void (*done_cb) (GPid
pid, gint status,
const char *output, gpointer user_data);
47 void (*fork_cb) (GPid
pid, gpointer user_data);
52 time_t initial_start_time;
54 int remaining_timeout;
64 typedef struct stonith_private_s {
68 GHashTable *stonith_op_callback_table;
77 typedef struct stonith_notify_client_s {
86 typedef struct stonith_callback_client_s {
90 gboolean only_success;
91 gboolean allow_timeout_updates;
96 struct notify_blob_s {
108 typedef int (*
stonith_op_t) (
const char *, int,
const char *, xmlNode *,
109 xmlNode *, xmlNode *, xmlNode **, xmlNode **);
114 static int stonith_send_command(
stonith_t *stonith,
const char *op,
115 xmlNode *
data, xmlNode **output_data,
116 int call_options,
int timeout);
118 static void stonith_connection_destroy(gpointer user_data);
119 static void stonith_send_notification(gpointer
data, gpointer user_data);
133 if ((namespace_s == NULL) || !strcmp(namespace_s,
"any")) {
136 }
else if (!strcmp(namespace_s,
"redhat")
137 || !strcmp(namespace_s,
"stonith-ng")) {
140 }
else if (!strcmp(namespace_s,
"internal")) {
143 }
else if (!strcmp(namespace_s,
"heartbeat")) {
159 switch (st_namespace) {
166 return "unsupported";
188 #if HAVE_STONITH_STONITH_H
194 crm_err(
"Unknown fence agent: %s", agent);
201 if (action->output) {
227 private->notify_refcnt++;
228 g_list_foreach(private->notify_list, func, user_data);
229 private->notify_refcnt--;
230 if ((private->notify_refcnt == 0) &&
231 private->notify_deletes) {
232 GList *list_item =
private->notify_list;
234 private->notify_deletes = FALSE;
235 while (list_item != NULL)
238 GList *next = g_list_next(list_item);
240 if (list_client->delete) {
242 private->notify_list =
243 g_list_delete_link(private->notify_list, list_item);
251 stonith_connection_destroy(gpointer user_data)
255 struct notify_blob_s blob;
257 crm_trace(
"Sending destroyed notification");
258 blob.stonith = stonith;
263 native->source = NULL;
265 free(native->token); native->token = NULL;
270 foreach_notify_entry(native, stonith_send_notification, &blob);
277 const char *rsc_provides)
282 #if HAVE_STONITH_STONITH_H
287 hash2field((gpointer)
"plugin", (gpointer) agent, args);
288 agent =
"fence_legacy";
302 for (; params; params = params->
next) {
310 stonith_api_register_device(
stonith_t *
st,
int call_options,
311 const char *
id,
const char *
namespace,
const char *agent,
315 xmlNode *
data = NULL;
318 agent, params, NULL);
327 stonith_api_remove_device(
stonith_t * st,
int call_options,
const char *
name)
330 xmlNode *data = NULL;
342 stonith_api_remove_level_full(
stonith_t *st,
int options,
343 const char *node,
const char *pattern,
344 const char *attr,
const char *value,
int level)
347 xmlNode *data = NULL;
349 CRM_CHECK(node || pattern || (attr && value),
return -EINVAL);
357 }
else if (pattern) {
373 stonith_api_remove_level(
stonith_t * st,
int options,
const char *node,
int level)
375 return stonith_api_remove_level_full(st, options, node,
376 NULL, NULL, NULL, level);
396 const char *attr,
const char *value,
403 CRM_CHECK(node || pattern || (attr && value),
return NULL);
415 }
else if (pattern) {
425 for (; device_list; device_list = device_list->
next) {
436 stonith_api_register_level_full(
stonith_t * st,
int options,
const char *node,
438 const char *attr,
const char *value,
453 stonith_api_register_level(
stonith_t * st,
int options,
const char *node,
int level,
456 return stonith_api_register_level_full(st, options, node, NULL, NULL, NULL,
461 append_config_arg(gpointer key, gpointer value, gpointer user_data)
473 crm_trace(
"Passing %s=%s with fence action",
474 (
const char *) key, (
const char *) (value? value :
""));
475 g_hash_table_insert((GHashTable *) user_data,
476 strdup(key), strdup(value? value :
""));
481 make_args(
const char *agent,
const char *action,
const char *victim,
482 uint32_t victim_nodeid, GHashTable * device_args,
483 GHashTable * port_map,
const char *host_arg)
485 GHashTable *arg_list = NULL;
486 const char *value = NULL;
496 snprintf(buffer,
sizeof(buffer),
"pcmk_%s_action", action);
497 value = g_hash_table_lookup(device_args, buffer);
499 crm_debug(
"Substituting '%s' for fence action %s targeting %s",
500 value, action, victim);
510 if (victim && device_args) {
511 const char *param = NULL;
516 g_hash_table_insert(arg_list, strdup(
"nodename"), strdup(victim));
523 crm_info(
"Passing '%s' as nodeid with fence action '%s' targeting %s",
524 nodeid, action, victim);
525 g_hash_table_insert(arg_list, strdup(
"nodeid"), nodeid);
537 param = (host_arg == NULL)?
"port" : host_arg;
539 value = g_hash_table_lookup(device_args, param);
541 if (pcmk__str_eq(value,
"dynamic",
546 const char *alias = NULL;
549 alias = g_hash_table_lookup(port_map, victim);
554 crm_debug(
"Passing %s='%s' with fence action %s targeting %s",
555 param, alias, action, victim);
556 g_hash_table_insert(arg_list, strdup(param), strdup(alias));
562 g_hash_table_foreach(device_args, append_config_arg, arg_list);
580 g_hash_table_destroy(action->args);
582 free(action->action);
583 free(action->victim);
584 if (action->svc_action) {
587 free(action->output);
616 *error_output = NULL;
618 if (action != NULL) {
622 if (output && action->output) {
623 *output = action->output;
624 action->output = NULL;
626 if (error_output && action->error) {
627 *error_output = action->error;
628 action->error = NULL;
633 #define FAILURE_MAX_RETRIES 2
638 uint32_t victim_nodeid,
639 int timeout, GHashTable * device_args,
640 GHashTable * port_map,
const char *host_arg)
645 action->args = make_args(agent, _action, victim, victim_nodeid,
646 device_args, port_map, host_arg);
647 crm_debug(
"Preparing '%s' action for %s using agent %s",
648 _action, (victim? victim :
"no target"), agent);
649 action->agent = strdup(agent);
650 action->action = strdup(_action);
652 action->victim = strdup(victim);
654 action->timeout = action->remaining_timeout =
timeout;
659 const char *value = NULL;
661 snprintf(buffer,
sizeof(buffer),
"pcmk_%s_retries", _action);
662 value = g_hash_table_lookup(device_args, buffer);
665 action->max_retries = atoi(value);
675 int diff = time(NULL) - action->initial_start_time;
677 if (action->tries >= action->max_retries) {
678 crm_info(
"Attempted to execute agent %s (%s) the maximum number of times (%d) allowed",
679 action->agent, action->action, action->max_retries);
680 action->remaining_timeout = 0;
681 }
else if ((action->rc != -
ETIME) && diff < (action->timeout * 0.7)) {
684 action->remaining_timeout = action->timeout - diff;
686 action->remaining_timeout = 0;
688 return action->remaining_timeout ? TRUE : FALSE;
695 if (svc_action->
rc > 0) {
705 }
else if (strstr(svc_action->
stderr_data,
"imed out")) {
709 }
else if (strstr(svc_action->
stderr_data,
"Unrecognised action")) {
724 action->rc = svc_action_to_errno(svc_action);
730 svc_action->
params = NULL;
732 crm_debug(
"Child process %d performing action '%s' exited with rc %d",
733 action->pid, action->action, svc_action->
rc);
737 if (action->rc !=
pcmk_ok && update_remaining_timeout(action)) {
738 int rc = internal_stonith_action_execute(action);
744 if (action->done_cb) {
745 action->done_cb(action->pid, action->rc, action->output, action->userdata);
748 action->svc_action = NULL;
757 action->pid = svc_action->
pid;
758 action->svc_action = svc_action;
760 if (action->fork_cb) {
761 (action->fork_cb) (svc_action->
pid, action->userdata);
764 crm_trace(
"Child process %d performing action '%s' successfully forked",
765 action->pid, action->action);
774 static int stonith_sequence = 0;
777 if (!action->tries) {
778 action->initial_start_time = time(NULL);
782 if (action->tries > 1) {
783 crm_info(
"Attempt %d to execute %s (%s). remaining timeout is %d",
784 action->tries, action->agent, action->action, action->remaining_timeout);
788 if (action->args == NULL || action->agent == NULL)
792 basename(action->agent));
795 svc_action->
timeout = 1000 * action->remaining_timeout;
798 action->action, action->tries);
799 svc_action->
agent = strdup(action->agent);
800 svc_action->
sequence = stonith_sequence++;
801 svc_action->
params = action->args;
802 svc_action->
cb_data = (
void *) action;
803 svc_action->
flags = pcmk__set_flags_as(__func__, __LINE__,
805 svc_action->
id, svc_action->
flags,
807 "SVC_ACTION_NON_BLOCKED");
811 free(action->output);
812 action->output = NULL;
814 action->error = NULL;
821 &stonith_action_async_done,
822 &stonith_action_async_forked) == FALSE) {
833 action->
rc = svc_action_to_errno(svc_action);
839 action->rc = -ECONNABORTED;
843 svc_action->
params = NULL;
865 void (*done) (GPid pid,
int rc,
const char *output,
867 void (*fork_cb) (GPid pid, gpointer user_data))
873 action->userdata = userdata;
874 action->done_cb = done;
875 action->fork_cb = fork_cb;
878 return internal_stonith_action_execute(action);
894 CRM_CHECK(action != NULL,
return -EINVAL);
898 rc = internal_stonith_action_execute(action);
899 }
while ((rc !=
pcmk_ok) && update_remaining_timeout(action));
905 stonith_api_device_list(
stonith_t * stonith,
int call_options,
const char *
namespace,
911 if (devices == NULL) {
912 crm_err(
"Parameter error: stonith_api_device_list");
916 #if HAVE_STONITH_STONITH_H
932 stonith_api_device_metadata(
stonith_t * stonith,
int call_options,
const char *agent,
933 const char *
namespace,
char **output,
int timeout)
941 crm_trace(
"Looking up metadata for %s agent %s",
948 #if HAVE_STONITH_STONITH_H
954 crm_err(
"Can't get fence agent '%s' meta-data: No such agent",
962 stonith_api_query(
stonith_t * stonith,
int call_options,
const char *
target,
965 int rc = 0, lpc = 0, max = 0;
967 xmlNode *data = NULL;
968 xmlNode *output = NULL;
969 xmlXPathObjectPtr xpathObj = NULL;
971 CRM_CHECK(devices != NULL,
return -EINVAL);
977 rc = stonith_send_command(stonith,
STONITH_OP_QUERY, data, &output, call_options, timeout);
985 max = numXpathResults(xpathObj);
987 for (lpc = 0; lpc < max; lpc++) {
992 xmlChar *match_path = xmlGetNodePath(match);
994 crm_info(
"%s[%d] = %s",
"//@agent", lpc, match_path);
1012 const char *action,
const char *victim,
int timeout, xmlNode ** output)
1015 xmlNode *data = NULL;
1023 rc = stonith_send_command(stonith,
STONITH_OP_EXEC, data, output, call_options, timeout);
1030 stonith_api_list(
stonith_t * stonith,
int call_options,
const char *
id,
char **list_info,
1034 xmlNode *output = NULL;
1036 rc = stonith_api_call(stonith, call_options,
id,
"list", NULL, timeout, &output);
1038 if (output && list_info) {
1039 const char *list_str;
1044 *list_info = strdup(list_str);
1056 stonith_api_monitor(
stonith_t * stonith,
int call_options,
const char *
id,
int timeout)
1058 return stonith_api_call(stonith, call_options,
id,
"monitor", NULL, timeout, NULL);
1062 stonith_api_status(
stonith_t * stonith,
int call_options,
const char *
id,
const char *port,
1065 return stonith_api_call(stonith, call_options,
id,
"status", port, timeout, NULL);
1069 stonith_api_fence_with_delay(
stonith_t * stonith,
int call_options,
const char *node,
1073 xmlNode *data = NULL;
1082 rc = stonith_send_command(stonith,
STONITH_OP_FENCE, data, NULL, call_options, timeout);
1089 stonith_api_fence(
stonith_t * stonith,
int call_options,
const char *node,
const char *action,
1092 return stonith_api_fence_with_delay(stonith, call_options, node, action,
1093 timeout, tolerance, 0);
1097 stonith_api_confirm(
stonith_t * stonith,
int call_options,
const char *target)
1100 return stonith_api_fence(stonith, call_options, target,
"off", 0, 0);
1104 stonith_api_history(
stonith_t * stonith,
int call_options,
const char *node,
1108 xmlNode *data = NULL;
1109 xmlNode *output = NULL;
1121 call_options, timeout);
1129 for (op = pcmk__xml_first_child(reply); op != NULL;
1130 op = pcmk__xml_next(op)) {
1132 long long completed;
1162 for (hp = history; hp; hp_old = hp, hp = hp->
next, free(hp_old)) {
1172 stonithlib_GCompareFunc(gconstpointer a, gconstpointer b)
1178 if (a_client->delete || b_client->delete) {
1182 CRM_CHECK(a_client->event != NULL && b_client->event != NULL,
return 0);
1183 rc = strcmp(a_client->event, b_client->event);
1185 if (a_client->notify == NULL || b_client->notify == NULL) {
1188 }
else if (a_client->notify == b_client->notify) {
1191 }
else if (((
long)a_client->notify) < ((
long)b_client->notify)) {
1192 crm_err(
"callbacks for %s are not equal: %p vs. %p",
1193 a_client->event, a_client->notify, b_client->notify);
1196 crm_err(
"callbacks for %s are not equal: %p vs. %p",
1197 a_client->event, a_client->notify, b_client->notify);
1217 crm_trace(
"Sending call options: %.8lx, %d", (
long)call_options, call_options);
1228 stonith_destroy_op_callback(gpointer data)
1232 if (blob->timer && blob->timer->ref > 0) {
1233 g_source_remove(blob->timer->ref);
1240 stonith_api_signoff(
stonith_t * stonith)
1244 crm_debug(
"Disconnecting from the fencer");
1246 if (native->source != NULL) {
1249 native->source = NULL;
1252 }
else if (native->ipc) {
1261 free(native->token); native->token = NULL;
1267 stonith_api_del_callback(
stonith_t * stonith,
int call_id,
bool all_callbacks)
1271 if (all_callbacks) {
1272 private->op_callback = NULL;
1273 g_hash_table_destroy(private->stonith_op_callback_table);
1274 private->stonith_op_callback_table = pcmk__intkey_table(stonith_destroy_op_callback);
1276 }
else if (call_id == 0) {
1277 private->op_callback = NULL;
1280 pcmk__intkey_table_remove(private->stonith_op_callback_table, call_id);
1286 invoke_callback(
stonith_t * st,
int call_id,
int rc,
void *userdata,
1295 callback(st, &data);
1299 stonith_perform_callback(
stonith_t * stonith, xmlNode * msg,
int call_id,
int rc)
1310 local_blob.id = NULL;
1311 local_blob.callback = NULL;
1312 local_blob.user_data = NULL;
1313 local_blob.only_success = FALSE;
1322 blob = pcmk__intkey_table_lookup(private->stonith_op_callback_table,
1328 stonith_api_del_callback(stonith, call_id, FALSE);
1331 crm_trace(
"No callback found for call %d", call_id);
1332 local_blob.callback = NULL;
1335 if (local_blob.callback != NULL && (rc ==
pcmk_ok || local_blob.only_success == FALSE)) {
1336 crm_trace(
"Invoking callback %s for call %d",
crm_str(local_blob.id), call_id);
1337 invoke_callback(stonith, call_id, rc, local_blob.user_data, local_blob.callback);
1339 }
else if (private->op_callback == NULL && rc !=
pcmk_ok) {
1344 if (private->op_callback != NULL) {
1345 crm_trace(
"Invoking global callback for call %d", call_id);
1346 invoke_callback(stonith, call_id, rc, NULL, private->op_callback);
1352 stonith_async_timeout_handler(gpointer data)
1369 struct timer_rec_s *async_timer = callback->timer;
1376 async_timer = calloc(1,
sizeof(
struct timer_rec_s));
1377 callback->timer = async_timer;
1385 async_timer->
timeout = (timeout + 60) * 1000;
1386 if (async_timer->
ref) {
1387 g_source_remove(async_timer->
ref);
1390 g_timeout_add(async_timer->
timeout, stonith_async_timeout_handler, async_timer);
1394 update_callback_timeout(
int call_id,
int timeout,
stonith_t * st)
1399 callback = pcmk__intkey_table_lookup(private->stonith_op_callback_table,
1401 if (!callback || !callback->allow_timeout_updates) {
1405 set_callback_timeout(callback, st, call_id, timeout);
1409 stonith_dispatch_internal(
const char *buffer, ssize_t length, gpointer userdata)
1411 const char *
type = NULL;
1412 struct notify_blob_s blob;
1418 private = st->st_private;
1422 if (blob.xml == NULL) {
1423 crm_warn(
"Received malformed message from fencer: %s", buffer);
1429 crm_trace(
"Activating %s callbacks...", type);
1432 stonith_perform_callback(st, blob.xml, 0, 0);
1435 foreach_notify_entry(
private, stonith_send_notification, &blob);
1443 update_callback_timeout(call_id, timeout, st);
1445 crm_err(
"Unknown message type: %s", type);
1454 stonith_api_signon(
stonith_t * stonith,
const char *
name,
int *stonith_fd)
1458 const char *display_name = name? name :
"client";
1461 .
dispatch = stonith_dispatch_internal,
1462 .destroy = stonith_connection_destroy
1465 CRM_CHECK(stonith != NULL,
return -EINVAL);
1470 crm_debug(
"Attempting fencer connection by %s with%s mainloop",
1471 display_name, (stonith_fd?
"out" :
""));
1480 }
else if (native->ipc) {
1493 if (native->ipc == NULL) {
1496 xmlNode *reply = NULL;
1505 crm_debug(
"Couldn't register with the fencer: %s "
1509 }
else if (reply == NULL) {
1510 crm_debug(
"Couldn't register with the fencer: no reply");
1518 crm_debug(
"Couldn't register with the fencer: invalid reply type '%s'",
1519 (msg_type? msg_type :
"(missing)"));
1523 }
else if (native->token == NULL) {
1524 crm_debug(
"Couldn't register with the fencer: no token in reply");
1529 #if HAVE_MSGFROMIPC_TIMEOUT
1532 crm_debug(
"Connection to fencer by %s succeeded (registration token: %s)",
1533 display_name, native->token);
1543 crm_debug(
"Connection attempt to fencer by %s failed: %s "
1551 stonith_set_notification(
stonith_t * stonith,
const char *callback,
int enabled)
1568 crm_perror(LOG_DEBUG,
"Couldn't register for fencing notifications: %d", rc);
1580 stonith_api_add_notification(
stonith_t * stonith,
const char *event,
1583 GList *list_item = NULL;
1588 crm_trace(
"Adding callback for %s events (%d)", event, g_list_length(private->notify_list));
1591 new_client->event = event;
1592 new_client->notify = callback;
1594 list_item = g_list_find_custom(private->notify_list, new_client, stonithlib_GCompareFunc);
1596 if (list_item != NULL) {
1597 crm_warn(
"Callback already present");
1602 private->notify_list = g_list_append(private->notify_list, new_client);
1604 stonith_set_notification(stonith, event, 1);
1606 crm_trace(
"Callback added (%d)", g_list_length(private->notify_list));
1612 stonith_api_del_notification(
stonith_t * stonith,
const char *event)
1614 GList *list_item = NULL;
1618 crm_debug(
"Removing callback for %s events", event);
1622 new_client->event = event;
1623 new_client->notify = NULL;
1625 list_item = g_list_find_custom(private->notify_list, new_client, stonithlib_GCompareFunc);
1627 stonith_set_notification(stonith, event, 0);
1629 if (list_item != NULL) {
1632 if (private->notify_refcnt) {
1633 list_client->delete = TRUE;
1634 private->notify_deletes = TRUE;
1636 private->notify_list = g_list_remove(private->notify_list, list_client);
1650 stonith_api_add_callback(
stonith_t * stonith,
int call_id,
int timeout,
int options,
1651 void *user_data,
const char *callback_name,
1657 CRM_CHECK(stonith != NULL,
return -EINVAL);
1662 private->op_callback = callback;
1664 }
else if (call_id < 0) {
1667 invoke_callback(stonith, call_id, call_id, user_data, callback);
1675 blob->id = callback_name;
1677 blob->user_data = user_data;
1678 blob->callback = callback;
1682 set_callback_timeout(blob, stonith, call_id, timeout);
1685 pcmk__intkey_table_insert(private->stonith_op_callback_table, call_id,
1687 crm_trace(
"Added callback to %s for call %d", callback_name, call_id);
1693 stonith_dump_pending_op(gpointer key, gpointer value, gpointer user_data)
1695 int call = GPOINTER_TO_INT(key);
1706 if (private->stonith_op_callback_table == NULL) {
1709 return g_hash_table_foreach(private->stonith_op_callback_table, stonith_dump_pending_op, NULL);
1732 xml_to_event(xmlNode * msg)
1756 crm_err(
"No data for %s event", ntype);
1782 stonith_send_notification(gpointer data, gpointer user_data)
1784 struct notify_blob_s *blob = user_data;
1787 const char *
event = NULL;
1789 if (blob->xml == NULL) {
1790 crm_warn(
"Skipping callback - NULL message");
1796 if (entry == NULL) {
1797 crm_warn(
"Skipping callback - NULL callback client");
1800 }
else if (entry->delete) {
1801 crm_trace(
"Skipping callback - marked for deletion");
1804 }
else if (entry->notify == NULL) {
1805 crm_warn(
"Skipping callback - NULL callback");
1809 crm_trace(
"Skipping callback - event mismatch %p/%s vs. %s", entry, entry->event, event);
1813 st_event = xml_to_event(blob->xml);
1815 crm_trace(
"Invoking callback for %p/%s event...", entry, event);
1816 entry->notify(blob->stonith, st_event);
1819 event_free(st_event);
1837 stonith_send_command(
stonith_t * stonith,
const char *op, xmlNode * data, xmlNode ** output_data,
1838 int call_options,
int timeout)
1843 xmlNode *op_msg = NULL;
1844 xmlNode *op_reply = NULL;
1850 if (output_data != NULL) {
1851 *output_data = NULL;
1868 if (op_msg == NULL) {
1873 crm_trace(
"Sending %s message to fencer with timeout %ds", op, timeout);
1891 1000 * (timeout + 60), &op_reply);
1896 crm_perror(LOG_ERR,
"Couldn't perform %s operation (timeout=%ds): %d", op, timeout, rc);
1912 if (reply_id == stonith->
call_id) {
1913 crm_trace(
"Synchronous reply %d received", reply_id);
1923 *output_data = op_reply;
1927 }
else if (reply_id <= 0) {
1928 crm_err(
"Received bad reply: No id set");
1934 crm_err(
"Received bad reply: %d (wanted %d)", reply_id, stonith->
call_id);
1942 crm_err(
"Fencer disconnected");
1943 free(native->token); native->token = NULL;
1955 gboolean stay_connected = TRUE;
1966 stonith_dispatch_internal(msg, strlen(msg), st);
1971 stay_connected = FALSE;
1975 return stay_connected;
1986 crm_trace(
"Disconnecting %p first", stonith);
1993 crm_trace(
"Removing %d callbacks", g_hash_table_size(private->stonith_op_callback_table));
1994 g_hash_table_destroy(private->stonith_op_callback_table);
1996 crm_trace(
"Destroying %d notification clients", g_list_length(private->notify_list));
1997 g_list_free_full(private->notify_list, free);
2000 free(stonith->
cmds);
2020 stonith_api_validate(
stonith_t *st,
int call_options,
const char *rsc_id,
2021 const char *namespace_s,
const char *agent,
2023 char **error_output)
2036 const char *target =
"node1";
2037 const char *host_arg = NULL;
2042 for (; params; params = params->
next) {
2045 host_arg = params->
value;
2048 g_hash_table_insert(params_table, strdup(params->
key),
2049 strdup(params->
value));
2053 #if SUPPORT_CIBSECRETS
2056 crm_warn(
"Could not replace secret parameters for validation of %s: %s",
2066 *error_output = NULL;
2072 params_table, host_arg, timeout,
2073 output, error_output);
2076 #if HAVE_STONITH_STONITH_H
2079 params_table, timeout, output,
2088 "Agent %s not found or does not support validation",
2092 g_hash_table_destroy(params_table);
2102 new_stonith = calloc(1,
sizeof(
stonith_t));
2103 if (new_stonith == NULL) {
2108 if (
private == NULL) {
2114 private->stonith_op_callback_table = pcmk__intkey_table(stonith_destroy_op_callback);
2115 private->notify_list = NULL;
2116 private->notify_refcnt = 0;
2117 private->notify_deletes = FALSE;
2123 if (new_stonith->
cmds == NULL) {
2130 new_stonith->
cmds->
free = stonith_api_free;
2134 new_stonith->
cmds->
list = stonith_api_list;
2136 new_stonith->
cmds->
status = stonith_api_status;
2137 new_stonith->
cmds->
fence = stonith_api_fence;
2143 new_stonith->
cmds->
metadata = stonith_api_device_metadata;
2145 new_stonith->
cmds->
query = stonith_api_query;
2179 for (
int attempt = 1; attempt <= max_attempts; attempt++) {
2183 }
else if (attempt < max_attempts) {
2184 crm_notice(
"Fencer connection attempt %d of %d failed (retrying in 2s): %s "
2202 p->
key = strdup(key);
2205 p->
value = strdup(value);
2209 while (end && end->
next) {
2240 #define api_log_open() openlog("stonith-api", LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON)
2241 #define api_log(level, fmt, args...) syslog(level, "%s: "fmt, __func__, args)
2248 const char *action = off?
"off" :
"reboot";
2252 api_log(LOG_ERR,
"API initialization failed, could not kick (%s) node %u/%s",
2253 action, nodeid, uname);
2259 api_log(LOG_ERR,
"Connection failed, could not kick (%s) node %u/%s : %s (%d)",
2262 char *name = (uname == NULL)? pcmk__itoa(nodeid) : strdup(uname);
2267 if ((uname == NULL) && (nodeid > 0)) {
2270 rc = st->
cmds->
fence(st, opts, name, action, timeout, 0);
2274 api_log(LOG_ERR,
"Could not kick (%s) node %u/%s : %s (%d)",
2277 api_log(LOG_NOTICE,
"Node %u/%s kicked: %s", nodeid, uname, action);
2294 api_log(LOG_ERR,
"Could not retrieve fence history for %u/%s: "
2295 "API initialization failed", nodeid, uname);
2307 char *name = (uname == NULL)? pcmk__itoa(nodeid) : strdup(uname);
2310 if ((uname == NULL) && (nodeid > 0)) {
2313 rc = st->
cmds->
history(st, opts, name, &history, 120);
2316 for (hp = history; hp; hp = hp->
next) {
2324 }
else if (hp->state ==
st_done) {
2326 if (hp->completed > when) {
2327 when = hp->completed;
2335 api_log(LOG_INFO,
"Found %d entries for %u/%s: %d in progress, %d completed", entries, nodeid, uname, progress, completed);
2337 api_log(LOG_ERR,
"Could not retrieve fence history for %u/%s: %s (%d)", nodeid, uname,
pcmk_strerror(rc), rc);
2344 api_log(LOG_INFO,
"Node %u/%s last kicked at: %ld", nodeid, uname, (
long int)when);
2357 if (agent == NULL) {
2363 crm_err(
"Could not list fence agents: API memory allocation failed");
2366 st->
cmds->
list_agents(st, st_opt_sync_call, NULL, &devices, timeout == 0 ? 120 : timeout);
2368 for (dIter = devices; dIter != NULL; dIter = dIter->
next) {
2383 if (action == NULL) {
2385 }
else if (!strcmp(action,
"on")) {
2387 }
else if (!strcmp(action,
"off")) {
2388 return "turning off";
2403 parse_list_line(
const char *line,
int len, GList **output)
2406 size_t entry_start = 0;
2412 if (strstr(line,
"invalid") || strstr(line,
"variable")) {
2413 crm_debug(
"Skipping list output line: %s", line);
2418 for (i = 0; i <= len; i++) {
2420 if (isspace(line[i]) || (line[i] ==
',') || (line[i] ==
';')
2421 || (line[i] ==
'\0')) {
2427 if (i == entry_start) {
2429 entry_start = i + 1;
2433 entry = calloc(i - entry_start + 1,
sizeof(
char));
2440 rc = sscanf(line + entry_start,
"%[a-zA-Z0-9_-.]", entry);
2442 crm_warn(
"Could not parse list output entry: %s "
2443 CRM_XS " entry_start=%d position=%d",
2444 line + entry_start, entry_start, i);
2460 *output = g_list_append(*output, entry);
2462 entry_start = i + 1;
2491 GList *targets = NULL;
2493 if (target_spec != NULL) {
2494 size_t out_len = strlen(target_spec);
2495 size_t line_start = 0;
2497 for (
size_t i = 0; i <= out_len; ++i) {
2498 if ((target_spec[i] ==
'\n') || (target_spec[i] ==
'\0')
2499 || ((target_spec[i] ==
'\\') && (target_spec[i + 1] ==
'n'))) {
2502 int len = i - line_start;
2505 char *line =
strndup(target_spec + line_start, len);
2508 parse_list_line(line, len, &targets);
2511 if (target_spec[i] ==
'\\') {
2531 gboolean ret = FALSE;
2534 if (prev_hp == event) {
2538 if ((prev_hp->state ==
st_done) &&
2542 (event->
completed < prev_hp->completed)) {
2564 for (hp = history; hp; ) {
2568 if ((!
new) || (hp->completed > new->completed)) {
2574 if ((!np->next) || (hp->completed > np->next->completed)) {
2594 while (last_pending->
next) {
2595 last_pending = last_pending->
next;
2598 last_pending->
next =
new;
2616 case st_exec:
return "executing";
2617 case st_done:
return "completed";
2630 if (matching_fn(hp, user_data)) {
2647 return history->
state == GPOINTER_TO_INT(user_data);
2653 return history->
state != GPOINTER_TO_INT(user_data);
2660 xmlXPathObjectPtr xpath = NULL;
2664 CRM_CHECK((device_flags != NULL) && (metadata != NULL),
return);
2667 max = numXpathResults(xpath);
2674 for (lpc = 0; lpc < max; lpc++) {
2675 const char *parameter = NULL;
2679 if (match == NULL) {
void stonith__destroy_action(stonith_action_t *action)
#define CRM_CHECK(expr, failure_action)
#define XML_ATTR_STONITH_TARGET_ATTRIBUTE
struct stonith_action_s stonith_action_t
const char * get_stonith_provider(const char *agent, const char *provider)
#define F_STONITH_REMOTE_OP_ID
int(* query)(stonith_t *st, int options, const char *node, stonith_key_value_t **devices, int timeout)
Retrieve a list of registered stonith devices.
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...)
#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)
stonith_history_t * stonith__first_matching_event(stonith_history_t *history, bool(*matching_fn)(stonith_history_t *, void *), void *user_data)
void services_action_free(svc_action_t *op)
void stonith__action_result(stonith_action_t *action, int *rc, char **output, char **error_output)
int(* register_notification)(stonith_t *st, const char *event, void(*notify)(stonith_t *st, stonith_event_t *e))
#define PCMK__FENCE_BINDIR
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.
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.
int stonith__execute(stonith_action_t *action)
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)
bool pcmk__strcase_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
#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 stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off)
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.
#define F_STONITH_CALLBACK_TOKEN
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...
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.
enum stonith_namespace stonith_get_namespace(const char *agent, const char *namespace_s)
Determine namespace of a fence agent.
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
bool pcmk_stonith_param(const char *param)
Check whether a given stonith parameter is handled by Pacemaker.
stonith_history_t * stonith__sort_history(stonith_history_t *history)
struct stonith_key_value_s * next
struct mainloop_io_s mainloop_io_t
int(* monitor)(stonith_t *st, int options, const char *id, int timeout)
Check to see if a local stonith device is reachable.
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 *))
#define F_STONITH_TIMEOUT
int stonith__lha_metadata(const char *agent, int timeout, char **output)
int(* free)(stonith_t *st)
Destroy the stonith api structure.
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 T_STONITH_TIMEOUT_VALUE
#define CRM_LOG_ASSERT(expr)
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.
long crm_ipc_read(crm_ipc_t *client)
enum crm_ais_msg_types type
#define F_STONITH_NOTIFY_DEACTIVATE
int(* confirm)(stonith_t *st, int options, const char *node)
Manually confirm that a node is down.
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.
int crm_element_value_int(const xmlNode *data, const char *name, int *dest)
Retrieve the integer value of an XML attribute.
xmlNode * get_xpath_object(const char *xpath, xmlNode *xml_obj, int error_level)
Wrappers for and extensions to glib mainloop.
#define STONITH_OP_LEVEL_DEL
bool stonith_dispatch(stonith_t *st)
char * strndup(const char *str, size_t len)
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))
#define STONITH_OP_DEVICE_ADD
stonith_t * stonith_api_new(void)
xmlNode * string2xml(const char *input)
bool stonith__event_state_pending(stonith_history_t *history, void *user_data)
int stonith_api_connect_retry(stonith_t *st, const char *name, int max_attempts)
Make a blocking connection attempt to the fencer.
const char * crm_ipc_buffer(crm_ipc_t *client)
int(* stonith_op_t)(const char *, int, const char *, xmlNode *, xmlNode *, xmlNode *, xmlNode **, xmlNode **)
int stonith__list_lha_agents(stonith_key_value_t **devices)
#define CRM_TRACE_INIT_DATA(name)
stonith_key_value_t * stonith_key_value_add(stonith_key_value_t *kvp, const char *key, const char *value)
int(* remove_callback)(stonith_t *st, int call_id, bool all_callbacks)
Remove a registered callback for a given call id.
GList * stonith__parse_targets(const char *hosts)
enum svc_action_flags flags
#define XML_ATTR_STONITH_TARGET_PATTERN
#define crm_warn(fmt, args...)
bool stonith__agent_is_rhcs(const char *agent)
bool stonith_agent_exists(const char *agent, int timeout)
const char * stonith_op_state_str(enum op_state state)
Return string equivalent of an operation state value.
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 crm_debug(fmt, args...)
#define STONITH_OP_LEVEL_ADD
struct crm_ipc_s crm_ipc_t
const char * stonith_action_str(const char *action)
Turn stonith action into a more readable string.
void stonith__device_parameter_flags(uint32_t *device_flags, const char *device_name, xmlNode *metadata)
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
#define crm_trace(fmt, args...)
#define XML_ATTR_STONITH_INDEX
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
#define stonith__set_call_options(st_call_opts, call_for, flags_to_set)
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 crm_log_xml_debug(xml, text)
#define XML_ATTR_STONITH_TARGET
gboolean stonith__later_succeeded(stonith_history_t *event, stonith_history_t *top_history)
Wrappers for and extensions to libxml2.
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.
xmlNode * create_xml_node(xmlNode *parent, const char *name)
#define crm_log_xml_warn(xml, text)
int(* remove_level)(stonith_t *st, int options, const char *node, int level)
Remove a fencing level for a specific node.
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.
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)
void stonith_key_value_freeall(stonith_key_value_t *kvp, int keys, int values)
#define T_STONITH_NOTIFY_DISCONNECT
#define PCMK__IPC_TIMEOUT
#define STONITH_OP_DEVICE_DEL
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
void stonith_dump_pending_callbacks(stonith_t *st)
gboolean add_message_xml(xmlNode *msg, const char *field, xmlNode *xml)
void free_xml(xmlNode *child)
#define api_log(level, fmt, args...)
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.
#define STONITH_ATTR_ACTION_OP
#define STONITH_OP_FENCE_HISTORY
#define F_STONITH_CALLOPTS
struct stonith_private_s stonith_private_t
bool crm_ipc_connected(crm_ipc_t *client)
#define PCMK_RESOURCE_CLASS_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.
int crm_ipc_ready(crm_ipc_t *client)
Check whether an IPC connection is ready to be read.
#define PCMK_STONITH_HOST_ARGUMENT
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.
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
void stonith_api_delete(stonith_t *st)
int stonith__list_rhcs_agents(stonith_key_value_t **devices)
GHashTable * pcmk__strkey_table(GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func)
#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(* fence)(stonith_t *st, int options, const char *node, const char *action, int timeout, int tolerance)
Issue a fencing action against a node.
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.
#define FAILURE_MAX_RETRIES
void stonith_history_free(stonith_history_t *history)
#define crm_log_xml_notice(xml, text)
xmlNode * getXpathResult(xmlXPathObjectPtr xpathObj, int index)
int(* connect)(stonith_t *st, const char *name, int *stonith_fd)
Connect to the local stonith daemon.
crm_ipc_t * crm_ipc_new(const char *name, size_t max_size)
Create a new (legacy) object for using Pacemaker daemon IPC.
int(* remove_device)(stonith_t *st, int options, const char *name)
Remove a registered stonith device with the local stonith daemon.
int(* disconnect)(stonith_t *st)
Disconnect from the local stonith daemon.
bool stonith__agent_is_lha(const char *agent)
Determine namespace of a fence agent.
time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress)
#define T_STONITH_NOTIFY_FENCE
#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)
enum stonith_namespace stonith_text2namespace(const char *namespace_s)
Get agent namespace by name.
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.
#define F_STONITH_NOTIFY_ACTIVATE
Deprecated Pacemaker fencing API.
const char * stonith_namespace2text(enum stonith_namespace st_namespace)
Get agent namespace name.
void freeXpathObject(xmlXPathObjectPtr xpathObj)
bool stonith__event_state_eq(stonith_history_t *history, void *user_data)
void crm_ipc_close(crm_ipc_t *client)
#define F_STONITH_CALLDATA
#define F_STONITH_DELEGATE
#define crm_info(fmt, args...)
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(* dispatch)(const char *buffer, ssize_t length, gpointer userdata)
Dispatch function for an IPC connection used as mainloop source.
#define F_STONITH_HISTORY_LIST
int(* remove_notification)(stonith_t *st, const char *event)
bool stonith__event_state_neq(stonith_history_t *history, void *user_data)
#define F_STONITH_TOLERANCE