16 #include <sys/types.h> 29 #if SUPPORT_CIBSECRETS 35 struct stonith_action_s {
44 void (*done_cb) (GPid
pid, gint status,
const char *output, gpointer user_data);
49 int last_timeout_signo;
52 time_t initial_start_time;
54 int remaining_timeout;
66 typedef struct stonith_private_s {
70 GHashTable *stonith_op_callback_table;
77 typedef struct stonith_notify_client_s {
85 typedef struct stonith_callback_client_s {
89 gboolean only_success;
90 gboolean allow_timeout_updates;
95 struct notify_blob_s {
107 typedef int (*
stonith_op_t) (
const char *, int,
const char *, xmlNode *,
108 xmlNode *, xmlNode *, xmlNode **, xmlNode **);
114 xmlNode ** output_data,
int call_options,
int timeout);
116 static void stonith_connection_destroy(gpointer user_data);
117 static void stonith_send_notification(gpointer
data, gpointer user_data);
131 if ((namespace_s == NULL) || !strcmp(namespace_s,
"any")) {
134 }
else if (!strcmp(namespace_s,
"redhat")
135 || !strcmp(namespace_s,
"stonith-ng")) {
138 }
else if (!strcmp(namespace_s,
"internal")) {
141 }
else if (!strcmp(namespace_s,
"heartbeat")) {
164 return "unsupported";
186 #if HAVE_STONITH_STONITH_H 192 crm_err(
"Unknown fence agent: %s", agent);
199 if (action->output) {
217 stonith_connection_destroy(gpointer user_data)
221 struct notify_blob_s blob;
223 crm_trace(
"Sending destroyed notification");
224 blob.stonith = stonith;
229 native->source = NULL;
235 g_list_foreach(native->notify_list, stonith_send_notification, &blob);
242 const char *rsc_provides)
247 #if HAVE_STONITH_STONITH_H 252 hash2field((gpointer)
"plugin", (gpointer) agent, args);
253 agent =
"fence_legacy";
267 for (; params; params = params->
next) {
275 stonith_api_register_device(
stonith_t * st,
int call_options,
276 const char *
id,
const char *
namespace,
const char *agent,
280 xmlNode *
data = NULL;
283 agent, params, NULL);
292 stonith_api_remove_device(
stonith_t * st,
int call_options,
const char *name)
295 xmlNode *
data = NULL;
307 stonith_api_remove_level_full(
stonith_t *st,
int options,
308 const char *node,
const char *pattern,
309 const char *attr,
const char *value,
int level)
312 xmlNode *
data = NULL;
314 CRM_CHECK(node || pattern || (attr && value),
return -EINVAL);
322 }
else if (pattern) {
338 stonith_api_remove_level(
stonith_t * st,
int options,
const char *node,
int level)
340 return stonith_api_remove_level_full(st, options, node,
341 NULL, NULL, NULL, level);
361 const char *attr,
const char *value,
368 CRM_CHECK(node || pattern || (attr && value),
return NULL);
380 }
else if (pattern) {
388 for (; device_list; device_list = device_list->
next) {
390 int adding = strlen(device_list->
value);
395 crm_trace(
"Adding %s (%dc) at offset %d", device_list->
value, adding, len);
396 list = realloc_safe(list, len + adding + 1);
398 crm_perror(LOG_CRIT,
"Could not create device list");
402 sprintf(list + len,
"%s%s", len?
",":
"", device_list->
value);
413 stonith_api_register_level_full(
stonith_t * st,
int options,
const char *node,
415 const char *attr,
const char *value,
430 stonith_api_register_level(
stonith_t * st,
int options,
const char *node,
int level,
433 return stonith_api_register_level_full(st, options, node, NULL, NULL, NULL,
438 append_arg(
const char *key,
const char *value,
char **args)
446 if (strstr(key,
"pcmk_")) {
455 len += strlen(value);
457 last = strlen(*args);
460 *args = realloc_safe(*args, last + len);
461 crm_trace(
"Appending: %s=%s", key, value);
462 sprintf((*args) + last,
"%s=%s\n", key, value);
466 append_config_arg(gpointer key, gpointer value, gpointer user_data)
473 append_arg(key, value, user_data);
479 make_args(
const char *agent,
const char *action,
const char *victim,
uint32_t victim_nodeid, GHashTable * device_args,
480 GHashTable * port_map)
483 char *arg_list = NULL;
484 const char *value = NULL;
488 snprintf(buffer,
sizeof(buffer),
"pcmk_%s_action", action);
490 value = g_hash_table_lookup(device_args, buffer);
493 crm_info(
"Substituting action '%s' for requested operation '%s'", value, action);
498 if (victim && device_args) {
499 const char *alias = victim;
502 if (port_map && g_hash_table_lookup(port_map, victim)) {
503 alias = g_hash_table_lookup(port_map, victim);
509 append_arg(
"nodename", victim, &arg_list);
511 char nodeid_str[33] = { 0, };
512 if (snprintf(nodeid_str, 33,
"%u", (
unsigned int)victim_nodeid)) {
513 crm_info(
"For stonith action (%s) for victim %s, adding nodeid (%s) to parameters",
514 action, victim, nodeid_str);
515 append_arg(
"nodeid", nodeid_str, &arg_list);
523 }
else if (param == NULL) {
525 value = g_hash_table_lookup(device_args, param);
531 value = g_hash_table_lookup(device_args, param);
535 if (value == NULL ||
safe_str_eq(value,
"dynamic")) {
536 crm_debug(
"Performing %s action for node '%s' as '%s=%s'", action, victim, param,
538 append_arg(param, alias, &arg_list);
543 g_hash_table_foreach(device_args, append_config_arg, &arg_list);
550 st_child_term(gpointer
data)
555 crm_info(
"Child %d timed out, sending SIGTERM", track->pid);
556 track->timer_sigterm = 0;
557 track->last_timeout_signo = SIGTERM;
558 rc = kill(-track->pid, SIGTERM);
560 crm_perror(LOG_ERR,
"Couldn't send SIGTERM to %d", track->pid);
566 st_child_kill(gpointer
data)
571 crm_info(
"Child %d timed out, sending SIGKILL", track->pid);
572 track->timer_sigkill = 0;
573 track->last_timeout_signo = SIGKILL;
574 rc = kill(-track->pid, SIGKILL);
576 crm_perror(LOG_ERR,
"Couldn't send SIGKILL to %d", track->pid);
584 if (action->timer_sigterm > 0) {
585 g_source_remove(action->timer_sigterm);
586 action->timer_sigterm = 0;
588 if (action->timer_sigkill > 0) {
589 g_source_remove(action->timer_sigkill);
590 action->timer_sigkill = 0;
592 if (action->fd_stdout) {
593 close(action->fd_stdout);
594 action->fd_stdout = 0;
596 if (action->fd_stderr) {
597 close(action->fd_stderr);
598 action->fd_stderr = 0;
600 free(action->output);
601 action->output = NULL;
603 action->error = NULL;
606 action->last_timeout_signo = 0;
619 stonith_action_clear_tracking_data(action);
622 free(action->action);
623 free(action->victim);
651 *error_output = NULL;
653 if (action != NULL) {
657 if (output && action->output) {
658 *output = action->output;
659 action->output = NULL;
661 if (error_output && action->error) {
662 *error_output = action->error;
663 action->error = NULL;
668 #define FAILURE_MAX_RETRIES 2 674 int timeout, GHashTable * device_args, GHashTable * port_map)
679 action->args = make_args(agent, _action, victim, victim_nodeid, device_args, port_map);
680 crm_debug(
"Preparing '%s' action for %s using agent %s",
681 _action, (victim? victim :
"no target"), agent);
682 action->agent = strdup(agent);
683 action->action = strdup(_action);
685 action->victim = strdup(victim);
687 action->timeout = action->remaining_timeout = timeout;
692 const char *value = NULL;
694 snprintf(buffer,
sizeof(buffer),
"pcmk_%s_retries", _action);
695 value = g_hash_table_lookup(device_args, buffer);
698 action->max_retries = atoi(value);
721 more = read(fd, buffer,
READ_MAX - 1);
727 output = realloc_safe(output, len + more + 1);
728 snprintf(output + len, more + 1,
"%s", buffer);
732 }
while (more == (
READ_MAX - 1) || (more < 0 && errno == EINTR));
740 int diff = time(NULL) - action->initial_start_time;
742 if (action->tries >= action->max_retries) {
743 crm_info(
"Attempted to execute agent %s (%s) the maximum number of times (%d) allowed",
744 action->agent, action->action, action->max_retries);
745 action->remaining_timeout = 0;
746 }
else if ((action->rc != -
ETIME) && diff < (action->timeout * 0.7)) {
749 action->remaining_timeout = action->timeout - diff;
751 action->remaining_timeout = 0;
753 return action->remaining_timeout ? TRUE : FALSE;
757 stonith_action_async_done(
mainloop_child_t * p, pid_t
pid,
int core,
int signo,
int exitcode)
761 if (action->timer_sigterm > 0) {
762 g_source_remove(action->timer_sigterm);
763 action->timer_sigterm = 0;
765 if (action->timer_sigkill > 0) {
766 g_source_remove(action->timer_sigkill);
767 action->timer_sigkill = 0;
770 action->output = read_output(action->fd_stdout);
771 action->error = read_output(action->fd_stderr);
773 if (action->last_timeout_signo) {
775 crm_notice(
"Child process %d performing action '%s' timed out with signal %d",
776 pid, action->action, action->last_timeout_signo);
779 action->rc = -ECONNABORTED;
780 crm_notice(
"Child process %d performing action '%s' timed out with signal %d",
781 pid, action->action, signo);
784 crm_debug(
"Child process %d performing action '%s' exited with rc %d",
785 pid, action->action, exitcode);
790 if (action->error == NULL) {
793 }
else if (strstr(action->error,
"imed out")) {
795 exitcode = -ETIMEDOUT;
797 }
else if (strstr(action->error,
"Unrecognised action")) {
798 exitcode = -EOPNOTSUPP;
804 action->rc = exitcode;
807 log_action(action,
pid);
809 if (action->rc !=
pcmk_ok && update_remaining_timeout(action)) {
810 int rc = internal_stonith_action_execute(action);
816 if (action->done_cb) {
817 action->done_cb(
pid, action->rc, action->output, action->userdata);
826 int pid, status = 0, len, rc = -EPROTO;
829 int p_read_fd, p_write_fd;
830 int c_read_fd, c_write_fd;
831 int c_stderr_fd, p_stderr_fd;
838 stonith_action_clear_tracking_data(action);
840 if (!action->tries) {
841 action->initial_start_time = time(NULL);
845 if (action->tries > 1) {
846 crm_info(
"Attempt %d to execute %s (%s). remaining timeout is %d",
847 action->tries, action->agent, action->action, action->remaining_timeout);
851 c_read_fd = c_write_fd = p_read_fd = p_write_fd = c_stderr_fd = p_stderr_fd = -1;
853 if (action->args == NULL || action->agent == NULL)
855 len = strlen(action->args);
869 p_stderr_fd = fd3[0];
870 c_stderr_fd = fd3[1];
885 if (dup(c_write_fd) < 0)
889 if (dup(c_stderr_fd) < 0)
893 if (dup(c_read_fd) < 0)
907 execlp(action->agent, action->agent, NULL);
915 crm_notice(
"Could not set output of %s to be non-blocking: %s " 921 crm_notice(
"Could not set error output of %s to be non-blocking: %s " 929 ret = write(p_write_fd, action->args + total, len - total);
934 }
while (errno == EINTR && total < len);
937 crm_perror(LOG_ERR,
"Sent %d not %d bytes", total, len);
944 close(p_write_fd); p_write_fd = -1;
948 action->fd_stdout = p_read_fd;
949 action->fd_stderr = p_stderr_fd;
951 crm_trace(
"Op: %s on %s, pid: %d, timeout: %ds", action->action, action->agent, pid,
952 action->remaining_timeout);
953 action->last_timeout_signo = 0;
954 if (action->remaining_timeout) {
955 action->timer_sigterm =
956 g_timeout_add(1000 * action->remaining_timeout, st_child_term, action);
957 action->timer_sigkill =
958 g_timeout_add(1000 * (action->remaining_timeout + 5), st_child_kill, action);
960 crm_err(
"No timeout set for stonith operation %s with device %s",
961 action->action, action->agent);
971 int timeout = action->remaining_timeout + 1;
974 while (action->remaining_timeout < 0 || timeout > 0) {
975 p = waitpid(pid, &status, WNOHANG);
984 int killrc = kill(-pid, SIGKILL);
986 if (killrc && errno != ESRCH) {
995 p = waitpid(pid, &status, 0);
1001 }
else if (p != pid) {
1002 crm_err(
"Waited for %d, got %d", pid, p);
1005 action->output = read_output(p_read_fd);
1006 action->error = read_output(p_stderr_fd);
1008 action->rc = -ECONNABORTED;
1010 log_action(action, pid);
1014 action->rc = -
ETIME;
1015 }
else if (WIFEXITED(status)) {
1016 crm_debug(
"result = %d", WEXITSTATUS(status));
1017 action->rc = -WEXITSTATUS(status);
1020 }
else if (WIFSIGNALED(status)) {
1021 crm_err(
"call %s for %s exited due to signal %d", action->action, action->agent,
1025 crm_err(
"call %s for %s returned unexpected status %#x",
1026 action->action, action->agent, status);
1032 if (p_read_fd >= 0) {
1035 if (p_write_fd >= 0) {
1038 if (p_stderr_fd >= 0) {
1042 if (c_read_fd >= 0) {
1045 if (c_write_fd >= 0) {
1048 if (c_stderr_fd >= 0) {
1058 void (*done) (GPid
pid,
int rc,
const char *output,
1059 gpointer user_data))
1067 action->userdata = userdata;
1068 action->done_cb = done;
1071 rc = internal_stonith_action_execute(action);
1073 return rc < 0 ? rc : action->pid;
1089 CRM_CHECK(action != NULL,
return -EINVAL);
1093 rc = internal_stonith_action_execute(action);
1094 }
while ((rc !=
pcmk_ok) && update_remaining_timeout(action));
1100 stonith_api_device_list(
stonith_t * stonith,
int call_options,
const char *
namespace,
1106 if (devices == NULL) {
1107 crm_err(
"Parameter error: stonith_api_device_list");
1111 #if HAVE_STONITH_STONITH_H 1127 stonith_api_device_metadata(
stonith_t * stonith,
int call_options,
const char *agent,
1128 const char *
namespace,
char **output,
int timeout)
1136 crm_trace(
"Looking up metadata for %s agent %s",
1143 #if HAVE_STONITH_STONITH_H 1151 "Agent %s not found or does not support meta-data",
1159 stonith_api_query(
stonith_t * stonith,
int call_options,
const char *target,
1162 int rc = 0, lpc = 0, max = 0;
1164 xmlNode *
data = NULL;
1165 xmlNode *output = NULL;
1166 xmlXPathObjectPtr xpathObj = NULL;
1168 CRM_CHECK(devices != NULL,
return -EINVAL);
1182 max = numXpathResults(xpathObj);
1184 for (lpc = 0; lpc < max; lpc++) {
1189 xmlChar *match_path = xmlGetNodePath(match);
1191 crm_info(
"%s[%d] = %s",
"//@agent", lpc, match_path);
1209 const char *action,
const char *victim,
int timeout, xmlNode ** output)
1212 xmlNode *
data = NULL;
1227 stonith_api_list(
stonith_t * stonith,
int call_options,
const char *
id,
char **list_info,
1231 xmlNode *output = NULL;
1233 rc = stonith_api_call(stonith, call_options,
id,
"list", NULL, timeout, &output);
1235 if (output && list_info) {
1236 const char *list_str;
1241 *list_info = strdup(list_str);
1253 stonith_api_monitor(
stonith_t * stonith,
int call_options,
const char *
id,
int timeout)
1255 return stonith_api_call(stonith, call_options,
id,
"monitor", NULL, timeout, NULL);
1259 stonith_api_status(
stonith_t * stonith,
int call_options,
const char *
id,
const char *port,
1262 return stonith_api_call(stonith, call_options,
id,
"status", port, timeout, NULL);
1266 stonith_api_fence(
stonith_t * stonith,
int call_options,
const char *node,
const char *action,
1267 int timeout,
int tolerance)
1270 xmlNode *
data = NULL;
1285 stonith_api_confirm(
stonith_t * stonith,
int call_options,
const char *target)
1287 return stonith_api_fence(stonith, call_options |
st_opt_manual_ack, target,
"off", 0, 0);
1291 stonith_api_history(
stonith_t * stonith,
int call_options,
const char *node,
1295 xmlNode *
data = NULL;
1296 xmlNode *output = NULL;
1314 for (op = __xml_first_child(reply); op != NULL; op = __xml_next(op)) {
1346 for (hp = history; hp; hp_old = hp, hp = hp->
next, free(hp_old)) {
1365 stonithlib_GCompareFunc(gconstpointer a, gconstpointer b)
1371 CRM_CHECK(a_client->event != NULL && b_client->event != NULL,
return 0);
1372 rc = strcmp(a_client->event, b_client->event);
1374 if (a_client->notify == NULL || b_client->notify == NULL) {
1377 }
else if (a_client->notify == b_client->notify) {
1380 }
else if (((
long)a_client->notify) < ((
long)b_client->notify)) {
1381 crm_err(
"callbacks for %s are not equal: %p vs. %p",
1382 a_client->event, a_client->notify, b_client->notify);
1385 crm_err(
"callbacks for %s are not equal: %p vs. %p",
1386 a_client->event, a_client->notify, b_client->notify);
1406 crm_trace(
"Sending call options: %.8lx, %d", (
long)call_options, call_options);
1417 stonith_destroy_op_callback(gpointer
data)
1421 if (blob->timer && blob->timer->ref > 0) {
1422 g_source_remove(blob->timer->ref);
1429 stonith_api_signoff(
stonith_t * stonith)
1433 crm_debug(
"Disconnecting from the fencer");
1435 if (native->source != NULL) {
1438 native->source = NULL;
1441 }
else if (native->ipc) {
1450 free(native->token); native->token = NULL;
1456 stonith_api_del_callback(
stonith_t * stonith,
int call_id,
bool all_callbacks)
1460 if (all_callbacks) {
1461 private->op_callback = NULL;
1462 g_hash_table_destroy(private->stonith_op_callback_table);
1463 private->stonith_op_callback_table = g_hash_table_new_full(g_direct_hash, g_direct_equal,
1465 stonith_destroy_op_callback);
1467 }
else if (call_id == 0) {
1468 private->op_callback = NULL;
1471 g_hash_table_remove(private->stonith_op_callback_table, GINT_TO_POINTER(call_id));
1477 invoke_callback(
stonith_t * st,
int call_id,
int rc,
void *userdata,
1486 callback(st, &data);
1490 stonith_perform_callback(
stonith_t * stonith, xmlNode * msg,
int call_id,
int rc)
1501 local_blob.id = NULL;
1502 local_blob.callback = NULL;
1503 local_blob.user_data = NULL;
1504 local_blob.only_success = FALSE;
1513 blob = g_hash_table_lookup(private->stonith_op_callback_table, GINT_TO_POINTER(call_id));
1519 stonith_api_del_callback(stonith, call_id, FALSE);
1522 crm_trace(
"No callback found for call %d", call_id);
1523 local_blob.callback = NULL;
1526 if (local_blob.callback != NULL && (rc ==
pcmk_ok || local_blob.only_success == FALSE)) {
1527 crm_trace(
"Invoking callback %s for call %d",
crm_str(local_blob.id), call_id);
1528 invoke_callback(stonith, call_id, rc, local_blob.user_data, local_blob.callback);
1530 }
else if (private->op_callback == NULL && rc !=
pcmk_ok) {
1535 if (private->op_callback != NULL) {
1536 crm_trace(
"Invoking global callback for call %d", call_id);
1537 invoke_callback(stonith, call_id, rc, NULL, private->op_callback);
1543 stonith_async_timeout_handler(gpointer data)
1560 struct timer_rec_s *async_timer = callback->timer;
1567 async_timer = calloc(1,
sizeof(
struct timer_rec_s));
1568 callback->timer = async_timer;
1576 async_timer->
timeout = (timeout + 60) * 1000;
1577 if (async_timer->
ref) {
1578 g_source_remove(async_timer->
ref);
1581 g_timeout_add(async_timer->
timeout, stonith_async_timeout_handler, async_timer);
1585 update_callback_timeout(
int call_id,
int timeout,
stonith_t * st)
1590 callback = g_hash_table_lookup(private->stonith_op_callback_table, GINT_TO_POINTER(call_id));
1591 if (!callback || !callback->allow_timeout_updates) {
1595 set_callback_timeout(callback, st, call_id, timeout);
1599 stonith_dispatch_internal(
const char *buffer, ssize_t length, gpointer userdata)
1601 const char *
type = NULL;
1602 struct notify_blob_s blob;
1608 private = st->st_private;
1612 if (blob.xml == NULL) {
1613 crm_warn(
"Received malformed message from fencer: %s", buffer);
1619 crm_trace(
"Activating %s callbacks...", type);
1622 stonith_perform_callback(st, blob.xml, 0, 0);
1625 g_list_foreach(private->notify_list, stonith_send_notification, &blob);
1633 update_callback_timeout(call_id, timeout, st);
1635 crm_err(
"Unknown message type: %s", type);
1644 stonith_api_signon(
stonith_t * stonith,
const char *name,
int *stonith_fd)
1650 .
dispatch = stonith_dispatch_internal,
1651 .destroy = stonith_connection_destroy
1654 crm_trace(
"Connecting command channel");
1663 }
else if (native->ipc) {
1664 crm_perror(LOG_ERR,
"Connection to fencer failed");
1675 if (native->ipc == NULL) {
1676 crm_debug(
"Could not connect to the Stonith API");
1681 xmlNode *reply = NULL;
1690 crm_perror(LOG_DEBUG,
"Couldn't complete registration with the fencing API: %d", rc);
1693 }
else if (reply == NULL) {
1694 crm_err(
"Did not receive registration reply");
1702 crm_err(
"Invalid registration message: %s", msg_type);
1706 }
else if (tmp_ticket == NULL) {
1707 crm_err(
"No registration token provided");
1712 crm_trace(
"Obtained registration token: %s", tmp_ticket);
1713 native->token = strdup(tmp_ticket);
1723 #if HAVE_MSGFROMIPC_TIMEOUT 1726 crm_debug(
"Connection to fencer successful");
1736 stonith_set_notification(
stonith_t * stonith,
const char *callback,
int enabled)
1753 crm_perror(LOG_DEBUG,
"Couldn't register for fencing notifications: %d", rc);
1765 stonith_api_add_notification(
stonith_t * stonith,
const char *event,
1768 GList *list_item = NULL;
1773 crm_trace(
"Adding callback for %s events (%d)", event, g_list_length(private->notify_list));
1776 new_client->event = event;
1777 new_client->notify = callback;
1779 list_item = g_list_find_custom(private->notify_list, new_client, stonithlib_GCompareFunc);
1781 if (list_item != NULL) {
1782 crm_warn(
"Callback already present");
1787 private->notify_list = g_list_append(private->notify_list, new_client);
1789 stonith_set_notification(stonith, event, 1);
1791 crm_trace(
"Callback added (%d)", g_list_length(private->notify_list));
1797 stonith_api_del_notification(
stonith_t * stonith,
const char *event)
1799 GList *list_item = NULL;
1803 crm_debug(
"Removing callback for %s events", event);
1807 new_client->event = event;
1808 new_client->notify = NULL;
1810 list_item = g_list_find_custom(private->notify_list, new_client, stonithlib_GCompareFunc);
1812 stonith_set_notification(stonith, event, 0);
1814 if (list_item != NULL) {
1817 private->notify_list = g_list_remove(private->notify_list, list_client);
1830 stonith_api_add_callback(
stonith_t * stonith,
int call_id,
int timeout,
int options,
1831 void *user_data,
const char *callback_name,
1837 CRM_CHECK(stonith != NULL,
return -EINVAL);
1842 private->op_callback = callback;
1844 }
else if (call_id < 0) {
1847 invoke_callback(stonith, call_id, call_id, user_data, callback);
1855 blob->id = callback_name;
1857 blob->user_data = user_data;
1858 blob->callback = callback;
1862 set_callback_timeout(blob, stonith, call_id, timeout);
1865 g_hash_table_insert(private->stonith_op_callback_table, GINT_TO_POINTER(call_id), blob);
1866 crm_trace(
"Added callback to %s for call %d", callback_name, call_id);
1872 stonith_dump_pending_op(gpointer key, gpointer value, gpointer user_data)
1874 int call = GPOINTER_TO_INT(key);
1885 if (private->stonith_op_callback_table == NULL) {
1888 return g_hash_table_foreach(private->stonith_op_callback_table, stonith_dump_pending_op, NULL);
1911 xml_to_event(xmlNode * msg)
1935 crm_err(
"No data for %s event", ntype);
1961 stonith_send_notification(gpointer data, gpointer user_data)
1963 struct notify_blob_s *blob = user_data;
1966 const char *
event = NULL;
1968 if (blob->xml == NULL) {
1969 crm_warn(
"Skipping callback - NULL message");
1975 if (entry == NULL) {
1976 crm_warn(
"Skipping callback - NULL callback client");
1979 }
else if (entry->notify == NULL) {
1980 crm_warn(
"Skipping callback - NULL callback");
1984 crm_trace(
"Skipping callback - event mismatch %p/%s vs. %s", entry, entry->event, event);
1988 st_event = xml_to_event(blob->xml);
1990 crm_trace(
"Invoking callback for %p/%s event...", entry, event);
1991 entry->notify(blob->stonith, st_event);
1994 event_free(st_event);
1999 int call_options,
int timeout)
2005 xmlNode *op_msg = NULL;
2006 xmlNode *op_reply = NULL;
2014 if (output_data != NULL) {
2015 *output_data = NULL;
2019 crm_err(
"No operation specified");
2039 if (op_msg == NULL) {
2044 crm_trace(
"Sending %s message to fencer with timeout %ds", op, timeout);
2046 rc =
crm_ipc_send(native->ipc, op_msg, ipc_flags, 1000 * (timeout + 60), &op_reply);
2050 crm_perror(LOG_ERR,
"Couldn't perform %s operation (timeout=%ds): %d", op, timeout, rc);
2057 if (!(call_options & st_opt_sync_call)) {
2068 if (reply_id == stonith->
call_id) {
2069 crm_trace(
"Synchronous reply %d received", reply_id);
2079 *output_data = op_reply;
2083 }
else if (reply_id <= 0) {
2084 crm_err(
"Received bad reply: No id set");
2090 crm_err(
"Received bad reply: %d (wanted %d)", reply_id, stonith->
call_id);
2098 crm_err(
"Fencer disconnected");
2110 gboolean stay_connected = TRUE;
2121 stonith_dispatch_internal(msg, strlen(msg), st);
2126 stay_connected = FALSE;
2130 return stay_connected;
2141 crm_trace(
"Disconnecting %p first", stonith);
2148 crm_trace(
"Removing %d callbacks", g_hash_table_size(private->stonith_op_callback_table));
2149 g_hash_table_destroy(private->stonith_op_callback_table);
2151 crm_trace(
"Destroying %d notification clients", g_list_length(private->notify_list));
2152 g_list_free_full(private->notify_list, free);
2155 free(stonith->
cmds);
2175 stonith_api_validate(
stonith_t *st,
int call_options,
const char *rsc_id,
2176 const char *namespace_s,
const char *agent,
2178 char **error_output)
2191 const char *target =
"node1";
2193 GHashTable *params_table = crm_str_table_new();
2196 for (; params; params = params->
next) {
2200 && strcmp(params->
key,
"provides")
2201 && strcmp(params->
key,
"stonith-timeout")) {
2202 g_hash_table_insert(params_table, strdup(params->
key),
2203 strdup(params->
value));
2207 #if SUPPORT_CIBSECRETS 2210 crm_warn(
"Could not replace secret parameters for validation of %s: %s",
2219 *error_output = NULL;
2225 params_table, timeout, output,
2229 #if HAVE_STONITH_STONITH_H 2232 params_table, timeout, output,
2241 "Agent %s not found or does not support validation",
2245 g_hash_table_destroy(params_table);
2255 new_stonith = calloc(1,
sizeof(
stonith_t));
2259 private->stonith_op_callback_table = g_hash_table_new_full(g_direct_hash, g_direct_equal,
2260 NULL, stonith_destroy_op_callback);
2261 private->notify_list = NULL;
2269 new_stonith->
cmds->
free = stonith_api_free;
2273 new_stonith->
cmds->
list = stonith_api_list;
2275 new_stonith->
cmds->
status = stonith_api_status;
2276 new_stonith->
cmds->
fence = stonith_api_fence;
2281 new_stonith->
cmds->
metadata = stonith_api_device_metadata;
2283 new_stonith->
cmds->
query = stonith_api_query;
2310 p->
key = strdup(key);
2313 p->
value = strdup(value);
2317 while (end && end->
next) {
2348 #define api_log_open() openlog("stonith-api", LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON) 2349 #define api_log(level, fmt, args...) syslog(level, "%s: "fmt, __FUNCTION__, args) 2355 const char *action =
"reboot";
2366 api_log(LOG_ERR,
"Connection failed, could not kick (%s) node %u/%s : %s (%d)", action, nodeid, uname,
pcmk_strerror(rc), rc);
2370 if (uname != NULL) {
2371 name = strdup(uname);
2373 }
else if (nodeid > 0) {
2375 name = crm_itoa(nodeid);
2383 rc = st->
cmds->
fence(st, opts, name, action, timeout, 0);
2385 api_log(LOG_ERR,
"Could not kick (%s) node %u/%s : %s (%d)", action, nodeid, uname,
pcmk_strerror(rc), rc);
2387 api_log(LOG_NOTICE,
"Node %u/%s kicked: %s ", nodeid, uname, action);
2419 if (uname != NULL) {
2420 name = strdup(uname);
2422 }
else if (nodeid > 0) {
2424 name = crm_itoa(nodeid);
2432 rc = st->
cmds->
history(st, opts, name, &history, 120);
2434 for (hp = history; hp; hp = hp->
next) {
2442 }
else if (hp->state ==
st_done) {
2444 if (hp->completed > when) {
2445 when = hp->completed;
2453 api_log(LOG_INFO,
"Found %d entries for %u/%s: %d in progress, %d completed", entries, nodeid, uname, progress, completed);
2455 api_log(LOG_ERR,
"Could not retrieve fence history for %u/%s: %s (%d)", nodeid, uname,
pcmk_strerror(rc), rc);
2465 api_log(LOG_INFO,
"Node %u/%s last kicked at: %ld", nodeid, uname, (
long int)when);
#define CRM_CHECK(expr, failure_action)
int stonith_send_command(stonith_t *stonith, const char *op, xmlNode *data, xmlNode **output_data, int call_options, int timeout)
#define XML_ATTR_STONITH_TARGET_ATTRIBUTE
struct stonith_action_s stonith_action_t
void stonith_history_free(stonith_history_t *history)
#define F_STONITH_REMOTE_OP_ID
struct stonith_history_s * next
bool crm_ipc_connect(crm_ipc_t *client)
Establish an IPC connection to a Pacemaker component.
#define crm_notice(fmt, args...)
int(* register_level_full)(stonith_t *st, int options, const char *node, const char *pattern, const char *attr, const char *value, int level, stonith_key_value_t *device_list)
Register fencing level for specific node, node regex or attribute.
#define F_STONITH_CLIENTID
const char * pcmk_strerror(int rc)
gboolean safe_str_neq(const char *a, const char *b)
int stonith__rhcs_metadata(const char *agent, int timeout, char **output)
Execute RHCS-compatible agent's meta-data action.
stonith_key_value_t * stonith_key_value_add(stonith_key_value_t *head, const char *key, const char *value)
void stonith_dump_pending_callbacks(stonith_t *stonith)
#define crm_log_output(level, prefix, output)
int crm_ipc_get_fd(crm_ipc_t *client)
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_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
xmlNode * stonith_create_op(int call_id, const char *token, const char *op, xmlNode *data, int call_options)
#define XML_TAG_FENCING_LEVEL
struct stonith_key_value_s * next
struct mainloop_io_s mainloop_io_t
int(* register_level)(stonith_t *st, int options, const char *node, int level, stonith_key_value_t *device_list)
Register a fencing level containing the fencing devices to be used at that level for a specific node...
struct mainloop_child_s mainloop_child_t
void stonith_key_value_freeall(stonith_key_value_t *head, int keys, int values)
#define F_STONITH_TIMEOUT
int stonith__lha_metadata(const char *agent, int timeout, char **output)
void stonith__destroy_action(stonith_action_t *action)
#define T_STONITH_TIMEOUT_VALUE
#define CRM_LOG_ASSERT(expr)
long crm_ipc_read(crm_ipc_t *client)
#define F_STONITH_NOTIFY_DEACTIVATE
void stonith__action_result(stonith_action_t *action, int *rc, char **output, char **error_output)
int(* remove_callback)(stonith_t *st, int call_id, bool all_callbacks)
Remove a registered callback for a given call id.
xmlNode * get_xpath_object(const char *xpath, xmlNode *xml_obj, int error_level)
int stonith__execute(stonith_action_t *action)
Wrappers for and extensions to glib mainloop.
bool crm_starts_with(const char *str, const char *prefix)
Check whether a string starts with a certain sequence.
#define STONITH_OP_LEVEL_DEL
#define STONITH_OP_DEVICE_ADD
xmlNode * string2xml(const char *input)
const char * crm_ipc_buffer(crm_ipc_t *client)
int stonith__list_lha_agents(stonith_key_value_t **devices)
time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress)
int(* free)(stonith_t *st)
Destroy the stonith api structure.
void hash2field(gpointer key, gpointer value, gpointer user_data)
#define XML_ATTR_STONITH_TARGET_PATTERN
xmlNode * create_level_registration_xml(const char *node, const char *pattern, const char *attr, const char *value, int level, stonith_key_value_t *device_list)
#define crm_warn(fmt, args...)
bool stonith__agent_is_rhcs(const char *agent)
#define STONITH_ATTR_HOSTARG
bool stonith_dispatch(stonith_t *st)
#define crm_debug(fmt, args...)
void * mainloop_child_userdata(mainloop_child_t *child)
#define STONITH_OP_LEVEL_ADD
struct crm_ipc_s crm_ipc_t
int(* metadata)(stonith_t *st, int options, const char *device, const char *provider, char **output, int timeout)
Get the metadata documentation for a resource.
#define XML_ATTR_STONITH_DEVICES
int(* register_device)(stonith_t *st, int options, const char *id, const char *provider, const char *agent, stonith_key_value_t *params)
Register a stonith device with the local stonith daemon.
int(* status)(stonith_t *st, int options, const char *id, const char *port, int timeout)
Check to see if a local stonith device's port is reachable.
enum stonith_namespace stonith_text2namespace(const char *namespace_s)
Get agent namespace by name.
#define crm_trace(fmt, args...)
#define XML_ATTR_STONITH_INDEX
int(* fence)(stonith_t *st, int options, const char *node, const char *action, int timeout, int tolerance)
Issue a fencing action against a node.
int(* register_callback)(stonith_t *st, int call_id, int timeout, int options, void *userdata, const char *callback_name, void(*callback)(stonith_t *st, stonith_callback_data_t *data))
Register a callback to receive the result of an async call id.
int crm_set_nonblocking(int fd)
#define crm_log_xml_debug(xml, text)
#define XML_ATTR_STONITH_TARGET
Wrappers for and extensions to libxml2.
xmlNode * create_xml_node(xmlNode *parent, const char *name)
#define crm_log_xml_warn(xml, text)
int(* disconnect)(stonith_t *st)
Disconnect from the local stonith daemon.
int(* stonith_op_t)(const char *, int, const char *, xmlNode *, xmlNode *, xmlNode *, xmlNode **, xmlNode **)
enum stonith_namespace stonith_get_namespace(const char *agent, const char *namespace_s)
Determine namespace of a fence agent.
#define T_STONITH_NOTIFY_DISCONNECT
const char * get_stonith_provider(const char *agent, const char *provider)
Deprecated (use stonith_get_namespace() instead)
#define STONITH_OP_DEVICE_DEL
int(* list)(stonith_t *st, int options, const char *id, char **list_output, int timeout)
Retrieve string listing hosts and port assignments from a local stonith device.
void mainloop_del_ipc_client(mainloop_io_t *client)
void crm_ipc_destroy(crm_ipc_t *client)
char * crm_element_value_copy(const xmlNode *data, const char *name)
#define XML_ATTR_STONITH_TARGET_VALUE
struct stonith_notify_client_s stonith_notify_client_t
int(* list_agents)(stonith_t *stonith, int call_options, const char *provider, stonith_key_value_t **devices, int timeout)
Retrieve a list of installed stonith agents.
gboolean add_message_xml(xmlNode *msg, const char *field, xmlNode *xml)
void stonith_api_delete(stonith_t *stonith)
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 * crm_element_value(const xmlNode *data, const char *name)
const char * stonith_namespace2text(enum stonith_namespace namespace)
Get agent namespace name.
#define STONITH_ATTR_ACTION_OP
#define STONITH_OP_FENCE_HISTORY
#define F_STONITH_CALLOPTS
GPid stonith_action_execute_async(stonith_action_t *action, void *userdata, void(*done)(GPid pid, int rc, const char *output, gpointer user_data))
int(* remove_device)(stonith_t *st, int options, const char *name)
Remove a registered stonith device with the local stonith daemon.
struct stonith_private_s stonith_private_t
bool crm_ipc_connected(crm_ipc_t *client)
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
const char * crm_xml_add_int(xmlNode *node, const char *name, int value)
int(* register_notification)(stonith_t *st, const char *event, void(*notify)(stonith_t *st, stonith_event_t *e))
int crm_ipc_ready(crm_ipc_t *client)
Check whether an IPC connection is ready to be read.
int(* monitor)(stonith_t *st, int options, const char *id, int timeout)
Check to see if a local stonith device is reachable.
int(* remove_notification)(stonith_t *st, const char *event)
void mainloop_child_add(pid_t pid, int timeout, const char *desc, void *userdata, void(*callback)(mainloop_child_t *p, pid_t pid, int core, int signo, int exitcode))
int replace_secret_params(const char *rsc_id, GHashTable *params)
#define crm_log_xml_err(xml, text)
struct stonith_callback_client_s stonith_callback_client_t
int(* validate)(stonith_t *st, int call_options, const char *rsc_id, const char *namespace_s, const char *agent, stonith_key_value_t *params, int timeout, char **output, char **error_output)
Validate an arbitrary stonith device configuration.
int stonith__list_rhcs_agents(stonith_key_value_t **devices)
#define crm_perror(level, fmt, args...)
Log a system error message.
crm_ipc_t * mainloop_get_ipc_client(mainloop_io_t *client)
#define crm_err(fmt, args...)
#define G_PRIORITY_MEDIUM
xmlXPathObjectPtr xpath_search(xmlNode *xml_top, const char *path)
int(* remove_level_full)(stonith_t *st, int options, const char *node, const char *pattern, const char *attr, const char *value, int level)
Remove fencing level for specific node, node regex or attribute.
stonith_api_operations_t * cmds
int crm_ipc_send(crm_ipc_t *client, xmlNode *message, enum crm_ipc_flags flags, int32_t ms_timeout, xmlNode **reply)
stonith_t * stonith_api_new(void)
int(* remove_level)(stonith_t *st, int options, const char *node, int level)
Remove a fencing level for a specific node.
#define FAILURE_MAX_RETRIES
#define crm_log_xml_notice(xml, text)
xmlNode * getXpathResult(xmlXPathObjectPtr xpathObj, int index)
crm_ipc_t * crm_ipc_new(const char *name, size_t max_size)
int crm_element_value_int(const xmlNode *data, const char *name, int *dest)
bool stonith__agent_is_lha(const char *agent)
Determine namespace of a fence agent.
#define T_STONITH_NOTIFY_FENCE
int(* confirm)(stonith_t *st, int options, const char *node)
Manually confirm that a node is down.
#define crm_log_xml_trace(xml, text)
#define F_STONITH_OPERATION
mainloop_io_t * mainloop_add_ipc_client(const char *name, int priority, size_t max_size, void *userdata, struct ipc_client_callbacks *callbacks)
#define safe_str_eq(a, b)
int stonith__rhcs_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_NOTIFY_ACTIVATE
void freeXpathObject(xmlXPathObjectPtr xpathObj)
void crm_ipc_close(crm_ipc_t *client)
#define F_STONITH_CALLDATA
CRM_TRACE_INIT_DATA(stonith)
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
#define F_STONITH_DELEGATE
#define crm_info(fmt, args...)
int(* history)(stonith_t *st, int options, const char *node, stonith_history_t **output, int timeout)
Retrieve a list of fencing operations that have occurred for a specific node.
int(* dispatch)(const char *buffer, ssize_t length, gpointer userdata)
#define F_STONITH_HISTORY_LIST
enum crm_ais_msg_types type
stonith_action_t * stonith_action_create(const char *agent, const char *_action, const char *victim, uint32_t victim_nodeid, int timeout, GHashTable *device_args, GHashTable *port_map)
#define F_STONITH_TOLERANCE