pacemaker  2.1.0-7c3f660
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
stonith-ng.h
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2021 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU Lesser General Public License
7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8  */
9 
10 #ifndef STONITH_NG__H
11 # define STONITH_NG__H
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
23 # include <dlfcn.h>
24 # include <errno.h>
25 # include <stdbool.h> // bool
26 # include <stdint.h> // uint32_t
27 # include <time.h> // time_t
28 
29 # define T_STONITH_NOTIFY_DISCONNECT "st_notify_disconnect"
30 # define T_STONITH_NOTIFY_FENCE "st_notify_fence"
31 # define T_STONITH_NOTIFY_HISTORY "st_notify_history"
32 # define T_STONITH_NOTIFY_HISTORY_SYNCED "st_notify_history_synced"
33 
34 /* *INDENT-OFF* */
39 };
40 
42  st_opt_none = 0x00000000,
43  st_opt_verbose = 0x00000001,
44  st_opt_allow_suicide = 0x00000002,
45 
46  st_opt_manual_ack = 0x00000008,
47  st_opt_discard_reply = 0x00000010,
48 /* st_opt_all_replies = 0x00000020, */
49  st_opt_topology = 0x00000040,
50  st_opt_scope_local = 0x00000100,
51  st_opt_cs_nodeid = 0x00000200,
52  st_opt_sync_call = 0x00001000,
55  st_opt_timeout_updates = 0x00002000,
58  /* used where ever apropriate - e.g. cleanup of history */
59  st_opt_cleanup = 0x000080000,
60  /* used where ever apropriate - e.g. send out a history query to all nodes */
61  st_opt_broadcast = 0x000100000,
62 };
63 
66 {
72 };
73 
74 // Supported fence agent interface standards
78  st_namespace_internal, // Implemented internally by Pacemaker
79 
80  /* Neither of these projects are active any longer, but the fence agent
81  * interfaces they created are still in use and supported by Pacemaker.
82  */
83  st_namespace_rhcs, // Red Hat Cluster Suite compatible
84  st_namespace_lha, // Linux-HA compatible
85 };
86 
87 enum stonith_namespace stonith_text2namespace(const char *namespace_s);
88 const char *stonith_namespace2text(enum stonith_namespace st_namespace);
89 enum stonith_namespace stonith_get_namespace(const char *agent,
90  const char *namespace_s);
91 
92 typedef struct stonith_key_value_s {
93  char *key;
94  char *value;
97 
98 typedef struct stonith_history_s {
99  char *target;
100  char *action;
101  char *origin;
102  char *delegate;
103  char *client;
104  int state;
105  time_t completed;
108 
109 typedef struct stonith_s stonith_t;
110 
111 typedef struct stonith_event_s
112 {
113  char *id;
114  char *type;
115  char *message;
116  char *operation;
117 
118  int result;
119  char *origin;
120  char *target;
121  char *action;
122  char *executioner;
123 
124  char *device;
125 
128 
130 
132 {
133  int rc;
134  int call_id;
135  void *userdata;
137 
139 {
143  int (*free) (stonith_t *st);
144 
151  int (*connect) (stonith_t *st, const char *name, int *stonith_fd);
152 
160 
170  stonith_t *st, int options, const char *name);
171 
181  stonith_t *st, int options, const char *id,
182  const char *provider, const char *agent, stonith_key_value_t *params);
183 
190  int (*remove_level)(
191  stonith_t *st, int options, const char *node, int level);
192 
201  stonith_t *st, int options, const char *node, int level, stonith_key_value_t *device_list);
202 
211  int (*metadata)(stonith_t *st, int options,
212  const char *device, const char *provider, char **output, int timeout);
213 
224  int (*list_agents)(stonith_t *stonith, int call_options, const char *provider,
225  stonith_key_value_t **devices, int timeout);
226 
233  int (*list)(stonith_t *st, int options, const char *id, char **list_output, int timeout);
234 
241  int (*monitor)(stonith_t *st, int options, const char *id, int timeout);
242 
249  int (*status)(stonith_t *st, int options, const char *id, const char *port, int timeout);
250 
260  int (*query)(stonith_t *st, int options, const char *node,
261  stonith_key_value_t **devices, int timeout);
262 
278  int (*fence)(stonith_t *st, int options, const char *node, const char *action,
279  int timeout, int tolerance);
280 
287  int (*confirm)(stonith_t *st, int options, const char *node);
288 
295  int (*history)(stonith_t *st, int options, const char *node, stonith_history_t **output, int timeout);
296 
298  stonith_t *st, const char *event,
299  void (*notify)(stonith_t *st, stonith_event_t *e));
300  int (*remove_notification)(stonith_t *st, const char *event);
301 
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 
347  int (*remove_level_full)(stonith_t *st, int options,
348  const char *node, const char *pattern,
349  const char *attr, const char *value, int level);
350 
367  int (*register_level_full)(stonith_t *st, int options,
368  const char *node, const char *pattern,
369  const char *attr, const char *value,
370  int level, stonith_key_value_t *device_list);
371 
390  int (*validate)(stonith_t *st, int call_options, const char *rsc_id,
391  const char *namespace_s, const char *agent,
392  stonith_key_value_t *params, int timeout, char **output,
393  char **error_output);
394 
412  int (*fence_with_delay)(stonith_t *st, int options, const char *node, const char *action,
413  int timeout, int tolerance, int delay);
414 
416 
417 struct stonith_s
418 {
420 
421  int call_id;
423  void *st_private;
424 
426 };
427 /* *INDENT-ON* */
428 
429 /* Core functions */
432 
434 
436 
438  const char *value);
439 void stonith_key_value_freeall(stonith_key_value_t * kvp, int keys, int values);
440 
442 
443 // Convenience functions
444 int stonith_api_connect_retry(stonith_t *st, const char *name,
445  int max_attempts);
446 const char *stonith_op_state_str(enum op_state state);
447 
448 /* Basic helpers that allows nodes to be fenced and the history to be
449  * queried without mainloop or the caller understanding the full API
450  *
451  * At least one of nodeid and uname are required
452  */
453 int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off);
454 time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress);
455 
456 /*
457  * Helpers for using the above functions without install-time dependencies
458  *
459  * Usage:
460  * #include <crm/stonith-ng.h>
461  *
462  * To turn a node off by corosync nodeid:
463  * stonith_api_kick_helper(nodeid, 120, 1);
464  *
465  * To check the last fence date/time (also by nodeid):
466  * last = stonith_api_time_helper(nodeid, 0);
467  *
468  * To check if fencing is in progress:
469  * if(stonith_api_time_helper(nodeid, 1) > 0) { ... }
470  *
471  * eg.
472 
473  #include <stdio.h>
474  #include <time.h>
475  #include <crm/stonith-ng.h>
476  int
477  main(int argc, char ** argv)
478  {
479  int rc = 0;
480  int nodeid = 102;
481 
482  rc = stonith_api_time_helper(nodeid, 0);
483  printf("%d last fenced at %s\n", nodeid, ctime(rc));
484 
485  rc = stonith_api_kick_helper(nodeid, 120, 1);
486  printf("%d fence result: %d\n", nodeid, rc);
487 
488  rc = stonith_api_time_helper(nodeid, 0);
489  printf("%d last fenced at %s\n", nodeid, ctime(rc));
490 
491  return 0;
492  }
493 
494  */
495 
496 # define STONITH_LIBRARY "libstonithd.so.26"
497 
498 typedef int (*st_api_kick_fn) (int nodeid, const char *uname, int timeout, bool off);
499 typedef time_t (*st_api_time_fn) (int nodeid, const char *uname, bool in_progress);
500 
501 static inline int
502 stonith_api_kick_helper(uint32_t nodeid, int timeout, bool off)
503 {
504  static void *st_library = NULL;
505  static st_api_kick_fn st_kick_fn;
506 
507  if (st_library == NULL) {
508  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
509  }
510  if (st_library && st_kick_fn == NULL) {
511  st_kick_fn = (st_api_kick_fn) dlsym(st_library, "stonith_api_kick");
512  }
513  if (st_kick_fn == NULL) {
514 #ifdef ELIBACC
515  return -ELIBACC;
516 #else
517  return -ENOSYS;
518 #endif
519  }
520 
521  return (*st_kick_fn) (nodeid, NULL, timeout, off);
522 }
523 
524 static inline time_t
525 stonith_api_time_helper(uint32_t nodeid, bool in_progress)
526 {
527  static void *st_library = NULL;
528  static st_api_time_fn st_time_fn;
529 
530  if (st_library == NULL) {
531  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
532  }
533  if (st_library && st_time_fn == NULL) {
534  st_time_fn = (st_api_time_fn) dlsym(st_library, "stonith_api_time");
535  }
536  if (st_time_fn == NULL) {
537  return 0;
538  }
539 
540  return (*st_time_fn) (nodeid, NULL, in_progress);
541 }
542 
552 bool stonith_agent_exists(const char *agent, int timeout);
553 
559 const char *stonith_action_str(const char *action);
560 
561 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
562 #include <crm/fencing/compat.h>
563 #endif
564 
565 #ifdef __cplusplus
566 }
567 #endif
568 
569 #endif
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:260
struct stonith_history_s * next
Definition: stonith-ng.h:106
char data[0]
Definition: cpg.c:55
int(* register_notification)(stonith_t *st, const char *event, void(*notify)(stonith_t *st, stonith_event_t *e))
Definition: stonith-ng.h:297
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:367
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:2244
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:295
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:200
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:178
struct stonith_key_value_s * next
Definition: stonith-ng.h:95
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:241
int(* free)(stonith_t *st)
Destroy the stonith api structure.
Definition: stonith-ng.h:143
stonith_namespace
Definition: stonith-ng.h:75
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:233
int(* confirm)(stonith_t *st, int options, const char *node)
Manually confirm that a node is down.
Definition: stonith-ng.h:287
bool stonith_dispatch(stonith_t *st)
Definition: st_client.c:1953
stonith_t * stonith_api_new(void)
Definition: st_client.c:2097
const char * action
Definition: pcmk_fence.c:30
int stonith_api_connect_retry(stonith_t *st, const char *name, int max_attempts)
Make a blocking connection attempt to the fencer.
Definition: st_client.c:2175
stonith_key_value_t * stonith_key_value_add(stonith_key_value_t *kvp, const char *key, const char *value)
Definition: st_client.c:2196
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:330
struct stonith_callback_data_s stonith_callback_data_t
stonith_t * st
Definition: pcmk_fence.c:28
bool stonith_agent_exists(const char *agent, int timeout)
Definition: st_client.c:2350
const char * stonith_op_state_str(enum op_state state)
Return string equivalent of an operation state value.
Definition: st_client.c:2612
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:319
enum stonith_state state
Definition: stonith-ng.h:419
unsigned int tolerance
Definition: pcmk_fence.c:33
const char * stonith_action_str(const char *action)
Turn stonith action into a more readable string.
Definition: st_client.c:2381
op_state
Definition: stonith-ng.h:65
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:211
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:249
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:190
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:224
void stonith_key_value_freeall(stonith_key_value_t *kvp, int keys, int values)
Definition: st_client.c:2223
void stonith_dump_pending_callbacks(stonith_t *st)
Definition: st_client.c:1702
uint32_t id
Definition: cpg.c:45
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:347
int call_timeout
Definition: stonith-ng.h:422
int(* st_api_kick_fn)(int nodeid, const char *uname, int timeout, bool off)
Definition: stonith-ng.h:498
stonith_state
Definition: stonith-ng.h:35
#define ELIBACC
Definition: portability.h:122
int(* fence_with_delay)(stonith_t *st, int options, const char *node, const char *action, int timeout, int tolerance, int delay)
Issue a fencing action against a node with requested fencing delay.
Definition: stonith-ng.h:412
stonith_call_options
Definition: stonith-ng.h:41
char * client_origin
Definition: stonith-ng.h:127
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:180
void stonith_api_delete(stonith_t *st)
Definition: st_client.c:2011
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:278
stonith_api_operations_t * cmds
Definition: stonith-ng.h:425
int delay
Definition: pcmk_fence.c:34
void stonith_history_free(stonith_history_t *history)
Definition: st_client.c:1158
char * executioner
Definition: stonith-ng.h:122
int(* connect)(stonith_t *st, const char *name, int *stonith_fd)
Connect to the local stonith daemon.
Definition: stonith-ng.h:151
char * operation
Definition: stonith-ng.h:116
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:169
struct stonith_event_s stonith_event_t
char uname[MAX_NAME]
Definition: cpg.c:50
int(* disconnect)(stonith_t *st)
Disconnect from the local stonith daemon.
Definition: stonith-ng.h:159
time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress)
Definition: st_client.c:2286
#define STONITH_LIBRARY
Definition: stonith-ng.h:496
void * st_private
Definition: stonith-ng.h:423
enum stonith_namespace stonith_text2namespace(const char *namespace_s)
Get agent namespace by name.
Definition: st_client.c:131
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:390
time_t(* st_api_time_fn)(int nodeid, const char *uname, bool in_progress)
Definition: stonith-ng.h:499
Deprecated Pacemaker fencing API.
char * name
Definition: pcmk_fence.c:31
const char * stonith_namespace2text(enum stonith_namespace st_namespace)
Get agent namespace name.
Definition: st_client.c:157
unsigned int timeout
Definition: pcmk_fence.c:32
int call_id
Definition: stonith-ng.h:421
int(* remove_notification)(stonith_t *st, const char *event)
Definition: stonith-ng.h:300