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);
296 const char *rsc_provides)
301 #if HAVE_STONITH_STONITH_H 306 hash2field((gpointer)
"plugin", (gpointer) agent, args);
307 agent =
"fence_legacy";
322 for (; params; params = params->
next) {
330 stonith_api_register_device(
stonith_t *
st,
int call_options,
331 const char *
id,
const char *namespace_s,
336 xmlNode *
data = NULL;
340 agent, params, NULL);
349 stonith_api_remove_device(
stonith_t *
st,
int call_options,
const char *
name)
352 xmlNode *
data = NULL;
364 stonith_api_remove_level_full(
stonith_t *
st,
int options,
365 const char *node,
const char *pattern,
366 const char *attr,
const char *value,
int level)
369 xmlNode *
data = NULL;
371 CRM_CHECK(node || pattern || (attr && value),
return -EINVAL);
379 }
else if (pattern) {
395 stonith_api_remove_level(
stonith_t *
st,
int options,
const char *node,
int level)
397 return stonith_api_remove_level_full(
st, options, node,
398 NULL, NULL, NULL, level);
418 const char *attr,
const char *value,
421 GString *list = NULL;
424 CRM_CHECK(node || pattern || (attr && value),
return NULL);
435 }
else if (pattern) {
443 for (; device_list; device_list = device_list->
next) {
449 g_string_free(list, TRUE);
455 stonith_api_register_level_full(
stonith_t *
st,
int options,
const char *node,
456 const char *pattern,
const char *attr,
457 const char *value,
int level,
472 stonith_api_register_level(
stonith_t *
st,
int options,
const char *node,
int level,
475 return stonith_api_register_level_full(
st, options, node, NULL, NULL, NULL,
480 stonith_api_device_list(
stonith_t *stonith,
int call_options,
487 if (devices == NULL) {
488 crm_err(
"Parameter error: stonith_api_device_list");
492 #if HAVE_STONITH_STONITH_H 509 stonith_api_device_metadata(
stonith_t *stonith,
int call_options,
510 const char *agent,
const char *namespace_s,
511 char **output,
int timeout_sec)
519 if (timeout_sec <= 0) {
523 crm_trace(
"Looking up metadata for %s agent %s",
530 #if HAVE_STONITH_STONITH_H 536 crm_err(
"Can't get fence agent '%s' meta-data: No such agent",
544 stonith_api_query(
stonith_t * stonith,
int call_options,
const char *
target,
547 int rc = 0, lpc = 0, max = 0;
549 xmlNode *
data = NULL;
550 xmlNode *output = NULL;
551 xmlXPathObjectPtr xpathObj = NULL;
553 CRM_CHECK(devices != NULL,
return -EINVAL);
567 max = numXpathResults(xpathObj);
569 for (lpc = 0; lpc < max; lpc++) {
574 xmlChar *match_path = xmlGetNodePath(match);
576 crm_info(
"%s[%d] = %s",
"//@agent", lpc, match_path);
605 stonith_api_call(
stonith_t *stonith,
int call_options,
const char *
id,
606 const char *
action,
const char *
target,
int timeout_sec,
610 xmlNode *
data = NULL;
619 call_options, timeout_sec);
626 stonith_api_list(
stonith_t * stonith,
int call_options,
const char *
id,
char **list_info,
630 xmlNode *output = NULL;
635 if (output && list_info) {
636 const char *list_str;
641 *list_info = strdup(list_str);
653 stonith_api_monitor(
stonith_t * stonith,
int call_options,
const char *
id,
int timeout)
660 stonith_api_status(
stonith_t * stonith,
int call_options,
const char *
id,
const char *port,
668 stonith_api_fence_with_delay(
stonith_t * stonith,
int call_options,
const char *node,
672 xmlNode *
data = NULL;
688 stonith_api_fence(
stonith_t * stonith,
int call_options,
const char *node,
const char *
action,
691 return stonith_api_fence_with_delay(stonith, call_options, node,
action,
696 stonith_api_confirm(
stonith_t * stonith,
int call_options,
const char *
target)
704 stonith_api_history(
stonith_t * stonith,
int call_options,
const char *node,
708 xmlNode *
data = NULL;
709 xmlNode *output = NULL;
730 op = pcmk__xe_next(op)) {
733 long long completed_nsec = 0L;
766 for (hp = history; hp; hp_old = hp, hp = hp->
next, free(hp_old)) {
772 free(hp->exit_reason);
777 stonithlib_GCompareFunc(gconstpointer a, gconstpointer b)
783 if (a_client->delete || b_client->delete) {
787 CRM_CHECK(a_client->event != NULL && b_client->event != NULL,
return 0);
788 rc = strcmp(a_client->event, b_client->event);
790 if (a_client->notify == NULL || b_client->notify == NULL) {
793 }
else if (a_client->notify == b_client->notify) {
796 }
else if (((
long)a_client->notify) < ((
long)b_client->notify)) {
797 crm_err(
"callbacks for %s are not equal: %p vs. %p",
798 a_client->event, a_client->notify, b_client->notify);
801 crm_err(
"callbacks for %s are not equal: %p vs. %p",
802 a_client->event, a_client->notify, b_client->notify);
811 xmlNode *op_msg = NULL;
819 crm_trace(
"Sending call options: %.8lx, %d", (
long)call_options, call_options);
832 stonith_destroy_op_callback(gpointer
data)
836 if (blob->timer && blob->timer->ref > 0) {
837 g_source_remove(blob->timer->ref);
848 crm_debug(
"Disconnecting from the fencer");
850 if (native->source != NULL) {
853 native->source = NULL;
856 }
else if (native->ipc) {
865 free(native->token); native->token = NULL;
871 stonith_api_del_callback(
stonith_t * stonith,
int call_id,
bool all_callbacks)
876 private->op_callback = NULL;
877 g_hash_table_destroy(private->stonith_op_callback_table);
878 private->stonith_op_callback_table = pcmk__intkey_table(stonith_destroy_op_callback);
880 }
else if (call_id == 0) {
881 private->op_callback = NULL;
884 pcmk__intkey_table_remove(private->stonith_op_callback_table, call_id);
901 invoke_fence_action_callback(
stonith_t *
st,
int call_id,
909 data.call_id = call_id;
911 data.userdata = userdata;
929 invoke_registered_callbacks(
stonith_t *stonith,
const xmlNode *msg,
int call_id)
943 "Fencer accepted request but did not reply in time");
956 cb_info = pcmk__intkey_table_lookup(private->stonith_op_callback_table,
960 if ((cb_info != NULL) && (cb_info->callback != NULL)
961 && (pcmk__result_ok(&
result) || !(cb_info->only_success))) {
962 crm_trace(
"Invoking callback %s for call %d",
963 pcmk__s(cb_info->id,
"without ID"), call_id);
964 invoke_fence_action_callback(stonith, call_id, &
result,
965 cb_info->user_data, cb_info->callback);
967 }
else if ((private->op_callback == NULL) && !pcmk__result_ok(&
result)) {
968 crm_warn(
"Fencing action without registered callback failed: %d (%s%s%s)",
976 if (private->op_callback != NULL) {
977 crm_trace(
"Invoking global callback for call %d", call_id);
978 invoke_fence_action_callback(stonith, call_id, &
result, NULL,
979 private->op_callback);
982 if (cb_info != NULL) {
983 stonith_api_del_callback(stonith, call_id, FALSE);
989 stonith_async_timeout_handler(gpointer
data)
994 invoke_registered_callbacks(timer->
stonith, NULL, timer->
call_id);
1006 struct timer_rec_s *async_timer = callback->timer;
1014 callback->timer = async_timer;
1023 if (async_timer->
ref) {
1024 g_source_remove(async_timer->
ref);
1027 g_timeout_add(async_timer->
timeout, stonith_async_timeout_handler, async_timer);
1036 callback = pcmk__intkey_table_lookup(private->stonith_op_callback_table,
1038 if (!callback || !callback->allow_timeout_updates) {
1046 stonith_dispatch_internal(
const char *buffer, ssize_t length, gpointer userdata)
1048 const char *
type = NULL;
1049 struct notify_blob_s blob;
1059 if (blob.xml == NULL) {
1060 crm_warn(
"Received malformed message from fencer: %s", buffer);
1069 invoke_registered_callbacks(
st, blob.xml, 0);
1072 foreach_notify_entry(
private, stonith_send_notification, &blob);
1082 update_callback_timeout(call_id,
timeout,
st);
1093 stonith_api_signon(
stonith_t * stonith,
const char *
name,
int *stonith_fd)
1097 const char *display_name =
name?
name :
"client";
1100 .
dispatch = stonith_dispatch_internal,
1101 .destroy = stonith_connection_destroy
1104 CRM_CHECK(stonith != NULL,
return -EINVAL);
1109 crm_debug(
"Attempting fencer connection by %s with%s mainloop",
1110 display_name, (stonith_fd?
"out" :
""));
1116 if (native->ipc != NULL) {
1121 crm_debug(
"Couldn't get file descriptor for IPC: %s",
1139 if (native->ipc == NULL) {
1142 xmlNode *reply = NULL;
1151 crm_debug(
"Couldn't register with the fencer: %s " 1155 }
else if (reply == NULL) {
1156 crm_debug(
"Couldn't register with the fencer: no reply");
1164 crm_debug(
"Couldn't register with the fencer: invalid reply type '%s'",
1165 (msg_type? msg_type :
"(missing)"));
1169 }
else if (native->token == NULL) {
1170 crm_debug(
"Couldn't register with the fencer: no token in reply");
1175 crm_debug(
"Connection to fencer by %s succeeded (registration token: %s)",
1176 display_name, native->token);
1186 crm_debug(
"Connection attempt to fencer by %s failed: %s " 1194 stonith_set_notification(
stonith_t * stonith,
const char *callback,
int enabled)
1211 crm_perror(LOG_DEBUG,
"Couldn't register for fencing notifications: %d", rc);
1223 stonith_api_add_notification(
stonith_t * stonith,
const char *event,
1226 GList *list_item = NULL;
1231 crm_trace(
"Adding callback for %s events (%d)", event, g_list_length(private->notify_list));
1234 new_client->event = event;
1235 new_client->notify = callback;
1237 list_item = g_list_find_custom(private->notify_list, new_client, stonithlib_GCompareFunc);
1239 if (list_item != NULL) {
1240 crm_warn(
"Callback already present");
1245 private->notify_list = g_list_append(private->notify_list, new_client);
1247 stonith_set_notification(stonith, event, 1);
1249 crm_trace(
"Callback added (%d)", g_list_length(private->notify_list));
1255 del_notify_entry(gpointer
data, gpointer user_data)
1260 if (!entry->delete) {
1261 crm_debug(
"Removing callback for %s events", entry->event);
1262 stonith_api_del_notification(stonith, entry->event);
1267 stonith_api_del_notification(
stonith_t * stonith,
const char *event)
1269 GList *list_item = NULL;
1273 if (event == NULL) {
1274 foreach_notify_entry(
private, del_notify_entry, stonith);
1280 crm_debug(
"Removing callback for %s events", event);
1283 new_client->event = event;
1284 new_client->notify = NULL;
1286 list_item = g_list_find_custom(private->notify_list, new_client, stonithlib_GCompareFunc);
1288 stonith_set_notification(stonith, event, 0);
1290 if (list_item != NULL) {
1293 if (private->notify_refcnt) {
1294 list_client->delete = TRUE;
1295 private->notify_deletes = TRUE;
1297 private->notify_list = g_list_remove(private->notify_list, list_client);
1311 stonith_api_add_callback(
stonith_t * stonith,
int call_id,
int timeout,
int options,
1312 void *user_data,
const char *callback_name,
1318 CRM_CHECK(stonith != NULL,
return -EINVAL);
1323 private->op_callback = callback;
1325 }
else if (call_id < 0) {
1332 invoke_fence_action_callback(stonith, call_id, &
result,
1333 user_data, callback);
1341 blob->id = callback_name;
1343 blob->user_data = user_data;
1344 blob->callback = callback;
1348 set_callback_timeout(blob, stonith, call_id,
timeout);
1351 pcmk__intkey_table_insert(private->stonith_op_callback_table, call_id,
1353 crm_trace(
"Added callback to %s for call %d", callback_name, call_id);
1359 stonith_dump_pending_op(gpointer key, gpointer value, gpointer user_data)
1361 int call = GPOINTER_TO_INT(key);
1364 crm_debug(
"Call %d (%s): pending", call, pcmk__s(blob->id,
"no ID"));
1372 if (private->stonith_op_callback_table == NULL) {
1375 return g_hash_table_foreach(private->stonith_op_callback_table, stonith_dump_pending_op, NULL);
1386 get_event_data_xml(xmlNode *msg,
const char *ntype)
1415 xml_to_event(xmlNode *msg)
1418 struct event_private *event_private = NULL;
1421 event_private = (
struct event_private *) event->opaque;
1436 xmlNode *
data = get_event_data_xml(msg, event->operation);
1439 crm_err(
"No data for %s event", event->operation);
1449 event->client_origin =
1458 xmlNode *
data = get_event_data_xml(msg, event->operation);
1461 crm_err(
"No data for %s event", event->operation);
1474 struct event_private *event_private =
event->opaque;
1492 stonith_send_notification(gpointer
data, gpointer user_data)
1494 struct notify_blob_s *blob = user_data;
1497 const char *
event = NULL;
1499 if (blob->xml == NULL) {
1500 crm_warn(
"Skipping callback - NULL message");
1506 if (entry == NULL) {
1507 crm_warn(
"Skipping callback - NULL callback client");
1510 }
else if (entry->delete) {
1511 crm_trace(
"Skipping callback - marked for deletion");
1514 }
else if (entry->notify == NULL) {
1515 crm_warn(
"Skipping callback - NULL callback");
1519 crm_trace(
"Skipping callback - event mismatch %p/%s vs. %s", entry, entry->event, event);
1523 st_event = xml_to_event(blob->xml);
1525 crm_trace(
"Invoking callback for %p/%s event...", entry, event);
1526 entry->notify(blob->stonith, st_event);
1529 event_free(st_event);
1547 stonith_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;
1669 gboolean stay_connected = TRUE;
1680 stonith_dispatch_internal(msg, strlen(msg),
st);
1685 stay_connected = FALSE;
1689 return stay_connected;
1700 crm_trace(
"Unregistering notifications and disconnecting %p first",
1709 crm_trace(
"Removing %d callbacks", g_hash_table_size(private->stonith_op_callback_table));
1710 g_hash_table_destroy(private->stonith_op_callback_table);
1712 crm_trace(
"Destroying %d notification clients", g_list_length(private->notify_list));
1713 g_list_free_full(private->notify_list, free);
1716 free(stonith->
cmds);
1736 stonith_api_validate(
stonith_t *
st,
int call_options,
const char *rsc_id,
1737 const char *namespace_s,
const char *agent,
1739 char **output,
char **error_output)
1752 const char *
target =
"node1";
1753 const char *host_arg = NULL;
1758 for (; params; params = params->
next) {
1761 host_arg = params->
value;
1768 #if SUPPORT_CIBSECRETS 1771 crm_warn(
"Could not replace secret parameters for validation of %s: %s",
1781 *error_output = NULL;
1784 if (timeout_sec <= 0) {
1791 params_table, host_arg, timeout_sec,
1792 output, error_output);
1795 #if HAVE_STONITH_STONITH_H 1798 params_table, timeout_sec, output,
1810 crm_err(
"Agent %s not found", agent);
1823 crm_err(
"Agent %s does not support validation", agent);
1829 g_hash_table_destroy(params_table);
1839 new_stonith = calloc(1,
sizeof(
stonith_t));
1840 if (new_stonith == NULL) {
1845 if (
private == NULL) {
1851 private->stonith_op_callback_table = pcmk__intkey_table(stonith_destroy_op_callback);
1852 private->notify_list = NULL;
1853 private->notify_refcnt = 0;
1854 private->notify_deletes = FALSE;
1860 if (new_stonith->
cmds == NULL) {
1867 new_stonith->
cmds->
free = stonith_api_free;
1871 new_stonith->
cmds->
list = stonith_api_list;
1873 new_stonith->
cmds->
status = stonith_api_status;
1874 new_stonith->
cmds->
fence = stonith_api_fence;
1880 new_stonith->
cmds->
metadata = stonith_api_device_metadata;
1882 new_stonith->
cmds->
query = stonith_api_query;
1916 for (
int attempt = 1; attempt <= max_attempts; attempt++) {
1920 }
else if (attempt < max_attempts) {
1921 crm_notice(
"Fencer connection attempt %d of %d failed (retrying in 2s): %s " 1942 while (end && end->
next) {
1973 #define api_log_open() openlog("stonith-api", LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON) 1974 #define api_log(level, fmt, args...) syslog(level, "%s: "fmt, __func__, args) 1985 api_log(LOG_ERR,
"API initialization failed, could not kick (%s) node %u/%s",
1992 api_log(LOG_ERR,
"Connection failed, could not kick (%s) node %u/%s : %s (%d)",
1995 char *
name = (
uname == NULL)? pcmk__itoa(nodeid) : strdup(
uname);
2000 if ((
uname == NULL) && (nodeid > 0)) {
2007 api_log(LOG_ERR,
"Could not kick (%s) node %u/%s : %s (%d)",
2027 api_log(LOG_ERR,
"Could not retrieve fence history for %u/%s: " 2028 "API initialization failed", nodeid,
uname);
2040 char *
name = (
uname == NULL)? pcmk__itoa(nodeid) : strdup(
uname);
2043 if ((
uname == NULL) && (nodeid > 0)) {
2049 for (hp = history; hp; hp = hp->
next) {
2057 }
else if (hp->state ==
st_done) {
2059 if (hp->completed > when) {
2060 when = hp->completed;
2068 api_log(LOG_INFO,
"Found %d entries for %u/%s: %d in progress, %d completed", entries, nodeid,
uname, progress, completed);
2077 api_log(LOG_INFO,
"Node %u/%s last kicked at: %ld", nodeid,
uname, (
long int)when);
2090 if (agent == NULL) {
2096 crm_err(
"Could not list fence agents: API memory allocation failed");
2101 for (dIter = devices; dIter != NULL; dIter = dIter->
next) {
2121 return "turning off";
2136 parse_list_line(
const char *line,
int len, GList **output)
2139 size_t entry_start = 0;
2145 if (strstr(line,
"invalid") || strstr(line,
"variable")) {
2146 crm_debug(
"Skipping list output line: %s", line);
2151 for (i = 0; i <= len; i++) {
2153 if (isspace(line[i]) || (line[i] ==
',') || (line[i] ==
';')
2154 || (line[i] ==
'\0')) {
2160 if (i == entry_start) {
2162 entry_start = i + 1;
2172 rc = sscanf(line + entry_start,
"%[a-zA-Z0-9_-.]", entry);
2174 crm_warn(
"Could not parse list output entry: %s " 2175 CRM_XS " entry_start=%d position=%d",
2176 line + entry_start, entry_start, i);
2193 *output = g_list_append(*output, entry);
2195 entry_start = i + 1;
2224 GList *targets = NULL;
2226 if (target_spec != NULL) {
2227 size_t out_len = strlen(target_spec);
2228 size_t line_start = 0;
2230 for (
size_t i = 0; i <= out_len; ++i) {
2231 if ((target_spec[i] ==
'\n') || (target_spec[i] ==
'\0')
2232 || ((target_spec[i] ==
'\\') && (target_spec[i + 1] ==
'n'))) {
2235 int len = i - line_start;
2238 char *line = strndup(target_spec + line_start, len);
2241 parse_list_line(line, len, &targets);
2244 if (target_spec[i] ==
'\\') {
2269 const char *other = NULL;
2272 prev_hp != NULL; prev_hp = prev_hp->
next) {
2273 if (prev_hp == event) {
2276 if ((prev_hp->state ==
st_done) &&
2279 ((event->
completed < prev_hp->completed) ||
2283 || pcmk__str_eq(event->
delegate, prev_hp->delegate,
2286 return prev_hp->delegate;
2288 }
else if (other == NULL) {
2290 other = (prev_hp->delegate == NULL)?
"some node" : prev_hp->delegate;
2310 for (hp = history; hp; ) {
2314 if ((!
new) || (hp->completed > new->completed) ||
2315 ((hp->completed == new->completed) && (hp->completed_nsec > new->completed_nsec))) {
2321 if ((!np->next) || (hp->completed > np->next->completed) ||
2322 ((hp->completed == np->next->completed) && (hp->completed_nsec > np->next->completed_nsec))) {
2342 while (last_pending->
next) {
2343 last_pending = last_pending->
next;
2346 last_pending->
next =
new;
2364 case st_exec:
return "executing";
2365 case st_done:
return "completed";
2378 if (matching_fn(hp, user_data)) {
2395 return history->
state == GPOINTER_TO_INT(user_data);
2401 return history->
state != GPOINTER_TO_INT(user_data);
2408 xmlXPathObjectPtr xpath = NULL;
2412 CRM_CHECK((device_flags != NULL) && (metadata != NULL),
return);
2415 max = numXpathResults(xpath);
2422 for (lpc = 0; lpc < max; lpc++) {
2423 const char *parameter = NULL;
2427 if (match == NULL) {
2467 void (*callback)(
int pid,
2479 NULL, 0, timeout_sec, NULL,
2490 #if HAVE_STONITH_STONITH_H 2497 .exit_reason = NULL,
2498 .action_stdout = NULL,
2499 .action_stderr = NULL,
2504 callback(0, &
result, user_data);
2517 .action_stdout = NULL,
2518 .action_stderr = NULL,
2521 callback(0, &
result, user_data);
2539 if ((
data == NULL) || (
data->opaque == NULL)) {
2556 if ((
data == NULL) || (
data->opaque == NULL)) {
2573 if ((
data == NULL) || (
data->opaque == NULL)) {
2590 if ((event == NULL) || (event->
opaque == NULL)) {
2593 struct event_private *event_private =
event->opaque;
2595 return event_private->result.exit_status;
2610 if ((event == NULL) || (event->
opaque == NULL)) {
2613 struct event_private *event_private =
event->opaque;
2615 return event_private->result.execution_status;
2630 if ((event == NULL) || (event->
opaque == NULL)) {
2633 struct event_private *event_private =
event->opaque;
2635 return event_private->result.exit_reason;
2653 const char *origin = pcmk__s(event->
client_origin,
"a client");
2654 const char *origin_node = pcmk__s(event->
origin,
"a node");
2655 const char *executioner = pcmk__s(event->
executioner,
"the cluster");
2656 const char *device = pcmk__s(event->
device,
"unknown");
2658 const char *
target = pcmk__s(event->
target,
"no node");
2699 return crm_strdup_printf(
"Operation %s of %s by %s for %s@%s: %s%s%s%s (ref=%s)",
2702 ((reason == NULL)?
"" :
" ("), pcmk__s(reason,
""),
2703 ((reason == NULL)?
"" :
")"),
2704 pcmk__s(event->
id,
"(none)"));
void stonith__destroy_action(stonith_action_t *action)
#define CRM_CHECK(expr, failure_action)
#define PCMK__XA_ST_DELEGATE
struct stonith_action_s stonith_action_t
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.
void stonith_history_free(stonith_history_t *history)
#define PCMK__XA_ST_CALLID
#define PCMK__VALUE_STONITH_NG
#define PCMK__XA_ST_TOLERANCE
int stonith__event_execution_status(const stonith_event_t *event)
struct stonith_history_s * next
xmlNode * pcmk__xml_copy(xmlNode *parent, xmlNode *src)
#define PCMK__VALUE_ST_NOTIFY
#define PCMK__XA_NAMESPACE
Invoke callback only if request succeeded.
#define crm_notice(fmt, args...)
const char * pcmk_strerror(int rc)
#define PCMK__XA_ST_CALLOPT
void stonith__device_parameter_flags(uint32_t *device_flags, const char *device_name, xmlNode *metadata)
int stonith__legacy2status(int rc)
#define PCMK__XA_ST_DEVICE_ID
void hash2field(gpointer key, gpointer value, gpointer user_data)
Set XML attribute based on hash table entry.
Requested item does not exist.
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)
#define PCMK__XA_ST_OUTPUT
void stonith_dump_pending_callbacks(stonith_t *stonith)
Interpret target as node cluster layer ID instead of name.
#define stonith__set_device_flags(device_flags, device_id, flags_to_set)
#define PCMK_DEFAULT_METADATA_TIMEOUT_MS
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)
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 PCMK_XA_TARGET_VALUE
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.
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)
bool pcmk_stonith_param(const char *param)
Check whether a given stonith parameter is handled by Pacemaker.
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.
const char * stonith_action_str(const char *action)
Turn fence action into a more readable string.
struct stonith_key_value_s * next
#define PCMK_ACTION_MONITOR
#define PCMK_XA_TARGET_PATTERN
#define PCMK_XA_EXIT_REASON
int stonith__result2rc(const pcmk__action_result_t *result)
enum pcmk_exec_status execution_status
struct mainloop_io_s mainloop_io_t
#define PCMK__XE_ATTRIBUTES
#define PCMK__XE_STONITH_COMMAND
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
const char * stonith__exit_reason(const stonith_callback_data_t *data)
void stonith_key_value_freeall(stonith_key_value_t *head, int keys, int values)
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 stonith__lha_metadata(const char *agent, int timeout, char **output)
#define PCMK__XA_ST_TIMEOUT
void pcmk__add_separated_word(GString **list, size_t init_size, const char *word, const char *separator)
#define PCMK__VALUE_ST_NOTIFY_DISCONNECT
#define CRM_LOG_ASSERT(expr)
#define PCMK__XA_ST_NOTIFY_ACTIVATE
long crm_ipc_read(crm_ipc_t *client)
#define PCMK__XA_RSC_PROVIDES
enum crm_ais_msg_types type
#define PCMK_XA_TARGET_ATTRIBUTE
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.
The fencing target is allowed to execute the request.
int crm_element_value_int(const xmlNode *data, const char *name, int *dest)
Retrieve the integer value of an XML attribute.
Execution failed, do not retry on node.
Do not return any reply from server.
#define STONITH_OP_NOTIFY
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
#define STONITH_OP_DEVICE_ADD
int(* confirm)(stonith_t *stonith, int call_options, const char *target)
Manually confirm that a node has been fenced.
#define PCMK__XE_ST_CALLDATA
const char * crm_ipc_buffer(crm_ipc_t *client)
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.
const char * stonith_namespace2text(enum stonith_namespace st_namespace)
Get agent namespace name.
int stonith__list_lha_agents(stonith_key_value_t **devices)
#define PCMK__XA_ST_REMOTE_OP
int(* remove_callback)(stonith_t *stonith, int call_id, bool all_callbacks)
Unregister callbacks for asynchronous fencing results.
int pcmk__connect_generic_ipc(crm_ipc_t *ipc)
#define PCMK_ACTION_STATUS
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.
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 a fencer connection.
#define PCMK__XA_ST_ORIGIN
#define PCMK__XA_ST_DELAY
#define PCMK__XA_ST_DATE_NSEC
#define PCMK__UNKNOWN_RESULT
#define PCMK_ACTION_REBOOT
#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)
const char * stonith__later_succeeded(const stonith_history_t *event, const stonith_history_t *top_history)
bool stonith_dispatch(stonith_t *st)
#define crm_debug(fmt, args...)
xmlNode * create_device_registration_xml(const char *id, enum stonith_namespace namespace, const char *agent, const stonith_key_value_t *params, const char *rsc_provides)
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
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.
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.
pcmk__action_result_t * stonith__action_result(stonith_action_t *action)
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
xmlNode * pcmk__xe_first_child(const xmlNode *parent, const char *node_name, const char *attr_n, const char *attr_v)
GList * stonith__parse_targets(const char *target_spec)
#define PCMK_XE_PARAMETER
#define PCMK__VALUE_ST_NOTIFY_HISTORY
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)
#define PCMK__XA_ST_CLIENTNAME
enum stonith_namespace stonith_text2namespace(const char *namespace_s)
Get agent namespace by name.
int stonith__execution_status(const stonith_callback_data_t *data)
#define crm_trace(fmt, args...)
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
#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 PCMK__XE_ST_DEVICE_ID
Wrappers for and extensions to libxml2.
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.
#define crm_log_xml_warn(xml, text)
Action completed, result is known.
void stonith__xe_get_result(const xmlNode *xml, pcmk__action_result_t *result)
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.
const char * get_stonith_provider(const char *agent, const char *provider)
#define STONITH_OP_DEVICE_DEL
void mainloop_del_ipc_client(mainloop_io_t *client)
void crm_ipc_destroy(crm_ipc_t *client)
int pcmk_legacy2rc(int legacy_rc)
G_GNUC_INTERNAL bool stonith__agent_is_rhcs(const char *agent)
struct stonith_notify_client_s stonith_notify_client_t
const char * stonith__event_exit_reason(const stonith_event_t *event)
void stonith_api_delete(stonith_t *stonith)
void free_xml(xmlNode *child)
int(* connect)(stonith_t *st, const char *name, int *stonith_fd)
Connect to the local fencer.
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.
char * stonith__event_description(const stonith_event_t *event)
#define api_log(level, fmt, args...)
bool pcmk__str_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
#define pcmk__str_copy(str)
#define PCMK__VALUE_ST_ASYNC_TIMEOUT_VALUE
xmlNode * pcmk__xml_parse(const char *input)
#define STONITH_OP_FENCE_HISTORY
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
Wait for request to be completed before returning.
bool crm_ipc_connected(crm_ipc_t *client)
#define pcmk__assert(expr)
#define PCMK__XA_ST_DEVICE_ACTION
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.
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.
#define PCMK_STONITH_HOST_ARGUMENT
xmlXPathObjectPtr xpath_search(const xmlNode *xml_top, const char *path)
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
#define PCMK_XE_FENCING_LEVEL
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.
#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
#define PCMK__XE_ST_HISTORY
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)
int stonith__event_exit_status(const stonith_event_t *event)
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
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.
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 pcmk__ipc_fd(crm_ipc_t *ipc, int *fd)
#define crm_log_xml_notice(xml, text)
Request that server send an update with optimal callback timeout.
xmlNode * getXpathResult(xmlXPathObjectPtr xpathObj, int index)
#define PCMK_ACTION_METADATA
crm_ipc_t * crm_ipc_new(const char *name, size_t max_size)
Create a new (legacy) object for using Pacemaker daemon IPC.
stonith_action_t * stonith__action_create(const char *agent, const char *action_name, const char *target, uint32_t target_nodeid, int timeout_sec, GHashTable *device_args, GHashTable *port_map, const char *host_arg)
#define PCMK__XA_ST_NOTIFY_DEACTIVATE
#define PCMK__VALUE_ST_NOTIFY_FENCE
int(* monitor)(stonith_t *stonith, int call_options, const char *id, int timeout)
Check whether a fence device is reachable by monitor action.
G_GNUC_INTERNAL int stonith__rhcs_metadata(const char *agent, int timeout, char **output)
Retrieve metadata for RHCS-compatible fence agent.
int(* query)(stonith_t *stonith, int call_options, const char *target, stonith_key_value_t **devices, int timeout)
List registered fence devices.
bool stonith__agent_is_lha(const char *agent)
bool stonith__event_state_pending(stonith_history_t *history, void *user_data)
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.
#define PCMK__XA_ST_TARGET
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)
mainloop_io_t * mainloop_add_ipc_client(const char *name, int priority, size_t max_size, void *userdata, struct ipc_client_callbacks *callbacks)
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(* remove_notification)(stonith_t *stonith, const char *event)
Unregister callbacks for fence notifications.
#define PCMK__XA_ST_STATE
xmlNode * pcmk__xe_create(xmlNode *parent, const char *name)
#define pcmk__assert_alloc(nmemb, size)
#define STONITH_WATCHDOG_ID
void pcmk__reset_result(pcmk__action_result_t *result)
void freeXpathObject(xmlXPathObjectPtr xpathObj)
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.
#define PCMK__XA_ST_CLIENTID
void crm_ipc_close(crm_ipc_t *client)
CRM_TRACE_INIT_DATA(stonith)
int stonith__exit_status(const stonith_callback_data_t *data)
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))
Execution failed, may be retried.
#define crm_info(fmt, args...)
void pcmk__insert_dup(GHashTable *table, const char *name, const char *value)
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)
int(* dispatch)(const char *buffer, ssize_t length, gpointer userdata)
Dispatch function for an IPC connection used as mainloop source.
gboolean pcmk__str_in_list(const gchar *s, const GList *lst, uint32_t flags)