pacemaker  2.1.2-ada5c3b36
Scalable High-Availability cluster resource manager
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 /* IMPORTANT: DLM source code includes this file directly, without having access
24  * to other Pacemaker headers on its include path, so this file should *not*
25  * include any other Pacemaker headers. (DLM might be updated to avoid the
26  * issue, but we should still follow this guideline for a long time after.)
27  */
28 
29 # include <dlfcn.h>
30 # include <errno.h>
31 # include <stdbool.h> // bool
32 # include <stdint.h> // uint32_t
33 # include <time.h> // time_t
34 
35 # define T_STONITH_NOTIFY_DISCONNECT "st_notify_disconnect"
36 # define T_STONITH_NOTIFY_FENCE "st_notify_fence"
37 # define T_STONITH_NOTIFY_HISTORY "st_notify_history"
38 # define T_STONITH_NOTIFY_HISTORY_SYNCED "st_notify_history_synced"
39 
40 /* *INDENT-OFF* */
45 };
46 
48  st_opt_none = 0x00000000,
49  st_opt_verbose = 0x00000001,
50  st_opt_allow_suicide = 0x00000002,
51 
52  st_opt_manual_ack = 0x00000008,
53  st_opt_discard_reply = 0x00000010,
54 /* st_opt_all_replies = 0x00000020, */
55  st_opt_topology = 0x00000040,
56  st_opt_scope_local = 0x00000100,
57  st_opt_cs_nodeid = 0x00000200,
58  st_opt_sync_call = 0x00001000,
61  st_opt_timeout_updates = 0x00002000,
64  /* used where ever apropriate - e.g. cleanup of history */
65  st_opt_cleanup = 0x000080000,
66  /* used where ever apropriate - e.g. send out a history query to all nodes */
67  st_opt_broadcast = 0x000100000,
68 };
69 
72 {
78 };
79 
80 // Supported fence agent interface standards
84  st_namespace_internal, // Implemented internally by Pacemaker
85 
86  /* Neither of these projects are active any longer, but the fence agent
87  * interfaces they created are still in use and supported by Pacemaker.
88  */
89  st_namespace_rhcs, // Red Hat Cluster Suite compatible
90  st_namespace_lha, // Linux-HA compatible
91 };
92 
93 enum stonith_namespace stonith_text2namespace(const char *namespace_s);
94 const char *stonith_namespace2text(enum stonith_namespace st_namespace);
95 enum stonith_namespace stonith_get_namespace(const char *agent,
96  const char *namespace_s);
97 
98 typedef struct stonith_key_value_s {
99  char *key;
100  char *value;
103 
104 typedef struct stonith_history_s {
105  char *target;
106  char *action;
107  char *origin;
108  char *delegate;
109  char *client;
110  int state;
111  time_t completed;
115 
116 typedef struct stonith_s stonith_t;
117 
118 typedef struct stonith_event_s
119 {
120  char *id;
121  char *type;
122  char *message;
123  char *operation;
124 
125  int result;
126  char *origin;
127  char *target;
128  char *action;
129  char *executioner;
130 
131  char *device;
132 
135 
137  void *opaque;
139 
140 typedef struct stonith_callback_data_s {
141  int rc;
142  int call_id;
143  void *userdata;
144 
146  void *opaque;
148 
150 {
154  int (*free) (stonith_t *st);
155 
161  int (*connect) (stonith_t *st, const char *name, int *stonith_fd);
162 
169 
178  stonith_t *st, int options, const char *name);
179 
188  stonith_t *st, int options, const char *id,
189  const char *provider, const char *agent, stonith_key_value_t *params);
190 
196  int (*remove_level)(
197  stonith_t *st, int options, const char *node, int level);
198 
206  stonith_t *st, int options, const char *node, int level, stonith_key_value_t *device_list);
207 
215  int (*metadata)(stonith_t *st, int options,
216  const char *device, const char *provider, char **output, int timeout);
217 
227  int (*list_agents)(stonith_t *stonith, int call_options, const char *provider,
228  stonith_key_value_t **devices, int timeout);
229 
235  int (*list)(stonith_t *st, int options, const char *id, char **list_output, int timeout);
236 
242  int (*monitor)(stonith_t *st, int options, const char *id, int timeout);
243 
249  int (*status)(stonith_t *st, int options, const char *id, const char *port, int timeout);
250 
259  int (*query)(stonith_t *st, int options, const char *node,
260  stonith_key_value_t **devices, int timeout);
261 
276  int (*fence)(stonith_t *st, int options, const char *node, const char *action,
277  int timeout, int tolerance);
278 
284  int (*confirm)(stonith_t *st, int options, const char *node);
285 
291  int (*history)(stonith_t *st, int options, const char *node, stonith_history_t **output, int timeout);
292 
294  stonith_t *st, const char *event,
295  void (*notify)(stonith_t *st, stonith_event_t *e));
296  int (*remove_notification)(stonith_t *st, const char *event);
297 
316  int call_id,
317  int timeout,
318  int options,
319  void *userdata,
320  const char *callback_name,
321  void (*callback)(stonith_t *st, stonith_callback_data_t *data));
322 
326  int (*remove_callback)(stonith_t *st, int call_id, bool all_callbacks);
327 
343  int (*remove_level_full)(stonith_t *st, int options,
344  const char *node, const char *pattern,
345  const char *attr, const char *value, int level);
346 
363  int (*register_level_full)(stonith_t *st, int options,
364  const char *node, const char *pattern,
365  const char *attr, const char *value,
366  int level, stonith_key_value_t *device_list);
367 
386  int (*validate)(stonith_t *st, int call_options, const char *rsc_id,
387  const char *namespace_s, const char *agent,
388  stonith_key_value_t *params, int timeout, char **output,
389  char **error_output);
390 
407  int (*fence_with_delay)(stonith_t *st, int options, const char *node, const char *action,
408  int timeout, int tolerance, int delay);
409 
411 
412 struct stonith_s
413 {
415 
416  int call_id;
418  void *st_private;
419 
421 };
422 /* *INDENT-ON* */
423 
424 /* Core functions */
427 
429 
431 
433  const char *value);
434 void stonith_key_value_freeall(stonith_key_value_t * kvp, int keys, int values);
435 
437 
438 // Convenience functions
439 int stonith_api_connect_retry(stonith_t *st, const char *name,
440  int max_attempts);
441 const char *stonith_op_state_str(enum op_state state);
442 
443 /* Basic helpers that allows nodes to be fenced and the history to be
444  * queried without mainloop or the caller understanding the full API
445  *
446  * At least one of nodeid and uname are required
447  */
448 int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off);
449 time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress);
450 
451 /*
452  * Helpers for using the above functions without install-time dependencies
453  *
454  * Usage:
455  * #include <crm/stonith-ng.h>
456  *
457  * To turn a node off by corosync nodeid:
458  * stonith_api_kick_helper(nodeid, 120, 1);
459  *
460  * To check the last fence date/time (also by nodeid):
461  * last = stonith_api_time_helper(nodeid, 0);
462  *
463  * To check if fencing is in progress:
464  * if(stonith_api_time_helper(nodeid, 1) > 0) { ... }
465  *
466  * eg.
467 
468  #include <stdio.h>
469  #include <time.h>
470  #include <crm/stonith-ng.h>
471  int
472  main(int argc, char ** argv)
473  {
474  int rc = 0;
475  int nodeid = 102;
476 
477  rc = stonith_api_time_helper(nodeid, 0);
478  printf("%d last fenced at %s\n", nodeid, ctime(rc));
479 
480  rc = stonith_api_kick_helper(nodeid, 120, 1);
481  printf("%d fence result: %d\n", nodeid, rc);
482 
483  rc = stonith_api_time_helper(nodeid, 0);
484  printf("%d last fenced at %s\n", nodeid, ctime(rc));
485 
486  return 0;
487  }
488 
489  */
490 
491 # define STONITH_LIBRARY "libstonithd.so.26"
492 
493 typedef int (*st_api_kick_fn) (int nodeid, const char *uname, int timeout, bool off);
494 typedef time_t (*st_api_time_fn) (int nodeid, const char *uname, bool in_progress);
495 
496 static inline int
497 stonith_api_kick_helper(uint32_t nodeid, int timeout, bool off)
498 {
499  static void *st_library = NULL;
500  static st_api_kick_fn st_kick_fn;
501 
502  if (st_library == NULL) {
503  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
504  }
505  if (st_library && st_kick_fn == NULL) {
506  st_kick_fn = (st_api_kick_fn) dlsym(st_library, "stonith_api_kick");
507  }
508  if (st_kick_fn == NULL) {
509 #ifdef ELIBACC
510  return -ELIBACC;
511 #else
512  return -ENOSYS;
513 #endif
514  }
515 
516  return (*st_kick_fn) (nodeid, NULL, timeout, off);
517 }
518 
519 static inline time_t
520 stonith_api_time_helper(uint32_t nodeid, bool in_progress)
521 {
522  static void *st_library = NULL;
523  static st_api_time_fn st_time_fn;
524 
525  if (st_library == NULL) {
526  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
527  }
528  if (st_library && st_time_fn == NULL) {
529  st_time_fn = (st_api_time_fn) dlsym(st_library, "stonith_api_time");
530  }
531  if (st_time_fn == NULL) {
532  return 0;
533  }
534 
535  return (*st_time_fn) (nodeid, NULL, in_progress);
536 }
537 
547 bool stonith_agent_exists(const char *agent, int timeout);
548 
554 const char *stonith_action_str(const char *action);
555 
556 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
557 /* Normally we'd put this section in a separate file (crm/fencing/compat.h), but
558  * we can't do that for the reason noted at the top of this file. That does mean
559  * we have to duplicate these declarations where they're implemented.
560  */
561 
563 const char *get_stonith_provider(const char *agent, const char *provider);
564 
565 #endif
566 
567 #ifdef __cplusplus
568 }
569 #endif
570 
571 #endif
struct stonith_history_s * next
Definition: stonith-ng.h:112
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:363
char data[0]
Definition: cpg.c:55
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:2309
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:259
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:179
struct stonith_key_value_s * next
Definition: stonith-ng.h:101
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:205
const char * get_stonith_provider(const char *agent, const char *provider)
Definition: st_client.c:2772
stonith_namespace
Definition: stonith-ng.h:81
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:326
bool stonith_dispatch(stonith_t *st)
Definition: st_client.c:2018
stonith_t * stonith_api_new(void)
Definition: st_client.c:2162
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:2240
stonith_key_value_t * stonith_key_value_add(stonith_key_value_t *kvp, const char *key, const char *value)
Definition: st_client.c:2261
int(* free)(stonith_t *st)
Destroy the stonith api structure.
Definition: stonith-ng.h:154
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:2415
const char * stonith_op_state_str(enum op_state state)
Return string equivalent of an operation state value.
Definition: st_client.c:2680
enum stonith_state state
Definition: stonith-ng.h:414
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:2446
time_t(* st_api_time_fn)(int nodeid, const char *uname, bool in_progress)
Definition: stonith-ng.h:494
op_state
Definition: stonith-ng.h:71
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:215
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:187
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(* 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:276
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:315
int(* disconnect)(stonith_t *st)
Disconnect from the local stonith daemon.
Definition: stonith-ng.h:168
void stonith_key_value_freeall(stonith_key_value_t *kvp, int keys, int values)
Definition: st_client.c:2288
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:235
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_dump_pending_callbacks(stonith_t *st)
Definition: st_client.c:1767
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:407
int(* connect)(stonith_t *st, const char *name, int *stonith_fd)
Connect to the local stonith daemon.
Definition: stonith-ng.h:161
uint32_t id
Definition: cpg.c:45
int call_timeout
Definition: stonith-ng.h:417
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:177
stonith_state
Definition: stonith-ng.h:41
int(* register_notification)(stonith_t *st, const char *event, void(*notify)(stonith_t *st, stonith_event_t *e))
Definition: stonith-ng.h:293
#define ELIBACC
Definition: portability.h:127
stonith_call_options
Definition: stonith-ng.h:47
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:242
char * client_origin
Definition: stonith-ng.h:134
int(* remove_notification)(stonith_t *st, const char *event)
Definition: stonith-ng.h:296
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:386
void stonith_api_delete(stonith_t *st)
Definition: st_client.c:2076
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:343
stonith_api_operations_t * cmds
Definition: stonith-ng.h:420
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:196
int delay
Definition: pcmk_fence.c:34
void stonith_history_free(stonith_history_t *history)
Definition: st_client.c:1223
char * executioner
Definition: stonith-ng.h:129
char * operation
Definition: stonith-ng.h:123
struct stonith_event_s stonith_event_t
char uname[MAX_NAME]
Definition: cpg.c:50
int(* st_api_kick_fn)(int nodeid, const char *uname, int timeout, bool off)
Definition: stonith-ng.h:493
time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress)
Definition: st_client.c:2351
int(* confirm)(stonith_t *st, int options, const char *node)
Manually confirm that a node is down.
Definition: stonith-ng.h:284
#define STONITH_LIBRARY
Definition: stonith-ng.h:491
void * st_private
Definition: stonith-ng.h:418
enum stonith_namespace stonith_text2namespace(const char *namespace_s)
Get agent namespace by name.
Definition: st_client.c:132
char * name
Definition: pcmk_fence.c:31
const char * stonith_namespace2text(enum stonith_namespace st_namespace)
Get agent namespace name.
Definition: st_client.c:158
unsigned int timeout
Definition: pcmk_fence.c:32
int call_id
Definition: stonith-ng.h:416
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:291