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