pacemaker  2.0.1-15814c6c0d
Scalable High-Availability cluster resource manager
stonith-ng.h
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 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
18 #ifndef STONITH_NG__H
19 # define STONITH_NG__H
20 
21 # include <dlfcn.h>
22 # include <errno.h>
23 # include <stdbool.h>
24 
25 /* TO-DO: Work out how to drop this requirement */
26 # include <libxml/tree.h>
27 
28 # define T_STONITH_NOTIFY_DISCONNECT "st_notify_disconnect"
29 # define T_STONITH_NOTIFY_FENCE "st_notify_fence"
30 # define T_STONITH_NOTIFY_HISTORY "st_notify_history"
31 
32 /* *INDENT-OFF* */
37 };
38 
40  st_opt_none = 0x00000000,
41  st_opt_verbose = 0x00000001,
42  st_opt_allow_suicide = 0x00000002,
43 
44  st_opt_manual_ack = 0x00000008,
45  st_opt_discard_reply = 0x00000010,
46 /* st_opt_all_replies = 0x00000020, */
47  st_opt_topology = 0x00000040,
48  st_opt_scope_local = 0x00000100,
49  st_opt_cs_nodeid = 0x00000200,
50  st_opt_sync_call = 0x00001000,
53  st_opt_timeout_updates = 0x00002000,
56  /* used where ever apropriate - e.g. cleanup of history */
57  st_opt_cleanup = 0x000080000,
58  /* used where ever apropriate - e.g. send out a history query to all nodes */
59  st_opt_broadcast = 0x000100000,
60 };
61 
64 {
70 };
71 
72 // Supported fence agent interface standards
76  st_namespace_internal, // Implemented internally by Pacemaker
77 
78  /* Neither of these projects are active any longer, but the fence agent
79  * interfaces they created are still in use and supported by Pacemaker.
80  */
81  st_namespace_rhcs, // Red Hat Cluster Suite compatible
82  st_namespace_lha, // Linux-HA compatible
83 };
84 
85 enum stonith_namespace stonith_text2namespace(const char *namespace_s);
86 const char *stonith_namespace2text(enum stonith_namespace namespace);
87 enum stonith_namespace stonith_get_namespace(const char *agent,
88  const char *namespace_s);
89 
90 typedef struct stonith_key_value_s {
91  char *key;
92  char *value;
95 
96 typedef struct stonith_history_s {
97  char *target;
98  char *action;
99  char *origin;
100  char *delegate;
101  char *client;
102  int state;
103  time_t completed;
106 
107 typedef struct stonith_s stonith_t;
108 
109 typedef struct stonith_event_s
110 {
111  char *id;
112  char *type;
113  char *message;
114  char *operation;
115 
116  int result;
117  char *origin;
118  char *target;
119  char *action;
120  char *executioner;
121 
122  char *device;
123 
126 
128 
130 {
131  int rc;
132  int call_id;
133  void *userdata;
135 
137 {
141  int (*free) (stonith_t *st);
142 
149  int (*connect) (stonith_t *st, const char *name, int *stonith_fd);
150 
157  int (*disconnect)(stonith_t *st);
158 
167  int (*remove_device)(
168  stonith_t *st, int options, const char *name);
169 
178  int (*register_device)(
179  stonith_t *st, int options, const char *id,
180  const char *provider, const char *agent, stonith_key_value_t *params);
181 
190  int (*remove_level)(
191  stonith_t *st, int options, const char *node, int level);
192 
202  int (*register_level)(
203  stonith_t *st, int options, const char *node, int level, stonith_key_value_t *device_list);
204 
213  int (*metadata)(stonith_t *st, int options,
214  const char *device, const char *provider, char **output, int timeout);
215 
226  int (*list_agents)(stonith_t *stonith, int call_options, const char *provider,
227  stonith_key_value_t **devices, int timeout);
228 
235  int (*list)(stonith_t *st, int options, const char *id, char **list_output, int timeout);
236 
243  int (*monitor)(stonith_t *st, int options, const char *id, int timeout);
244 
251  int (*status)(stonith_t *st, int options, const char *id, const char *port, int timeout);
252 
262  int (*query)(stonith_t *st, int options, const char *node,
263  stonith_key_value_t **devices, int timeout);
264 
280  int (*fence)(stonith_t *st, int options, const char *node, const char *action,
281  int timeout, int tolerance);
282 
289  int (*confirm)(stonith_t *st, int options, const char *node);
290 
299  int (*history)(stonith_t *st, int options, const char *node, stonith_history_t **output, int timeout);
300 
301  int (*register_notification)(
302  stonith_t *st, const char *event,
303  void (*notify)(stonith_t *st, stonith_event_t *e));
304  int (*remove_notification)(stonith_t *st, const char *event);
305 
320  int (*register_callback)(stonith_t *st,
321  int call_id,
322  int timeout,
323  int options,
324  void *userdata,
325  const char *callback_name,
326  void (*callback)(stonith_t *st, stonith_callback_data_t *data));
327 
331  int (*remove_callback)(stonith_t *st, int call_id, bool all_callbacks);
332 
349  int (*remove_level_full)(stonith_t *st, int options,
350  const char *node, const char *pattern,
351  const char *attr, const char *value, int level);
352 
370  int (*register_level_full)(stonith_t *st, int options,
371  const char *node, const char *pattern,
372  const char *attr, const char *value,
373  int level, stonith_key_value_t *device_list);
374 
393  int (*validate)(stonith_t *st, int call_options, const char *rsc_id,
394  const char *namespace_s, const char *agent,
395  stonith_key_value_t *params, int timeout, char **output,
396  char **error_output);
397 
399 
400 struct stonith_s
401 {
402  enum stonith_state state;
403 
404  int call_id;
406  void *st_private;
407 
409 };
410 /* *INDENT-ON* */
411 
412 /* Core functions */
414 void stonith_api_delete(stonith_t * st);
415 
417 
418 // deprecated (use stonith_get_namespace() instead)
419 const char *get_stonith_provider(const char *agent, const char *provider);
420 
421 bool stonith_dispatch(stonith_t * st);
422 
424  const char *value);
425 void stonith_key_value_freeall(stonith_key_value_t * kvp, int keys, int values);
426 
428 
429 /* Basic helpers that allows nodes to be fenced and the history to be
430  * queried without mainloop or the caller understanding the full API
431  *
432  * At least one of nodeid and uname are required
433  */
434 int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off);
435 time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress);
436 
437 /*
438  * Helpers for using the above functions without install-time dependencies
439  *
440  * Usage:
441  * #include <crm/stonith-ng.h>
442  *
443  * To turn a node off by corosync nodeid:
444  * stonith_api_kick_helper(nodeid, 120, 1);
445  *
446  * To check the last fence date/time (also by nodeid):
447  * last = stonith_api_time_helper(nodeid, 0);
448  *
449  * To check if fencing is in progress:
450  * if(stonith_api_time_helper(nodeid, 1) > 0) { ... }
451  *
452  * eg.
453 
454  #include <stdio.h>
455  #include <time.h>
456  #include <crm/stonith-ng.h>
457  int
458  main(int argc, char ** argv)
459  {
460  int rc = 0;
461  int nodeid = 102;
462 
463  rc = stonith_api_time_helper(nodeid, 0);
464  printf("%d last fenced at %s\n", nodeid, ctime(rc));
465 
466  rc = stonith_api_kick_helper(nodeid, 120, 1);
467  printf("%d fence result: %d\n", nodeid, rc);
468 
469  rc = stonith_api_time_helper(nodeid, 0);
470  printf("%d last fenced at %s\n", nodeid, ctime(rc));
471 
472  return 0;
473  }
474 
475  */
476 
477 # define STONITH_LIBRARY "libstonithd.so.26"
478 
479 typedef int (*st_api_kick_fn) (int nodeid, const char *uname, int timeout, bool off);
480 typedef time_t (*st_api_time_fn) (int nodeid, const char *uname, bool in_progress);
481 
482 static inline int
483 stonith_api_kick_helper(uint32_t nodeid, int timeout, bool off)
484 {
485  static void *st_library = NULL;
486  static st_api_kick_fn st_kick_fn;
487 
488  if (st_library == NULL) {
489  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
490  }
491  if (st_library && st_kick_fn == NULL) {
492  st_kick_fn = (st_api_kick_fn) dlsym(st_library, "stonith_api_kick");
493  }
494  if (st_kick_fn == NULL) {
495 #ifdef ELIBACC
496  return -ELIBACC;
497 #else
498  return -ENOSYS;
499 #endif
500  }
501 
502  return (*st_kick_fn) (nodeid, NULL, timeout, off);
503 }
504 
505 static inline time_t
506 stonith_api_time_helper(uint32_t nodeid, bool in_progress)
507 {
508  static void *st_library = NULL;
509  static st_api_time_fn st_time_fn;
510 
511  if (st_library == NULL) {
512  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
513  }
514  if (st_library && st_time_fn == NULL) {
515  st_time_fn = (st_api_time_fn) dlsym(st_library, "stonith_api_time");
516  }
517  if (st_time_fn == NULL) {
518  return 0;
519  }
520 
521  return (*st_time_fn) (nodeid, NULL, in_progress);
522 }
523 
524 #ifdef __cplusplus
525 }
526 #endif
527 
528 #endif
char uname[MAX_NAME]
Definition: internal.h:82
struct stonith_history_s * next
Definition: stonith-ng.h:104
const char * get_stonith_provider(const char *agent, const char *provider)
Deprecated (use stonith_get_namespace() instead)
Definition: st_client.c:1359
struct stonith_api_operations_s stonith_api_operations_t
struct stonith_key_value_s stonith_key_value_t
int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off)
Definition: st_client.c:2352
const char * stonith_namespace2text(enum stonith_namespace namespace)
Get agent namespace name.
Definition: st_client.c:155
struct stonith_history_s stonith_history_t
enum stonith_namespace stonith_get_namespace(const char *agent, const char *namespace_s)
Determine namespace of a fence agent.
Definition: st_client.c:176
struct stonith_key_value_s * next
Definition: stonith-ng.h:93
stonith_namespace
Definition: stonith-ng.h:73
bool stonith_dispatch(stonith_t *st)
Definition: st_client.c:2108
stonith_t * stonith_api_new(void)
Definition: st_client.c:2250
uint32_t id
Definition: internal.h:77
stonith_key_value_t * stonith_key_value_add(stonith_key_value_t *kvp, const char *key, const char *value)
Definition: st_client.c:2304
struct stonith_callback_data_s stonith_callback_data_t
time_t(* st_api_time_fn)(int nodeid, const char *uname, bool in_progress)
Definition: stonith-ng.h:480
op_state
Definition: stonith-ng.h:63
void stonith_key_value_freeall(stonith_key_value_t *kvp, int keys, int values)
Definition: st_client.c:2331
void stonith_dump_pending_callbacks(stonith_t *st)
Definition: st_client.c:1881
int call_timeout
Definition: stonith-ng.h:405
stonith_state
Definition: stonith-ng.h:33
#define ELIBACC
Definition: portability.h:140
stonith_call_options
Definition: stonith-ng.h:39
char * client_origin
Definition: stonith-ng.h:125
void stonith_api_delete(stonith_t *st)
Definition: st_client.c:2166
stonith_api_operations_t * cmds
Definition: stonith-ng.h:408
void stonith_history_free(stonith_history_t *history)
Definition: st_client.c:1342
char * executioner
Definition: stonith-ng.h:120
char * operation
Definition: stonith-ng.h:114
#define uint32_t
Definition: stdint.in.h:158
struct stonith_event_s stonith_event_t
int(* st_api_kick_fn)(int nodeid, const char *uname, int timeout, bool off)
Definition: stonith-ng.h:479
char data[0]
Definition: internal.h:87
time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress)
Definition: st_client.c:2401
#define STONITH_LIBRARY
Definition: stonith-ng.h:477
void * st_private
Definition: stonith-ng.h:406
enum stonith_namespace stonith_text2namespace(const char *namespace_s)
Get agent namespace by name.
Definition: st_client.c:129
int call_id
Definition: stonith-ng.h:404