pacemaker  2.0.2-debe490
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-2019 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 
33 /* *INDENT-OFF* */
38 };
39 
41  st_opt_none = 0x00000000,
42  st_opt_verbose = 0x00000001,
43  st_opt_allow_suicide = 0x00000002,
44 
45  st_opt_manual_ack = 0x00000008,
46  st_opt_discard_reply = 0x00000010,
47 /* st_opt_all_replies = 0x00000020, */
48  st_opt_topology = 0x00000040,
49  st_opt_scope_local = 0x00000100,
50  st_opt_cs_nodeid = 0x00000200,
51  st_opt_sync_call = 0x00001000,
54  st_opt_timeout_updates = 0x00002000,
57  /* used where ever apropriate - e.g. cleanup of history */
58  st_opt_cleanup = 0x000080000,
59  /* used where ever apropriate - e.g. send out a history query to all nodes */
60  st_opt_broadcast = 0x000100000,
61 };
62 
65 {
71 };
72 
73 // Supported fence agent interface standards
77  st_namespace_internal, // Implemented internally by Pacemaker
78 
79  /* Neither of these projects are active any longer, but the fence agent
80  * interfaces they created are still in use and supported by Pacemaker.
81  */
82  st_namespace_rhcs, // Red Hat Cluster Suite compatible
83  st_namespace_lha, // Linux-HA compatible
84 };
85 
86 enum stonith_namespace stonith_text2namespace(const char *namespace_s);
87 const char *stonith_namespace2text(enum stonith_namespace st_namespace);
88 enum stonith_namespace stonith_get_namespace(const char *agent,
89  const char *namespace_s);
90 
91 typedef struct stonith_key_value_s {
92  char *key;
93  char *value;
96 
97 typedef struct stonith_history_s {
98  char *target;
99  char *action;
100  char *origin;
101  char *delegate;
102  char *client;
103  int state;
104  time_t completed;
107 
108 typedef struct stonith_s stonith_t;
109 
110 typedef struct stonith_event_s
111 {
112  char *id;
113  char *type;
114  char *message;
115  char *operation;
116 
117  int result;
118  char *origin;
119  char *target;
120  char *action;
121  char *executioner;
122 
123  char *device;
124 
127 
129 
131 {
132  int rc;
133  int call_id;
134  void *userdata;
136 
138 {
142  int (*free) (stonith_t *st);
143 
150  int (*connect) (stonith_t *st, const char *name, int *stonith_fd);
151 
158  int (*disconnect)(stonith_t *st);
159 
169  stonith_t *st, int options, const char *name);
170 
180  stonith_t *st, int options, const char *id,
181  const char *provider, const char *agent, stonith_key_value_t *params);
182 
191  int (*remove_level)(
192  stonith_t *st, int options, const char *node, int level);
193 
204  stonith_t *st, int options, const char *node, int level, stonith_key_value_t *device_list);
205 
214  int (*metadata)(stonith_t *st, int options,
215  const char *device, const char *provider, char **output, int timeout);
216 
227  int (*list_agents)(stonith_t *stonith, int call_options, const char *provider,
228  stonith_key_value_t **devices, int timeout);
229 
236  int (*list)(stonith_t *st, int options, const char *id, char **list_output, int timeout);
237 
244  int (*monitor)(stonith_t *st, int options, const char *id, int timeout);
245 
252  int (*status)(stonith_t *st, int options, const char *id, const char *port, int timeout);
253 
263  int (*query)(stonith_t *st, int options, const char *node,
264  stonith_key_value_t **devices, int timeout);
265 
281  int (*fence)(stonith_t *st, int options, const char *node, const char *action,
282  int timeout, int tolerance);
283 
290  int (*confirm)(stonith_t *st, int options, const char *node);
291 
300  int (*history)(stonith_t *st, int options, const char *node, stonith_history_t **output, int timeout);
301 
303  stonith_t *st, const char *event,
304  void (*notify)(stonith_t *st, stonith_event_t *e));
305  int (*remove_notification)(stonith_t *st, const char *event);
306 
325  int call_id,
326  int timeout,
327  int options,
328  void *userdata,
329  const char *callback_name,
330  void (*callback)(stonith_t *st, stonith_callback_data_t *data));
331 
335  int (*remove_callback)(stonith_t *st, int call_id, bool all_callbacks);
336 
353  int (*remove_level_full)(stonith_t *st, int options,
354  const char *node, const char *pattern,
355  const char *attr, const char *value, int level);
356 
374  int (*register_level_full)(stonith_t *st, int options,
375  const char *node, const char *pattern,
376  const char *attr, const char *value,
377  int level, stonith_key_value_t *device_list);
378 
397  int (*validate)(stonith_t *st, int call_options, const char *rsc_id,
398  const char *namespace_s, const char *agent,
399  stonith_key_value_t *params, int timeout, char **output,
400  char **error_output);
401 
403 
404 struct stonith_s
405 {
407 
408  int call_id;
410  void *st_private;
411 
413 };
414 /* *INDENT-ON* */
415 
416 /* Core functions */
418 void stonith_api_delete(stonith_t * st);
419 
421 
422 // deprecated (use stonith_get_namespace() instead)
423 const char *get_stonith_provider(const char *agent, const char *provider);
424 
425 bool stonith_dispatch(stonith_t * st);
426 
428  const char *value);
429 void stonith_key_value_freeall(stonith_key_value_t * kvp, int keys, int values);
430 
432 
433 /* Basic helpers that allows nodes to be fenced and the history to be
434  * queried without mainloop or the caller understanding the full API
435  *
436  * At least one of nodeid and uname are required
437  */
438 int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off);
439 time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress);
440 
441 /*
442  * Helpers for using the above functions without install-time dependencies
443  *
444  * Usage:
445  * #include <crm/stonith-ng.h>
446  *
447  * To turn a node off by corosync nodeid:
448  * stonith_api_kick_helper(nodeid, 120, 1);
449  *
450  * To check the last fence date/time (also by nodeid):
451  * last = stonith_api_time_helper(nodeid, 0);
452  *
453  * To check if fencing is in progress:
454  * if(stonith_api_time_helper(nodeid, 1) > 0) { ... }
455  *
456  * eg.
457 
458  #include <stdio.h>
459  #include <time.h>
460  #include <crm/stonith-ng.h>
461  int
462  main(int argc, char ** argv)
463  {
464  int rc = 0;
465  int nodeid = 102;
466 
467  rc = stonith_api_time_helper(nodeid, 0);
468  printf("%d last fenced at %s\n", nodeid, ctime(rc));
469 
470  rc = stonith_api_kick_helper(nodeid, 120, 1);
471  printf("%d fence result: %d\n", nodeid, rc);
472 
473  rc = stonith_api_time_helper(nodeid, 0);
474  printf("%d last fenced at %s\n", nodeid, ctime(rc));
475 
476  return 0;
477  }
478 
479  */
480 
481 # define STONITH_LIBRARY "libstonithd.so.26"
482 
483 typedef int (*st_api_kick_fn) (int nodeid, const char *uname, int timeout, bool off);
484 typedef time_t (*st_api_time_fn) (int nodeid, const char *uname, bool in_progress);
485 
486 static inline int
487 stonith_api_kick_helper(uint32_t nodeid, int timeout, bool off)
488 {
489  static void *st_library = NULL;
490  static st_api_kick_fn st_kick_fn;
491 
492  if (st_library == NULL) {
493  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
494  }
495  if (st_library && st_kick_fn == NULL) {
496  st_kick_fn = (st_api_kick_fn) dlsym(st_library, "stonith_api_kick");
497  }
498  if (st_kick_fn == NULL) {
499 #ifdef ELIBACC
500  return -ELIBACC;
501 #else
502  return -ENOSYS;
503 #endif
504  }
505 
506  return (*st_kick_fn) (nodeid, NULL, timeout, off);
507 }
508 
509 static inline time_t
510 stonith_api_time_helper(uint32_t nodeid, bool in_progress)
511 {
512  static void *st_library = NULL;
513  static st_api_time_fn st_time_fn;
514 
515  if (st_library == NULL) {
516  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
517  }
518  if (st_library && st_time_fn == NULL) {
519  st_time_fn = (st_api_time_fn) dlsym(st_library, "stonith_api_time");
520  }
521  if (st_time_fn == NULL) {
522  return 0;
523  }
524 
525  return (*st_time_fn) (nodeid, NULL, in_progress);
526 }
527 
537 bool stonith_agent_exists(const char *agent, int timeout);
538 
544 const char *stonith_action_str(const char *action);
545 
546 #ifdef __cplusplus
547 }
548 #endif
549 
550 #endif
char uname[MAX_NAME]
Definition: internal.h:87
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:263
struct stonith_history_s * next
Definition: stonith-ng.h:105
int(* register_notification)(stonith_t *st, const char *event, void(*notify)(stonith_t *st, stonith_event_t *e))
Definition: stonith-ng.h:302
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:374
const char * get_stonith_provider(const char *agent, const char *provider)
Deprecated (use stonith_get_namespace() instead)
Definition: st_client.c:1130
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:2123
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:300
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:203
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:173
struct stonith_key_value_s * next
Definition: stonith-ng.h:94
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:244
int(* free)(stonith_t *st)
Destroy the stonith api structure.
Definition: stonith-ng.h:142
stonith_namespace
Definition: stonith-ng.h:74
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:236
int(* confirm)(stonith_t *st, int options, const char *node)
Manually confirm that a node is down.
Definition: stonith-ng.h:290
bool stonith_dispatch(stonith_t *st)
Definition: st_client.c:1879
stonith_t * stonith_api_new(void)
Definition: st_client.c:2021
uint32_t id
Definition: internal.h:82
stonith_key_value_t * stonith_key_value_add(stonith_key_value_t *kvp, const char *key, const char *value)
Definition: st_client.c:2075
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:335
struct stonith_callback_data_s stonith_callback_data_t
bool stonith_agent_exists(const char *agent, int timeout)
Definition: st_client.c:2243
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:324
enum stonith_state state
Definition: stonith-ng.h:406
const char * stonith_action_str(const char *action)
Turn stonith action into a more readable string.
Definition: st_client.c:2270
op_state
Definition: stonith-ng.h:64
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:214
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:252
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:191
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:227
void stonith_key_value_freeall(stonith_key_value_t *kvp, int keys, int values)
Definition: st_client.c:2102
void stonith_dump_pending_callbacks(stonith_t *st)
Definition: st_client.c:1652
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:353
int call_timeout
Definition: stonith-ng.h:409
int(* st_api_kick_fn)(int nodeid, const char *uname, int timeout, bool off)
Definition: stonith-ng.h:483
stonith_state
Definition: stonith-ng.h:34
#define ELIBACC
Definition: portability.h:142
stonith_call_options
Definition: stonith-ng.h:40
char * client_origin
Definition: stonith-ng.h:126
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:179
void stonith_api_delete(stonith_t *st)
Definition: st_client.c:1937
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:281
stonith_api_operations_t * cmds
Definition: stonith-ng.h:412
void stonith_history_free(stonith_history_t *history)
Definition: st_client.c:1113
char * executioner
Definition: stonith-ng.h:121
int(* connect)(stonith_t *st, const char *name, int *stonith_fd)
Connect to the local stonith daemon.
Definition: stonith-ng.h:150
char * operation
Definition: stonith-ng.h:115
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:168
struct stonith_event_s stonith_event_t
char data[0]
Definition: internal.h:92
int(* disconnect)(stonith_t *st)
Disconnect from the local stonith daemon.
Definition: stonith-ng.h:158
time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress)
Definition: st_client.c:2172
#define STONITH_LIBRARY
Definition: stonith-ng.h:481
void * st_private
Definition: stonith-ng.h:410
enum stonith_namespace stonith_text2namespace(const char *namespace_s)
Get agent namespace by name.
Definition: st_client.c:126
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:397
time_t(* st_api_time_fn)(int nodeid, const char *uname, bool in_progress)
Definition: stonith-ng.h:484
const char * stonith_namespace2text(enum stonith_namespace st_namespace)
Get agent namespace name.
Definition: st_client.c:152
int call_id
Definition: stonith-ng.h:408
int(* remove_notification)(stonith_t *st, const char *event)
Definition: stonith-ng.h:305