pacemaker  2.0.4-2deceaa
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-2020 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 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
20 #ifndef STONITH_NG__H
21 # define STONITH_NG__H
22 
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 
447 /* Basic helpers that allows nodes to be fenced and the history to be
448  * queried without mainloop or the caller understanding the full API
449  *
450  * At least one of nodeid and uname are required
451  */
452 int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off);
453 time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress);
454 
455 /*
456  * Helpers for using the above functions without install-time dependencies
457  *
458  * Usage:
459  * #include <crm/stonith-ng.h>
460  *
461  * To turn a node off by corosync nodeid:
462  * stonith_api_kick_helper(nodeid, 120, 1);
463  *
464  * To check the last fence date/time (also by nodeid):
465  * last = stonith_api_time_helper(nodeid, 0);
466  *
467  * To check if fencing is in progress:
468  * if(stonith_api_time_helper(nodeid, 1) > 0) { ... }
469  *
470  * eg.
471 
472  #include <stdio.h>
473  #include <time.h>
474  #include <crm/stonith-ng.h>
475  int
476  main(int argc, char ** argv)
477  {
478  int rc = 0;
479  int nodeid = 102;
480 
481  rc = stonith_api_time_helper(nodeid, 0);
482  printf("%d last fenced at %s\n", nodeid, ctime(rc));
483 
484  rc = stonith_api_kick_helper(nodeid, 120, 1);
485  printf("%d fence result: %d\n", nodeid, rc);
486 
487  rc = stonith_api_time_helper(nodeid, 0);
488  printf("%d last fenced at %s\n", nodeid, ctime(rc));
489 
490  return 0;
491  }
492 
493  */
494 
495 # define STONITH_LIBRARY "libstonithd.so.26"
496 
497 typedef int (*st_api_kick_fn) (int nodeid, const char *uname, int timeout, bool off);
498 typedef time_t (*st_api_time_fn) (int nodeid, const char *uname, bool in_progress);
499 
500 static inline int
501 stonith_api_kick_helper(uint32_t nodeid, int timeout, bool off)
502 {
503  static void *st_library = NULL;
504  static st_api_kick_fn st_kick_fn;
505 
506  if (st_library == NULL) {
507  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
508  }
509  if (st_library && st_kick_fn == NULL) {
510  st_kick_fn = (st_api_kick_fn) dlsym(st_library, "stonith_api_kick");
511  }
512  if (st_kick_fn == NULL) {
513 #ifdef ELIBACC
514  return -ELIBACC;
515 #else
516  return -ENOSYS;
517 #endif
518  }
519 
520  return (*st_kick_fn) (nodeid, NULL, timeout, off);
521 }
522 
523 static inline time_t
524 stonith_api_time_helper(uint32_t nodeid, bool in_progress)
525 {
526  static void *st_library = NULL;
527  static st_api_time_fn st_time_fn;
528 
529  if (st_library == NULL) {
530  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
531  }
532  if (st_library && st_time_fn == NULL) {
533  st_time_fn = (st_api_time_fn) dlsym(st_library, "stonith_api_time");
534  }
535  if (st_time_fn == NULL) {
536  return 0;
537  }
538 
539  return (*st_time_fn) (nodeid, NULL, in_progress);
540 }
541 
551 bool stonith_agent_exists(const char *agent, int timeout);
552 
558 const char *stonith_action_str(const char *action);
559 
560 #ifndef PCMK__NO_COMPAT
561 /* Everything here is deprecated and kept only for public API backward
562  * compatibility. It will be moved to compatibility.h when 2.1.0 is released.
563  */
564 
566 const char *get_stonith_provider(const char *agent, const char *provider);
567 
568 #endif
569 
570 #ifdef __cplusplus
571 }
572 #endif
573 
574 #endif
char uname[MAX_NAME]
Definition: internal.h:85
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
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:2259
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:176
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
const char * get_stonith_provider(const char *agent, const char *provider)
Deprecated (use stonith_get_namespace() instead)
Definition: st_client.c:2629
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:1964
stonith_t * stonith_api_new(void)
Definition: st_client.c:2111
const char * action
Definition: pcmk_fence.c:29
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:2190
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:2211
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:27
bool stonith_agent_exists(const char *agent, int timeout)
Definition: st_client.c:2368
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:32
const char * stonith_action_str(const char *action)
Turn stonith action into a more readable string.
Definition: st_client.c:2399
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:2238
void stonith_dump_pending_callbacks(stonith_t *st)
Definition: st_client.c:1714
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:497
stonith_state
Definition: stonith-ng.h:35
#define ELIBACC
Definition: portability.h:142
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:2022
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:33
void stonith_history_free(stonith_history_t *history)
Definition: st_client.c:1170
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 data[0]
Definition: internal.h:90
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:2302
#define STONITH_LIBRARY
Definition: stonith-ng.h:495
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:129
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:498
char * name
Definition: pcmk_fence.c:30
const char * stonith_namespace2text(enum stonith_namespace st_namespace)
Get agent namespace name.
Definition: st_client.c:155
unsigned int timeout
Definition: pcmk_fence.c:31
int call_id
Definition: stonith-ng.h:421
int(* remove_notification)(stonith_t *st, const char *event)
Definition: stonith-ng.h:300