pacemaker  2.0.1-9e909a5bdd
Scalable High-Availability cluster resource manager
st_client.c
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2018 Andrew Beekhof <andrew@beekhof.net>
3  *
4  * This source code is licensed under the GNU Lesser General Public License
5  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
6  */
7 
8 #include <crm_internal.h>
9 #include <unistd.h>
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <ctype.h>
14 
15 #include <sys/stat.h>
16 #include <sys/types.h>
17 #include <sys/wait.h>
18 
19 #include <glib.h>
20 
21 #include <crm/crm.h>
22 #include <crm/stonith-ng.h>
23 #include <crm/fencing/internal.h>
24 #include <crm/msg_xml.h>
25 #include <crm/common/xml.h>
26 
27 #include <crm/common/mainloop.h>
28 
29 #if SUPPORT_CIBSECRETS
30 # include <crm/common/cib_secrets.h>
31 #endif
32 
33 CRM_TRACE_INIT_DATA(stonith);
34 
35 struct stonith_action_s {
37  char *agent;
38  char *action;
39  char *victim;
40  char *args;
41  int timeout;
42  int async;
43  void *userdata;
44  void (*done_cb) (GPid pid, gint status, const char *output, gpointer user_data);
45 
47  int fd_stdout;
48  int fd_stderr;
49  int last_timeout_signo;
50 
52  time_t initial_start_time;
53  int tries;
54  int remaining_timeout;
55  guint timer_sigterm;
56  guint timer_sigkill;
57  int max_retries;
58 
59  /* device output data */
60  GPid pid;
61  int rc;
62  char *output;
63  char *error;
64 };
65 
66 typedef struct stonith_private_s {
67  char *token;
68  crm_ipc_t *ipc;
69  mainloop_io_t *source;
70  GHashTable *stonith_op_callback_table;
71  GList *notify_list;
72 
73  void (*op_callback) (stonith_t * st, stonith_callback_data_t * data);
74 
76 
77 typedef struct stonith_notify_client_s {
78  const char *event;
79  const char *obj_id; /* implement one day */
80  const char *obj_type; /* implement one day */
81  void (*notify) (stonith_t * st, stonith_event_t * e);
82 
84 
85 typedef struct stonith_callback_client_s {
86  void (*callback) (stonith_t * st, stonith_callback_data_t * data);
87  const char *id;
88  void *user_data;
89  gboolean only_success;
90  gboolean allow_timeout_updates;
91  struct timer_rec_s *timer;
92 
94 
95 struct notify_blob_s {
96  stonith_t *stonith;
97  xmlNode *xml;
98 };
99 
100 struct timer_rec_s {
101  int call_id;
102  int timeout;
103  guint ref;
105 };
106 
107 typedef int (*stonith_op_t) (const char *, int, const char *, xmlNode *,
108  xmlNode *, xmlNode *, xmlNode **, xmlNode **);
109 
110 bool stonith_dispatch(stonith_t * st);
111 xmlNode *stonith_create_op(int call_id, const char *token, const char *op, xmlNode * data,
112  int call_options);
113 int stonith_send_command(stonith_t * stonith, const char *op, xmlNode * data,
114  xmlNode ** output_data, int call_options, int timeout);
115 
116 static void stonith_connection_destroy(gpointer user_data);
117 static void stonith_send_notification(gpointer data, gpointer user_data);
118 static int internal_stonith_action_execute(stonith_action_t * action);
119 static void log_action(stonith_action_t *action, pid_t pid);
120 
129 stonith_text2namespace(const char *namespace_s)
130 {
131  if ((namespace_s == NULL) || !strcmp(namespace_s, "any")) {
132  return st_namespace_any;
133 
134  } else if (!strcmp(namespace_s, "redhat")
135  || !strcmp(namespace_s, "stonith-ng")) {
136  return st_namespace_rhcs;
137 
138  } else if (!strcmp(namespace_s, "internal")) {
139  return st_namespace_internal;
140 
141  } else if (!strcmp(namespace_s, "heartbeat")) {
142  return st_namespace_lha;
143  }
144  return st_namespace_invalid;
145 }
146 
154 const char *
156 {
157  switch (st_namespace) {
158  case st_namespace_any: return "any";
159  case st_namespace_rhcs: return "stonith-ng";
160  case st_namespace_internal: return "internal";
161  case st_namespace_lha: return "heartbeat";
162  default: break;
163  }
164  return "unsupported";
165 }
166 
176 stonith_get_namespace(const char *agent, const char *namespace_s)
177 {
178  if (safe_str_eq(namespace_s, "internal")) {
179  return st_namespace_internal;
180  }
181 
182  if (stonith__agent_is_rhcs(agent)) {
183  return st_namespace_rhcs;
184  }
185 
186 #if HAVE_STONITH_STONITH_H
187  if (stonith__agent_is_lha(agent)) {
188  return st_namespace_lha;
189  }
190 #endif
191 
192  crm_err("Unknown fence agent: %s", agent);
193  return st_namespace_invalid;
194 }
195 
196 static void
197 log_action(stonith_action_t *action, pid_t pid)
198 {
199  if (action->output) {
200  /* Logging the whole string confuses syslog when the string is xml */
201  char *prefix = crm_strdup_printf("%s[%d] stdout:", action->agent, pid);
202 
203  crm_log_output(LOG_TRACE, prefix, action->output);
204  free(prefix);
205  }
206 
207  if (action->error) {
208  /* Logging the whole string confuses syslog when the string is xml */
209  char *prefix = crm_strdup_printf("%s[%d] stderr:", action->agent, pid);
210 
211  crm_log_output(LOG_WARNING, prefix, action->error);
212  free(prefix);
213  }
214 }
215 
216 static void
217 stonith_connection_destroy(gpointer user_data)
218 {
219  stonith_t *stonith = user_data;
220  stonith_private_t *native = NULL;
221  struct notify_blob_s blob;
222 
223  crm_trace("Sending destroyed notification");
224  blob.stonith = stonith;
225  blob.xml = create_xml_node(NULL, "notify");
226 
227  native = stonith->st_private;
228  native->ipc = NULL;
229  native->source = NULL;
230 
231  stonith->state = stonith_disconnected;
232  crm_xml_add(blob.xml, F_TYPE, T_STONITH_NOTIFY);
234 
235  g_list_foreach(native->notify_list, stonith_send_notification, &blob);
236  free_xml(blob.xml);
237 }
238 
239 xmlNode *
240 create_device_registration_xml(const char *id, enum stonith_namespace namespace,
241  const char *agent, stonith_key_value_t *params,
242  const char *rsc_provides)
243 {
244  xmlNode *data = create_xml_node(NULL, F_STONITH_DEVICE);
245  xmlNode *args = create_xml_node(data, XML_TAG_ATTRS);
246 
247 #if HAVE_STONITH_STONITH_H
248  if (namespace == st_namespace_any) {
249  namespace = stonith_get_namespace(agent, NULL);
250  }
251  if (namespace == st_namespace_lha) {
252  hash2field((gpointer) "plugin", (gpointer) agent, args);
253  agent = "fence_legacy";
254  }
255 #endif
256 
257  crm_xml_add(data, XML_ATTR_ID, id);
258  crm_xml_add(data, F_STONITH_ORIGIN, __FUNCTION__);
259  crm_xml_add(data, "agent", agent);
260  if ((namespace != st_namespace_any) && (namespace != st_namespace_invalid)) {
261  crm_xml_add(data, "namespace", stonith_namespace2text(namespace));
262  }
263  if (rsc_provides) {
264  crm_xml_add(data, "rsc_provides", rsc_provides);
265  }
266 
267  for (; params; params = params->next) {
268  hash2field((gpointer) params->key, (gpointer) params->value, args);
269  }
270 
271  return data;
272 }
273 
274 static int
275 stonith_api_register_device(stonith_t * st, int call_options,
276  const char *id, const char *namespace, const char *agent,
277  stonith_key_value_t * params)
278 {
279  int rc = 0;
280  xmlNode *data = NULL;
281 
283  agent, params, NULL);
284 
285  rc = stonith_send_command(st, STONITH_OP_DEVICE_ADD, data, NULL, call_options, 0);
286  free_xml(data);
287 
288  return rc;
289 }
290 
291 static int
292 stonith_api_remove_device(stonith_t * st, int call_options, const char *name)
293 {
294  int rc = 0;
295  xmlNode *data = NULL;
296 
297  data = create_xml_node(NULL, F_STONITH_DEVICE);
298  crm_xml_add(data, F_STONITH_ORIGIN, __FUNCTION__);
299  crm_xml_add(data, XML_ATTR_ID, name);
300  rc = stonith_send_command(st, STONITH_OP_DEVICE_DEL, data, NULL, call_options, 0);
301  free_xml(data);
302 
303  return rc;
304 }
305 
306 static int
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)
310 {
311  int rc = 0;
312  xmlNode *data = NULL;
313 
314  CRM_CHECK(node || pattern || (attr && value), return -EINVAL);
315 
317  crm_xml_add(data, F_STONITH_ORIGIN, __FUNCTION__);
318 
319  if (node) {
321 
322  } else if (pattern) {
324 
325  } else {
328  }
329 
331  rc = stonith_send_command(st, STONITH_OP_LEVEL_DEL, data, NULL, options, 0);
332  free_xml(data);
333 
334  return rc;
335 }
336 
337 static int
338 stonith_api_remove_level(stonith_t * st, int options, const char *node, int level)
339 {
340  return stonith_api_remove_level_full(st, options, node,
341  NULL, NULL, NULL, level);
342 }
343 
359 xmlNode *
360 create_level_registration_xml(const char *node, const char *pattern,
361  const char *attr, const char *value,
362  int level, stonith_key_value_t *device_list)
363 {
364  int len = 0;
365  char *list = NULL;
366  xmlNode *data;
367 
368  CRM_CHECK(node || pattern || (attr && value), return NULL);
369 
371  CRM_CHECK(data, return NULL);
372 
373  crm_xml_add(data, F_STONITH_ORIGIN, __FUNCTION__);
374  crm_xml_add_int(data, XML_ATTR_ID, level);
376 
377  if (node) {
379 
380  } else if (pattern) {
382 
383  } else {
386  }
387 
388  for (; device_list; device_list = device_list->next) {
389 
390  int adding = strlen(device_list->value);
391  if(list) {
392  adding++; /* +1 space */
393  }
394 
395  crm_trace("Adding %s (%dc) at offset %d", device_list->value, adding, len);
396  list = realloc_safe(list, len + adding + 1); /* +1 EOS */
397  if (list == NULL) {
398  crm_perror(LOG_CRIT, "Could not create device list");
399  free_xml(data);
400  return NULL;
401  }
402  sprintf(list + len, "%s%s", len?",":"", device_list->value);
403  len += adding;
404  }
405 
407 
408  free(list);
409  return data;
410 }
411 
412 static int
413 stonith_api_register_level_full(stonith_t * st, int options, const char *node,
414  const char *pattern,
415  const char *attr, const char *value,
416  int level, stonith_key_value_t *device_list)
417 {
418  int rc = 0;
419  xmlNode *data = create_level_registration_xml(node, pattern, attr, value,
420  level, device_list);
421  CRM_CHECK(data != NULL, return -EINVAL);
422 
423  rc = stonith_send_command(st, STONITH_OP_LEVEL_ADD, data, NULL, options, 0);
424  free_xml(data);
425 
426  return rc;
427 }
428 
429 static int
430 stonith_api_register_level(stonith_t * st, int options, const char *node, int level,
431  stonith_key_value_t * device_list)
432 {
433  return stonith_api_register_level_full(st, options, node, NULL, NULL, NULL,
434  level, device_list);
435 }
436 
437 static void
438 append_arg(const char *key, const char *value, char **args)
439 {
440  int len = 3; /* =, \n, \0 */
441  int last = 0;
442 
443  CRM_CHECK(key != NULL, return);
444  CRM_CHECK(value != NULL, return);
445 
446  if (strstr(key, "pcmk_")) {
447  return;
448  } else if (strstr(key, CRM_META)) {
449  return;
450  } else if (safe_str_eq(key, "crm_feature_set")) {
451  return;
452  }
453 
454  len += strlen(key);
455  len += strlen(value);
456  if (*args != NULL) {
457  last = strlen(*args);
458  }
459 
460  *args = realloc_safe(*args, last + len);
461  crm_trace("Appending: %s=%s", key, value);
462  sprintf((*args) + last, "%s=%s\n", key, value);
463 }
464 
465 static void
466 append_config_arg(gpointer key, gpointer value, gpointer user_data)
467 {
468  /* The fencer will filter action out when it registers the device,
469  * but ignore it here just in case any other library callers
470  * fail to do so.
471  */
473  append_arg(key, value, user_data);
474  return;
475  }
476 }
477 
478 static char *
479 make_args(const char *agent, const char *action, const char *victim, uint32_t victim_nodeid, GHashTable * device_args,
480  GHashTable * port_map)
481 {
482  char buffer[512];
483  char *arg_list = NULL;
484  const char *value = NULL;
485 
486  CRM_CHECK(action != NULL, return NULL);
487 
488  snprintf(buffer, sizeof(buffer), "pcmk_%s_action", action);
489  if (device_args) {
490  value = g_hash_table_lookup(device_args, buffer);
491  }
492  if (value) {
493  crm_info("Substituting action '%s' for requested operation '%s'", value, action);
494  action = value;
495  }
496 
497  append_arg(STONITH_ATTR_ACTION_OP, action, &arg_list);
498  if (victim && device_args) {
499  const char *alias = victim;
500  const char *param = g_hash_table_lookup(device_args, STONITH_ATTR_HOSTARG);
501 
502  if (port_map && g_hash_table_lookup(port_map, victim)) {
503  alias = g_hash_table_lookup(port_map, victim);
504  }
505 
506  /* Always supply the node's name, too:
507  * https://github.com/ClusterLabs/fence-agents/blob/master/doc/FenceAgentAPI.md
508  */
509  append_arg("nodename", victim, &arg_list);
510  if (victim_nodeid) {
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);
516  }
517  }
518 
519  /* Check if we need to supply the victim in any other form */
520  if(safe_str_eq(agent, "fence_legacy")) {
521  value = agent;
522 
523  } else if (param == NULL) {
524  param = "port";
525  value = g_hash_table_lookup(device_args, param);
526 
527  } else if (safe_str_eq(param, "none")) {
528  value = param; /* Nothing more to do */
529 
530  } else {
531  value = g_hash_table_lookup(device_args, param);
532  }
533 
534  /* Don't overwrite explictly set values for $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,
537  alias);
538  append_arg(param, alias, &arg_list);
539  }
540  }
541 
542  if (device_args) {
543  g_hash_table_foreach(device_args, append_config_arg, &arg_list);
544  }
545 
546  return arg_list;
547 }
548 
549 static gboolean
550 st_child_term(gpointer data)
551 {
552  int rc = 0;
553  stonith_action_t *track = data;
554 
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);
559  if (rc < 0) {
560  crm_perror(LOG_ERR, "Couldn't send SIGTERM to %d", track->pid);
561  }
562  return FALSE;
563 }
564 
565 static gboolean
566 st_child_kill(gpointer data)
567 {
568  int rc = 0;
569  stonith_action_t *track = data;
570 
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);
575  if (rc < 0) {
576  crm_perror(LOG_ERR, "Couldn't send SIGKILL to %d", track->pid);
577  }
578  return FALSE;
579 }
580 
581 static void
582 stonith_action_clear_tracking_data(stonith_action_t * action)
583 {
584  if (action->timer_sigterm > 0) {
585  g_source_remove(action->timer_sigterm);
586  action->timer_sigterm = 0;
587  }
588  if (action->timer_sigkill > 0) {
589  g_source_remove(action->timer_sigkill);
590  action->timer_sigkill = 0;
591  }
592  if (action->fd_stdout) {
593  close(action->fd_stdout);
594  action->fd_stdout = 0;
595  }
596  if (action->fd_stderr) {
597  close(action->fd_stderr);
598  action->fd_stderr = 0;
599  }
600  free(action->output);
601  action->output = NULL;
602  free(action->error);
603  action->error = NULL;
604  action->rc = 0;
605  action->pid = 0;
606  action->last_timeout_signo = 0;
607 }
608 
615 void
617 {
618  if (action) {
619  stonith_action_clear_tracking_data(action);
620  free(action->agent);
621  free(action->args);
622  free(action->action);
623  free(action->victim);
624  free(action);
625  }
626 }
627 
640 void
641 stonith__action_result(stonith_action_t *action, int *rc, char **output,
642  char **error_output)
643 {
644  if (rc) {
645  *rc = pcmk_ok;
646  }
647  if (output) {
648  *output = NULL;
649  }
650  if (error_output) {
651  *error_output = NULL;
652  }
653  if (action != NULL) {
654  if (rc) {
655  *rc = action->rc;
656  }
657  if (output && action->output) {
658  *output = action->output;
659  action->output = NULL; // hand off memory management to caller
660  }
661  if (error_output && action->error) {
662  *error_output = action->error;
663  action->error = NULL; // hand off memory management to caller
664  }
665  }
666 }
667 
668 #define FAILURE_MAX_RETRIES 2
670 stonith_action_create(const char *agent,
671  const char *_action,
672  const char *victim,
673  uint32_t victim_nodeid,
674  int timeout, GHashTable * device_args, GHashTable * port_map)
675 {
676  stonith_action_t *action;
677 
678  action = calloc(1, sizeof(stonith_action_t));
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);
684  if (victim) {
685  action->victim = strdup(victim);
686  }
687  action->timeout = action->remaining_timeout = timeout;
688  action->max_retries = FAILURE_MAX_RETRIES;
689 
690  if (device_args) {
691  char buffer[512];
692  const char *value = NULL;
693 
694  snprintf(buffer, sizeof(buffer), "pcmk_%s_retries", _action);
695  value = g_hash_table_lookup(device_args, buffer);
696 
697  if (value) {
698  action->max_retries = atoi(value);
699  }
700  }
701 
702  return action;
703 }
704 
705 #define READ_MAX 500
706 static char *
707 read_output(int fd)
708 {
709  char buffer[READ_MAX];
710  char *output = NULL;
711  int len = 0;
712  int more = 0;
713 
714  if (!fd) {
715  return NULL;
716  }
717 
718  do {
719  errno = 0;
720  memset(&buffer, 0, READ_MAX);
721  more = read(fd, buffer, READ_MAX - 1);
722 
723  if (more > 0) {
724  buffer[more] = 0; /* Make sure it's nul-terminated for logging
725  * 'more' is always less than our buffer size
726  */
727  output = realloc_safe(output, len + more + 1);
728  snprintf(output + len, more + 1, "%s", buffer);
729  len += more;
730  }
731 
732  } while (more == (READ_MAX - 1) || (more < 0 && errno == EINTR));
733 
734  return output;
735 }
736 
737 static gboolean
738 update_remaining_timeout(stonith_action_t * action)
739 {
740  int diff = time(NULL) - action->initial_start_time;
741 
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)) {
747  /* only set remaining timeout period if there is 30%
748  * or greater of the original timeout period left */
749  action->remaining_timeout = action->timeout - diff;
750  } else {
751  action->remaining_timeout = 0;
752  }
753  return action->remaining_timeout ? TRUE : FALSE;
754 }
755 
756 static void
757 stonith_action_async_done(mainloop_child_t * p, pid_t pid, int core, int signo, int exitcode)
758 {
760 
761  if (action->timer_sigterm > 0) {
762  g_source_remove(action->timer_sigterm);
763  action->timer_sigterm = 0;
764  }
765  if (action->timer_sigkill > 0) {
766  g_source_remove(action->timer_sigkill);
767  action->timer_sigkill = 0;
768  }
769 
770  action->output = read_output(action->fd_stdout);
771  action->error = read_output(action->fd_stderr);
772 
773  if (action->last_timeout_signo) {
774  action->rc = -ETIME;
775  crm_notice("Child process %d performing action '%s' timed out with signal %d",
776  pid, action->action, action->last_timeout_signo);
777 
778  } else if (signo) {
779  action->rc = -ECONNABORTED;
780  crm_notice("Child process %d performing action '%s' timed out with signal %d",
781  pid, action->action, signo);
782 
783  } else {
784  crm_debug("Child process %d performing action '%s' exited with rc %d",
785  pid, action->action, exitcode);
786  if (exitcode > 0) {
787  /* Try to provide a useful error code based on the fence agent's
788  * error output.
789  */
790  if (action->error == NULL) {
791  exitcode = -ENODATA;
792 
793  } else if (strstr(action->error, "imed out")) {
794  /* Some agents have their own internal timeouts */
795  exitcode = -ETIMEDOUT;
796 
797  } else if (strstr(action->error, "Unrecognised action")) {
798  exitcode = -EOPNOTSUPP;
799 
800  } else {
801  exitcode = -pcmk_err_generic;
802  }
803  }
804  action->rc = exitcode;
805  }
806 
807  log_action(action, pid);
808 
809  if (action->rc != pcmk_ok && update_remaining_timeout(action)) {
810  int rc = internal_stonith_action_execute(action);
811  if (rc == pcmk_ok) {
812  return;
813  }
814  }
815 
816  if (action->done_cb) {
817  action->done_cb(pid, action->rc, action->output, action->userdata);
818  }
819 
820  stonith__destroy_action(action);
821 }
822 
823 static int
824 internal_stonith_action_execute(stonith_action_t * action)
825 {
826  int pid, status = 0, len, rc = -EPROTO;
827  int ret;
828  int total = 0;
829  int p_read_fd, p_write_fd; /* parent read/write file descriptors */
830  int c_read_fd, c_write_fd; /* child read/write file descriptors */
831  int c_stderr_fd, p_stderr_fd; /* parent/child side file descriptors for stderr */
832  int fd1[2];
833  int fd2[2];
834  int fd3[2];
835  int is_retry = 0;
836 
837  /* clear any previous tracking data */
838  stonith_action_clear_tracking_data(action);
839 
840  if (!action->tries) {
841  action->initial_start_time = time(NULL);
842  }
843  action->tries++;
844 
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);
848  is_retry = 1;
849  }
850 
851  c_read_fd = c_write_fd = p_read_fd = p_write_fd = c_stderr_fd = p_stderr_fd = -1;
852 
853  if (action->args == NULL || action->agent == NULL)
854  goto fail;
855  len = strlen(action->args);
856 
857  if (pipe(fd1))
858  goto fail;
859  p_read_fd = fd1[0];
860  c_write_fd = fd1[1];
861 
862  if (pipe(fd2))
863  goto fail;
864  c_read_fd = fd2[0];
865  p_write_fd = fd2[1];
866 
867  if (pipe(fd3))
868  goto fail;
869  p_stderr_fd = fd3[0];
870  c_stderr_fd = fd3[1];
871 
872  crm_debug("forking");
873  pid = fork();
874  if (pid < 0) {
875  rc = -ECHILD;
876  goto fail;
877  }
878 
879  if (!pid) {
880  /* child */
881  setpgid(0, 0);
882 
883  close(1);
884  /* coverity[leaked_handle] False positive */
885  if (dup(c_write_fd) < 0)
886  goto fail;
887  close(2);
888  /* coverity[leaked_handle] False positive */
889  if (dup(c_stderr_fd) < 0)
890  goto fail;
891  close(0);
892  /* coverity[leaked_handle] False positive */
893  if (dup(c_read_fd) < 0)
894  goto fail;
895 
896  /* keep c_stderr_fd open so parent can report all errors. */
897  /* keep c_write_fd open so hostlist can be sent to parent. */
898  close(c_read_fd);
899  close(p_read_fd);
900  close(p_write_fd);
901  close(p_stderr_fd);
902 
903  /* keep retries from executing out of control */
904  if (is_retry) {
905  sleep(1);
906  }
907  execlp(action->agent, action->agent, NULL);
908  exit(CRM_EX_ERROR);
909  }
910 
911  /* parent */
912  action->pid = pid;
913  ret = crm_set_nonblocking(p_read_fd);
914  if (ret < 0) {
915  crm_notice("Could not set output of %s to be non-blocking: %s "
916  CRM_XS " rc=%d",
917  action->agent, pcmk_strerror(rc), rc);
918  }
919  ret = crm_set_nonblocking(p_stderr_fd);
920  if (ret < 0) {
921  crm_notice("Could not set error output of %s to be non-blocking: %s "
922  CRM_XS " rc=%d",
923  action->agent, pcmk_strerror(rc), rc);
924  }
925 
926  errno = 0;
927  do {
928  crm_debug("sending args");
929  ret = write(p_write_fd, action->args + total, len - total);
930  if (ret > 0) {
931  total += ret;
932  }
933 
934  } while (errno == EINTR && total < len);
935 
936  if (total != len) {
937  crm_perror(LOG_ERR, "Sent %d not %d bytes", total, len);
938  if (ret >= 0) {
939  rc = -ECOMM;
940  }
941  goto fail;
942  }
943 
944  close(p_write_fd); p_write_fd = -1;
945 
946  /* async */
947  if (action->async) {
948  action->fd_stdout = p_read_fd;
949  action->fd_stderr = p_stderr_fd;
950  mainloop_child_add(pid, 0/* Move the timeout here? */, action->action, action, stonith_action_async_done);
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);
959  } else {
960  crm_err("No timeout set for stonith operation %s with device %s",
961  action->action, action->agent);
962  }
963 
964  close(c_write_fd);
965  close(c_read_fd);
966  close(c_stderr_fd);
967  return 0;
968 
969  } else {
970  /* sync */
971  int timeout = action->remaining_timeout + 1;
972  pid_t p = 0;
973 
974  while (action->remaining_timeout < 0 || timeout > 0) {
975  p = waitpid(pid, &status, WNOHANG);
976  if (p > 0) {
977  break;
978  }
979  sleep(1);
980  timeout--;
981  }
982 
983  if (timeout == 0) {
984  int killrc = kill(-pid, SIGKILL);
985 
986  if (killrc && errno != ESRCH) {
987  crm_err("kill(%d, KILL) failed: %s (%d)", pid, pcmk_strerror(errno), errno);
988  }
989  /*
990  * From sigprocmask(2):
991  * It is not possible to block SIGKILL or SIGSTOP. Attempts to do so are silently ignored.
992  *
993  * This makes it safe to skip WNOHANG here
994  */
995  p = waitpid(pid, &status, 0);
996  }
997 
998  if (p <= 0) {
999  crm_perror(LOG_ERR, "waitpid(%d)", pid);
1000 
1001  } else if (p != pid) {
1002  crm_err("Waited for %d, got %d", pid, p);
1003  }
1004 
1005  action->output = read_output(p_read_fd);
1006  action->error = read_output(p_stderr_fd);
1007 
1008  action->rc = -ECONNABORTED;
1009 
1010  log_action(action, pid);
1011 
1012  rc = action->rc;
1013  if (timeout == 0) {
1014  action->rc = -ETIME;
1015  } else if (WIFEXITED(status)) {
1016  crm_debug("result = %d", WEXITSTATUS(status));
1017  action->rc = -WEXITSTATUS(status);
1018  rc = 0;
1019 
1020  } else if (WIFSIGNALED(status)) {
1021  crm_err("call %s for %s exited due to signal %d", action->action, action->agent,
1022  WTERMSIG(status));
1023 
1024  } else {
1025  crm_err("call %s for %s returned unexpected status %#x",
1026  action->action, action->agent, status);
1027  }
1028  }
1029 
1030  fail:
1031 
1032  if (p_read_fd >= 0) {
1033  close(p_read_fd);
1034  }
1035  if (p_write_fd >= 0) {
1036  close(p_write_fd);
1037  }
1038  if (p_stderr_fd >= 0) {
1039  close(p_stderr_fd);
1040  }
1041 
1042  if (c_read_fd >= 0) {
1043  close(c_read_fd);
1044  }
1045  if (c_write_fd >= 0) {
1046  close(c_write_fd);
1047  }
1048  if (c_stderr_fd >= 0) {
1049  close(c_stderr_fd);
1050  }
1051 
1052  return rc;
1053 }
1054 
1055 GPid
1057  void *userdata,
1058  void (*done) (GPid pid, int rc, const char *output,
1059  gpointer user_data))
1060 {
1061  int rc = 0;
1062 
1063  if (!action) {
1064  return -1;
1065  }
1066 
1067  action->userdata = userdata;
1068  action->done_cb = done;
1069  action->async = 1;
1070 
1071  rc = internal_stonith_action_execute(action);
1072 
1073  return rc < 0 ? rc : action->pid;
1074 }
1075 
1084 int
1086 {
1087  int rc = pcmk_ok;
1088 
1089  CRM_CHECK(action != NULL, return -EINVAL);
1090 
1091  // Keep trying until success, max retries, or timeout
1092  do {
1093  rc = internal_stonith_action_execute(action);
1094  } while ((rc != pcmk_ok) && update_remaining_timeout(action));
1095 
1096  return rc;
1097 }
1098 
1099 static int
1100 stonith_api_device_list(stonith_t * stonith, int call_options, const char *namespace,
1101  stonith_key_value_t ** devices, int timeout)
1102 {
1103  int count = 0;
1104  enum stonith_namespace ns = stonith_text2namespace(namespace);
1105 
1106  if (devices == NULL) {
1107  crm_err("Parameter error: stonith_api_device_list");
1108  return -EFAULT;
1109  }
1110 
1111 #if HAVE_STONITH_STONITH_H
1112  // Include Linux-HA agents if requested
1113  if ((ns == st_namespace_any) || (ns == st_namespace_lha)) {
1114  count += stonith__list_lha_agents(devices);
1115  }
1116 #endif
1117 
1118  // Include Red Hat agents if requested
1119  if ((ns == st_namespace_any) || (ns == st_namespace_rhcs)) {
1120  count += stonith__list_rhcs_agents(devices);
1121  }
1122 
1123  return count;
1124 }
1125 
1126 static int
1127 stonith_api_device_metadata(stonith_t * stonith, int call_options, const char *agent,
1128  const char *namespace, char **output, int timeout)
1129 {
1130  /* By executing meta-data directly, we can get it from stonith_admin when
1131  * the cluster is not running, which is important for higher-level tools.
1132  */
1133 
1134  enum stonith_namespace ns = stonith_get_namespace(agent, namespace);
1135 
1136  crm_trace("Looking up metadata for %s agent %s",
1137  stonith_namespace2text(ns), agent);
1138 
1139  switch (ns) {
1140  case st_namespace_rhcs:
1141  return stonith__rhcs_metadata(agent, timeout, output);
1142 
1143 #if HAVE_STONITH_STONITH_H
1144  case st_namespace_lha:
1145  return stonith__lha_metadata(agent, timeout, output);
1146 #endif
1147 
1148  default:
1149  errno = EINVAL;
1150  crm_perror(LOG_ERR,
1151  "Agent %s not found or does not support meta-data",
1152  agent);
1153  break;
1154  }
1155  return -EINVAL;
1156 }
1157 
1158 static int
1159 stonith_api_query(stonith_t * stonith, int call_options, const char *target,
1160  stonith_key_value_t ** devices, int timeout)
1161 {
1162  int rc = 0, lpc = 0, max = 0;
1163 
1164  xmlNode *data = NULL;
1165  xmlNode *output = NULL;
1166  xmlXPathObjectPtr xpathObj = NULL;
1167 
1168  CRM_CHECK(devices != NULL, return -EINVAL);
1169 
1170  data = create_xml_node(NULL, F_STONITH_DEVICE);
1171  crm_xml_add(data, F_STONITH_ORIGIN, __FUNCTION__);
1172  crm_xml_add(data, F_STONITH_TARGET, target);
1173  crm_xml_add(data, F_STONITH_ACTION, "off");
1174  rc = stonith_send_command(stonith, STONITH_OP_QUERY, data, &output, call_options, timeout);
1175 
1176  if (rc < 0) {
1177  return rc;
1178  }
1179 
1180  xpathObj = xpath_search(output, "//@agent");
1181  if (xpathObj) {
1182  max = numXpathResults(xpathObj);
1183 
1184  for (lpc = 0; lpc < max; lpc++) {
1185  xmlNode *match = getXpathResult(xpathObj, lpc);
1186 
1187  CRM_LOG_ASSERT(match != NULL);
1188  if(match != NULL) {
1189  xmlChar *match_path = xmlGetNodePath(match);
1190 
1191  crm_info("%s[%d] = %s", "//@agent", lpc, match_path);
1192  free(match_path);
1193  *devices = stonith_key_value_add(*devices, NULL, crm_element_value(match, XML_ATTR_ID));
1194  }
1195  }
1196 
1197  freeXpathObject(xpathObj);
1198  }
1199 
1200  free_xml(output);
1201  free_xml(data);
1202  return max;
1203 }
1204 
1205 static int
1206 stonith_api_call(stonith_t * stonith,
1207  int call_options,
1208  const char *id,
1209  const char *action, const char *victim, int timeout, xmlNode ** output)
1210 {
1211  int rc = 0;
1212  xmlNode *data = NULL;
1213 
1214  data = create_xml_node(NULL, F_STONITH_DEVICE);
1215  crm_xml_add(data, F_STONITH_ORIGIN, __FUNCTION__);
1216  crm_xml_add(data, F_STONITH_DEVICE, id);
1217  crm_xml_add(data, F_STONITH_ACTION, action);
1218  crm_xml_add(data, F_STONITH_TARGET, victim);
1219 
1220  rc = stonith_send_command(stonith, STONITH_OP_EXEC, data, output, call_options, timeout);
1221  free_xml(data);
1222 
1223  return rc;
1224 }
1225 
1226 static int
1227 stonith_api_list(stonith_t * stonith, int call_options, const char *id, char **list_info,
1228  int timeout)
1229 {
1230  int rc;
1231  xmlNode *output = NULL;
1232 
1233  rc = stonith_api_call(stonith, call_options, id, "list", NULL, timeout, &output);
1234 
1235  if (output && list_info) {
1236  const char *list_str;
1237 
1238  list_str = crm_element_value(output, "st_output");
1239 
1240  if (list_str) {
1241  *list_info = strdup(list_str);
1242  }
1243  }
1244 
1245  if (output) {
1246  free_xml(output);
1247  }
1248 
1249  return rc;
1250 }
1251 
1252 static int
1253 stonith_api_monitor(stonith_t * stonith, int call_options, const char *id, int timeout)
1254 {
1255  return stonith_api_call(stonith, call_options, id, "monitor", NULL, timeout, NULL);
1256 }
1257 
1258 static int
1259 stonith_api_status(stonith_t * stonith, int call_options, const char *id, const char *port,
1260  int timeout)
1261 {
1262  return stonith_api_call(stonith, call_options, id, "status", port, timeout, NULL);
1263 }
1264 
1265 static int
1266 stonith_api_fence(stonith_t * stonith, int call_options, const char *node, const char *action,
1267  int timeout, int tolerance)
1268 {
1269  int rc = 0;
1270  xmlNode *data = NULL;
1271 
1272  data = create_xml_node(NULL, __FUNCTION__);
1273  crm_xml_add(data, F_STONITH_TARGET, node);
1274  crm_xml_add(data, F_STONITH_ACTION, action);
1275  crm_xml_add_int(data, F_STONITH_TIMEOUT, timeout);
1276  crm_xml_add_int(data, F_STONITH_TOLERANCE, tolerance);
1277 
1278  rc = stonith_send_command(stonith, STONITH_OP_FENCE, data, NULL, call_options, timeout);
1279  free_xml(data);
1280 
1281  return rc;
1282 }
1283 
1284 static int
1285 stonith_api_confirm(stonith_t * stonith, int call_options, const char *target)
1286 {
1287  return stonith_api_fence(stonith, call_options | st_opt_manual_ack, target, "off", 0, 0);
1288 }
1289 
1290 static int
1291 stonith_api_history(stonith_t * stonith, int call_options, const char *node,
1292  stonith_history_t ** history, int timeout)
1293 {
1294  int rc = 0;
1295  xmlNode *data = NULL;
1296  xmlNode *output = NULL;
1297  stonith_history_t *last = NULL;
1298 
1299  *history = NULL;
1300 
1301  if (node) {
1302  data = create_xml_node(NULL, __FUNCTION__);
1303  crm_xml_add(data, F_STONITH_TARGET, node);
1304  }
1305 
1306  rc = stonith_send_command(stonith, STONITH_OP_FENCE_HISTORY, data, &output,
1307  call_options | st_opt_sync_call, timeout);
1308  free_xml(data);
1309 
1310  if (rc == 0) {
1311  xmlNode *op = NULL;
1312  xmlNode *reply = get_xpath_object("//" F_STONITH_HISTORY_LIST, output, LOG_TRACE);
1313 
1314  for (op = __xml_first_child(reply); op != NULL; op = __xml_next(op)) {
1315  stonith_history_t *kvp;
1316  int completed;
1317 
1318  kvp = calloc(1, sizeof(stonith_history_t));
1324  crm_element_value_int(op, F_STONITH_DATE, &completed);
1325  kvp->completed = (time_t) completed;
1327 
1328  if (last) {
1329  last->next = kvp;
1330  } else {
1331  *history = kvp;
1332  }
1333  last = kvp;
1334  }
1335  }
1336 
1337  free_xml(output);
1338 
1339  return rc;
1340 }
1341 
1343 {
1344  stonith_history_t *hp, *hp_old;
1345 
1346  for (hp = history; hp; hp_old = hp, hp = hp->next, free(hp_old)) {
1347  free(hp->target);
1348  free(hp->action);
1349  free(hp->origin);
1350  free(hp->delegate);
1351  free(hp->client);
1352  }
1353 }
1354 
1358 const char *
1359 get_stonith_provider(const char *agent, const char *provider)
1360 {
1361  return stonith_namespace2text(stonith_get_namespace(agent, provider));
1362 }
1363 
1364 static gint
1365 stonithlib_GCompareFunc(gconstpointer a, gconstpointer b)
1366 {
1367  int rc = 0;
1368  const stonith_notify_client_t *a_client = a;
1369  const stonith_notify_client_t *b_client = b;
1370 
1371  CRM_CHECK(a_client->event != NULL && b_client->event != NULL, return 0);
1372  rc = strcmp(a_client->event, b_client->event);
1373  if (rc == 0) {
1374  if (a_client->notify == NULL || b_client->notify == NULL) {
1375  return 0;
1376 
1377  } else if (a_client->notify == b_client->notify) {
1378  return 0;
1379 
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);
1383  return -1;
1384  }
1385  crm_err("callbacks for %s are not equal: %p vs. %p",
1386  a_client->event, a_client->notify, b_client->notify);
1387  return 1;
1388  }
1389  return rc;
1390 }
1391 
1392 xmlNode *
1393 stonith_create_op(int call_id, const char *token, const char *op, xmlNode * data, int call_options)
1394 {
1395  xmlNode *op_msg = create_xml_node(NULL, "stonith_command");
1396 
1397  CRM_CHECK(op_msg != NULL, return NULL);
1398  CRM_CHECK(token != NULL, return NULL);
1399 
1400  crm_xml_add(op_msg, F_XML_TAGNAME, "stonith_command");
1401 
1402  crm_xml_add(op_msg, F_TYPE, T_STONITH_NG);
1403  crm_xml_add(op_msg, F_STONITH_CALLBACK_TOKEN, token);
1404  crm_xml_add(op_msg, F_STONITH_OPERATION, op);
1405  crm_xml_add_int(op_msg, F_STONITH_CALLID, call_id);
1406  crm_trace("Sending call options: %.8lx, %d", (long)call_options, call_options);
1407  crm_xml_add_int(op_msg, F_STONITH_CALLOPTS, call_options);
1408 
1409  if (data != NULL) {
1410  add_message_xml(op_msg, F_STONITH_CALLDATA, data);
1411  }
1412 
1413  return op_msg;
1414 }
1415 
1416 static void
1417 stonith_destroy_op_callback(gpointer data)
1418 {
1420 
1421  if (blob->timer && blob->timer->ref > 0) {
1422  g_source_remove(blob->timer->ref);
1423  }
1424  free(blob->timer);
1425  free(blob);
1426 }
1427 
1428 static int
1429 stonith_api_signoff(stonith_t * stonith)
1430 {
1431  stonith_private_t *native = stonith->st_private;
1432 
1433  crm_debug("Disconnecting from the fencer");
1434 
1435  if (native->source != NULL) {
1436  /* Attached to mainloop */
1437  mainloop_del_ipc_client(native->source);
1438  native->source = NULL;
1439  native->ipc = NULL;
1440 
1441  } else if (native->ipc) {
1442  /* Not attached to mainloop */
1443  crm_ipc_t *ipc = native->ipc;
1444 
1445  native->ipc = NULL;
1446  crm_ipc_close(ipc);
1447  crm_ipc_destroy(ipc);
1448  }
1449 
1450  free(native->token); native->token = NULL;
1451  stonith->state = stonith_disconnected;
1452  return pcmk_ok;
1453 }
1454 
1455 static int
1456 stonith_api_del_callback(stonith_t * stonith, int call_id, bool all_callbacks)
1457 {
1458  stonith_private_t *private = stonith->st_private;
1459 
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,
1464  NULL,
1465  stonith_destroy_op_callback);
1466 
1467  } else if (call_id == 0) {
1468  private->op_callback = NULL;
1469 
1470  } else {
1471  g_hash_table_remove(private->stonith_op_callback_table, GINT_TO_POINTER(call_id));
1472  }
1473  return pcmk_ok;
1474 }
1475 
1476 static void
1477 invoke_callback(stonith_t * st, int call_id, int rc, void *userdata,
1478  void (*callback) (stonith_t * st, stonith_callback_data_t * data))
1479 {
1480  stonith_callback_data_t data = { 0, };
1481 
1482  data.call_id = call_id;
1483  data.rc = rc;
1484  data.userdata = userdata;
1485 
1486  callback(st, &data);
1487 }
1488 
1489 static void
1490 stonith_perform_callback(stonith_t * stonith, xmlNode * msg, int call_id, int rc)
1491 {
1492  stonith_private_t *private = NULL;
1493  stonith_callback_client_t *blob = NULL;
1494  stonith_callback_client_t local_blob;
1495 
1496  CRM_CHECK(stonith != NULL, return);
1497  CRM_CHECK(stonith->st_private != NULL, return);
1498 
1499  private = stonith->st_private;
1500 
1501  local_blob.id = NULL;
1502  local_blob.callback = NULL;
1503  local_blob.user_data = NULL;
1504  local_blob.only_success = FALSE;
1505 
1506  if (msg != NULL) {
1508  crm_element_value_int(msg, F_STONITH_CALLID, &call_id);
1509  }
1510 
1511  CRM_CHECK(call_id > 0, crm_log_xml_err(msg, "Bad result"));
1512 
1513  blob = g_hash_table_lookup(private->stonith_op_callback_table, GINT_TO_POINTER(call_id));
1514 
1515  if (blob != NULL) {
1516  local_blob = *blob;
1517  blob = NULL;
1518 
1519  stonith_api_del_callback(stonith, call_id, FALSE);
1520 
1521  } else {
1522  crm_trace("No callback found for call %d", call_id);
1523  local_blob.callback = NULL;
1524  }
1525 
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);
1529 
1530  } else if (private->op_callback == NULL && rc != pcmk_ok) {
1531  crm_warn("Fencing command failed: %s", pcmk_strerror(rc));
1532  crm_log_xml_debug(msg, "Failed fence update");
1533  }
1534 
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);
1538  }
1539  crm_trace("OP callback activated.");
1540 }
1541 
1542 static gboolean
1543 stonith_async_timeout_handler(gpointer data)
1544 {
1545  struct timer_rec_s *timer = data;
1546 
1547  crm_err("Async call %d timed out after %dms", timer->call_id, timer->timeout);
1548  stonith_perform_callback(timer->stonith, NULL, timer->call_id, -ETIME);
1549 
1550  /* Always return TRUE, never remove the handler
1551  * We do that in stonith_del_callback()
1552  */
1553  return TRUE;
1554 }
1555 
1556 static void
1557 set_callback_timeout(stonith_callback_client_t * callback, stonith_t * stonith, int call_id,
1558  int timeout)
1559 {
1560  struct timer_rec_s *async_timer = callback->timer;
1561 
1562  if (timeout <= 0) {
1563  return;
1564  }
1565 
1566  if (!async_timer) {
1567  async_timer = calloc(1, sizeof(struct timer_rec_s));
1568  callback->timer = async_timer;
1569  }
1570 
1571  async_timer->stonith = stonith;
1572  async_timer->call_id = call_id;
1573  /* Allow a fair bit of grace to allow the server to tell us of a timeout
1574  * This is only a fallback
1575  */
1576  async_timer->timeout = (timeout + 60) * 1000;
1577  if (async_timer->ref) {
1578  g_source_remove(async_timer->ref);
1579  }
1580  async_timer->ref =
1581  g_timeout_add(async_timer->timeout, stonith_async_timeout_handler, async_timer);
1582 }
1583 
1584 static void
1585 update_callback_timeout(int call_id, int timeout, stonith_t * st)
1586 {
1587  stonith_callback_client_t *callback = NULL;
1588  stonith_private_t *private = st->st_private;
1589 
1590  callback = g_hash_table_lookup(private->stonith_op_callback_table, GINT_TO_POINTER(call_id));
1591  if (!callback || !callback->allow_timeout_updates) {
1592  return;
1593  }
1594 
1595  set_callback_timeout(callback, st, call_id, timeout);
1596 }
1597 
1598 static int
1599 stonith_dispatch_internal(const char *buffer, ssize_t length, gpointer userdata)
1600 {
1601  const char *type = NULL;
1602  struct notify_blob_s blob;
1603 
1604  stonith_t *st = userdata;
1605  stonith_private_t *private = NULL;
1606 
1607  CRM_ASSERT(st != NULL);
1608  private = st->st_private;
1609 
1610  blob.stonith = st;
1611  blob.xml = string2xml(buffer);
1612  if (blob.xml == NULL) {
1613  crm_warn("Received malformed message from fencer: %s", buffer);
1614  return 0;
1615  }
1616 
1617  /* do callbacks */
1618  type = crm_element_value(blob.xml, F_TYPE);
1619  crm_trace("Activating %s callbacks...", type);
1620 
1621  if (safe_str_eq(type, T_STONITH_NG)) {
1622  stonith_perform_callback(st, blob.xml, 0, 0);
1623 
1624  } else if (safe_str_eq(type, T_STONITH_NOTIFY)) {
1625  g_list_foreach(private->notify_list, stonith_send_notification, &blob);
1626  } else if (safe_str_eq(type, T_STONITH_TIMEOUT_VALUE)) {
1627  int call_id = 0;
1628  int timeout = 0;
1629 
1630  crm_element_value_int(blob.xml, F_STONITH_TIMEOUT, &timeout);
1631  crm_element_value_int(blob.xml, F_STONITH_CALLID, &call_id);
1632 
1633  update_callback_timeout(call_id, timeout, st);
1634  } else {
1635  crm_err("Unknown message type: %s", type);
1636  crm_log_xml_warn(blob.xml, "BadReply");
1637  }
1638 
1639  free_xml(blob.xml);
1640  return 1;
1641 }
1642 
1643 static int
1644 stonith_api_signon(stonith_t * stonith, const char *name, int *stonith_fd)
1645 {
1646  int rc = pcmk_ok;
1647  stonith_private_t *native = stonith->st_private;
1648 
1649  static struct ipc_client_callbacks st_callbacks = {
1650  .dispatch = stonith_dispatch_internal,
1651  .destroy = stonith_connection_destroy
1652  };
1653 
1654  crm_trace("Connecting command channel");
1655 
1656  stonith->state = stonith_connected_command;
1657  if (stonith_fd) {
1658  /* No mainloop */
1659  native->ipc = crm_ipc_new("stonith-ng", 0);
1660 
1661  if (native->ipc && crm_ipc_connect(native->ipc)) {
1662  *stonith_fd = crm_ipc_get_fd(native->ipc);
1663  } else if (native->ipc) {
1664  crm_perror(LOG_ERR, "Connection to fencer failed");
1665  rc = -ENOTCONN;
1666  }
1667 
1668  } else {
1669  /* With mainloop */
1670  native->source =
1671  mainloop_add_ipc_client("stonith-ng", G_PRIORITY_MEDIUM, 0, stonith, &st_callbacks);
1672  native->ipc = mainloop_get_ipc_client(native->source);
1673  }
1674 
1675  if (native->ipc == NULL) {
1676  crm_debug("Could not connect to the Stonith API");
1677  rc = -ENOTCONN;
1678  }
1679 
1680  if (rc == pcmk_ok) {
1681  xmlNode *reply = NULL;
1682  xmlNode *hello = create_xml_node(NULL, "stonith_command");
1683 
1684  crm_xml_add(hello, F_TYPE, T_STONITH_NG);
1686  crm_xml_add(hello, F_STONITH_CLIENTNAME, name);
1687  rc = crm_ipc_send(native->ipc, hello, crm_ipc_client_response, -1, &reply);
1688 
1689  if (rc < 0) {
1690  crm_perror(LOG_DEBUG, "Couldn't complete registration with the fencing API: %d", rc);
1691  rc = -ECOMM;
1692 
1693  } else if (reply == NULL) {
1694  crm_err("Did not receive registration reply");
1695  rc = -EPROTO;
1696 
1697  } else {
1698  const char *msg_type = crm_element_value(reply, F_STONITH_OPERATION);
1699  const char *tmp_ticket = crm_element_value(reply, F_STONITH_CLIENTID);
1700 
1701  if (safe_str_neq(msg_type, CRM_OP_REGISTER)) {
1702  crm_err("Invalid registration message: %s", msg_type);
1703  crm_log_xml_err(reply, "Bad reply");
1704  rc = -EPROTO;
1705 
1706  } else if (tmp_ticket == NULL) {
1707  crm_err("No registration token provided");
1708  crm_log_xml_err(reply, "Bad reply");
1709  rc = -EPROTO;
1710 
1711  } else {
1712  crm_trace("Obtained registration token: %s", tmp_ticket);
1713  native->token = strdup(tmp_ticket);
1714  rc = pcmk_ok;
1715  }
1716  }
1717 
1718  free_xml(reply);
1719  free_xml(hello);
1720  }
1721 
1722  if (rc == pcmk_ok) {
1723 #if HAVE_MSGFROMIPC_TIMEOUT
1724  stonith->call_timeout = MAX_IPC_DELAY;
1725 #endif
1726  crm_debug("Connection to fencer successful");
1727  return pcmk_ok;
1728  }
1729 
1730  crm_debug("Connection to fencer failed: %s", pcmk_strerror(rc));
1731  stonith->cmds->disconnect(stonith);
1732  return rc;
1733 }
1734 
1735 static int
1736 stonith_set_notification(stonith_t * stonith, const char *callback, int enabled)
1737 {
1738  int rc = pcmk_ok;
1739  xmlNode *notify_msg = create_xml_node(NULL, __FUNCTION__);
1740  stonith_private_t *native = stonith->st_private;
1741 
1742  if (stonith->state != stonith_disconnected) {
1743 
1745  if (enabled) {
1746  crm_xml_add(notify_msg, F_STONITH_NOTIFY_ACTIVATE, callback);
1747  } else {
1748  crm_xml_add(notify_msg, F_STONITH_NOTIFY_DEACTIVATE, callback);
1749  }
1750 
1751  rc = crm_ipc_send(native->ipc, notify_msg, crm_ipc_client_response, -1, NULL);
1752  if (rc < 0) {
1753  crm_perror(LOG_DEBUG, "Couldn't register for fencing notifications: %d", rc);
1754  rc = -ECOMM;
1755  } else {
1756  rc = pcmk_ok;
1757  }
1758  }
1759 
1760  free_xml(notify_msg);
1761  return rc;
1762 }
1763 
1764 static int
1765 stonith_api_add_notification(stonith_t * stonith, const char *event,
1766  void (*callback) (stonith_t * stonith, stonith_event_t * e))
1767 {
1768  GList *list_item = NULL;
1769  stonith_notify_client_t *new_client = NULL;
1770  stonith_private_t *private = NULL;
1771 
1772  private = stonith->st_private;
1773  crm_trace("Adding callback for %s events (%d)", event, g_list_length(private->notify_list));
1774 
1775  new_client = calloc(1, sizeof(stonith_notify_client_t));
1776  new_client->event = event;
1777  new_client->notify = callback;
1778 
1779  list_item = g_list_find_custom(private->notify_list, new_client, stonithlib_GCompareFunc);
1780 
1781  if (list_item != NULL) {
1782  crm_warn("Callback already present");
1783  free(new_client);
1784  return -ENOTUNIQ;
1785 
1786  } else {
1787  private->notify_list = g_list_append(private->notify_list, new_client);
1788 
1789  stonith_set_notification(stonith, event, 1);
1790 
1791  crm_trace("Callback added (%d)", g_list_length(private->notify_list));
1792  }
1793  return pcmk_ok;
1794 }
1795 
1796 static int
1797 stonith_api_del_notification(stonith_t * stonith, const char *event)
1798 {
1799  GList *list_item = NULL;
1800  stonith_notify_client_t *new_client = NULL;
1801  stonith_private_t *private = NULL;
1802 
1803  crm_debug("Removing callback for %s events", event);
1804 
1805  private = stonith->st_private;
1806  new_client = calloc(1, sizeof(stonith_notify_client_t));
1807  new_client->event = event;
1808  new_client->notify = NULL;
1809 
1810  list_item = g_list_find_custom(private->notify_list, new_client, stonithlib_GCompareFunc);
1811 
1812  stonith_set_notification(stonith, event, 0);
1813 
1814  if (list_item != NULL) {
1815  stonith_notify_client_t *list_client = list_item->data;
1816 
1817  private->notify_list = g_list_remove(private->notify_list, list_client);
1818  free(list_client);
1819 
1820  crm_trace("Removed callback");
1821 
1822  } else {
1823  crm_trace("Callback not present");
1824  }
1825  free(new_client);
1826  return pcmk_ok;
1827 }
1828 
1829 static int
1830 stonith_api_add_callback(stonith_t * stonith, int call_id, int timeout, int options,
1831  void *user_data, const char *callback_name,
1832  void (*callback) (stonith_t * st, stonith_callback_data_t * data))
1833 {
1834  stonith_callback_client_t *blob = NULL;
1835  stonith_private_t *private = NULL;
1836 
1837  CRM_CHECK(stonith != NULL, return -EINVAL);
1838  CRM_CHECK(stonith->st_private != NULL, return -EINVAL);
1839  private = stonith->st_private;
1840 
1841  if (call_id == 0) {
1842  private->op_callback = callback;
1843 
1844  } else if (call_id < 0) {
1845  if (!(options & st_opt_report_only_success)) {
1846  crm_trace("Call failed, calling %s: %s", callback_name, pcmk_strerror(call_id));
1847  invoke_callback(stonith, call_id, call_id, user_data, callback);
1848  } else {
1849  crm_warn("Fencer call failed: %s", pcmk_strerror(call_id));
1850  }
1851  return FALSE;
1852  }
1853 
1854  blob = calloc(1, sizeof(stonith_callback_client_t));
1855  blob->id = callback_name;
1856  blob->only_success = (options & st_opt_report_only_success) ? TRUE : FALSE;
1857  blob->user_data = user_data;
1858  blob->callback = callback;
1859  blob->allow_timeout_updates = (options & st_opt_timeout_updates) ? TRUE : FALSE;
1860 
1861  if (timeout > 0) {
1862  set_callback_timeout(blob, stonith, call_id, timeout);
1863  }
1864 
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);
1867 
1868  return TRUE;
1869 }
1870 
1871 static void
1872 stonith_dump_pending_op(gpointer key, gpointer value, gpointer user_data)
1873 {
1874  int call = GPOINTER_TO_INT(key);
1875  stonith_callback_client_t *blob = value;
1876 
1877  crm_debug("Call %d (%s): pending", call, crm_str(blob->id));
1878 }
1879 
1880 void
1882 {
1883  stonith_private_t *private = stonith->st_private;
1884 
1885  if (private->stonith_op_callback_table == NULL) {
1886  return;
1887  }
1888  return g_hash_table_foreach(private->stonith_op_callback_table, stonith_dump_pending_op, NULL);
1889 }
1890 
1891 /*
1892  <notify t="st_notify" subt="st_device_register" st_op="st_device_register" st_rc="0" >
1893  <st_calldata >
1894  <stonith_command t="stonith-ng" st_async_id="088fb640-431a-48b9-b2fc-c4ff78d0a2d9" st_op="st_device_register" st_callid="2" st_callopt="4096" st_timeout="0" st_clientid="088fb640-431a-48b9-b2fc-c4ff78d0a2d9" st_clientname="cts-fence-helper" >
1895  <st_calldata >
1896  <st_device_id id="test-id" origin="create_device_registration_xml" agent="fence_virsh" namespace="stonith-ng" >
1897  <attributes ipaddr="localhost" pcmk-portmal="some-host=pcmk-1 pcmk-3=3,4" login="root" identity_file="/root/.ssh/id_dsa" />
1898  </st_device_id>
1899  </st_calldata>
1900  </stonith_command>
1901  </st_calldata>
1902  </notify>
1903 
1904  <notify t="st_notify" subt="st_notify_fence" st_op="st_notify_fence" st_rc="0" >
1905  <st_calldata >
1906  <st_notify_fence st_rc="0" st_target="some-host" st_op="st_fence" st_delegate="test-id" st_origin="61dd7759-e229-4be7-b1f8-ef49dd14d9f0" />
1907  </st_calldata>
1908  </notify>
1909 */
1910 static stonith_event_t *
1911 xml_to_event(xmlNode * msg)
1912 {
1913  stonith_event_t *event = calloc(1, sizeof(stonith_event_t));
1914  const char *ntype = crm_element_value(msg, F_SUBTYPE);
1915  char *data_addr = crm_strdup_printf("//%s", ntype);
1916  xmlNode *data = get_xpath_object(data_addr, msg, LOG_DEBUG);
1917 
1918  crm_log_xml_trace(msg, "stonith_notify");
1919 
1920  crm_element_value_int(msg, F_STONITH_RC, &(event->result));
1921 
1922  if (safe_str_eq(ntype, T_STONITH_NOTIFY_FENCE)) {
1923  event->operation = crm_element_value_copy(msg, F_STONITH_OPERATION);
1924 
1925  if (data) {
1926  event->origin = crm_element_value_copy(data, F_STONITH_ORIGIN);
1927  event->action = crm_element_value_copy(data, F_STONITH_ACTION);
1928  event->target = crm_element_value_copy(data, F_STONITH_TARGET);
1929  event->executioner = crm_element_value_copy(data, F_STONITH_DELEGATE);
1931  event->client_origin = crm_element_value_copy(data, F_STONITH_CLIENTNAME);
1932  event->device = crm_element_value_copy(data, F_STONITH_DEVICE);
1933 
1934  } else {
1935  crm_err("No data for %s event", ntype);
1936  crm_log_xml_notice(msg, "BadEvent");
1937  }
1938  }
1939 
1940  free(data_addr);
1941  return event;
1942 }
1943 
1944 static void
1945 event_free(stonith_event_t * event)
1946 {
1947  free(event->id);
1948  free(event->type);
1949  free(event->message);
1950  free(event->operation);
1951  free(event->origin);
1952  free(event->action);
1953  free(event->target);
1954  free(event->executioner);
1955  free(event->device);
1956  free(event->client_origin);
1957  free(event);
1958 }
1959 
1960 static void
1961 stonith_send_notification(gpointer data, gpointer user_data)
1962 {
1963  struct notify_blob_s *blob = user_data;
1964  stonith_notify_client_t *entry = data;
1965  stonith_event_t *st_event = NULL;
1966  const char *event = NULL;
1967 
1968  if (blob->xml == NULL) {
1969  crm_warn("Skipping callback - NULL message");
1970  return;
1971  }
1972 
1973  event = crm_element_value(blob->xml, F_SUBTYPE);
1974 
1975  if (entry == NULL) {
1976  crm_warn("Skipping callback - NULL callback client");
1977  return;
1978 
1979  } else if (entry->notify == NULL) {
1980  crm_warn("Skipping callback - NULL callback");
1981  return;
1982 
1983  } else if (safe_str_neq(entry->event, event)) {
1984  crm_trace("Skipping callback - event mismatch %p/%s vs. %s", entry, entry->event, event);
1985  return;
1986  }
1987 
1988  st_event = xml_to_event(blob->xml);
1989 
1990  crm_trace("Invoking callback for %p/%s event...", entry, event);
1991  entry->notify(blob->stonith, st_event);
1992  crm_trace("Callback invoked...");
1993 
1994  event_free(st_event);
1995 }
1996 
1997 int
1998 stonith_send_command(stonith_t * stonith, const char *op, xmlNode * data, xmlNode ** output_data,
1999  int call_options, int timeout)
2000 {
2001  int rc = 0;
2002  int reply_id = -1;
2003  enum crm_ipc_flags ipc_flags = crm_ipc_flags_none;
2004 
2005  xmlNode *op_msg = NULL;
2006  xmlNode *op_reply = NULL;
2007 
2008  stonith_private_t *native = stonith->st_private;
2009 
2010  if (stonith->state == stonith_disconnected) {
2011  return -ENOTCONN;
2012  }
2013 
2014  if (output_data != NULL) {
2015  *output_data = NULL;
2016  }
2017 
2018  if (op == NULL) {
2019  crm_err("No operation specified");
2020  return -EINVAL;
2021  }
2022 
2023  if (call_options & st_opt_sync_call) {
2024  ipc_flags |= crm_ipc_client_response;
2025  }
2026 
2027  stonith->call_id++;
2028  /* prevent call_id from being negative (or zero) and conflicting
2029  * with the stonith_errors enum
2030  * use 2 because we use it as (stonith->call_id - 1) below
2031  */
2032  if (stonith->call_id < 1) {
2033  stonith->call_id = 1;
2034  }
2035 
2036  CRM_CHECK(native->token != NULL,;
2037  );
2038  op_msg = stonith_create_op(stonith->call_id, native->token, op, data, call_options);
2039  if (op_msg == NULL) {
2040  return -EINVAL;
2041  }
2042 
2043  crm_xml_add_int(op_msg, F_STONITH_TIMEOUT, timeout);
2044  crm_trace("Sending %s message to fencer with timeout %ds", op, timeout);
2045 
2046  rc = crm_ipc_send(native->ipc, op_msg, ipc_flags, 1000 * (timeout + 60), &op_reply);
2047  free_xml(op_msg);
2048 
2049  if (rc < 0) {
2050  crm_perror(LOG_ERR, "Couldn't perform %s operation (timeout=%ds): %d", op, timeout, rc);
2051  rc = -ECOMM;
2052  goto done;
2053  }
2054 
2055  crm_log_xml_trace(op_reply, "Reply");
2056 
2057  if (!(call_options & st_opt_sync_call)) {
2058  crm_trace("Async call %d, returning", stonith->call_id);
2059  CRM_CHECK(stonith->call_id != 0, return -EPROTO);
2060  free_xml(op_reply);
2061 
2062  return stonith->call_id;
2063  }
2064 
2065  rc = pcmk_ok;
2066  crm_element_value_int(op_reply, F_STONITH_CALLID, &reply_id);
2067 
2068  if (reply_id == stonith->call_id) {
2069  crm_trace("Synchronous reply %d received", reply_id);
2070 
2071  if (crm_element_value_int(op_reply, F_STONITH_RC, &rc) != 0) {
2072  rc = -ENOMSG;
2073  }
2074 
2075  if ((call_options & st_opt_discard_reply) || output_data == NULL) {
2076  crm_trace("Discarding reply");
2077 
2078  } else {
2079  *output_data = op_reply;
2080  op_reply = NULL; /* Prevent subsequent free */
2081  }
2082 
2083  } else if (reply_id <= 0) {
2084  crm_err("Received bad reply: No id set");
2085  crm_log_xml_err(op_reply, "Bad reply");
2086  free_xml(op_reply);
2087  rc = -ENOMSG;
2088 
2089  } else {
2090  crm_err("Received bad reply: %d (wanted %d)", reply_id, stonith->call_id);
2091  crm_log_xml_err(op_reply, "Old reply");
2092  free_xml(op_reply);
2093  rc = -ENOMSG;
2094  }
2095 
2096  done:
2097  if (crm_ipc_connected(native->ipc) == FALSE) {
2098  crm_err("Fencer disconnected");
2099  stonith->state = stonith_disconnected;
2100  }
2101 
2102  free_xml(op_reply);
2103  return rc;
2104 }
2105 
2106 /* Not used with mainloop */
2107 bool
2109 {
2110  gboolean stay_connected = TRUE;
2111  stonith_private_t *private = NULL;
2112 
2113  CRM_ASSERT(st != NULL);
2114  private = st->st_private;
2115 
2116  while (crm_ipc_ready(private->ipc)) {
2117 
2118  if (crm_ipc_read(private->ipc) > 0) {
2119  const char *msg = crm_ipc_buffer(private->ipc);
2120 
2121  stonith_dispatch_internal(msg, strlen(msg), st);
2122  }
2123 
2124  if (crm_ipc_connected(private->ipc) == FALSE) {
2125  crm_err("Connection closed");
2126  stay_connected = FALSE;
2127  }
2128  }
2129 
2130  return stay_connected;
2131 }
2132 
2133 static int
2134 stonith_api_free(stonith_t * stonith)
2135 {
2136  int rc = pcmk_ok;
2137 
2138  crm_trace("Destroying %p", stonith);
2139 
2140  if (stonith->state != stonith_disconnected) {
2141  crm_trace("Disconnecting %p first", stonith);
2142  rc = stonith->cmds->disconnect(stonith);
2143  }
2144 
2145  if (stonith->state == stonith_disconnected) {
2146  stonith_private_t *private = stonith->st_private;
2147 
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);
2150 
2151  crm_trace("Destroying %d notification clients", g_list_length(private->notify_list));
2152  g_list_free_full(private->notify_list, free);
2153 
2154  free(stonith->st_private);
2155  free(stonith->cmds);
2156  free(stonith);
2157 
2158  } else {
2159  crm_err("Not free'ing active connection: %s (%d)", pcmk_strerror(rc), rc);
2160  }
2161 
2162  return rc;
2163 }
2164 
2165 void
2167 {
2168  crm_trace("Destroying %p", stonith);
2169  if(stonith) {
2170  stonith->cmds->free(stonith);
2171  }
2172 }
2173 
2174 static int
2175 stonith_api_validate(stonith_t *st, int call_options, const char *rsc_id,
2176  const char *namespace_s, const char *agent,
2177  stonith_key_value_t *params, int timeout, char **output,
2178  char **error_output)
2179 {
2180  /* Validation should be done directly via the agent, so we can get it from
2181  * stonith_admin when the cluster is not running, which is important for
2182  * higher-level tools.
2183  */
2184 
2185  int rc = pcmk_ok;
2186 
2187  /* Use a dummy node name in case the agent requires a target. We assume the
2188  * actual target doesn't matter for validation purposes (if in practice,
2189  * that is incorrect, we will need to allow the caller to pass the target).
2190  */
2191  const char *target = "node1";
2192 
2193  GHashTable *params_table = crm_str_table_new();
2194 
2195  // Convert parameter list to a hash table
2196  for (; params; params = params->next) {
2197 
2198  // Strip out Pacemaker-implemented parameters
2199  if (!crm_starts_with(params->key, "pcmk_")
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));
2204  }
2205  }
2206 
2207 #if SUPPORT_CIBSECRETS
2208  rc = replace_secret_params(rsc_id, params_table);
2209  if (rc < 0) {
2210  crm_warn("Could not replace secret parameters for validation of %s: %s",
2211  agent, pcmk_strerror(rc));
2212  }
2213 #endif
2214 
2215  if (output) {
2216  *output = NULL;
2217  }
2218  if (error_output) {
2219  *error_output = NULL;
2220  }
2221 
2222  switch (stonith_get_namespace(agent, namespace_s)) {
2223  case st_namespace_rhcs:
2224  rc = stonith__rhcs_validate(st, call_options, target, agent,
2225  params_table, timeout, output,
2226  error_output);
2227  break;
2228 
2229 #if HAVE_STONITH_STONITH_H
2230  case st_namespace_lha:
2231  rc = stonith__lha_validate(st, call_options, target, agent,
2232  params_table, timeout, output,
2233  error_output);
2234  break;
2235 #endif
2236 
2237  default:
2238  rc = -EINVAL;
2239  errno = EINVAL;
2240  crm_perror(LOG_ERR,
2241  "Agent %s not found or does not support validation",
2242  agent);
2243  break;
2244  }
2245  g_hash_table_destroy(params_table);
2246  return rc;
2247 }
2248 
2249 stonith_t *
2251 {
2252  stonith_t *new_stonith = NULL;
2253  stonith_private_t *private = NULL;
2254 
2255  new_stonith = calloc(1, sizeof(stonith_t));
2256  private = calloc(1, sizeof(stonith_private_t));
2257  new_stonith->st_private = private;
2258 
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;
2262 
2263  new_stonith->call_id = 1;
2264  new_stonith->state = stonith_disconnected;
2265 
2266  new_stonith->cmds = calloc(1, sizeof(stonith_api_operations_t));
2267 
2268 /* *INDENT-OFF* */
2269  new_stonith->cmds->free = stonith_api_free;
2270  new_stonith->cmds->connect = stonith_api_signon;
2271  new_stonith->cmds->disconnect = stonith_api_signoff;
2272 
2273  new_stonith->cmds->list = stonith_api_list;
2274  new_stonith->cmds->monitor = stonith_api_monitor;
2275  new_stonith->cmds->status = stonith_api_status;
2276  new_stonith->cmds->fence = stonith_api_fence;
2277  new_stonith->cmds->confirm = stonith_api_confirm;
2278  new_stonith->cmds->history = stonith_api_history;
2279 
2280  new_stonith->cmds->list_agents = stonith_api_device_list;
2281  new_stonith->cmds->metadata = stonith_api_device_metadata;
2282 
2283  new_stonith->cmds->query = stonith_api_query;
2284  new_stonith->cmds->remove_device = stonith_api_remove_device;
2285  new_stonith->cmds->register_device = stonith_api_register_device;
2286 
2287  new_stonith->cmds->remove_level = stonith_api_remove_level;
2288  new_stonith->cmds->remove_level_full = stonith_api_remove_level_full;
2289  new_stonith->cmds->register_level = stonith_api_register_level;
2290  new_stonith->cmds->register_level_full = stonith_api_register_level_full;
2291 
2292  new_stonith->cmds->remove_callback = stonith_api_del_callback;
2293  new_stonith->cmds->register_callback = stonith_api_add_callback;
2294  new_stonith->cmds->remove_notification = stonith_api_del_notification;
2295  new_stonith->cmds->register_notification = stonith_api_add_notification;
2296 
2297  new_stonith->cmds->validate = stonith_api_validate;
2298 /* *INDENT-ON* */
2299 
2300  return new_stonith;
2301 }
2302 
2304 stonith_key_value_add(stonith_key_value_t * head, const char *key, const char *value)
2305 {
2306  stonith_key_value_t *p, *end;
2307 
2308  p = calloc(1, sizeof(stonith_key_value_t));
2309  if (key) {
2310  p->key = strdup(key);
2311  }
2312  if (value) {
2313  p->value = strdup(value);
2314  }
2315 
2316  end = head;
2317  while (end && end->next) {
2318  end = end->next;
2319  }
2320 
2321  if (end) {
2322  end->next = p;
2323  } else {
2324  head = p;
2325  }
2326 
2327  return head;
2328 }
2329 
2330 void
2331 stonith_key_value_freeall(stonith_key_value_t * head, int keys, int values)
2332 {
2334 
2335  while (head) {
2336  p = head->next;
2337  if (keys) {
2338  free(head->key);
2339  }
2340  if (values) {
2341  free(head->value);
2342  }
2343  free(head);
2344  head = p;
2345  }
2346 }
2347 
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)
2350 
2351 int
2352 stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off)
2353 {
2354  char *name = NULL;
2355  const char *action = "reboot";
2356 
2357  int rc = -EPROTO;
2358  stonith_t *st = NULL;
2360 
2361  api_log_open();
2362  st = stonith_api_new();
2363  if (st) {
2364  rc = st->cmds->connect(st, "stonith-api", NULL);
2365  if(rc != pcmk_ok) {
2366  api_log(LOG_ERR, "Connection failed, could not kick (%s) node %u/%s : %s (%d)", action, nodeid, uname, pcmk_strerror(rc), rc);
2367  }
2368  }
2369 
2370  if (uname != NULL) {
2371  name = strdup(uname);
2372 
2373  } else if (nodeid > 0) {
2374  opts |= st_opt_cs_nodeid;
2375  name = crm_itoa(nodeid);
2376  }
2377 
2378  if (off) {
2379  action = "off";
2380  }
2381 
2382  if (rc == pcmk_ok) {
2383  rc = st->cmds->fence(st, opts, name, action, timeout, 0);
2384  if(rc != pcmk_ok) {
2385  api_log(LOG_ERR, "Could not kick (%s) node %u/%s : %s (%d)", action, nodeid, uname, pcmk_strerror(rc), rc);
2386  } else {
2387  api_log(LOG_NOTICE, "Node %u/%s kicked: %s ", nodeid, uname, action);
2388  }
2389  }
2390 
2391  if (st) {
2392  st->cmds->disconnect(st);
2393  stonith_api_delete(st);
2394  }
2395 
2396  free(name);
2397  return rc;
2398 }
2399 
2400 time_t
2401 stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress)
2402 {
2403  int rc = 0;
2404  char *name = NULL;
2405 
2406  time_t when = 0;
2407  stonith_t *st = NULL;
2408  stonith_history_t *history = NULL, *hp = NULL;
2410 
2411  st = stonith_api_new();
2412  if (st) {
2413  rc = st->cmds->connect(st, "stonith-api", NULL);
2414  if(rc != pcmk_ok) {
2415  api_log(LOG_NOTICE, "Connection failed: %s (%d)", pcmk_strerror(rc), rc);
2416  }
2417  }
2418 
2419  if (uname != NULL) {
2420  name = strdup(uname);
2421 
2422  } else if (nodeid > 0) {
2423  opts |= st_opt_cs_nodeid;
2424  name = crm_itoa(nodeid);
2425  }
2426 
2427  if (st && rc == pcmk_ok) {
2428  int entries = 0;
2429  int progress = 0;
2430  int completed = 0;
2431 
2432  rc = st->cmds->history(st, opts, name, &history, 120);
2433 
2434  for (hp = history; hp; hp = hp->next) {
2435  entries++;
2436  if (in_progress) {
2437  progress++;
2438  if (hp->state != st_done && hp->state != st_failed) {
2439  when = time(NULL);
2440  }
2441 
2442  } else if (hp->state == st_done) {
2443  completed++;
2444  if (hp->completed > when) {
2445  when = hp->completed;
2446  }
2447  }
2448  }
2449 
2450  stonith_history_free(history);
2451 
2452  if(rc == pcmk_ok) {
2453  api_log(LOG_INFO, "Found %d entries for %u/%s: %d in progress, %d completed", entries, nodeid, uname, progress, completed);
2454  } else {
2455  api_log(LOG_ERR, "Could not retrieve fence history for %u/%s: %s (%d)", nodeid, uname, pcmk_strerror(rc), rc);
2456  }
2457  }
2458 
2459  if (st) {
2460  st->cmds->disconnect(st);
2461  stonith_api_delete(st);
2462  }
2463 
2464  if(when) {
2465  api_log(LOG_INFO, "Node %u/%s last kicked at: %ld", nodeid, uname, (long int)when);
2466  }
2467  free(name);
2468  return when;
2469 }
#define LOG_TRACE
Definition: logging.h:35
#define CRM_CHECK(expr, failure_action)
Definition: logging.h:165
char uname[MAX_NAME]
Definition: internal.h:85
int stonith_send_command(stonith_t *stonith, const char *op, xmlNode *data, xmlNode **output_data, int call_options, int timeout)
Definition: st_client.c:1998
#define XML_ATTR_STONITH_TARGET_ATTRIBUTE
Definition: msg_xml.h:395
struct stonith_action_s stonith_action_t
Definition: internal.h:15
void stonith_history_free(stonith_history_t *history)
Definition: st_client.c:1342
#define F_STONITH_REMOTE_OP_ID
Definition: internal.h:54
struct stonith_history_s * next
Definition: stonith-ng.h:103
bool crm_ipc_connect(crm_ipc_t *client)
Establish an IPC connection to a Pacemaker component.
Definition: ipc.c:938
A dumping ground.
#define F_TYPE
Definition: msg_xml.h:28
#define crm_notice(fmt, args...)
Definition: logging.h:251
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.
Definition: stonith-ng.h:372
#define F_STONITH_CLIENTID
Definition: internal.h:48
const char * pcmk_strerror(int rc)
Definition: results.c:184
#define ETIME
Definition: portability.h:160
gboolean safe_str_neq(const char *a, const char *b)
Definition: strings.c:141
stonith_t * stonith
Definition: st_client.c:104
#define api_log_open()
Definition: st_client.c:2348
#define READ_MAX
Definition: st_client.c:705
void hash2field(gpointer key, gpointer value, gpointer user_data)
Set XML attribute based on hash table entry.
Definition: nvpair.c:551
int stonith__rhcs_metadata(const char *agent, int timeout, char **output)
Execute RHCS-compatible agent&#39;s meta-data action.
Definition: st_rhcs.c:77
stonith_key_value_t * stonith_key_value_add(stonith_key_value_t *head, const char *key, const char *value)
Definition: st_client.c:2304
void stonith_dump_pending_callbacks(stonith_t *stonith)
Definition: st_client.c:1881
#define crm_log_output(level, prefix, output)
Definition: logging.h:93
int crm_ipc_get_fd(crm_ipc_t *client)
Definition: ipc.c:1007
int(* query)(stonith_t *st, int options, const char *node, stonith_key_value_t **devices, int timeout)
Retrieve a list of registered stonith devices.
Definition: stonith-ng.h:261
xmlNode * create_device_registration_xml(const char *id, enum stonith_namespace namespace, const char *agent, stonith_key_value_t *params, const char *rsc_provides)
Definition: st_client.c:240
#define F_SUBTYPE
Definition: msg_xml.h:24
int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off)
Definition: st_client.c:2352
#define F_STONITH_CALLBACK_TOKEN
Definition: internal.h:74
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)
Definition: st_lha.c:251
#define F_STONITH_CLIENTNAME
Definition: internal.h:75
const char * crm_xml_add_int(xmlNode *node, const char *name, int value)
Create an XML attribute with specified name and integer value.
Definition: nvpair.c:320
xmlNode * stonith_create_op(int call_id, const char *token, const char *op, xmlNode *data, int call_options)
Definition: st_client.c:1393
#define XML_TAG_FENCING_LEVEL
Definition: msg_xml.h:390
#define STONITH_OP_FENCE
Definition: internal.h:116
struct stonith_key_value_s * next
Definition: stonith-ng.h:92
#define XML_TAG_ATTRS
Definition: msg_xml.h:163
struct mainloop_io_s mainloop_io_t
Definition: mainloop.h:29
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
Definition: nvpair.c:212
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...
Definition: stonith-ng.h:201
struct mainloop_child_s mainloop_child_t
Definition: mainloop.h:30
#define pcmk_err_generic
Definition: results.h:38
void stonith_key_value_freeall(stonith_key_value_t *head, int keys, int values)
Definition: st_client.c:2331
#define F_STONITH_TIMEOUT
Definition: internal.h:57
int stonith__lha_metadata(const char *agent, int timeout, char **output)
Definition: st_lha.c:152
#define MAX_IPC_DELAY
Definition: crm.h:54
void stonith__destroy_action(stonith_action_t *action)
Definition: st_client.c:616
#define T_STONITH_TIMEOUT_VALUE
Definition: internal.h:100
#define CRM_LOG_ASSERT(expr)
Definition: logging.h:151
stonith_namespace
Definition: stonith-ng.h:72
long crm_ipc_read(crm_ipc_t *client)
Definition: ipc.c:1116
uint32_t pid
Definition: internal.h:81
int call_id
Definition: internal.h:97
#define F_STONITH_NOTIFY_DEACTIVATE
Definition: internal.h:78
void stonith__action_result(stonith_action_t *action, int *rc, char **output, char **error_output)
Definition: st_client.c:641
int crm_element_value_int(const xmlNode *data, const char *name, int *dest)
Retrieve the integer value of an XML attribute.
Definition: nvpair.c:395
int(* remove_callback)(stonith_t *st, int call_id, bool all_callbacks)
Remove a registered callback for a given call id.
Definition: stonith-ng.h:333
xmlNode * get_xpath_object(const char *xpath, xmlNode *xml_obj, int error_level)
Definition: xpath.c:220
int stonith__execute(stonith_action_t *action)
Definition: st_client.c:1085
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.
Definition: strings.c:243
#define STONITH_OP_LEVEL_DEL
Definition: internal.h:122
#define STONITH_OP_DEVICE_ADD
Definition: internal.h:118
#define STONITH_OP_EXEC
Definition: internal.h:113
#define CRM_OP_REGISTER
Definition: crm.h:118
xmlNode * string2xml(const char *input)
Definition: xml.c:2056
const char * crm_ipc_buffer(crm_ipc_t *client)
Definition: ipc.c:1163
const char * stonith_namespace2text(enum stonith_namespace st_namespace)
Get agent namespace name.
Definition: st_client.c:155
int stonith__list_lha_agents(stonith_key_value_t **devices)
Definition: st_lha.c:84
uint32_t id
Definition: internal.h:80
#define F_STONITH_ACTION
Definition: internal.h:92
#define T_STONITH_NG
Definition: internal.h:95
time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress)
Definition: st_client.c:2401
int(* free)(stonith_t *st)
Destroy the stonith api structure.
Definition: stonith-ng.h:140
int timeout
Definition: internal.h:98
#define XML_ATTR_STONITH_TARGET_PATTERN
Definition: msg_xml.h:394
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)
Definition: st_client.c:360
#define crm_warn(fmt, args...)
Definition: logging.h:250
bool stonith__agent_is_rhcs(const char *agent)
Definition: st_rhcs.c:160
#define STONITH_ATTR_HOSTARG
Definition: internal.h:103
bool stonith_dispatch(stonith_t *st)
Definition: st_client.c:2108
#define F_STONITH_CALLID
Definition: internal.h:50
#define crm_debug(fmt, args...)
Definition: logging.h:254
void * mainloop_child_userdata(mainloop_child_t *child)
Definition: mainloop.c:882
#define STONITH_OP_LEVEL_ADD
Definition: internal.h:121
struct crm_ipc_s crm_ipc_t
Definition: ipc.h:56
enum stonith_state state
Definition: stonith-ng.h:404
char * crm_element_value_copy(const xmlNode *data, const char *name)
Retrieve a copy of the value of an XML attribute.
Definition: nvpair.c:492
#define XML_ATTR_ID
Definition: msg_xml.h:94
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
Definition: nvpair.c:360
#define STONITH_OP_QUERY
Definition: internal.h:115
int(* metadata)(stonith_t *st, int options, const char *device, const char *provider, char **output, int timeout)
Get the metadata documentation for a resource.
Definition: stonith-ng.h:212
#define F_STONITH_DEVICE
Definition: internal.h:91
#define XML_ATTR_STONITH_DEVICES
Definition: msg_xml.h:396
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.
Definition: stonith-ng.h:177
int(* status)(stonith_t *st, int options, const char *id, const char *port, int timeout)
Check to see if a local stonith device&#39;s port is reachable.
Definition: stonith-ng.h:250
guint ref
Definition: internal.h:99
enum stonith_namespace stonith_text2namespace(const char *namespace_s)
Get agent namespace by name.
Definition: st_client.c:129
#define crm_trace(fmt, args...)
Definition: logging.h:255
#define XML_ATTR_STONITH_INDEX
Definition: msg_xml.h:391
int(* fence)(stonith_t *st, int options, const char *node, const char *action, int timeout, int tolerance)
Issue a fencing action against a node.
Definition: stonith-ng.h:279
int(* register_callback)(stonith_t *st, int call_id, int timeout, int options, void *userdata, const char *callback_name, void(*callback)(stonith_t *st, stonith_callback_data_t *data))
Register a callback to receive the result of an asynchronous call.
Definition: stonith-ng.h:322
int crm_set_nonblocking(int fd)
Definition: io.c:486
#define crm_log_xml_debug(xml, text)
Definition: logging.h:262
#define F_STONITH_RC
Definition: internal.h:55
#define XML_ATTR_STONITH_TARGET
Definition: msg_xml.h:392
Wrappers for and extensions to libxml2.
xmlNode * create_xml_node(xmlNode *parent, const char *name)
Definition: xml.c:1888
#define F_STONITH_STATE
Definition: internal.h:87
#define crm_log_xml_warn(xml, text)
Definition: logging.h:259
int(* disconnect)(stonith_t *st)
Disconnect from the local stonith daemon.
Definition: stonith-ng.h:156
int(* stonith_op_t)(const char *, int, const char *, xmlNode *, xmlNode *, xmlNode *, xmlNode **, xmlNode **)
Definition: st_client.c:107
enum stonith_namespace stonith_get_namespace(const char *agent, const char *namespace_s)
Determine namespace of a fence agent.
Definition: st_client.c:176
#define T_STONITH_NOTIFY_DISCONNECT
Definition: stonith-ng.h:27
const char * get_stonith_provider(const char *agent, const char *provider)
Deprecated (use stonith_get_namespace() instead)
Definition: st_client.c:1359
#define STONITH_OP_DEVICE_DEL
Definition: internal.h:119
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.
Definition: stonith-ng.h:234
#define ECOMM
Definition: portability.h:136
void mainloop_del_ipc_client(mainloop_io_t *client)
Definition: mainloop.c:789
void crm_ipc_destroy(crm_ipc_t *client)
Definition: ipc.c:984
#define XML_ATTR_STONITH_TARGET_VALUE
Definition: msg_xml.h:393
#define F_STONITH_TARGET
Definition: internal.h:53
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.
Definition: stonith-ng.h:225
gboolean add_message_xml(xmlNode *msg, const char *field, xmlNode *xml)
Definition: xml.c:2510
void stonith_api_delete(stonith_t *stonith)
Definition: st_client.c:2166
void free_xml(xmlNode *child)
Definition: xml.c:2012
int(* connect)(stonith_t *st, const char *name, int *stonith_fd)
Connect to the local stonith daemon.
Definition: stonith-ng.h:148
#define api_log(level, fmt, args...)
Definition: st_client.c:2349
#define STONITH_ATTR_ACTION_OP
Definition: internal.h:111
#define STONITH_OP_FENCE_HISTORY
Definition: internal.h:120
#define F_STONITH_CALLOPTS
Definition: internal.h:49
GPid stonith_action_execute_async(stonith_action_t *action, void *userdata, void(*done)(GPid pid, int rc, const char *output, gpointer user_data))
Definition: st_client.c:1056
int call_timeout
Definition: stonith-ng.h:407
int(* remove_device)(stonith_t *st, int options, const char *name)
Remove a registered stonith device with the local stonith daemon.
Definition: stonith-ng.h:166
struct stonith_private_s stonith_private_t
bool crm_ipc_connected(crm_ipc_t *client)
Definition: ipc.c:1021
#define CRM_XS
Definition: logging.h:43
int(* register_notification)(stonith_t *st, const char *event, void(*notify)(stonith_t *st, stonith_event_t *e))
Definition: stonith-ng.h:300
stonith_call_options
Definition: stonith-ng.h:38
int crm_ipc_ready(crm_ipc_t *client)
Check whether an IPC connection is ready to be read.
Definition: ipc.c:1053
int(* monitor)(stonith_t *st, int options, const char *id, int timeout)
Check to see if a local stonith device is reachable.
Definition: stonith-ng.h:242
char * client_origin
Definition: stonith-ng.h:124
#define F_STONITH_DATE
Definition: internal.h:86
#define ENODATA
Definition: portability.h:156
int(* remove_notification)(stonith_t *st, const char *event)
Definition: stonith-ng.h:303
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))
Definition: mainloop.c:1125
int replace_secret_params(const char *rsc_id, GHashTable *params)
Definition: cib_secrets.c:90
#define crm_log_xml_err(xml, text)
Definition: logging.h:258
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.
Definition: stonith-ng.h:395
int stonith__list_rhcs_agents(stonith_key_value_t **devices)
Definition: st_rhcs.c:29
#define crm_perror(level, fmt, args...)
Log a system error message.
Definition: logging.h:227
crm_ipc_t * mainloop_get_ipc_client(mainloop_io_t *client)
Definition: mainloop.c:795
#define CRM_META
Definition: crm.h:47
#define crm_err(fmt, args...)
Definition: logging.h:249
#define G_PRIORITY_MEDIUM
Definition: mainloop.h:121
#define CRM_ASSERT(expr)
Definition: results.h:20
xmlXPathObjectPtr xpath_search(xmlNode *xml_top, const char *path)
Definition: xpath.c:145
#define ENOTUNIQ
Definition: portability.h:132
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.
Definition: stonith-ng.h:351
stonith_api_operations_t * cmds
Definition: stonith-ng.h:410
int crm_ipc_send(crm_ipc_t *client, xmlNode *message, enum crm_ipc_flags flags, int32_t ms_timeout, xmlNode **reply)
Definition: ipc.c:1266
stonith_t * stonith_api_new(void)
Definition: st_client.c:2250
int(* remove_level)(stonith_t *st, int options, const char *node, int level)
Remove a fencing level for a specific node.
Definition: stonith-ng.h:189
#define FAILURE_MAX_RETRIES
Definition: st_client.c:668
#define crm_log_xml_notice(xml, text)
Definition: logging.h:260
Fencing aka. STONITH.
xmlNode * getXpathResult(xmlXPathObjectPtr xpathObj, int index)
Definition: xpath.c:64
char * executioner
Definition: stonith-ng.h:119
crm_ipc_t * crm_ipc_new(const char *name, size_t max_size)
Definition: ipc.c:910
char * operation
Definition: stonith-ng.h:113
#define uint32_t
Definition: stdint.in.h:158
char data[0]
Definition: internal.h:90
#define crm_str(x)
Definition: logging.h:275
#define F_STONITH_ORIGIN
Definition: internal.h:84
#define pcmk_ok
Definition: results.h:35
bool stonith__agent_is_lha(const char *agent)
Determine namespace of a fence agent.
Definition: st_lha.c:57
#define T_STONITH_NOTIFY_FENCE
Definition: stonith-ng.h:28
int(* confirm)(stonith_t *st, int options, const char *node)
Manually confirm that a node is down.
Definition: stonith-ng.h:288
void * st_private
Definition: stonith-ng.h:408
#define T_STONITH_NOTIFY
Definition: internal.h:101
#define crm_log_xml_trace(xml, text)
Definition: logging.h:263
#define F_STONITH_OPERATION
Definition: internal.h:52
mainloop_io_t * mainloop_add_ipc_client(const char *name, int priority, size_t max_size, void *userdata, struct ipc_client_callbacks *callbacks)
Definition: mainloop.c:761
#define safe_str_eq(a, b)
Definition: util.h:54
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)
Definition: st_rhcs.c:171
#define F_STONITH_NOTIFY_ACTIVATE
Definition: internal.h:77
#define F_XML_TAGNAME
Definition: msg_xml.h:36
void freeXpathObject(xmlXPathObjectPtr xpathObj)
Definition: xpath.c:45
crm_ipc_flags
Definition: ipc.h:37
void crm_ipc_close(crm_ipc_t *client)
Definition: ipc.c:969
#define F_STONITH_CALLDATA
Definition: internal.h:51
CRM_TRACE_INIT_DATA(stonith)
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
#define F_STONITH_DELEGATE
Definition: internal.h:79
#define crm_info(fmt, args...)
Definition: logging.h:252
int call_id
Definition: stonith-ng.h:406
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.
Definition: stonith-ng.h:298
int(* dispatch)(const char *buffer, ssize_t length, gpointer userdata)
Definition: mainloop.h:67
#define F_STONITH_HISTORY_LIST
Definition: internal.h:85
enum crm_ais_msg_types type
Definition: internal.h:83
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)
Definition: st_client.c:670
#define F_STONITH_TOLERANCE
Definition: internal.h:58