pacemaker  3.0.0-d8340737c4
Scalable High-Availability cluster resource manager
stonith-ng.h
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2024 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 PCMK__CRM_STONITH_NG__H
11 # define PCMK__CRM_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 /* *INDENT-OFF* */
40 };
41 
46 
47 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
48  st_opt_verbose = (1 << 0),
50 #endif
51 
54 
55 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
58 #endif
59 
60  // Used internally to indicate that request is manual fence confirmation
62  st_opt_manual_ack = (1 << 3),
63 
66 
67  // Used internally to indicate that request requires a fencing topology
69  st_opt_topology = (1 << 6),
70 
71 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
73  st_opt_scope_local = (1 << 8),
74 #endif
75 
77  st_opt_cs_nodeid = (1 << 9),
78 
80  st_opt_sync_call = (1 << 12),
81 
84 
87 
89  st_opt_cleanup = (1 << 19),
90 
92  st_opt_broadcast = (1 << 20),
93 };
94 
97 {
103 };
104 
105 // Supported fence agent interface standards
109  st_namespace_internal, // Implemented internally by Pacemaker
110 
111  /* Neither of these projects are active any longer, but the fence agent
112  * interfaces they created are still in use and supported by Pacemaker.
113  */
114  st_namespace_rhcs, // Red Hat Cluster Suite compatible
115  st_namespace_lha, // Linux-HA compatible
116 };
117 
118 enum stonith_namespace stonith_text2namespace(const char *namespace_s);
119 const char *stonith_namespace2text(enum stonith_namespace st_namespace);
120 enum stonith_namespace stonith_get_namespace(const char *agent,
121  const char *namespace_s);
122 
123 typedef struct stonith_key_value_s {
124  char *key;
125  char *value;
128 
129 typedef struct stonith_history_s {
130  char *target;
131  char *action;
132  char *origin;
133  char *delegate;
134  char *client;
135  int state;
136  time_t completed;
139  char *exit_reason;
141 
142 typedef struct stonith_s stonith_t;
143 
144 typedef struct stonith_event_s {
145  char *id;
146  char *operation;
147  int result;
148  char *origin;
149  char *target;
150  char *action;
151  char *executioner;
152 
153  char *device;
154 
157 
159  void *opaque;
161 
162 typedef struct stonith_callback_data_s {
163  int rc;
164  int call_id;
165  void *userdata;
166 
168  void *opaque;
170 
172 {
178  int (*free) (stonith_t *st);
179 
190  int (*connect) (stonith_t *st, const char *name, int *stonith_fd);
191 
200 
211  int (*remove_device)(stonith_t *st, int options, const char *name);
212 
229  int (*register_device)(stonith_t *st, int options, const char *id,
230  const char *namespace_s, const char *agent,
231  const stonith_key_value_t *params);
232 
244  int (*remove_level)(stonith_t *st, int options, const char *node,
245  int level);
246 
259  int (*register_level)(stonith_t *st, int options, const char *node,
260  int level, const stonith_key_value_t *device_list);
261 
279  int (*metadata)(stonith_t *stonith, int call_options, const char *agent,
280  const char *namespace_s, char **output, int timeout_sec);
281 
300  int (*list_agents)(stonith_t *stonith, int call_options,
301  const char *namespace_s, stonith_key_value_t **devices,
302  int timeout);
303 
316  int (*list)(stonith_t *stonith, int call_options, const char *id,
317  char **list_info, int timeout);
318 
330  int (*monitor)(stonith_t *stonith, int call_options, const char *id,
331  int timeout);
332 
345  int (*status)(stonith_t *stonith, int call_options, const char *id,
346  const char *port, int timeout);
347 
362  int (*query)(stonith_t *stonith, int call_options, const char *target,
363  stonith_key_value_t **devices, int timeout);
364 
380  int (*fence)(stonith_t *stonith, int call_options, const char *node,
381  const char *action, int timeout, int tolerance);
382 
393  int (*confirm)(stonith_t *stonith, int call_options, const char *target);
394 
406  int (*history)(stonith_t *stonith, int call_options, const char *node,
408 
418  int (*register_notification)(stonith_t *stonith, const char *event,
419  void (*callback)(stonith_t *st,
420  stonith_event_t *e));
421 
430  int (*remove_notification)(stonith_t *stonith, const char *event);
431 
449  int (*register_callback)(stonith_t *stonith, int call_id, int timeout,
450  int options, void *user_data,
451  const char *callback_name,
452  void (*callback)(stonith_t *st,
454 
465  int (*remove_callback)(stonith_t *stonith, int call_id, bool all_callbacks);
466 
488  int (*remove_level_full)(stonith_t *st, int options,
489  const char *node, const char *pattern,
490  const char *attr, const char *value, int level);
491 
515  int (*register_level_full)(stonith_t *st, int options,
516  const char *node, const char *pattern,
517  const char *attr, const char *value, int level,
518  const stonith_key_value_t *device_list);
519 
540  int (*validate)(stonith_t *st, int call_options, const char *rsc_id,
541  const char *namespace_s, const char *agent,
542  const stonith_key_value_t *params, int timeout,
543  char **output, char **error_output);
544 
563  int (*fence_with_delay)(stonith_t *stonith, int call_options,
564  const char *node, const char *action, int timeout,
565  int tolerance, int delay);
566 
568 
569 struct stonith_s {
571  int call_id;
572  void *st_private;
574 };
575 /* *INDENT-ON* */
576 
577 /* Core functions */
580 
582 
584 
586  const char *value);
587 void stonith_key_value_freeall(stonith_key_value_t * kvp, int keys, int values);
588 
590 
591 // Convenience functions
592 int stonith_api_connect_retry(stonith_t *st, const char *name,
593  int max_attempts);
594 const char *stonith_op_state_str(enum op_state state);
595 
596 /* Basic helpers that allows nodes to be fenced and the history to be
597  * queried without mainloop or the caller understanding the full API
598  *
599  * At least one of nodeid and uname are required
600  *
601  * NOTE: DLM uses both of these
602  */
603 int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off);
604 time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress);
605 
606 /*
607  * Helpers for using the above functions without install-time dependencies
608  *
609  * Usage:
610  * #include <crm/stonith-ng.h>
611  *
612  * To turn a node off by corosync nodeid:
613  * stonith_api_kick_helper(nodeid, 120, 1);
614  *
615  * To check the last fence date/time (also by nodeid):
616  * last = stonith_api_time_helper(nodeid, 0);
617  *
618  * To check if fencing is in progress:
619  * if(stonith_api_time_helper(nodeid, 1) > 0) { ... }
620  *
621  * eg.
622 
623  #include <stdio.h>
624  #include <time.h>
625  #include <crm/stonith-ng.h>
626  int
627  main(int argc, char ** argv)
628  {
629  int rc = 0;
630  int nodeid = 102;
631 
632  rc = stonith_api_time_helper(nodeid, 0);
633  printf("%d last fenced at %s\n", nodeid, ctime(rc));
634 
635  rc = stonith_api_kick_helper(nodeid, 120, 1);
636  printf("%d fence result: %d\n", nodeid, rc);
637 
638  rc = stonith_api_time_helper(nodeid, 0);
639  printf("%d last fenced at %s\n", nodeid, ctime(rc));
640 
641  return 0;
642  }
643 
644  */
645 
646 # define STONITH_LIBRARY "libstonithd.so.26"
647 
648 typedef int (*st_api_kick_fn) (int nodeid, const char *uname, int timeout, bool off);
649 typedef time_t (*st_api_time_fn) (int nodeid, const char *uname, bool in_progress);
650 
651 static inline int
652 stonith_api_kick_helper(uint32_t nodeid, int timeout, bool off)
653 {
654  static void *st_library = NULL;
655  static st_api_kick_fn st_kick_fn;
656 
657  if (st_library == NULL) {
658  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
659  }
660  if (st_library && st_kick_fn == NULL) {
661  st_kick_fn = (st_api_kick_fn) dlsym(st_library, "stonith_api_kick");
662  }
663  if (st_kick_fn == NULL) {
664 #ifdef ELIBACC
665  return -ELIBACC;
666 #else
667  return -ENOSYS;
668 #endif
669  }
670 
671  return (*st_kick_fn) (nodeid, NULL, timeout, off);
672 }
673 
674 static inline time_t
675 stonith_api_time_helper(uint32_t nodeid, bool in_progress)
676 {
677  static void *st_library = NULL;
678  static st_api_time_fn st_time_fn;
679 
680  if (st_library == NULL) {
681  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
682  }
683  if (st_library && st_time_fn == NULL) {
684  st_time_fn = (st_api_time_fn) dlsym(st_library, "stonith_api_time");
685  }
686  if (st_time_fn == NULL) {
687  return 0;
688  }
689 
690  return (*st_time_fn) (nodeid, NULL, in_progress);
691 }
692 
702 bool stonith_agent_exists(const char *agent, int timeout);
703 
709 const char *stonith_action_str(const char *action);
710 
711 #ifdef __cplusplus
712 }
713 #endif
714 
715 #endif
int(* fence_with_delay)(stonith_t *stonith, int call_options, const char *node, const char *action, int timeout, int tolerance, int delay)
Request delayed fencing of a target.
Definition: stonith-ng.h:563
struct stonith_history_s * next
Definition: stonith-ng.h:137
Invoke callback only if request succeeded.
Definition: stonith-ng.h:86
char data[0]
Definition: cpg.c:58
struct stonith_api_operations_s stonith_api_operations_t
struct stonith_key_value_s stonith_key_value_t
const char * name
Definition: cib.c:26
Interpret target as node cluster layer ID instead of name.
Definition: stonith-ng.h:77
int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off)
Definition: st_client.c:2001
struct stonith_history_s stonith_history_t
int(* register_level_full)(stonith_t *st, int options, const char *node, const char *pattern, const char *attr, const char *value, int level, const stonith_key_value_t *device_list)
Register fencing level for specified node, pattern or attribute.
Definition: stonith-ng.h:515
enum stonith_namespace stonith_get_namespace(const char *agent, const char *namespace_s)
Determine namespace of a fence agent.
Definition: st_client.c:151
int(* register_callback)(stonith_t *stonith, int call_id, int timeout, int options, void *user_data, const char *callback_name, void(*callback)(stonith_t *st, stonith_callback_data_t *data))
Register a callback for an asynchronous fencing result.
Definition: stonith-ng.h:449
struct stonith_key_value_s * next
Definition: stonith-ng.h:126
int(* register_notification)(stonith_t *stonith, const char *event, void(*callback)(stonith_t *st, stonith_event_t *e))
Register a callback for fence notifications.
Definition: stonith-ng.h:418
stonith_namespace
Definition: stonith-ng.h:106
The fencing target is allowed to execute the request.
Definition: stonith-ng.h:53
Do not return any reply from server.
Definition: stonith-ng.h:65
bool stonith_dispatch(stonith_t *st)
Definition: st_client.c:1665
int(* confirm)(stonith_t *stonith, int call_options, const char *target)
Manually confirm that a node has been fenced.
Definition: stonith-ng.h:393
stonith_t * stonith_api_new(void)
Definition: st_client.c:1858
const char * action
Definition: pcmk_fence.c:32
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:1936
int(* list_agents)(stonith_t *stonith, int call_options, const char *namespace_s, stonith_key_value_t **devices, int timeout)
Retrieve a list of installed fence agents.
Definition: stonith-ng.h:300
stonith_key_value_t * stonith_key_value_add(stonith_key_value_t *kvp, const char *key, const char *value)
Definition: st_client.c:1957
int(* remove_callback)(stonith_t *stonith, int call_id, bool all_callbacks)
Unregister callbacks for asynchronous fencing results.
Definition: stonith-ng.h:465
int(* validate)(stonith_t *st, int call_options, const char *rsc_id, const char *namespace_s, const char *agent, const stonith_key_value_t *params, int timeout, char **output, char **error_output)
Validate an arbitrary stonith device configuration.
Definition: stonith-ng.h:540
int(* free)(stonith_t *st)
Destroy a fencer connection.
Definition: stonith-ng.h:178
struct stonith_callback_data_s stonith_callback_data_t
stonith_t * st
Definition: pcmk_fence.c:30
bool stonith_agent_exists(const char *agent, int timeout)
Definition: st_client.c:2107
For a fence history request, broadcast the request to all nodes.
Definition: stonith-ng.h:92
const char * stonith_op_state_str(enum op_state state)
Return string equivalent of an operation state value.
Definition: st_client.c:2384
int(* status)(stonith_t *stonith, int call_options, const char *id, const char *port, int timeout)
Check whether a fence device target is reachable by status action.
Definition: stonith-ng.h:345
enum stonith_state state
Definition: stonith-ng.h:570
For a fence history request, request that the history be cleared.
Definition: stonith-ng.h:89
unsigned int tolerance
Definition: pcmk_fence.c:35
const char * stonith_action_str(const char *action)
Turn fence action into a more readable string.
Definition: st_client.c:2138
time_t(* st_api_time_fn)(int nodeid, const char *uname, bool in_progress)
Definition: stonith-ng.h:649
op_state
Definition: stonith-ng.h:96
int(* register_level)(stonith_t *st, int options, const char *node, int level, const stonith_key_value_t *device_list)
Register a fencing level for specified node with local fencer.
Definition: stonith-ng.h:259
int(* disconnect)(stonith_t *st)
Disconnect from the local stonith daemon.
Definition: stonith-ng.h:199
void stonith_key_value_freeall(stonith_key_value_t *kvp, int keys, int values)
Definition: st_client.c:1980
void stonith_dump_pending_callbacks(stonith_t *st)
Definition: st_client.c:1368
int(* connect)(stonith_t *st, const char *name, int *stonith_fd)
Connect to the local fencer.
Definition: stonith-ng.h:190
int(* metadata)(stonith_t *stonith, int call_options, const char *agent, const char *namespace_s, char **output, int timeout_sec)
Retrieve a fence agent&#39;s metadata.
Definition: stonith-ng.h:279
#define PCMK_ALLOW_DEPRECATED
Allow use of deprecated Pacemaker APIs.
Definition: crm.h:46
uint32_t id
Definition: cpg.c:48
int(* remove_device)(stonith_t *st, int options, const char *name)
Unregister a fence device with the local fencer.
Definition: stonith-ng.h:211
Wait for request to be completed before returning.
Definition: stonith-ng.h:80
const char * target
Definition: pcmk_fence.c:31
stonith_state
Definition: stonith-ng.h:36
int(* history)(stonith_t *stonith, int call_options, const char *node, stonith_history_t **history, int timeout)
List fencing actions that have occurred for a target.
Definition: stonith-ng.h:406
#define ELIBACC
Definition: portability.h:46
stonith_call_options
Flags that can be set in call options for API requests.
Definition: stonith-ng.h:43
char * client_origin
Definition: stonith-ng.h:156
void stonith_api_delete(stonith_t *st)
Definition: st_client.c:1725
int(* remove_level_full)(stonith_t *st, int options, const char *node, const char *pattern, const char *attr, const char *value, int level)
Unregister fencing level for specified node, pattern or attribute.
Definition: stonith-ng.h:488
stonith_api_operations_t * cmds
Definition: stonith-ng.h:573
int(* remove_level)(stonith_t *st, int options, const char *node, int level)
Unregister a fencing level for specified node with local fencer.
Definition: stonith-ng.h:244
int delay
Definition: pcmk_fence.c:36
int(* register_device)(stonith_t *st, int options, const char *id, const char *namespace_s, const char *agent, const stonith_key_value_t *params)
Register a fence device with the local fencer.
Definition: stonith-ng.h:229
void stonith_history_free(stonith_history_t *history)
Definition: st_client.c:761
Request that server send an update with optimal callback timeout.
Definition: stonith-ng.h:83
char * executioner
Definition: stonith-ng.h:151
char * operation
Definition: stonith-ng.h:146
struct stonith_event_s stonith_event_t
char uname[MAX_NAME]
Definition: cpg.c:53
int(* st_api_kick_fn)(int nodeid, const char *uname, int timeout, bool off)
Definition: stonith-ng.h:648
int(* monitor)(stonith_t *stonith, int call_options, const char *id, int timeout)
Check whether a fence device is reachable by monitor action.
Definition: stonith-ng.h:330
int(* query)(stonith_t *stonith, int call_options, const char *target, stonith_key_value_t **devices, int timeout)
List registered fence devices.
Definition: stonith-ng.h:362
time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress)
Definition: st_client.c:2043
int(* list)(stonith_t *stonith, int call_options, const char *id, char **list_info, int timeout)
Get the output of a fence device&#39;s list action.
Definition: stonith-ng.h:316
#define STONITH_LIBRARY
Definition: stonith-ng.h:646
void * st_private
Definition: stonith-ng.h:572
int(* fence)(stonith_t *stonith, int call_options, const char *node, const char *action, int timeout, int tolerance)
Request that a target get fenced.
Definition: stonith-ng.h:380
enum stonith_namespace stonith_text2namespace(const char *namespace_s)
Get agent namespace by name.
Definition: st_client.c:104
int(* remove_notification)(stonith_t *stonith, const char *event)
Unregister callbacks for fence notifications.
Definition: stonith-ng.h:430
const char * stonith_namespace2text(enum stonith_namespace st_namespace)
Get agent namespace name.
Definition: st_client.c:130
No options.
Definition: stonith-ng.h:45
unsigned int timeout
Definition: pcmk_fence.c:34
int call_id
Definition: stonith-ng.h:571