18 #include <sys/types.h> 33 typedef struct stonith_private_s {
37 GHashTable *stonith_op_callback_table;
47 struct event_private {
51 typedef struct stonith_notify_client_s {
60 typedef struct stonith_callback_client_s {
64 gboolean only_success;
65 gboolean allow_timeout_updates;
70 struct notify_blob_s {
82 typedef int (*
stonith_op_t) (
const char *, int,
const char *, xmlNode *,
83 xmlNode *, xmlNode *, xmlNode **, xmlNode **);
88 static int stonith_send_command(
stonith_t *stonith,
const char *op,
89 xmlNode *
data, xmlNode **output_data,
92 static void stonith_connection_destroy(gpointer user_data);
93 static void stonith_send_notification(gpointer
data, gpointer user_data);
94 static int stonith_api_del_notification(
stonith_t *stonith,
109 }
else if (!strcmp(namespace_s,
"redhat")
110 || !strcmp(namespace_s,
"stonith-ng")) {
113 }
else if (!strcmp(namespace_s,
"internal")) {
116 }
else if (!strcmp(namespace_s,
"heartbeat")) {
132 switch (st_namespace) {
139 return "unsupported";
161 #if HAVE_STONITH_STONITH_H 167 crm_err(
"Unknown fence agent: %s", agent);
180 int rc = stonith_api->
cmds->
connect(stonith_api,
"stonith-api", NULL);
183 crm_err(
"Failed connecting to Stonith-API for watchdog-fencing-query.");
192 if ((rc !=
pcmk_ok) || (list == NULL)) {
198 crm_notice(
"Cluster does not have watchdog fencing device");
200 crm_warn(
"Could not check for watchdog fencing device: %s",
203 }
else if (list[0] ==
'\0') {
208 g_list_free_full(targets, free);
223 crm_err(
"Stonith-API for watchdog-fencing-query couldn't be created.");
225 crm_trace(
"Pacemaker assumes node %s %sto do watchdog-fencing.",
245 private->notify_refcnt++;
246 g_list_foreach(private->notify_list, func, user_data);
247 private->notify_refcnt--;
248 if ((private->notify_refcnt == 0) &&
249 private->notify_deletes) {
250 GList *list_item =
private->notify_list;
252 private->notify_deletes = FALSE;
253 while (list_item != NULL)
256 GList *next = g_list_next(list_item);
258 if (list_client->delete) {
260 private->notify_list =
261 g_list_delete_link(private->notify_list, list_item);
269 stonith_connection_destroy(gpointer user_data)
273 struct notify_blob_s blob;
275 crm_trace(
"Sending destroyed notification");
276 blob.stonith = stonith;
281 native->source = NULL;
283 free(native->token); native->token = NULL;
288 foreach_notify_entry(native, stonith_send_notification, &blob);
295 const char *rsc_provides)
300 #if HAVE_STONITH_STONITH_H 305 hash2field((gpointer)
"plugin", (gpointer) agent, args);
306 agent =
"fence_legacy";
320 for (; params; params = params->
next) {
328 stonith_api_register_device(
stonith_t *
st,
int call_options,
329 const char *
id,
const char *
namespace,
const char *agent,
333 xmlNode *
data = NULL;
336 agent, params, NULL);
345 stonith_api_remove_device(
stonith_t *
st,
int call_options,
const char *
name)
348 xmlNode *
data = NULL;
360 stonith_api_remove_level_full(
stonith_t *
st,
int options,
361 const char *node,
const char *pattern,
362 const char *attr,
const char *value,
int level)
365 xmlNode *
data = NULL;
367 CRM_CHECK(node || pattern || (attr && value),
return -EINVAL);
375 }
else if (pattern) {
391 stonith_api_remove_level(
stonith_t *
st,
int options,
const char *node,
int level)
393 return stonith_api_remove_level_full(
st, options, node,
394 NULL, NULL, NULL, level);
414 const char *attr,
const char *value,
421 CRM_CHECK(node || pattern || (attr && value),
return NULL);
433 }
else if (pattern) {
443 for (; device_list; device_list = device_list->
next) {
454 stonith_api_register_level_full(
stonith_t *
st,
int options,
const char *node,
456 const char *attr,
const char *value,
471 stonith_api_register_level(
stonith_t *
st,
int options,
const char *node,
int level,
474 return stonith_api_register_level_full(
st, options, node, NULL, NULL, NULL,
479 stonith_api_device_list(
stonith_t * stonith,
int call_options,
const char *
namespace,
485 if (devices == NULL) {
486 crm_err(
"Parameter error: stonith_api_device_list");
490 #if HAVE_STONITH_STONITH_H 506 stonith_api_device_metadata(
stonith_t * stonith,
int call_options,
const char *agent,
507 const char *
namespace,
char **output,
int timeout)
515 crm_trace(
"Looking up metadata for %s agent %s",
522 #if HAVE_STONITH_STONITH_H 528 crm_err(
"Can't get fence agent '%s' meta-data: No such agent",
536 stonith_api_query(
stonith_t * stonith,
int call_options,
const char *
target,
539 int rc = 0, lpc = 0, max = 0;
541 xmlNode *
data = NULL;
542 xmlNode *output = NULL;
543 xmlXPathObjectPtr xpathObj = NULL;
545 CRM_CHECK(devices != NULL,
return -EINVAL);
559 max = numXpathResults(xpathObj);
561 for (lpc = 0; lpc < max; lpc++) {
566 xmlChar *match_path = xmlGetNodePath(match);
568 crm_info(
"%s[%d] = %s",
"//@agent", lpc, match_path);
586 const char *
action,
const char *victim,
int timeout, xmlNode ** output)
589 xmlNode *
data = NULL;
604 stonith_api_list(
stonith_t * stonith,
int call_options,
const char *
id,
char **list_info,
608 xmlNode *output = NULL;
610 rc = stonith_api_call(stonith, call_options,
id,
"list", NULL,
timeout, &output);
612 if (output && list_info) {
613 const char *list_str;
618 *list_info = strdup(list_str);
630 stonith_api_monitor(
stonith_t * stonith,
int call_options,
const char *
id,
int timeout)
632 return stonith_api_call(stonith, call_options,
id,
"monitor", NULL,
timeout, NULL);
636 stonith_api_status(
stonith_t * stonith,
int call_options,
const char *
id,
const char *port,
639 return stonith_api_call(stonith, call_options,
id,
"status", port,
timeout, NULL);
643 stonith_api_fence_with_delay(
stonith_t * stonith,
int call_options,
const char *node,
647 xmlNode *
data = NULL;
663 stonith_api_fence(
stonith_t * stonith,
int call_options,
const char *node,
const char *
action,
666 return stonith_api_fence_with_delay(stonith, call_options, node,
action,
671 stonith_api_confirm(
stonith_t * stonith,
int call_options,
const char *
target)
674 return stonith_api_fence(stonith, call_options,
target,
"off", 0, 0);
678 stonith_api_history(
stonith_t * stonith,
int call_options,
const char *node,
682 xmlNode *
data = NULL;
683 xmlNode *output = NULL;
703 for (op = pcmk__xml_first_child(reply); op != NULL;
704 op = pcmk__xml_next(op)) {
707 long long completed_nsec = 0L;
741 for (hp = history; hp; hp_old = hp, hp = hp->
next, free(hp_old)) {
747 free(hp->exit_reason);
752 stonithlib_GCompareFunc(gconstpointer a, gconstpointer b)
758 if (a_client->delete || b_client->delete) {
762 CRM_CHECK(a_client->event != NULL && b_client->event != NULL,
return 0);
763 rc = strcmp(a_client->event, b_client->event);
765 if (a_client->notify == NULL || b_client->notify == NULL) {
768 }
else if (a_client->notify == b_client->notify) {
771 }
else if (((
long)a_client->notify) < ((
long)b_client->notify)) {
772 crm_err(
"callbacks for %s are not equal: %p vs. %p",
773 a_client->event, a_client->notify, b_client->notify);
776 crm_err(
"callbacks for %s are not equal: %p vs. %p",
777 a_client->event, a_client->notify, b_client->notify);
797 crm_trace(
"Sending call options: %.8lx, %d", (
long)call_options, call_options);
808 stonith_destroy_op_callback(gpointer
data)
812 if (blob->timer && blob->timer->ref > 0) {
813 g_source_remove(blob->timer->ref);
824 crm_debug(
"Disconnecting from the fencer");
826 if (native->source != NULL) {
829 native->source = NULL;
832 }
else if (native->ipc) {
841 free(native->token); native->token = NULL;
847 stonith_api_del_callback(
stonith_t * stonith,
int call_id,
bool all_callbacks)
852 private->op_callback = NULL;
853 g_hash_table_destroy(private->stonith_op_callback_table);
854 private->stonith_op_callback_table = pcmk__intkey_table(stonith_destroy_op_callback);
856 }
else if (call_id == 0) {
857 private->op_callback = NULL;
860 pcmk__intkey_table_remove(private->stonith_op_callback_table, call_id);
877 invoke_fence_action_callback(
stonith_t *
st,
int call_id,
885 data.call_id = call_id;
887 data.userdata = userdata;
905 invoke_registered_callbacks(
stonith_t *stonith, xmlNode *msg,
int call_id)
919 "Fencer accepted request but did not reply in time");
932 cb_info = pcmk__intkey_table_lookup(private->stonith_op_callback_table,
936 if ((cb_info != NULL) && (cb_info->callback != NULL)
937 && (pcmk__result_ok(&
result) || !(cb_info->only_success))) {
938 crm_trace(
"Invoking callback %s for call %d",
939 crm_str(cb_info->id), call_id);
940 invoke_fence_action_callback(stonith, call_id, &
result,
941 cb_info->user_data, cb_info->callback);
943 }
else if ((private->op_callback == NULL) && !pcmk__result_ok(&
result)) {
944 crm_warn(
"Fencing action without registered callback failed: %d (%s%s%s)",
952 if (private->op_callback != NULL) {
953 crm_trace(
"Invoking global callback for call %d", call_id);
954 invoke_fence_action_callback(stonith, call_id, &
result, NULL,
955 private->op_callback);
958 if (cb_info != NULL) {
959 stonith_api_del_callback(stonith, call_id, FALSE);
965 stonith_async_timeout_handler(gpointer
data)
970 invoke_registered_callbacks(timer->
stonith, NULL, timer->
call_id);
989 async_timer = calloc(1,
sizeof(
struct timer_rec_s));
990 callback->timer = async_timer;
999 if (async_timer->
ref) {
1000 g_source_remove(async_timer->
ref);
1003 g_timeout_add(async_timer->
timeout, stonith_async_timeout_handler, async_timer);
1012 callback = pcmk__intkey_table_lookup(private->stonith_op_callback_table,
1014 if (!callback || !callback->allow_timeout_updates) {
1022 stonith_dispatch_internal(
const char *buffer, ssize_t length, gpointer userdata)
1024 const char *
type = NULL;
1025 struct notify_blob_s blob;
1035 if (blob.xml == NULL) {
1036 crm_warn(
"Received malformed message from fencer: %s", buffer);
1045 invoke_registered_callbacks(
st, blob.xml, 0);
1048 foreach_notify_entry(
private, stonith_send_notification, &blob);
1056 update_callback_timeout(call_id,
timeout,
st);
1067 stonith_api_signon(
stonith_t * stonith,
const char *
name,
int *stonith_fd)
1071 const char *display_name =
name?
name :
"client";
1074 .
dispatch = stonith_dispatch_internal,
1075 .destroy = stonith_connection_destroy
1078 CRM_CHECK(stonith != NULL,
return -EINVAL);
1083 crm_debug(
"Attempting fencer connection by %s with%s mainloop",
1084 display_name, (stonith_fd?
"out" :
""));
1093 }
else if (native->ipc) {
1106 if (native->ipc == NULL) {
1109 xmlNode *reply = NULL;
1118 crm_debug(
"Couldn't register with the fencer: %s " 1122 }
else if (reply == NULL) {
1123 crm_debug(
"Couldn't register with the fencer: no reply");
1131 crm_debug(
"Couldn't register with the fencer: invalid reply type '%s'",
1132 (msg_type? msg_type :
"(missing)"));
1136 }
else if (native->token == NULL) {
1137 crm_debug(
"Couldn't register with the fencer: no token in reply");
1142 crm_debug(
"Connection to fencer by %s succeeded (registration token: %s)",
1143 display_name, native->token);
1153 crm_debug(
"Connection attempt to fencer by %s failed: %s " 1161 stonith_set_notification(
stonith_t * stonith,
const char *callback,
int enabled)
1178 crm_perror(LOG_DEBUG,
"Couldn't register for fencing notifications: %d", rc);
1190 stonith_api_add_notification(
stonith_t * stonith,
const char *event,
1193 GList *list_item = NULL;
1198 crm_trace(
"Adding callback for %s events (%d)", event, g_list_length(private->notify_list));
1201 new_client->event = event;
1202 new_client->notify = callback;
1204 list_item = g_list_find_custom(private->notify_list, new_client, stonithlib_GCompareFunc);
1206 if (list_item != NULL) {
1207 crm_warn(
"Callback already present");
1212 private->notify_list = g_list_append(private->notify_list, new_client);
1214 stonith_set_notification(stonith, event, 1);
1216 crm_trace(
"Callback added (%d)", g_list_length(private->notify_list));
1222 del_notify_entry(gpointer
data, gpointer user_data)
1227 if (!entry->delete) {
1228 crm_debug(
"Removing callback for %s events", entry->event);
1229 stonith_api_del_notification(stonith, entry->event);
1234 stonith_api_del_notification(
stonith_t * stonith,
const char *event)
1236 GList *list_item = NULL;
1240 if (event == NULL) {
1241 foreach_notify_entry(
private, del_notify_entry, stonith);
1247 crm_debug(
"Removing callback for %s events", event);
1250 new_client->event = event;
1251 new_client->notify = NULL;
1253 list_item = g_list_find_custom(private->notify_list, new_client, stonithlib_GCompareFunc);
1255 stonith_set_notification(stonith, event, 0);
1257 if (list_item != NULL) {
1260 if (private->notify_refcnt) {
1261 list_client->delete = TRUE;
1262 private->notify_deletes = TRUE;
1264 private->notify_list = g_list_remove(private->notify_list, list_client);
1278 stonith_api_add_callback(
stonith_t * stonith,
int call_id,
int timeout,
int options,
1279 void *user_data,
const char *callback_name,
1285 CRM_CHECK(stonith != NULL,
return -EINVAL);
1290 private->op_callback = callback;
1292 }
else if (call_id < 0) {
1299 invoke_fence_action_callback(stonith, call_id, &
result,
1300 user_data, callback);
1308 blob->id = callback_name;
1310 blob->user_data = user_data;
1311 blob->callback = callback;
1315 set_callback_timeout(blob, stonith, call_id,
timeout);
1318 pcmk__intkey_table_insert(private->stonith_op_callback_table, call_id,
1320 crm_trace(
"Added callback to %s for call %d", callback_name, call_id);
1326 stonith_dump_pending_op(gpointer key, gpointer value, gpointer user_data)
1328 int call = GPOINTER_TO_INT(key);
1339 if (private->stonith_op_callback_table == NULL) {
1342 return g_hash_table_foreach(private->stonith_op_callback_table, stonith_dump_pending_op, NULL);
1353 get_event_data_xml(xmlNode *msg,
const char *ntype)
1382 xml_to_event(xmlNode *msg)
1386 struct event_private *event_private = NULL;
1390 event->opaque = calloc(1,
sizeof(
struct event_private));
1392 event_private = (
struct event_private *) event->opaque;
1404 xmlNode *
data = get_event_data_xml(msg, ntype);
1407 crm_err(
"No data for %s event", ntype);
1427 struct event_private *event_private =
event->opaque;
1445 stonith_send_notification(gpointer
data, gpointer user_data)
1447 struct notify_blob_s *blob = user_data;
1450 const char *
event = NULL;
1452 if (blob->xml == NULL) {
1453 crm_warn(
"Skipping callback - NULL message");
1459 if (entry == NULL) {
1460 crm_warn(
"Skipping callback - NULL callback client");
1463 }
else if (entry->delete) {
1464 crm_trace(
"Skipping callback - marked for deletion");
1467 }
else if (entry->notify == NULL) {
1468 crm_warn(
"Skipping callback - NULL callback");
1472 crm_trace(
"Skipping callback - event mismatch %p/%s vs. %s", entry, entry->event, event);
1476 st_event = xml_to_event(blob->xml);
1478 crm_trace(
"Invoking callback for %p/%s event...", entry, event);
1479 entry->notify(blob->stonith, st_event);
1482 event_free(st_event);
1500 stonith_send_command(
stonith_t * stonith,
const char *op, xmlNode *
data, xmlNode ** output_data,
1501 int call_options,
int timeout)
1506 xmlNode *op_msg = NULL;
1507 xmlNode *op_reply = NULL;
1513 if (output_data != NULL) {
1514 *output_data = NULL;
1531 if (op_msg == NULL) {
1554 1000 * (
timeout + 60), &op_reply);
1559 crm_perror(LOG_ERR,
"Couldn't perform %s operation (timeout=%ds): %d", op,
timeout, rc);
1575 if (reply_id == stonith->
call_id) {
1578 crm_trace(
"Synchronous reply %d received", reply_id);
1588 *output_data = op_reply;
1592 }
else if (reply_id <= 0) {
1593 crm_err(
"Received bad reply: No id set");
1599 crm_err(
"Received bad reply: %d (wanted %d)", reply_id, stonith->
call_id);
1607 crm_err(
"Fencer disconnected");
1608 free(native->token); native->token = NULL;
1620 gboolean stay_connected = TRUE;
1631 stonith_dispatch_internal(msg, strlen(msg),
st);
1636 stay_connected = FALSE;
1640 return stay_connected;
1651 crm_trace(
"Disconnecting %p first", stonith);
1658 crm_trace(
"Removing %d callbacks", g_hash_table_size(private->stonith_op_callback_table));
1659 g_hash_table_destroy(private->stonith_op_callback_table);
1661 crm_trace(
"Destroying %d notification clients", g_list_length(private->notify_list));
1662 g_list_free_full(private->notify_list, free);
1665 free(stonith->
cmds);
1685 stonith_api_validate(
stonith_t *
st,
int call_options,
const char *rsc_id,
1686 const char *namespace_s,
const char *agent,
1688 char **error_output)
1701 const char *
target =
"node1";
1702 const char *host_arg = NULL;
1707 for (; params; params = params->
next) {
1710 host_arg = params->
value;
1713 g_hash_table_insert(params_table, strdup(params->
key),
1714 strdup(params->
value));
1718 #if SUPPORT_CIBSECRETS 1721 crm_warn(
"Could not replace secret parameters for validation of %s: %s",
1731 *error_output = NULL;
1737 params_table, host_arg,
timeout,
1738 output, error_output);
1741 #if HAVE_STONITH_STONITH_H 1744 params_table,
timeout, output,
1753 "Agent %s not found or does not support validation",
1757 g_hash_table_destroy(params_table);
1767 new_stonith = calloc(1,
sizeof(
stonith_t));
1768 if (new_stonith == NULL) {
1773 if (
private == NULL) {
1779 private->stonith_op_callback_table = pcmk__intkey_table(stonith_destroy_op_callback);
1780 private->notify_list = NULL;
1781 private->notify_refcnt = 0;
1782 private->notify_deletes = FALSE;
1788 if (new_stonith->
cmds == NULL) {
1795 new_stonith->
cmds->
free = stonith_api_free;
1799 new_stonith->
cmds->
list = stonith_api_list;
1801 new_stonith->
cmds->
status = stonith_api_status;
1802 new_stonith->
cmds->
fence = stonith_api_fence;
1808 new_stonith->
cmds->
metadata = stonith_api_device_metadata;
1810 new_stonith->
cmds->
query = stonith_api_query;
1844 for (
int attempt = 1; attempt <= max_attempts; attempt++) {
1848 }
else if (attempt < max_attempts) {
1849 crm_notice(
"Fencer connection attempt %d of %d failed (retrying in 2s): %s " 1870 while (end && end->
next) {
1901 #define api_log_open() openlog("stonith-api", LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON) 1902 #define api_log(level, fmt, args...) syslog(level, "%s: "fmt, __func__, args) 1909 const char *
action = off?
"off" :
"reboot";
1913 api_log(LOG_ERR,
"API initialization failed, could not kick (%s) node %u/%s",
1920 api_log(LOG_ERR,
"Connection failed, could not kick (%s) node %u/%s : %s (%d)",
1923 char *
name = (
uname == NULL)? pcmk__itoa(nodeid) : strdup(
uname);
1928 if ((
uname == NULL) && (nodeid > 0)) {
1935 api_log(LOG_ERR,
"Could not kick (%s) node %u/%s : %s (%d)",
1955 api_log(LOG_ERR,
"Could not retrieve fence history for %u/%s: " 1956 "API initialization failed", nodeid,
uname);
1968 char *
name = (
uname == NULL)? pcmk__itoa(nodeid) : strdup(
uname);
1971 if ((
uname == NULL) && (nodeid > 0)) {
1977 for (hp = history; hp; hp = hp->
next) {
1985 }
else if (hp->state ==
st_done) {
1987 if (hp->completed > when) {
1988 when = hp->completed;
1996 api_log(LOG_INFO,
"Found %d entries for %u/%s: %d in progress, %d completed", entries, nodeid,
uname, progress, completed);
2005 api_log(LOG_INFO,
"Node %u/%s last kicked at: %ld", nodeid,
uname, (
long int)when);
2018 if (agent == NULL) {
2024 crm_err(
"Could not list fence agents: API memory allocation failed");
2029 for (dIter = devices; dIter != NULL; dIter = dIter->
next) {
2046 }
else if (!strcmp(
action,
"on")) {
2048 }
else if (!strcmp(
action,
"off")) {
2049 return "turning off";
2064 parse_list_line(
const char *line,
int len, GList **output)
2067 size_t entry_start = 0;
2073 if (strstr(line,
"invalid") || strstr(line,
"variable")) {
2074 crm_debug(
"Skipping list output line: %s", line);
2079 for (i = 0; i <= len; i++) {
2081 if (isspace(line[i]) || (line[i] ==
',') || (line[i] ==
';')
2082 || (line[i] ==
'\0')) {
2088 if (i == entry_start) {
2090 entry_start = i + 1;
2094 entry = calloc(i - entry_start + 1,
sizeof(
char));
2101 rc = sscanf(line + entry_start,
"%[a-zA-Z0-9_-.]", entry);
2103 crm_warn(
"Could not parse list output entry: %s " 2104 CRM_XS " entry_start=%d position=%d",
2105 line + entry_start, entry_start, i);
2121 *output = g_list_append(*output, entry);
2123 entry_start = i + 1;
2152 GList *targets = NULL;
2154 if (target_spec != NULL) {
2155 size_t out_len = strlen(target_spec);
2156 size_t line_start = 0;
2158 for (
size_t i = 0; i <= out_len; ++i) {
2159 if ((target_spec[i] ==
'\n') || (target_spec[i] ==
'\0')
2160 || ((target_spec[i] ==
'\\') && (target_spec[i + 1] ==
'n'))) {
2163 int len = i - line_start;
2166 char *line =
strndup(target_spec + line_start, len);
2169 parse_list_line(line, len, &targets);
2172 if (target_spec[i] ==
'\\') {
2192 gboolean ret = FALSE;
2195 if (prev_hp == event) {
2199 if ((prev_hp->state ==
st_done) &&
2202 ((event->
completed < prev_hp->completed) ||
2225 for (hp = history; hp; ) {
2229 if ((!
new) || (hp->completed > new->completed) ||
2230 ((hp->completed == new->completed) && (hp->completed_nsec > new->completed_nsec))) {
2236 if ((!np->next) || (hp->completed > np->next->completed) ||
2237 ((hp->completed == np->next->completed) && (hp->completed_nsec > np->next->completed_nsec))) {
2257 while (last_pending->
next) {
2258 last_pending = last_pending->
next;
2261 last_pending->
next =
new;
2279 case st_exec:
return "executing";
2280 case st_done:
return "completed";
2293 if (matching_fn(hp, user_data)) {
2310 return history->
state == GPOINTER_TO_INT(user_data);
2316 return history->
state != GPOINTER_TO_INT(user_data);
2323 xmlXPathObjectPtr xpath = NULL;
2327 CRM_CHECK((device_flags != NULL) && (metadata != NULL),
return);
2330 max = numXpathResults(xpath);
2337 for (lpc = 0; lpc < max; lpc++) {
2338 const char *parameter = NULL;
2342 if (match == NULL) {
2372 if ((
data == NULL) || (
data->opaque == NULL)) {
2389 if ((
data == NULL) || (
data->opaque == NULL)) {
2406 if ((
data == NULL) || (
data->opaque == NULL)) {
2423 if ((event == NULL) || (event->
opaque == NULL)) {
2426 struct event_private *event_private =
event->opaque;
2428 return event_private->result.exit_status;
2443 if ((event == NULL) || (event->
opaque == NULL)) {
2446 struct event_private *event_private =
event->opaque;
2448 return event_private->result.execution_status;
2463 if ((event == NULL) || (event->
opaque == NULL)) {
2466 struct event_private *event_private =
event->opaque;
2468 return event_private->result.exit_reason;
2487 const char *origin =
event->client_origin;
2488 const char *executioner =
event->executioner;
2492 if (origin == NULL) {
2493 origin =
"a client";
2495 if (executioner == NULL) {
2496 executioner =
"the cluster";
2507 return crm_strdup_printf(
"Operation %s of %s by %s for %s@%s: %s%s%s%s (ref=%s)",
2510 ((reason == NULL)?
"" :
" ("),
2511 ((reason == NULL)?
"" : reason),
2512 ((reason == NULL)?
"" :
")"),
#define CRM_CHECK(expr, failure_action)
#define XML_ATTR_STONITH_TARGET_ATTRIBUTE
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 specified node, pattern 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 stonith__device_parameter_flags(uint32_t *device_flags, const char *device_name, xmlNode *metadata)
int stonith__legacy2status(int rc)
void hash2field(gpointer key, gpointer value, gpointer user_data)
Set XML attribute based on hash table entry.
int pcmk_rc2legacy(int rc)
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)
int crm_ipc_get_fd(crm_ipc_t *client)
#define F_STONITH_DATE_NSEC
#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)
int stonith__execution_status(stonith_callback_data_t *data)
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
bool pcmk_stonith_param(const char *param)
Check whether a given stonith parameter is handled by Pacemaker.
const char * stonith_action_str(const char *action)
Turn stonith action into a more readable string.
struct stonith_key_value_s * next
int stonith__result2rc(const pcmk__action_result_t *result)
enum pcmk_exec_status execution_status
struct mainloop_io_s mainloop_io_t
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
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 for specified node with local fencer.
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)
#define T_STONITH_TIMEOUT_VALUE
const char * stonith__event_exit_reason(stonith_event_t *event)
#define CRM_LOG_ASSERT(expr)
long crm_ipc_read(crm_ipc_t *client)
enum crm_ais_msg_types type
#define F_STONITH_NOTIFY_DEACTIVATE
Action did not complete in time.
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.
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)
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)
gboolean stonith__watchdog_fencing_enabled_for_node(const char *node)
time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress)
int(* free)(stonith_t *st)
Destroy the stonith api structure.
#define PCMK__UNKNOWN_RESULT
#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...)
const char * stonith_op_state_str(enum op_state state)
Return string equivalent of an operation state value.
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_exit_str(crm_exit_t exit_code)
void stonith__xe_get_result(xmlNode *xml, pcmk__action_result_t *result)
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.
Used only to initialize variables.
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
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 fence device with the local fencer.
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.
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)
enum stonith_namespace stonith_text2namespace(const char *namespace_s)
Get agent namespace by name.
int stonith__event_exit_status(stonith_event_t *event)
#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.
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
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
void pcmk__str_update(char **str, const char *value)
gboolean pcmk__str_in_list(const gchar *s, GList *lst, uint32_t flags)
xmlNode * create_xml_node(xmlNode *parent, const char *name)
#define crm_log_xml_warn(xml, text)
char * stonith__event_description(stonith_event_t *event)
Action completed, result is known.
int(* disconnect)(stonith_t *st)
Disconnect from the local stonith daemon.
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)
#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
G_GNUC_INTERNAL bool stonith__agent_is_rhcs(const char *agent)
struct stonith_notify_client_s stonith_notify_client_t
#define XML_LRM_ATTR_EXIT_REASON
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...)
const char * stonith__exit_reason(stonith_callback_data_t *data)
#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)
Unregister a fence device with the local fencer.
struct stonith_private_s stonith_private_t
bool crm_ipc_connected(crm_ipc_t *client)
int(* register_notification)(stonith_t *st, const char *event, void(*notify)(stonith_t *st, stonith_event_t *e))
gboolean stonith__watchdog_fencing_enabled_for_node_api(stonith_t *st, const char *node)
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.
#define PCMK_STONITH_HOST_ARGUMENT
int(* remove_notification)(stonith_t *st, const char *event)
Remove a previously registered notification for event, or all notifications if NULL.
G_GNUC_INTERNAL int stonith__list_rhcs_agents(stonith_key_value_t **devices)
#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.
GHashTable * pcmk__strkey_table(GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func)
pcmk__action_result_t result
#define crm_perror(level, fmt, args...)
Send a system error message to both the log and stderr.
int stonith__event_execution_status(stonith_event_t *event)
#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)
Unregister fencing level for specified node, pattern 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)
Unregister a fencing level for specified node with local fencer.
#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.
G_GNUC_INTERNAL int stonith__rhcs_metadata(const char *agent, int timeout, char **output)
Execute RHCS-compatible agent's meta-data action.
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.
void pcmk__set_result(pcmk__action_result_t *result, int exit_status, enum pcmk_exec_status exec_status, const char *exit_reason)
#define crm_log_xml_trace(xml, text)
#define F_STONITH_OPERATION
int stonith__exit_status(stonith_callback_data_t *data)
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
#define STONITH_WATCHDOG_ID
void pcmk__reset_result(pcmk__action_result_t *result)
void freeXpathObject(xmlXPathObjectPtr xpathObj)
void crm_ipc_close(crm_ipc_t *client)
#define F_STONITH_CALLDATA
CRM_TRACE_INIT_DATA(stonith)
Execution failed, may be retried.
#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)
Dispatch function for an IPC connection used as mainloop source.
#define F_STONITH_HISTORY_LIST
#define F_STONITH_TOLERANCE