27 #include <sys/types.h> 40 #if SUPPORT_CIBSECRETS 46 struct stonith_action_s {
55 void (*done_cb) (GPid
pid, gint status,
const char *output, gpointer user_data);
60 int last_timeout_signo;
63 time_t initial_start_time;
65 int remaining_timeout;
77 typedef struct stonith_private_s {
81 GHashTable *stonith_op_callback_table;
88 typedef struct stonith_notify_client_s {
96 typedef struct stonith_callback_client_s {
100 gboolean only_success;
101 gboolean allow_timeout_updates;
106 struct notify_blob_s {
118 typedef int (*
stonith_op_t) (
const char *, int,
const char *, xmlNode *,
119 xmlNode *, xmlNode *, xmlNode **, xmlNode **);
127 xmlNode ** output_data,
int call_options,
int timeout);
129 static void stonith_connection_destroy(gpointer user_data);
130 static void stonith_send_notification(gpointer
data, gpointer user_data);
144 if ((namespace_s == NULL) || !strcmp(namespace_s,
"any")) {
147 }
else if (!strcmp(namespace_s,
"redhat")
148 || !strcmp(namespace_s,
"stonith-ng")) {
151 }
else if (!strcmp(namespace_s,
"internal")) {
154 }
else if (!strcmp(namespace_s,
"heartbeat")) {
177 return "unsupported";
199 #if HAVE_STONITH_STONITH_H 205 crm_err(
"Unknown fence agent: %s", agent);
212 if (action->output) {
230 stonith_connection_destroy(gpointer user_data)
234 struct notify_blob_s blob;
236 crm_trace(
"Sending destroyed notification");
237 blob.stonith = stonith;
242 native->source = NULL;
248 g_list_foreach(native->notify_list, stonith_send_notification, &blob);
255 const char *rsc_provides)
260 #if HAVE_STONITH_STONITH_H 265 hash2field((gpointer)
"plugin", (gpointer) agent, args);
266 agent =
"fence_legacy";
280 for (; params; params = params->
next) {
288 stonith_api_register_device(
stonith_t * st,
int call_options,
289 const char *
id,
const char *
namespace,
const char *agent,
293 xmlNode *
data = NULL;
296 agent, params, NULL);
305 stonith_api_remove_device(
stonith_t * st,
int call_options,
const char *name)
308 xmlNode *
data = NULL;
320 stonith_api_remove_level_full(
stonith_t *st,
int options,
321 const char *node,
const char *pattern,
322 const char *attr,
const char *value,
int level)
325 xmlNode *
data = NULL;
327 CRM_CHECK(node || pattern || (attr && value),
return -EINVAL);
335 }
else if (pattern) {
351 stonith_api_remove_level(
stonith_t * st,
int options,
const char *node,
int level)
353 return stonith_api_remove_level_full(st, options, node,
354 NULL, NULL, NULL, level);
374 const char *attr,
const char *value,
381 CRM_CHECK(node || pattern || (attr && value),
return NULL);
393 }
else if (pattern) {
401 for (; device_list; device_list = device_list->
next) {
403 int adding = strlen(device_list->
value);
408 crm_trace(
"Adding %s (%dc) at offset %d", device_list->
value, adding, len);
409 list = realloc_safe(list, len + adding + 1);
411 crm_perror(LOG_CRIT,
"Could not create device list");
415 sprintf(list + len,
"%s%s", len?
",":
"", device_list->
value);
426 stonith_api_register_level_full(
stonith_t * st,
int options,
const char *node,
428 const char *attr,
const char *value,
443 stonith_api_register_level(
stonith_t * st,
int options,
const char *node,
int level,
446 return stonith_api_register_level_full(st, options, node, NULL, NULL, NULL,
451 append_arg(
const char *key,
const char *value,
char **args)
459 if (strstr(key,
"pcmk_")) {
468 len += strlen(value);
470 last = strlen(*args);
473 *args = realloc_safe(*args, last + len);
474 crm_trace(
"Appending: %s=%s", key, value);
475 sprintf((*args) + last,
"%s=%s\n", key, value);
479 append_config_arg(gpointer key, gpointer value, gpointer user_data)
486 append_arg(key, value, user_data);
492 append_host_specific_args(
const char *victim,
const char *map, GHashTable * params,
char **arg_list)
495 int last = 0, lpc = 0, max = 0;
499 crm_debug(
"Using default arg map: port=uname");
500 append_arg(
"port", victim, arg_list);
505 crm_debug(
"Processing arg map: %s", map);
506 for (; lpc < max + 1; lpc++) {
507 if (isalpha(map[lpc])) {
510 }
else if (map[lpc] ==
'=' || map[lpc] ==
':') {
512 name = calloc(1, 1 + lpc - last);
513 memcpy(name, map + last, lpc - last);
517 }
else if (map[lpc] == 0 || map[lpc] ==
',' || isspace(map[lpc])) {
519 const char *value = NULL;
521 param = calloc(1, 1 + lpc - last);
522 memcpy(param, map + last, lpc - last);
527 crm_err(
"Misparsed '%s', found '%s' without a name", map, param);
537 value = g_hash_table_lookup(params, key);
542 crm_debug(
"Setting '%s'='%s' (%s) for %s", name, value, param, victim);
543 append_arg(name, value, arg_list);
546 crm_err(
"No node attribute '%s' for '%s'", name, victim);
556 }
else if (isspace(map[lpc])) {
564 make_args(
const char *agent,
const char *action,
const char *victim,
uint32_t victim_nodeid, GHashTable * device_args,
565 GHashTable * port_map)
568 char *arg_list = NULL;
569 const char *value = NULL;
573 snprintf(buffer,
sizeof(buffer),
"pcmk_%s_action", action);
575 value = g_hash_table_lookup(device_args, buffer);
578 if (value == NULL && device_args) {
580 snprintf(buffer,
sizeof(buffer),
"pcmk_%s_cmd", action);
581 value = g_hash_table_lookup(device_args, buffer);
584 if (value == NULL && device_args &&
safe_str_eq(action,
"off")) {
586 value = g_hash_table_lookup(device_args,
"pcmk_poweroff_action");
590 crm_info(
"Substituting action '%s' for requested operation '%s'", value, action);
595 if (victim && device_args) {
596 const char *alias = victim;
599 if (port_map && g_hash_table_lookup(port_map, victim)) {
600 alias = g_hash_table_lookup(port_map, victim);
606 append_arg(
"nodename", victim, &arg_list);
608 char nodeid_str[33] = { 0, };
609 if (snprintf(nodeid_str, 33,
"%u", (
unsigned int)victim_nodeid)) {
610 crm_info(
"For stonith action (%s) for victim %s, adding nodeid (%s) to parameters",
611 action, victim, nodeid_str);
612 append_arg(
"nodeid", nodeid_str, &arg_list);
620 }
else if (param == NULL) {
627 value = g_hash_table_lookup(device_args, param);
630 append_host_specific_args(alias, map, device_args, &arg_list);
638 value = g_hash_table_lookup(device_args, param);
642 if (value == NULL ||
safe_str_eq(value,
"dynamic")) {
643 crm_debug(
"Performing %s action for node '%s' as '%s=%s'", action, victim, param,
645 append_arg(param, alias, &arg_list);
650 g_hash_table_foreach(device_args, append_config_arg, &arg_list);
657 st_child_term(gpointer
data)
662 crm_info(
"Child %d timed out, sending SIGTERM", track->pid);
663 track->timer_sigterm = 0;
664 track->last_timeout_signo = SIGTERM;
665 rc = kill(-track->pid, SIGTERM);
667 crm_perror(LOG_ERR,
"Couldn't send SIGTERM to %d", track->pid);
673 st_child_kill(gpointer
data)
678 crm_info(
"Child %d timed out, sending SIGKILL", track->pid);
679 track->timer_sigkill = 0;
680 track->last_timeout_signo = SIGKILL;
681 rc = kill(-track->pid, SIGKILL);
683 crm_perror(LOG_ERR,
"Couldn't send SIGKILL to %d", track->pid);
691 if (action->timer_sigterm > 0) {
692 g_source_remove(action->timer_sigterm);
693 action->timer_sigterm = 0;
695 if (action->timer_sigkill > 0) {
696 g_source_remove(action->timer_sigkill);
697 action->timer_sigkill = 0;
699 if (action->fd_stdout) {
700 close(action->fd_stdout);
701 action->fd_stdout = 0;
703 if (action->fd_stderr) {
704 close(action->fd_stderr);
705 action->fd_stderr = 0;
707 free(action->output);
708 action->output = NULL;
710 action->error = NULL;
713 action->last_timeout_signo = 0;
726 stonith_action_clear_tracking_data(action);
729 free(action->action);
730 free(action->victim);
758 *error_output = NULL;
760 if (action != NULL) {
764 if (output && action->output) {
765 *output = action->output;
766 action->output = NULL;
768 if (error_output && action->error) {
769 *error_output = action->error;
770 action->error = NULL;
775 #define FAILURE_MAX_RETRIES 2 781 int timeout, GHashTable * device_args, GHashTable * port_map)
786 action->args = make_args(agent, _action, victim, victim_nodeid, device_args, port_map);
787 crm_debug(
"Preparing '%s' action for %s using agent %s",
788 _action, (victim? victim :
"no target"), agent);
789 action->agent = strdup(agent);
790 action->action = strdup(_action);
792 action->victim = strdup(victim);
794 action->timeout = action->remaining_timeout = timeout;
799 const char *value = NULL;
801 snprintf(buffer,
sizeof(buffer),
"pcmk_%s_retries", _action);
802 value = g_hash_table_lookup(device_args, buffer);
805 action->max_retries = atoi(value);
828 more = read(fd, buffer,
READ_MAX - 1);
834 output = realloc_safe(output, len + more + 1);
835 snprintf(output + len, more + 1,
"%s", buffer);
839 }
while (more == (
READ_MAX - 1) || (more < 0 && errno == EINTR));
847 int diff = time(NULL) - action->initial_start_time;
849 if (action->tries >= action->max_retries) {
850 crm_info(
"Attempted to execute agent %s (%s) the maximum number of times (%d) allowed",
851 action->agent, action->action, action->max_retries);
852 action->remaining_timeout = 0;
853 }
else if ((action->rc != -
ETIME) && diff < (action->timeout * 0.7)) {
856 action->remaining_timeout = action->timeout - diff;
858 action->remaining_timeout = 0;
860 return action->remaining_timeout ? TRUE : FALSE;
864 stonith_action_async_done(
mainloop_child_t * p, pid_t
pid,
int core,
int signo,
int exitcode)
868 if (action->timer_sigterm > 0) {
869 g_source_remove(action->timer_sigterm);
870 action->timer_sigterm = 0;
872 if (action->timer_sigkill > 0) {
873 g_source_remove(action->timer_sigkill);
874 action->timer_sigkill = 0;
877 action->output = read_output(action->fd_stdout);
878 action->error = read_output(action->fd_stderr);
880 if (action->last_timeout_signo) {
882 crm_notice(
"Child process %d performing action '%s' timed out with signal %d",
883 pid, action->action, action->last_timeout_signo);
886 action->rc = -ECONNABORTED;
887 crm_notice(
"Child process %d performing action '%s' timed out with signal %d",
888 pid, action->action, signo);
891 crm_debug(
"Child process %d performing action '%s' exited with rc %d",
892 pid, action->action, exitcode);
897 if (action->error == NULL) {
900 }
else if (strstr(action->error,
"imed out")) {
902 exitcode = -ETIMEDOUT;
904 }
else if (strstr(action->error,
"Unrecognised action")) {
905 exitcode = -EOPNOTSUPP;
911 action->rc = exitcode;
914 log_action(action,
pid);
916 if (action->rc !=
pcmk_ok && update_remaining_timeout(action)) {
917 int rc = internal_stonith_action_execute(action);
923 if (action->done_cb) {
924 action->done_cb(
pid, action->rc, action->output, action->userdata);
933 int pid, status = 0, len, rc = -EPROTO;
936 int p_read_fd, p_write_fd;
937 int c_read_fd, c_write_fd;
938 int c_stderr_fd, p_stderr_fd;
945 stonith_action_clear_tracking_data(action);
947 if (!action->tries) {
948 action->initial_start_time = time(NULL);
952 if (action->tries > 1) {
953 crm_info(
"Attempt %d to execute %s (%s). remaining timeout is %d",
954 action->tries, action->agent, action->action, action->remaining_timeout);
958 c_read_fd = c_write_fd = p_read_fd = p_write_fd = c_stderr_fd = p_stderr_fd = -1;
960 if (action->args == NULL || action->agent == NULL)
962 len = strlen(action->args);
976 p_stderr_fd = fd3[0];
977 c_stderr_fd = fd3[1];
992 if (dup(c_write_fd) < 0)
996 if (dup(c_stderr_fd) < 0)
1000 if (dup(c_read_fd) < 0)
1014 execlp(action->agent, action->agent, NULL);
1022 crm_notice(
"Could not set output of %s to be non-blocking: %s " 1028 crm_notice(
"Could not set error output of %s to be non-blocking: %s " 1036 ret = write(p_write_fd, action->args + total, len - total);
1041 }
while (errno == EINTR && total < len);
1044 crm_perror(LOG_ERR,
"Sent %d not %d bytes", total, len);
1051 close(p_write_fd); p_write_fd = -1;
1054 if (action->async) {
1055 action->fd_stdout = p_read_fd;
1056 action->fd_stderr = p_stderr_fd;
1058 crm_trace(
"Op: %s on %s, pid: %d, timeout: %ds", action->action, action->agent, pid,
1059 action->remaining_timeout);
1060 action->last_timeout_signo = 0;
1061 if (action->remaining_timeout) {
1062 action->timer_sigterm =
1063 g_timeout_add(1000 * action->remaining_timeout, st_child_term, action);
1064 action->timer_sigkill =
1065 g_timeout_add(1000 * (action->remaining_timeout + 5), st_child_kill, action);
1067 crm_err(
"No timeout set for stonith operation %s with device %s",
1068 action->action, action->agent);
1078 int timeout = action->remaining_timeout + 1;
1081 while (action->remaining_timeout < 0 || timeout > 0) {
1082 p = waitpid(pid, &status, WNOHANG);
1091 int killrc = kill(-pid, SIGKILL);
1093 if (killrc && errno != ESRCH) {
1102 p = waitpid(pid, &status, 0);
1108 }
else if (p != pid) {
1109 crm_err(
"Waited for %d, got %d", pid, p);
1112 action->output = read_output(p_read_fd);
1113 action->error = read_output(p_stderr_fd);
1115 action->rc = -ECONNABORTED;
1117 log_action(action, pid);
1121 action->rc = -
ETIME;
1122 }
else if (WIFEXITED(status)) {
1123 crm_debug(
"result = %d", WEXITSTATUS(status));
1124 action->rc = -WEXITSTATUS(status);
1127 }
else if (WIFSIGNALED(status)) {
1128 crm_err(
"call %s for %s exited due to signal %d", action->action, action->agent,
1132 crm_err(
"call %s for %s returned unexpected status %#x",
1133 action->action, action->agent, status);
1139 if (p_read_fd >= 0) {
1142 if (p_write_fd >= 0) {
1145 if (p_stderr_fd >= 0) {
1149 if (c_read_fd >= 0) {
1152 if (c_write_fd >= 0) {
1155 if (c_stderr_fd >= 0) {
1165 void (*done) (GPid
pid,
int rc,
const char *output,
1166 gpointer user_data))
1174 action->userdata = userdata;
1175 action->done_cb = done;
1178 rc = internal_stonith_action_execute(action);
1180 return rc < 0 ? rc : action->pid;
1196 CRM_CHECK(action != NULL,
return -EINVAL);
1200 rc = internal_stonith_action_execute(action);
1201 }
while ((rc !=
pcmk_ok) && update_remaining_timeout(action));
1207 stonith_api_device_list(
stonith_t * stonith,
int call_options,
const char *
namespace,
1213 if (devices == NULL) {
1214 crm_err(
"Parameter error: stonith_api_device_list");
1218 #if HAVE_STONITH_STONITH_H 1234 stonith_api_device_metadata(
stonith_t * stonith,
int call_options,
const char *agent,
1235 const char *
namespace,
char **output,
int timeout)
1243 crm_trace(
"Looking up metadata for %s agent %s",
1250 #if HAVE_STONITH_STONITH_H 1258 "Agent %s not found or does not support meta-data",
1266 stonith_api_query(
stonith_t * stonith,
int call_options,
const char *target,
1269 int rc = 0, lpc = 0, max = 0;
1271 xmlNode *
data = NULL;
1272 xmlNode *output = NULL;
1273 xmlXPathObjectPtr xpathObj = NULL;
1275 CRM_CHECK(devices != NULL,
return -EINVAL);
1289 max = numXpathResults(xpathObj);
1291 for (lpc = 0; lpc < max; lpc++) {
1296 xmlChar *match_path = xmlGetNodePath(match);
1298 crm_info(
"%s[%d] = %s",
"//@agent", lpc, match_path);
1316 const char *action,
const char *victim,
int timeout, xmlNode ** output)
1319 xmlNode *
data = NULL;
1334 stonith_api_list(
stonith_t * stonith,
int call_options,
const char *
id,
char **list_info,
1338 xmlNode *output = NULL;
1340 rc = stonith_api_call(stonith, call_options,
id,
"list", NULL, timeout, &output);
1342 if (output && list_info) {
1343 const char *list_str;
1348 *list_info = strdup(list_str);
1360 stonith_api_monitor(
stonith_t * stonith,
int call_options,
const char *
id,
int timeout)
1362 return stonith_api_call(stonith, call_options,
id,
"monitor", NULL, timeout, NULL);
1366 stonith_api_status(
stonith_t * stonith,
int call_options,
const char *
id,
const char *port,
1369 return stonith_api_call(stonith, call_options,
id,
"status", port, timeout, NULL);
1373 stonith_api_fence(
stonith_t * stonith,
int call_options,
const char *node,
const char *action,
1374 int timeout,
int tolerance)
1377 xmlNode *
data = NULL;
1392 stonith_api_confirm(
stonith_t * stonith,
int call_options,
const char *target)
1394 return stonith_api_fence(stonith, call_options |
st_opt_manual_ack, target,
"off", 0, 0);
1398 stonith_api_history(
stonith_t * stonith,
int call_options,
const char *node,
1402 xmlNode *
data = NULL;
1403 xmlNode *output = NULL;
1421 for (op = __xml_first_child(reply); op != NULL; op = __xml_next(op)) {
1448 for (hp = history; hp; hp_old = hp, hp = hp->
next, free(hp_old)) {
1467 stonithlib_GCompareFunc(gconstpointer a, gconstpointer b)
1473 CRM_CHECK(a_client->event != NULL && b_client->event != NULL,
return 0);
1474 rc = strcmp(a_client->event, b_client->event);
1476 if (a_client->notify == NULL || b_client->notify == NULL) {
1479 }
else if (a_client->notify == b_client->notify) {
1482 }
else if (((
long)a_client->notify) < ((
long)b_client->notify)) {
1483 crm_err(
"callbacks for %s are not equal: %p vs. %p",
1484 a_client->event, a_client->notify, b_client->notify);
1487 crm_err(
"callbacks for %s are not equal: %p vs. %p",
1488 a_client->event, a_client->notify, b_client->notify);
1508 crm_trace(
"Sending call options: %.8lx, %d", (
long)call_options, call_options);
1519 stonith_destroy_op_callback(gpointer
data)
1523 if (blob->timer && blob->timer->ref > 0) {
1524 g_source_remove(blob->timer->ref);
1531 stonith_api_signoff(
stonith_t * stonith)
1535 crm_debug(
"Signing out of the STONITH Service");
1537 if (native->source != NULL) {
1540 native->source = NULL;
1543 }
else if (native->ipc) {
1552 free(native->token); native->token = NULL;
1558 stonith_api_signon(
stonith_t * stonith,
const char *name,
int *stonith_fd)
1565 .destroy = stonith_connection_destroy
1568 crm_trace(
"Connecting command channel");
1577 }
else if (native->ipc) {
1578 crm_perror(LOG_ERR,
"Connection to STONITH manager failed");
1589 if (native->ipc == NULL) {
1590 crm_debug(
"Could not connect to the Stonith API");
1595 xmlNode *reply = NULL;
1604 crm_perror(LOG_DEBUG,
"Couldn't complete registration with the fencing API: %d", rc);
1607 }
else if (reply == NULL) {
1608 crm_err(
"Did not receive registration reply");
1616 crm_err(
"Invalid registration message: %s", msg_type);
1620 }
else if (tmp_ticket == NULL) {
1621 crm_err(
"No registration token provided");
1626 crm_trace(
"Obtained registration token: %s", tmp_ticket);
1627 native->token = strdup(tmp_ticket);
1637 #if HAVE_MSGFROMIPC_TIMEOUT 1640 crm_debug(
"Connection to STONITH successful");
1650 stonith_set_notification(
stonith_t * stonith,
const char *callback,
int enabled)
1667 crm_perror(LOG_DEBUG,
"Couldn't register for fencing notifications: %d", rc);
1679 stonith_api_add_notification(
stonith_t * stonith,
const char *event,
1682 GList *list_item = NULL;
1687 crm_trace(
"Adding callback for %s events (%d)", event, g_list_length(private->notify_list));
1690 new_client->event = event;
1691 new_client->notify = callback;
1693 list_item = g_list_find_custom(private->notify_list, new_client, stonithlib_GCompareFunc);
1695 if (list_item != NULL) {
1696 crm_warn(
"Callback already present");
1701 private->notify_list = g_list_append(private->notify_list, new_client);
1703 stonith_set_notification(stonith, event, 1);
1705 crm_trace(
"Callback added (%d)", g_list_length(private->notify_list));
1711 stonith_api_del_notification(
stonith_t * stonith,
const char *event)
1713 GList *list_item = NULL;
1717 crm_debug(
"Removing callback for %s events", event);
1721 new_client->event = event;
1722 new_client->notify = NULL;
1724 list_item = g_list_find_custom(private->notify_list, new_client, stonithlib_GCompareFunc);
1726 stonith_set_notification(stonith, event, 0);
1728 if (list_item != NULL) {
1731 private->notify_list = g_list_remove(private->notify_list, list_client);
1744 stonith_async_timeout_handler(gpointer data)
1761 struct timer_rec_s *async_timer = callback->timer;
1768 async_timer = calloc(1,
sizeof(
struct timer_rec_s));
1769 callback->timer = async_timer;
1777 async_timer->
timeout = (timeout + 60) * 1000;
1778 if (async_timer->
ref) {
1779 g_source_remove(async_timer->
ref);
1782 g_timeout_add(async_timer->
timeout, stonith_async_timeout_handler, async_timer);
1786 update_callback_timeout(
int call_id,
int timeout,
stonith_t * st)
1791 callback = g_hash_table_lookup(private->stonith_op_callback_table, GINT_TO_POINTER(call_id));
1792 if (!callback || !callback->allow_timeout_updates) {
1796 set_callback_timeout(callback, st, call_id, timeout);
1800 invoke_callback(
stonith_t * st,
int call_id,
int rc,
void *userdata,
1809 callback(st, &data);
1813 stonith_api_add_callback(
stonith_t * stonith,
int call_id,
int timeout,
int options,
1814 void *user_data,
const char *callback_name,
1820 CRM_CHECK(stonith != NULL,
return -EINVAL);
1825 private->op_callback = callback;
1827 }
else if (call_id < 0) {
1830 invoke_callback(stonith, call_id, call_id, user_data, callback);
1838 blob->id = callback_name;
1840 blob->user_data = user_data;
1841 blob->callback = callback;
1845 set_callback_timeout(blob, stonith, call_id, timeout);
1848 g_hash_table_insert(private->stonith_op_callback_table, GINT_TO_POINTER(call_id), blob);
1849 crm_trace(
"Added callback to %s for call %d", callback_name, call_id);
1855 stonith_api_del_callback(
stonith_t * stonith,
int call_id,
bool all_callbacks)
1859 if (all_callbacks) {
1860 private->op_callback = NULL;
1861 g_hash_table_destroy(private->stonith_op_callback_table);
1862 private->stonith_op_callback_table = g_hash_table_new_full(g_direct_hash, g_direct_equal,
1864 stonith_destroy_op_callback);
1866 }
else if (call_id == 0) {
1867 private->op_callback = NULL;
1870 g_hash_table_remove(private->stonith_op_callback_table, GINT_TO_POINTER(call_id));
1876 stonith_dump_pending_op(gpointer key, gpointer value, gpointer user_data)
1878 int call = GPOINTER_TO_INT(key);
1889 if (private->stonith_op_callback_table == NULL) {
1892 return g_hash_table_foreach(private->stonith_op_callback_table, stonith_dump_pending_op, NULL);
1907 local_blob.id = NULL;
1908 local_blob.callback = NULL;
1909 local_blob.user_data = NULL;
1910 local_blob.only_success = FALSE;
1919 blob = g_hash_table_lookup(private->stonith_op_callback_table, GINT_TO_POINTER(call_id));
1925 stonith_api_del_callback(stonith, call_id, FALSE);
1928 crm_trace(
"No callback found for call %d", call_id);
1929 local_blob.callback = NULL;
1932 if (local_blob.callback != NULL && (rc ==
pcmk_ok || local_blob.only_success == FALSE)) {
1933 crm_trace(
"Invoking callback %s for call %d",
crm_str(local_blob.id), call_id);
1934 invoke_callback(stonith, call_id, rc, local_blob.user_data, local_blob.callback);
1936 }
else if (private->op_callback == NULL && rc !=
pcmk_ok) {
1941 if (private->op_callback != NULL) {
1942 crm_trace(
"Invoking global callback for call %d", call_id);
1943 invoke_callback(stonith, call_id, rc, NULL, private->op_callback);
1968 xml_to_event(xmlNode * msg)
1992 crm_err(
"No data for %s event", ntype);
2018 stonith_send_notification(gpointer data, gpointer user_data)
2020 struct notify_blob_s *blob = user_data;
2023 const char *
event = NULL;
2025 if (blob->xml == NULL) {
2026 crm_warn(
"Skipping callback - NULL message");
2032 if (entry == NULL) {
2033 crm_warn(
"Skipping callback - NULL callback client");
2036 }
else if (entry->notify == NULL) {
2037 crm_warn(
"Skipping callback - NULL callback");
2041 crm_trace(
"Skipping callback - event mismatch %p/%s vs. %s", entry, entry->event, event);
2045 st_event = xml_to_event(blob->xml);
2047 crm_trace(
"Invoking callback for %p/%s event...", entry, event);
2048 entry->notify(blob->stonith, st_event);
2051 event_free(st_event);
2056 int call_options,
int timeout)
2062 xmlNode *op_msg = NULL;
2063 xmlNode *op_reply = NULL;
2071 if (output_data != NULL) {
2072 *output_data = NULL;
2076 crm_err(
"No operation specified");
2096 if (op_msg == NULL) {
2101 crm_trace(
"Sending %s message to STONITH service, Timeout: %ds", op, timeout);
2103 rc =
crm_ipc_send(native->ipc, op_msg, ipc_flags, 1000 * (timeout + 60), &op_reply);
2107 crm_perror(LOG_ERR,
"Couldn't perform %s operation (timeout=%ds): %d", op, timeout, rc);
2114 if (!(call_options & st_opt_sync_call)) {
2125 if (reply_id == stonith->
call_id) {
2126 crm_trace(
"Synchronous reply %d received", reply_id);
2136 *output_data = op_reply;
2140 }
else if (reply_id <= 0) {
2141 crm_err(
"Received bad reply: No id set");
2147 crm_err(
"Received bad reply: %d (wanted %d)", reply_id, stonith->
call_id);
2155 crm_err(
"STONITH disconnected");
2167 gboolean stay_connected = TRUE;
2183 stay_connected = FALSE;
2187 return stay_connected;
2193 const char *
type = NULL;
2194 struct notify_blob_s blob;
2200 private = st->private;
2204 if (blob.xml == NULL) {
2205 crm_warn(
"Received a NULL msg from STONITH service: %s.", buffer);
2211 crm_trace(
"Activating %s callbacks...", type);
2217 g_list_foreach(private->notify_list, stonith_send_notification, &blob);
2225 update_callback_timeout(call_id, timeout, st);
2227 crm_err(
"Unknown message type: %s", type);
2243 crm_trace(
"Disconnecting %p first", stonith);
2250 crm_trace(
"Removing %d callbacks", g_hash_table_size(private->stonith_op_callback_table));
2251 g_hash_table_destroy(private->stonith_op_callback_table);
2253 crm_trace(
"Destroying %d notification clients", g_list_length(private->notify_list));
2254 g_list_free_full(private->notify_list, free);
2257 free(stonith->
cmds);
2277 stonith_api_validate(
stonith_t *st,
int call_options,
const char *rsc_id,
2278 const char *namespace_s,
const char *agent,
2280 char **error_output)
2293 const char *target =
"node1";
2295 GHashTable *params_table = crm_str_table_new();
2298 for (; params; params = params->
next) {
2302 && strcmp(params->
key,
"provides")
2303 && strcmp(params->
key,
"stonith-timeout")) {
2304 g_hash_table_insert(params_table, strdup(params->
key),
2305 strdup(params->
value));
2309 #if SUPPORT_CIBSECRETS 2312 crm_warn(
"Could not replace secret parameters for validation of %s: %s",
2321 *error_output = NULL;
2327 params_table, timeout, output,
2331 #if HAVE_STONITH_STONITH_H 2334 params_table, timeout, output,
2343 "Agent %s not found or does not support validation",
2347 g_hash_table_destroy(params_table);
2357 new_stonith = calloc(1,
sizeof(
stonith_t));
2359 new_stonith->
private =
private;
2361 private->stonith_op_callback_table = g_hash_table_new_full(g_direct_hash, g_direct_equal,
2362 NULL, stonith_destroy_op_callback);
2363 private->notify_list = NULL;
2371 new_stonith->
cmds->
free = stonith_api_free;
2375 new_stonith->
cmds->
list = stonith_api_list;
2377 new_stonith->
cmds->
status = stonith_api_status;
2378 new_stonith->
cmds->
fence = stonith_api_fence;
2383 new_stonith->
cmds->
metadata = stonith_api_device_metadata;
2385 new_stonith->
cmds->
query = stonith_api_query;
2412 p->
key = strdup(key);
2415 p->
value = strdup(value);
2419 while (end && end->
next) {
2450 #define api_log_open() openlog("stonith-api", LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON) 2451 #define api_log(level, fmt, args...) syslog(level, "%s: "fmt, __FUNCTION__, args) 2457 const char *action =
"reboot";
2468 api_log(LOG_ERR,
"Connection failed, could not kick (%s) node %u/%s : %s (%d)", action, nodeid, uname,
pcmk_strerror(rc), rc);
2472 if (uname != NULL) {
2473 name = strdup(uname);
2475 }
else if (nodeid > 0) {
2485 rc = st->
cmds->
fence(st, opts, name, action, timeout, 0);
2487 api_log(LOG_ERR,
"Could not kick (%s) node %u/%s : %s (%d)", action, nodeid, uname,
pcmk_strerror(rc), rc);
2489 api_log(LOG_NOTICE,
"Node %u/%s kicked: %s ", nodeid, uname, action);
2521 if (uname != NULL) {
2522 name = strdup(uname);
2524 }
else if (nodeid > 0) {
2534 rc = st->
cmds->
history(st, opts, name, &history, 120);
2536 for (hp = history; hp; hp = hp->
next) {
2544 }
else if (hp->state ==
st_done) {
2546 if (hp->completed > when) {
2547 when = hp->completed;
2555 api_log(LOG_INFO,
"Found %d entries for %u/%s: %d in progress, %d completed", entries, nodeid, uname, progress, completed);
2557 api_log(LOG_ERR,
"Could not retrieve fence history for %u/%s: %s (%d)", nodeid, uname,
pcmk_strerror(rc), rc);
2567 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
gboolean safe_str_neq(const char *a, const char *b)
int(* register_device)(stonith_t *st, int options, const char *id, const char *namespace, const char *agent, stonith_key_value_t *params)
Register a stonith device with the local stonith daemon.
int stonith__rhcs_metadata(const char *agent, int timeout, char **output)
Execute RHCS-compatible agent's meta-data action.
int(* list_agents)(stonith_t *stonith, int call_options, const char *namespace, stonith_key_value_t **devices, int timeout)
Retrieve a list of installed stonith agents.
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)
const char * pcmk_strerror(int rc)
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)
char * crm_element_value_copy(xmlNode *data, const char *name)
#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)
int stonith_dispatch_internal(const char *buffer, ssize_t length, gpointer userdata)
#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
char * crm_meta_name(const char *field)
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
#define XML_ATTR_STONITH_DEVICES
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 crm_element_value_int(xmlNode *data, const char *name, int *dest)
const char * crm_element_value(xmlNode *data, const char *name)
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)
#define XML_ATTR_STONITH_TARGET_VALUE
struct stonith_notify_client_s stonith_notify_client_t
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 * 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
void stonith_perform_callback(stonith_t *stonith, xmlNode *msg, int call_id, int rc)
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)
#define STONITH_ATTR_ARGMAP
crm_ipc_t * crm_ipc_new(const char *name, size_t max_size)
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)
char * crm_itoa(int an_int)
#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)
int(* metadata)(stonith_t *st, int options, const char *device, const char *namespace, char **output, int timeout)
Get the metadata documentation for a resource.
#define F_STONITH_NOTIFY_ACTIVATE
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
void freeXpathObject(xmlXPathObjectPtr xpathObj)
void crm_ipc_close(crm_ipc_t *client)
#define F_STONITH_CALLDATA
CRM_TRACE_INIT_DATA(stonith)
#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