21#include <libxml/tree.h>
22#include <libxml/xpath.h>
36typedef struct stonith_private_s {
40 GHashTable *stonith_op_callback_table;
54typedef struct stonith_notify_client_s {
63typedef struct stonith_callback_client_s {
67 gboolean only_success;
68 gboolean allow_timeout_updates;
85typedef int (*
stonith_op_t) (
const char *, int,
const char *, xmlNode *,
86 xmlNode *, xmlNode *, xmlNode **, xmlNode **);
90static int stonith_send_command(
stonith_t *stonith,
const char *op,
91 xmlNode *
data, xmlNode **output_data,
94static void stonith_connection_destroy(gpointer user_data);
95static void stonith_send_notification(gpointer
data, gpointer user_data);
96static int stonith_api_del_notification(
stonith_t *stonith,
108parse_namespace(
const char *namespace_s)
139 switch (st_namespace) {
149 return "unsupported";
166get_namespace_from_agent(
const char *agent)
172#if HAVE_STONITH_STONITH_H
190 int rc = stonith_api->
cmds->
connect(stonith_api,
"stonith-api", NULL);
193 crm_err(
"Failed connecting to Stonith-API for watchdog-fencing-query.");
202 if ((rc !=
pcmk_ok) || (list == NULL)) {
208 crm_notice(
"Cluster does not have watchdog fencing device");
210 crm_warn(
"Could not check for watchdog fencing device: %s",
213 }
else if (list[0] ==
'\0') {
218 g_list_free_full(targets, free);
233 crm_err(
"Stonith-API for watchdog-fencing-query couldn't be created.");
235 crm_trace(
"Pacemaker assumes node %s %sto do watchdog-fencing.",
255 private->notify_refcnt++;
256 g_list_foreach(private->notify_list, func, user_data);
257 private->notify_refcnt--;
258 if ((private->notify_refcnt == 0) &&
259 private->notify_deletes) {
260 GList *list_item =
private->notify_list;
262 private->notify_deletes = FALSE;
263 while (list_item != NULL)
266 GList *next = g_list_next(list_item);
268 if (list_client->delete) {
270 private->notify_list =
271 g_list_delete_link(private->notify_list, list_item);
279stonith_connection_destroy(gpointer user_data)
283 struct notify_blob_s blob;
285 crm_trace(
"Sending destroyed notification");
286 blob.stonith = stonith;
291 native->source = NULL;
293 free(native->token); native->token = NULL;
298 foreach_notify_entry(native, stonith_send_notification, &blob);
306 const char *rsc_provides)
311#if HAVE_STONITH_STONITH_H
313 standard = get_namespace_from_agent(agent);
316 hash2field((gpointer)
"plugin", (gpointer) agent, args);
317 agent =
"fence_legacy";
331 for (; params; params = params->
next) {
339stonith_api_register_device(
stonith_t *
st,
int call_options,
340 const char *
id,
const char *namespace_s,
345 xmlNode *
data = NULL;
348 agent, params, NULL);
357stonith_api_remove_device(
stonith_t *
st,
int call_options,
const char *
name)
360 xmlNode *
data = NULL;
372stonith_api_remove_level_full(
stonith_t *
st,
int options,
373 const char *node,
const char *pattern,
374 const char *attr,
const char *value,
int level)
377 xmlNode *
data = NULL;
379 CRM_CHECK(node || pattern || (attr && value),
return -EINVAL);
387 }
else if (pattern) {
403stonith_api_remove_level(
stonith_t *
st,
int options,
const char *node,
int level)
405 return stonith_api_remove_level_full(
st, options, node,
406 NULL, NULL, NULL, level);
426 const char *attr,
const char *value,
429 GString *list = NULL;
432 CRM_CHECK(node || pattern || (attr && value),
return NULL);
443 }
else if (pattern) {
451 for (; device_list; device_list = device_list->
next) {
457 g_string_free(list, TRUE);
463stonith_api_register_level_full(
stonith_t *
st,
int options,
const char *node,
464 const char *pattern,
const char *attr,
465 const char *value,
int level,
480stonith_api_register_level(
stonith_t *
st,
int options,
const char *node,
int level,
483 return stonith_api_register_level_full(
st, options, node, NULL, NULL, NULL,
488stonith_api_device_list(
stonith_t *stonith,
int call_options,
495 if (devices == NULL) {
496 crm_err(
"Parameter error: stonith_api_device_list");
500#if HAVE_STONITH_STONITH_H
517stonith_api_device_metadata(
stonith_t *stonith,
int call_options,
518 const char *agent,
const char *namespace_s,
519 char **output,
int timeout_sec)
527 if (timeout_sec <= 0) {
531 crm_trace(
"Looking up metadata for %s agent %s", namespace_text(ns), agent);
537#if HAVE_STONITH_STONITH_H
543 crm_err(
"Can't get fence agent '%s' meta-data: No such agent",
551stonith_api_query(
stonith_t * stonith,
int call_options,
const char *
target,
554 int rc = 0, lpc = 0, max = 0;
556 xmlNode *
data = NULL;
557 xmlNode *output = NULL;
558 xmlXPathObject *xpathObj = NULL;
560 CRM_CHECK(devices != NULL,
return -EINVAL);
574 max = pcmk__xpath_num_results(xpathObj);
576 for (lpc = 0; lpc < max; lpc++) {
582 xmlChar *match_path = xmlGetNodePath(match);
590 xmlXPathFreeObject(xpathObj);
611stonith_api_call(
stonith_t *stonith,
int call_options,
const char *
id,
612 const char *
action,
const char *
target,
int timeout_sec,
616 xmlNode *
data = NULL;
625 call_options, timeout_sec);
632stonith_api_list(
stonith_t * stonith,
int call_options,
const char *
id,
char **list_info,
636 xmlNode *output = NULL;
641 if (output && list_info) {
642 const char *list_str;
647 *list_info = strdup(list_str);
659stonith_api_monitor(
stonith_t * stonith,
int call_options,
const char *
id,
int timeout)
666stonith_api_status(
stonith_t * stonith,
int call_options,
const char *
id,
const char *port,
674stonith_api_fence_with_delay(
stonith_t * stonith,
int call_options,
const char *node,
678 xmlNode *
data = NULL;
694stonith_api_fence(
stonith_t * stonith,
int call_options,
const char *node,
const char *
action,
697 return stonith_api_fence_with_delay(stonith, call_options, node,
action,
702stonith_api_confirm(
stonith_t * stonith,
int call_options,
const char *
target)
710stonith_api_history(
stonith_t * stonith,
int call_options,
const char *node,
714 xmlNode *
data = NULL;
715 xmlNode *output = NULL;
740 long long completed_nsec = 0L;
782 while (head != NULL) {
797stonithlib_GCompareFunc(gconstpointer a, gconstpointer b)
803 if (a_client->delete || b_client->delete) {
807 CRM_CHECK(a_client->event != NULL && b_client->event != NULL,
return 0);
808 rc = strcmp(a_client->event, b_client->event);
810 if (a_client->notify == NULL || b_client->notify == NULL) {
813 }
else if (a_client->notify == b_client->notify) {
816 }
else if (((
long)a_client->notify) < ((
long)b_client->notify)) {
817 crm_err(
"callbacks for %s are not equal: %p vs. %p",
818 a_client->event, a_client->notify, b_client->notify);
821 crm_err(
"callbacks for %s are not equal: %p vs. %p",
822 a_client->event, a_client->notify, b_client->notify);
831 xmlNode *op_msg = NULL;
839 crm_trace(
"Sending call options: %.8lx, %d", (
long)call_options, call_options);
852stonith_destroy_op_callback(gpointer
data)
856 if (blob->timer && blob->timer->
ref > 0) {
857 g_source_remove(blob->timer->
ref);
868 crm_debug(
"Disconnecting from the fencer");
870 if (native->source != NULL) {
873 native->source = NULL;
876 }
else if (native->ipc) {
885 free(native->token); native->token = NULL;
891stonith_api_del_callback(
stonith_t * stonith,
int call_id,
bool all_callbacks)
896 private->op_callback = NULL;
897 g_hash_table_destroy(private->stonith_op_callback_table);
898 private->stonith_op_callback_table = pcmk__intkey_table(stonith_destroy_op_callback);
900 }
else if (call_id == 0) {
901 private->op_callback = NULL;
904 pcmk__intkey_table_remove(private->stonith_op_callback_table, call_id);
921invoke_fence_action_callback(
stonith_t *
st,
int call_id,
931 data.userdata = userdata;
949invoke_registered_callbacks(
stonith_t *stonith,
const xmlNode *msg,
int call_id)
963 "Fencer accepted request but did not reply in time");
976 cb_info = pcmk__intkey_table_lookup(private->stonith_op_callback_table,
980 if ((cb_info != NULL) && (cb_info->callback != NULL)
981 && (pcmk__result_ok(&
result) || !(cb_info->only_success))) {
982 crm_trace(
"Invoking callback %s for call %d",
983 pcmk__s(cb_info->id,
"without ID"), call_id);
984 invoke_fence_action_callback(stonith, call_id, &
result,
985 cb_info->user_data, cb_info->callback);
987 }
else if ((private->op_callback == NULL) && !pcmk__result_ok(&
result)) {
988 crm_warn(
"Fencing action without registered callback failed: %d (%s%s%s)",
996 if (private->op_callback != NULL) {
997 crm_trace(
"Invoking global callback for call %d", call_id);
998 invoke_fence_action_callback(stonith, call_id, &
result, NULL,
999 private->op_callback);
1002 if (cb_info != NULL) {
1003 stonith_api_del_callback(stonith, call_id, FALSE);
1009stonith_async_timeout_handler(gpointer
data)
1014 invoke_registered_callbacks(timer->
stonith, NULL, timer->
call_id);
1026 struct timer_rec_s *async_timer = callback->timer;
1034 callback->timer = async_timer;
1043 if (async_timer->
ref) {
1044 g_source_remove(async_timer->
ref);
1057 callback = pcmk__intkey_table_lookup(private->stonith_op_callback_table,
1059 if (!callback || !callback->allow_timeout_updates) {
1067stonith_dispatch_internal(
const char *buffer, ssize_t length, gpointer userdata)
1069 const char *
type = NULL;
1070 struct notify_blob_s blob;
1080 if (blob.xml == NULL) {
1081 crm_warn(
"Received malformed message from fencer: %s", buffer);
1090 invoke_registered_callbacks(
st, blob.xml, 0);
1093 foreach_notify_entry(
private, stonith_send_notification, &blob);
1103 update_callback_timeout(call_id,
timeout,
st);
1114stonith_api_signon(
stonith_t * stonith,
const char *
name,
int *stonith_fd)
1118 const char *display_name =
name?
name :
"client";
1121 .dispatch = stonith_dispatch_internal,
1122 .destroy = stonith_connection_destroy
1125 CRM_CHECK(stonith != NULL,
return -EINVAL);
1130 crm_debug(
"Attempting fencer connection by %s with%s mainloop",
1131 display_name, (stonith_fd?
"out" :
""));
1137 if (native->ipc != NULL) {
1142 crm_debug(
"Couldn't get file descriptor for IPC: %s",
1160 if (native->ipc == NULL) {
1163 xmlNode *reply = NULL;
1172 crm_debug(
"Couldn't register with the fencer: %s "
1176 }
else if (reply == NULL) {
1177 crm_debug(
"Couldn't register with the fencer: no reply");
1185 crm_debug(
"Couldn't register with the fencer: invalid reply type '%s'",
1186 (msg_type? msg_type :
"(missing)"));
1190 }
else if (native->token == NULL) {
1191 crm_debug(
"Couldn't register with the fencer: no token in reply");
1196 crm_debug(
"Connection to fencer by %s succeeded (registration token: %s)",
1197 display_name, native->token);
1207 crm_debug(
"Connection attempt to fencer by %s failed: %s "
1215stonith_set_notification(
stonith_t * stonith,
const char *callback,
int enabled)
1232 crm_perror(LOG_DEBUG,
"Couldn't register for fencing notifications: %d", rc);
1244stonith_api_add_notification(
stonith_t * stonith,
const char *event,
1247 GList *list_item = NULL;
1252 crm_trace(
"Adding callback for %s events (%d)", event, g_list_length(private->notify_list));
1255 new_client->event = event;
1256 new_client->notify = callback;
1258 list_item = g_list_find_custom(private->notify_list, new_client, stonithlib_GCompareFunc);
1260 if (list_item != NULL) {
1261 crm_warn(
"Callback already present");
1266 private->notify_list = g_list_append(private->notify_list, new_client);
1268 stonith_set_notification(stonith, event, 1);
1270 crm_trace(
"Callback added (%d)", g_list_length(private->notify_list));
1276del_notify_entry(gpointer
data, gpointer user_data)
1281 if (!entry->delete) {
1282 crm_debug(
"Removing callback for %s events", entry->event);
1283 stonith_api_del_notification(stonith, entry->event);
1288stonith_api_del_notification(
stonith_t * stonith,
const char *event)
1290 GList *list_item = NULL;
1294 if (event == NULL) {
1295 foreach_notify_entry(
private, del_notify_entry, stonith);
1301 crm_debug(
"Removing callback for %s events", event);
1304 new_client->event = event;
1305 new_client->notify = NULL;
1307 list_item = g_list_find_custom(private->notify_list, new_client, stonithlib_GCompareFunc);
1309 stonith_set_notification(stonith, event, 0);
1311 if (list_item != NULL) {
1314 if (private->notify_refcnt) {
1315 list_client->delete = TRUE;
1316 private->notify_deletes = TRUE;
1318 private->notify_list = g_list_remove(private->notify_list, list_client);
1332stonith_api_add_callback(
stonith_t * stonith,
int call_id,
int timeout,
int options,
1333 void *user_data,
const char *callback_name,
1339 CRM_CHECK(stonith != NULL,
return -EINVAL);
1344 private->op_callback = callback;
1346 }
else if (call_id < 0) {
1353 invoke_fence_action_callback(stonith, call_id, &
result,
1354 user_data, callback);
1362 blob->id = callback_name;
1364 blob->user_data = user_data;
1365 blob->callback = callback;
1369 set_callback_timeout(blob, stonith, call_id,
timeout);
1372 pcmk__intkey_table_insert(private->stonith_op_callback_table, call_id,
1374 crm_trace(
"Added callback to %s for call %d", callback_name, call_id);
1387get_event_data_xml(xmlNode *msg,
const char *ntype)
1416xml_to_event(xmlNode *msg)
1419 struct event_private *event_private = NULL;
1422 event_private = (
struct event_private *) event->opaque;
1437 xmlNode *
data = get_event_data_xml(msg, event->operation);
1440 crm_err(
"No data for %s event", event->operation);
1450 event->client_origin =
1459 xmlNode *
data = get_event_data_xml(msg, event->operation);
1462 crm_err(
"No data for %s event", event->operation);
1475 struct event_private *event_private =
event->opaque;
1491stonith_send_notification(gpointer
data, gpointer user_data)
1493 struct notify_blob_s *blob = user_data;
1496 const char *
event = NULL;
1498 if (blob->xml == NULL) {
1499 crm_warn(
"Skipping callback - NULL message");
1505 if (entry == NULL) {
1506 crm_warn(
"Skipping callback - NULL callback client");
1509 }
else if (entry->delete) {
1510 crm_trace(
"Skipping callback - marked for deletion");
1513 }
else if (entry->notify == NULL) {
1514 crm_warn(
"Skipping callback - NULL callback");
1518 crm_trace(
"Skipping callback - event mismatch %p/%s vs. %s", entry, entry->event, event);
1522 st_event = xml_to_event(blob->xml);
1524 crm_trace(
"Invoking callback for %p/%s event...", entry, event);
1526 entry->notify(blob->stonith, st_event);
1529 event_free(st_event);
1547stonith_send_command(
stonith_t * stonith,
const char *op, xmlNode *
data, xmlNode ** output_data,
1548 int call_options,
int timeout)
1553 xmlNode *op_msg = NULL;
1554 xmlNode *op_reply = NULL;
1561 if (output_data != NULL) {
1562 *output_data = NULL;
1579 if (op_msg == NULL) {
1602 1000 * (
timeout + 60), &op_reply);
1607 crm_perror(LOG_ERR,
"Couldn't perform %s operation (timeout=%ds): %d", op,
timeout, rc);
1622 if (reply_id == stonith->
call_id) {
1625 crm_trace(
"Synchronous reply %d received", reply_id);
1635 *output_data = op_reply;
1639 }
else if (reply_id <= 0) {
1640 crm_err(
"Received bad reply: No id set");
1647 crm_err(
"Received bad reply: %d (wanted %d)", reply_id, stonith->
call_id);
1656 crm_err(
"Fencer disconnected");
1657 free(native->token); native->token = NULL;
1688 stonith_dispatch_internal(msg, strlen(msg), stonith_api);
1709 crm_trace(
"Unregistering notifications and disconnecting %p first",
1718 crm_trace(
"Removing %d callbacks", g_hash_table_size(private->stonith_op_callback_table));
1719 g_hash_table_destroy(private->stonith_op_callback_table);
1721 crm_trace(
"Destroying %d notification clients", g_list_length(private->notify_list));
1722 g_list_free_full(private->notify_list, free);
1725 free(stonith->
cmds);
1736is_stonith_param(gpointer key, gpointer value, gpointer user_data)
1743 const char *agent, GHashTable *params,
int timeout_sec,
1744 char **output,
char **error_output)
1752 const char *
target =
"node1";
1753 char *host_arg = NULL;
1755 if (params != NULL) {
1759 g_hash_table_foreach_remove(params, is_stonith_param, NULL);
1762#if PCMK__ENABLE_CIBSECRETS
1765 crm_warn(
"Could not replace secret parameters for validation of %s: %s",
1775 *error_output = NULL;
1778 if (timeout_sec <= 0) {
1782 switch (get_namespace_from_agent(agent)) {
1785 params, host_arg, timeout_sec,
1786 output, error_output);
1790#if HAVE_STONITH_STONITH_H
1793 params, timeout_sec, output,
1806 crm_err(
"Agent %s not found", agent);
1819 crm_err(
"Agent %s does not support validation", agent);
1830stonith_api_validate(
stonith_t *
st,
int call_options,
const char *rsc_id,
1831 const char *namespace_s,
const char *agent,
1833 char **output,
char **error_output)
1845 for (; params; params = params->
next) {
1852 timeout_sec, output, error_output);
1854 g_hash_table_destroy(params_table);
1871 new_stonith = calloc(1,
sizeof(
stonith_t));
1872 if (new_stonith == NULL) {
1877 if (
private == NULL) {
1883 private->stonith_op_callback_table = pcmk__intkey_table(stonith_destroy_op_callback);
1884 private->notify_list = NULL;
1885 private->notify_refcnt = 0;
1886 private->notify_deletes = FALSE;
1892 if (new_stonith->
cmds == NULL) {
1898 new_stonith->
cmds->
free = free_stonith_api;
1902 new_stonith->
cmds->
list = stonith_api_list;
1904 new_stonith->
cmds->
status = stonith_api_status;
1905 new_stonith->
cmds->
fence = stonith_api_fence;
1911 new_stonith->
cmds->
metadata = stonith_api_device_metadata;
1913 new_stonith->
cmds->
query = stonith_api_query;
1941 crm_trace(
"Destroying %p", stonith_api);
1942 if (stonith_api != NULL) {
1943 stonith_api->
cmds->
free(stonith_api);
1963 for (
int attempt = 1; attempt <= max_attempts; attempt++) {
1970 if (attempt < max_attempts) {
1971 crm_notice(
"Fencer connection attempt %d of %d failed "
1972 "(retrying in 2s): %s " QB_XS
" rc=%d",
1977 crm_notice(
"Could not connect to fencer: %s " QB_XS
" rc=%d",
2011 for (; end->
next != NULL; end = end->
next);
2035 while (head != NULL) {
2049#define api_log_open() openlog("stonith-api", LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON)
2050#define api_log(level, fmt, args...) syslog(level, "%s: "fmt, __func__, args)
2061 api_log(LOG_ERR,
"API initialization failed, could not kick (%s) node %u/%s",
2068 api_log(LOG_ERR,
"Connection failed, could not kick (%s) node %u/%s : %s (%d)",
2071 char *
name = (
uname == NULL)? pcmk__itoa(nodeid) : strdup(
uname);
2076 if ((
uname == NULL) && (nodeid > 0)) {
2083 api_log(LOG_ERR,
"Could not kick (%s) node %u/%s : %s (%d)",
2103 api_log(LOG_ERR,
"Could not retrieve fence history for %u/%s: "
2104 "API initialization failed", nodeid,
uname);
2116 char *
name = (
uname == NULL)? pcmk__itoa(nodeid) : strdup(
uname);
2119 if ((
uname == NULL) && (nodeid > 0)) {
2125 for (hp = history; hp; hp = hp->
next) {
2133 }
else if (hp->state ==
st_done) {
2135 if (hp->completed > when) {
2136 when = hp->completed;
2144 api_log(LOG_INFO,
"Found %d entries for %u/%s: %d in progress, %d completed", entries, nodeid,
uname, progress, completed);
2153 api_log(LOG_INFO,
"Node %u/%s last kicked at: %ld", nodeid,
uname, (
long int)when);
2179 if (stonith_api == NULL) {
2180 crm_err(
"Could not list fence agents: API memory allocation failed");
2189 iter = iter->
next) {
2210parse_list_line(
const char *line,
int len, GList **output)
2213 size_t entry_start = 0;
2223 if (strstr(line,
"invalid") || strstr(line,
"variable")) {
2224 crm_debug(
"Skipping list output line: %s", line);
2229 for (i = 0; i <= len; i++) {
2231 if (isspace(line[i]) || (line[i] ==
',') || (line[i] ==
';')
2232 || (line[i] ==
'\0')) {
2238 if (i == entry_start) {
2240 entry_start = i + 1;
2250 rc = sscanf(line + entry_start,
"%[a-zA-Z0-9_-.]", entry);
2252 crm_warn(
"Could not parse list output entry: %s "
2253 QB_XS
" entry_start=%d position=%d",
2254 line + entry_start, entry_start, i);
2271 *output = g_list_append(*output, entry);
2273 entry_start = i + 1;
2302 GList *targets = NULL;
2304 if (target_spec != NULL) {
2305 size_t out_len = strlen(target_spec);
2306 size_t line_start = 0;
2308 for (
size_t i = 0; i <= out_len; ++i) {
2309 if ((target_spec[i] ==
'\n') || (target_spec[i] ==
'\0')
2310 || ((target_spec[i] ==
'\\') && (target_spec[i + 1] ==
'n'))) {
2313 int len = i - line_start;
2316 char *line = strndup(target_spec + line_start, len);
2322 parse_list_line(line, len, &targets);
2325 if (target_spec[i] ==
'\\') {
2350 const char *other = NULL;
2353 prev_hp != NULL; prev_hp = prev_hp->
next) {
2354 if (prev_hp == event) {
2357 if ((prev_hp->state ==
st_done) &&
2360 ((event->
completed < prev_hp->completed) ||
2364 || pcmk__str_eq(event->
delegate, prev_hp->delegate,
2367 return prev_hp->delegate;
2369 }
else if (other == NULL) {
2371 other = (prev_hp->delegate == NULL)?
"some node" : prev_hp->delegate;
2391 for (hp = history; hp; ) {
2395 if ((!
new) || (hp->completed > new->completed) ||
2396 ((hp->completed == new->completed) && (hp->completed_nsec > new->completed_nsec))) {
2402 if ((!np->next) || (hp->completed > np->next->completed) ||
2403 ((hp->completed == np->next->completed) && (hp->completed_nsec > np->next->completed_nsec))) {
2404 hp->next = np->next;
2423 while (last_pending->
next) {
2424 last_pending = last_pending->
next;
2427 last_pending->
next =
new;
2467 if (matching_fn(hp, user_data)) {
2484 return history->
state == GPOINTER_TO_INT(user_data);
2490 return history->
state != GPOINTER_TO_INT(user_data);
2504param_is_supported(xmlNode *metadata,
const char *
name)
2510 bool supported = (pcmk__xpath_num_results(xpath) > 0);
2513 xmlXPathFreeObject(xpath);
2531 CRM_CHECK(metadata != NULL,
return NULL);
2533 if (param_is_supported(metadata,
"plug")) {
2536 if (param_is_supported(metadata,
"port")) {
2563 void (*callback)(
int pid,
2568 switch (get_namespace_from_agent(agent)) {
2575 NULL, timeout_sec, NULL, NULL,
2586#if HAVE_STONITH_STONITH_H
2593 .exit_reason = NULL,
2594 .action_stdout = NULL,
2595 .action_stderr = NULL,
2600 callback(0, &
result, user_data);
2613 .action_stdout = NULL,
2614 .action_stderr = NULL,
2617 callback(0, &
result, user_data);
2635 if ((
data == NULL) || (
data->opaque == NULL)) {
2652 if ((
data == NULL) || (
data->opaque == NULL)) {
2669 if ((
data == NULL) || (
data->opaque == NULL)) {
2686 if ((event == NULL) || (event->
opaque == NULL)) {
2689 struct event_private *event_private =
event->opaque;
2691 return event_private->result.exit_status;
2706 if ((event == NULL) || (event->
opaque == NULL)) {
2709 struct event_private *event_private =
event->opaque;
2711 return event_private->result.execution_status;
2726 if ((event == NULL) || (event->
opaque == NULL)) {
2729 struct event_private *event_private =
event->opaque;
2731 return event_private->result.exit_reason;
2749 const char *origin = pcmk__s(event->
client_origin,
"a client");
2750 const char *origin_node = pcmk__s(event->
origin,
"a node");
2751 const char *executioner = pcmk__s(event->
executioner,
"the cluster");
2752 const char *device = pcmk__s(event->
device,
"unknown");
2754 const char *
target = pcmk__s(event->
target,
"no node");
2795 return crm_strdup_printf(
"Operation %s of %s by %s for %s@%s: %s%s%s%s (ref=%s)",
2798 ((reason == NULL)?
"" :
" ("), pcmk__s(reason,
""),
2799 ((reason == NULL)?
"" :
")"),
2800 pcmk__s(event->
id,
"(none)"));
2825stonith_dump_pending_op(gpointer key, gpointer value, gpointer user_data)
2827 int call = GPOINTER_TO_INT(key);
2830 crm_debug(
"Call %d (%s): pending", call, pcmk__s(blob->id,
"no ID"));
2840 if (private->stonith_op_callback_table == NULL) {
2843 return g_hash_table_foreach(private->stonith_op_callback_table,
2844 stonith_dump_pending_op, NULL);
2856 const char *key,
const char *value);
2916 return "turning off";
2927 return parse_namespace(namespace_s);
2935 return namespace_text(st_namespace);
2939 const char *namespace_s);
2947 return get_namespace_from_agent(agent);
#define PCMK_ACTION_STATUS
#define PCMK_ACTION_REBOOT
#define PCMK_ACTION_METADATA
#define PCMK_DEFAULT_ACTION_TIMEOUT_MS
Default timeout (in milliseconds) for non-metadata actions.
#define PCMK_ACTION_MONITOR
#define PCMK_STONITH_HOST_ARGUMENT
bool pcmk_stonith_param(const char *param)
Check whether a given stonith parameter is handled by Pacemaker.
int pcmk__substitute_secrets(const char *rsc_id, GHashTable *params)
guint pcmk__create_timer(guint interval_ms, GSourceFunc fn, gpointer data)
#define pcmk__assert_alloc(nmemb, size)
enum pcmk_ipc_server type
int stonith__legacy2status(int rc)
int stonith__execute_async(stonith_action_t *action, void *userdata, void(*done)(int pid, const pcmk__action_result_t *result, void *user_data), void(*fork_cb)(int pid, void *user_data))
void stonith__destroy_action(stonith_action_t *action)
#define STONITH_OP_DEVICE_ADD
#define STONITH_WATCHDOG_ID
#define STONITH_OP_LEVEL_ADD
#define STONITH_OP_FENCE_HISTORY
#define STONITH_OP_NOTIFY
pcmk__action_result_t * stonith__action_result(stonith_action_t *action)
struct stonith_action_s stonith_action_t
#define stonith__set_call_options(st_call_opts, call_for, flags_to_set)
void stonith__xe_get_result(const xmlNode *xml, pcmk__action_result_t *result)
#define STONITH_OP_LEVEL_DEL
int stonith__result2rc(const pcmk__action_result_t *result)
#define STONITH_OP_DEVICE_DEL
stonith_action_t * stonith__action_create(const char *agent, const char *action_name, const char *target, int timeout_sec, GHashTable *device_args, GHashTable *port_map, const char *host_arg)
G_GNUC_INTERNAL bool stonith__agent_is_rhcs(const char *agent)
G_GNUC_INTERNAL 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)
G_GNUC_INTERNAL int stonith__list_rhcs_agents(stonith_key_value_t **devices)
G_GNUC_INTERNAL int stonith__rhcs_metadata(const char *agent, int timeout, char **output)
Retrieve metadata for RHCS-compatible fence agent.
void crm_ipc_destroy(crm_ipc_t *client)
int crm_ipc_send(crm_ipc_t *client, const xmlNode *message, enum crm_ipc_flags flags, int32_t ms_timeout, xmlNode **reply)
Send an IPC XML message.
long crm_ipc_read(crm_ipc_t *client)
@ crm_ipc_client_response
A response is expected in reply.
int crm_ipc_ready(crm_ipc_t *client)
Check whether an IPC connection is ready to be read.
bool crm_ipc_connected(crm_ipc_t *client)
void crm_ipc_close(crm_ipc_t *client)
const char * crm_ipc_buffer(crm_ipc_t *client)
struct crm_ipc_s crm_ipc_t
crm_ipc_t * crm_ipc_new(const char *name, size_t max_size)
Create a new (legacy) object for using Pacemaker daemon IPC.
int pcmk__connect_generic_ipc(crm_ipc_t *ipc)
int pcmk__ipc_fd(crm_ipc_t *ipc, int *fd)
#define pcmk__set_ipc_flags(ipc_flags, ipc_name, flags_to_set)
void pcmk__ipc_free_client_buffer(crm_ipc_t *client)
#define CRM_TRACE_INIT_DATA(name)
#define crm_info(fmt, args...)
#define crm_warn(fmt, args...)
#define crm_log_xml_debug(xml, text)
#define CRM_LOG_ASSERT(expr)
#define crm_log_xml_err(xml, text)
#define crm_notice(fmt, args...)
#define crm_perror(level, fmt, args...)
Send a system error message to both the log and stderr.
#define CRM_CHECK(expr, failure_action)
#define crm_debug(fmt, args...)
#define crm_err(fmt, args...)
#define crm_log_xml_trace(xml, text)
#define crm_log_xml_warn(xml, text)
#define crm_trace(fmt, args...)
#define crm_log_xml_notice(xml, text)
Wrappers for and extensions to glib mainloop.
crm_ipc_t * mainloop_get_ipc_client(mainloop_io_t *client)
mainloop_io_t * mainloop_add_ipc_client(const char *name, int priority, size_t max_size, void *userdata, struct ipc_client_callbacks *callbacks)
struct mainloop_io_s mainloop_io_t
#define G_PRIORITY_MEDIUM
void mainloop_del_ipc_client(mainloop_io_t *client)
void hash2field(gpointer key, gpointer value, gpointer user_data)
Set XML attribute based on hash table entry.
#define PCMK__VALUE_ST_NOTIFY_FENCE
#define PCMK__VALUE_ST_NOTIFY
#define PCMK__VALUE_ST_NOTIFY_DISCONNECT
#define PCMK__VALUE_STONITH_NG
#define PCMK__VALUE_ST_NOTIFY_HISTORY
#define PCMK__VALUE_ST_ASYNC_TIMEOUT_VALUE
pcmk__action_result_t result
const char * pcmk_strerror(int rc)
const char * pcmk_rc_str(int rc)
Get a user-friendly description of a return code.
@ CRM_EX_NOSUCH
Requested item does not exist.
@ CRM_EX_ERROR
Unspecified error.
int pcmk_rc2legacy(int rc)
const char * crm_exit_str(crm_exit_t exit_code)
@ PCMK_EXEC_DONE
Action completed, result is known.
@ PCMK_EXEC_ERROR
Execution failed, may be retried.
@ PCMK_EXEC_TIMEOUT
Action did not complete in time.
@ PCMK_EXEC_UNKNOWN
Used only to initialize variables.
@ PCMK_EXEC_ERROR_HARD
Execution failed, do not retry on node.
int pcmk_legacy2rc(int legacy_rc)
void pcmk__set_result(pcmk__action_result_t *result, int exit_status, enum pcmk_exec_status exec_status, const char *exit_reason)
#define pcmk__assert(expr)
#define PCMK__UNKNOWN_RESULT
void pcmk__reset_result(pcmk__action_result_t *result)
int stonith__metadata_async(const char *agent, int timeout_sec, void(*callback)(int pid, const pcmk__action_result_t *result, void *user_data), void *user_data)
void stonith_api_delete(stonith_t *stonith)
const char * stonith__default_host_arg(xmlNode *metadata)
gboolean stonith__watchdog_fencing_enabled_for_node(const char *node)
const char * stonith__exit_reason(const stonith_callback_data_t *data)
const char * stonith_namespace2text(enum stonith_namespace st_namespace)
time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress)
char * stonith__event_description(const stonith_event_t *event)
stonith_key_value_t * stonith_key_value_add(stonith_key_value_t *head, const char *key, const char *value)
bool stonith__event_state_pending(stonith_history_t *history, void *user_data)
GList * stonith__parse_targets(const char *target_spec)
enum stonith_namespace stonith_get_namespace(const char *agent, const char *namespace_s)
xmlNode * stonith_create_op(int call_id, const char *token, const char *op, xmlNode *data, int call_options)
bool stonith__event_state_neq(stonith_history_t *history, void *user_data)
enum stonith_namespace stonith_text2namespace(const char *namespace_s)
bool stonith__event_state_eq(stonith_history_t *history, void *user_data)
void stonith_history_free(stonith_history_t *head)
xmlNode * create_device_registration_xml(const char *id, enum stonith_namespace standard, const char *agent, const stonith_key_value_t *params, const char *rsc_provides)
const char * stonith_action_str(const char *action)
xmlNode * create_level_registration_xml(const char *node, const char *pattern, const char *attr, const char *value, int level, const stonith_key_value_t *device_list)
void stonith__api_free(stonith_t *stonith_api)
struct stonith_private_s stonith_private_t
int stonith_api_connect_retry(stonith_t *st, const char *name, int max_attempts)
stonith_history_t * stonith__first_matching_event(stonith_history_t *history, bool(*matching_fn)(stonith_history_t *, void *), void *user_data)
#define api_log(level, fmt, args...)
int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off)
int stonith__exit_status(const stonith_callback_data_t *data)
stonith_key_value_t * stonith__key_value_add(stonith_key_value_t *head, const char *key, const char *value)
int stonith__api_connect_retry(stonith_t *stonith_api, const char *name, int max_attempts)
bool stonith__agent_exists(const char *name)
stonith_history_t * stonith__sort_history(stonith_history_t *history)
gboolean stonith__watchdog_fencing_enabled_for_node_api(stonith_t *st, const char *node)
int stonith__validate(stonith_t *st, int call_options, const char *rsc_id, const char *agent, GHashTable *params, int timeout_sec, char **output, char **error_output)
int stonith__execution_status(const stonith_callback_data_t *data)
int stonith__api_dispatch(stonith_t *stonith_api)
void stonith__key_value_freeall(stonith_key_value_t *head, bool keys, bool values)
int(* stonith_op_t)(const char *, int, const char *, xmlNode *, xmlNode *, xmlNode *, xmlNode **, xmlNode **)
bool stonith_dispatch(stonith_t *stonith_api)
int stonith__event_exit_status(const stonith_event_t *event)
const char * stonith__op_state_text(enum op_state state)
void stonith__history_free(stonith_history_t *head)
int stonith__event_execution_status(const stonith_event_t *event)
stonith_t * stonith_api_new(void)
const char * stonith__later_succeeded(const stonith_history_t *event, const stonith_history_t *top_history)
const char * stonith__event_exit_reason(const stonith_event_t *event)
struct stonith_notify_client_s stonith_notify_client_t
stonith_t * stonith__api_new(void)
void stonith_key_value_freeall(stonith_key_value_t *head, int keys, int values)
struct stonith_callback_client_s stonith_callback_client_t
bool stonith_agent_exists(const char *agent, int timeout)
void stonith_dump_pending_callbacks(stonith_t *stonith)
const char * stonith_op_state_str(enum op_state state)
int stonith__lha_metadata(const char *agent, int timeout, char **output)
int stonith__list_lha_agents(stonith_key_value_t **devices)
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)
bool stonith__agent_is_lha(const char *agent)
@ st_opt_allow_self_fencing
@ st_opt_report_only_success
stonith_namespace
Supported fence agent interface standards.
@ stonith_connected_command
op_state
Fencing operation states.
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
void pcmk__insert_dup(GHashTable *table, const char *name, const char *value)
gboolean pcmk__str_in_list(const gchar *s, const GList *lst, uint32_t flags)
GHashTable * pcmk__strkey_table(GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func)
bool pcmk__strcase_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
bool pcmk__str_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
#define pcmk__str_copy(str)
void pcmk__add_separated_word(GString **list, size_t init_size, const char *word, const char *separator)
enum pcmk_exec_status execution_status
int(* fence_with_delay)(stonith_t *stonith, int call_options, const char *node, const char *action, int timeout, int tolerance, int delay)
Request delayed fencing of a target.
int(* register_level)(stonith_t *st, int options, const char *node, int level, const stonith_key_value_t *device_list)
Register a fencing level for specified node with local fencer.
int(* free)(stonith_t *st)
Destroy a fencer connection.
int(* register_callback)(stonith_t *stonith, int call_id, int timeout, int options, void *user_data, const char *callback_name, void(*callback)(stonith_t *st, stonith_callback_data_t *data))
Register a callback for an asynchronous fencing result.
int(* query)(stonith_t *stonith, int call_options, const char *target, stonith_key_value_t **devices, int timeout)
List registered fence devices.
int(* register_notification)(stonith_t *stonith, const char *event, void(*callback)(stonith_t *st, stonith_event_t *e))
Register a callback for fence notifications.
int(* connect)(stonith_t *st, const char *name, int *stonith_fd)
Connect to the local fencer.
int(* register_device)(stonith_t *st, int options, const char *id, const char *namespace_s, const char *agent, const stonith_key_value_t *params)
Register a fence device with the local fencer.
int(* remove_level)(stonith_t *st, int options, const char *node, int level)
Unregister a fencing level for specified node with local fencer.
int(* disconnect)(stonith_t *st)
Disconnect from the local stonith daemon.
int(* list)(stonith_t *stonith, int call_options, const char *id, char **list_info, int timeout)
Get the output of a fence device's list action.
int(* remove_callback)(stonith_t *stonith, int call_id, bool all_callbacks)
Unregister callbacks for asynchronous fencing results.
int(* remove_level_full)(stonith_t *st, int options, const char *node, const char *pattern, const char *attr, const char *value, int level)
Unregister fencing level for specified node, pattern or attribute.
int(* fence)(stonith_t *stonith, int call_options, const char *node, const char *action, int timeout, int tolerance)
Request that a target get fenced.
int(* list_agents)(stonith_t *stonith, int call_options, const char *namespace_s, stonith_key_value_t **devices, int timeout)
Retrieve a list of installed fence agents.
int(* confirm)(stonith_t *stonith, int call_options, const char *target)
Manually confirm that a node has been fenced.
int(* status)(stonith_t *stonith, int call_options, const char *id, const char *port, int timeout)
Check whether a fence device target is reachable by status action.
int(* register_level_full)(stonith_t *st, int options, const char *node, const char *pattern, const char *attr, const char *value, int level, const stonith_key_value_t *device_list)
Register fencing level for specified node, pattern or attribute.
int(* validate)(stonith_t *st, int call_options, const char *rsc_id, const char *namespace_s, const char *agent, const stonith_key_value_t *params, int timeout, char **output, char **error_output)
Validate an arbitrary stonith device configuration.
int(* monitor)(stonith_t *stonith, int call_options, const char *id, int timeout)
Check whether a fence device is reachable by monitor action.
int(* remove_notification)(stonith_t *stonith, const char *event)
Unregister callbacks for fence notifications.
int(* remove_device)(stonith_t *st, int options, const char *name)
Unregister a fence device with the local fencer.
int(* history)(stonith_t *stonith, int call_options, const char *node, stonith_history_t **history, int timeout)
List fencing actions that have occurred for a target.
int(* metadata)(stonith_t *stonith, int call_options, const char *agent, const char *namespace_s, char **output, int timeout_sec)
Retrieve a fence agent's metadata.
Data for an asynchronous fencing request callback.
struct stonith_history_s * next
Key-value pair list node.
struct stonith_key_value_s * next
Fencer API connection object.
stonith_api_operations_t * cmds
Wrappers for and extensions to libxml2.
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the 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.
const char * crm_xml_add_int(xmlNode *node, const char *name, int value)
Create an XML attribute with specified name and integer value.
char * crm_element_value_copy(const xmlNode *data, const char *name)
Retrieve a copy of the value of an XML attribute.
int crm_element_value_ll(const xmlNode *data, const char *name, long long *dest)
Retrieve the long long integer value of an XML attribute.
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
xmlNode * pcmk__xe_first_child(const xmlNode *parent, const char *node_name, const char *attr_n, const char *attr_v)
xmlNode * pcmk__xe_next(const xmlNode *node, const char *element_name)
xmlNode * pcmk__xe_create(xmlNode *parent, const char *name)
xmlNode * pcmk__xml_copy(xmlNode *parent, xmlNode *src)
void pcmk__xml_free(xmlNode *xml)
xmlNode * pcmk__xml_parse(const char *input)
#define PCMK_XA_TARGET_PATTERN
#define PCMK_XE_FENCING_LEVEL
#define PCMK_XA_TARGET_VALUE
#define PCMK_XA_EXIT_REASON
#define PCMK_XA_TARGET_ATTRIBUTE
#define PCMK_XE_PARAMETER
#define PCMK__XA_ST_CLIENTID
#define PCMK__XA_NAMESPACE
#define PCMK__XE_ST_CALLDATA
#define PCMK__XA_ST_TARGET
#define PCMK__XA_ST_CALLOPT
#define PCMK__XA_ST_DATE_NSEC
#define PCMK__XA_ST_CALLID
#define PCMK__XA_ST_STATE
#define PCMK__XA_ST_DELEGATE
#define PCMK__XE_ST_DEVICE_ID
#define PCMK__XA_ST_NOTIFY_DEACTIVATE
#define PCMK__XA_ST_ORIGIN
#define PCMK__XA_ST_DELAY
#define PCMK__XE_ST_HISTORY
#define PCMK__XA_RSC_PROVIDES
#define PCMK__XA_ST_TOLERANCE
#define PCMK__XA_ST_REMOTE_OP
#define PCMK__XA_ST_OUTPUT
#define PCMK__XA_ST_DEVICE_ID
#define PCMK__XA_ST_NOTIFY_ACTIVATE
#define PCMK__XA_ST_CLIENTNAME
#define PCMK__XA_ST_DEVICE_ACTION
#define PCMK__XA_ST_TIMEOUT
#define PCMK__XE_ATTRIBUTES
#define PCMK__XE_STONITH_COMMAND
xmlXPathObject * pcmk__xpath_search(xmlDoc *doc, const char *path)
xmlNode * pcmk__xpath_result(xmlXPathObject *xpath_obj, int index)
xmlNode * pcmk__xpath_find_one(xmlDoc *doc, const char *path, uint8_t level)