pacemaker  2.1.8-3980678f03
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 
43  st_opt_none = 0x00000000,
44  st_opt_verbose = 0x00000001,
45  st_opt_allow_suicide = 0x00000002,
46 
47  st_opt_manual_ack = 0x00000008,
48  st_opt_discard_reply = 0x00000010,
49 /* st_opt_all_replies = 0x00000020, */
50  st_opt_topology = 0x00000040,
51  st_opt_scope_local = 0x00000100,
52  st_opt_cs_nodeid = 0x00000200,
53  st_opt_sync_call = 0x00001000,
56  st_opt_timeout_updates = 0x00002000,
59  /* used where ever apropriate - e.g. cleanup of history */
60  st_opt_cleanup = 0x000080000,
61  /* used where ever apropriate - e.g. send out a history query to all nodes */
62  st_opt_broadcast = 0x000100000,
63 };
64 
67 {
73 };
74 
75 // Supported fence agent interface standards
79  st_namespace_internal, // Implemented internally by Pacemaker
80 
81  /* Neither of these projects are active any longer, but the fence agent
82  * interfaces they created are still in use and supported by Pacemaker.
83  */
84  st_namespace_rhcs, // Red Hat Cluster Suite compatible
85  st_namespace_lha, // Linux-HA compatible
86 };
87 
88 enum stonith_namespace stonith_text2namespace(const char *namespace_s);
89 const char *stonith_namespace2text(enum stonith_namespace st_namespace);
90 enum stonith_namespace stonith_get_namespace(const char *agent,
91  const char *namespace_s);
92 
93 typedef struct stonith_key_value_s {
94  char *key;
95  char *value;
98 
99 typedef struct stonith_history_s {
100  char *target;
101  char *action;
102  char *origin;
103  char *delegate;
104  char *client;
105  int state;
106  time_t completed;
109  char *exit_reason;
111 
112 typedef struct stonith_s stonith_t;
113 
114 typedef struct stonith_event_s
115 {
116  char *id;
117  char *type;
118  char *message;
119  char *operation;
120 
121  int result;
122  char *origin;
123  char *target;
124  char *action;
125  char *executioner;
126 
127  char *device;
128 
131 
133  void *opaque;
135 
136 typedef struct stonith_callback_data_s {
137  int rc;
138  int call_id;
139  void *userdata;
140 
142  void *opaque;
144 
146 {
152  int (*free) (stonith_t *st);
153 
164  int (*connect) (stonith_t *st, const char *name, int *stonith_fd);
165 
174 
185  int (*remove_device)(stonith_t *st, int options, const char *name);
186 
203  int (*register_device)(stonith_t *st, int options, const char *id,
204  const char *namespace_s, const char *agent,
205  const stonith_key_value_t *params);
206 
218  int (*remove_level)(stonith_t *st, int options, const char *node,
219  int level);
220 
233  int (*register_level)(stonith_t *st, int options, const char *node,
234  int level, const stonith_key_value_t *device_list);
235 
253  int (*metadata)(stonith_t *stonith, int call_options, const char *agent,
254  const char *namespace_s, char **output, int timeout_sec);
255 
274  int (*list_agents)(stonith_t *stonith, int call_options,
275  const char *namespace_s, stonith_key_value_t **devices,
276  int timeout);
277 
290  int (*list)(stonith_t *stonith, int call_options, const char *id,
291  char **list_info, int timeout);
292 
304  int (*monitor)(stonith_t *stonith, int call_options, const char *id,
305  int timeout);
306 
319  int (*status)(stonith_t *stonith, int call_options, const char *id,
320  const char *port, int timeout);
321 
336  int (*query)(stonith_t *stonith, int call_options, const char *target,
337  stonith_key_value_t **devices, int timeout);
338 
354  int (*fence)(stonith_t *stonith, int call_options, const char *node,
355  const char *action, int timeout, int tolerance);
356 
367  int (*confirm)(stonith_t *stonith, int call_options, const char *target);
368 
380  int (*history)(stonith_t *stonith, int call_options, const char *node,
382 
392  int (*register_notification)(stonith_t *stonith, const char *event,
393  void (*callback)(stonith_t *st,
394  stonith_event_t *e));
395 
404  int (*remove_notification)(stonith_t *stonith, const char *event);
405 
423  int (*register_callback)(stonith_t *stonith, int call_id, int timeout,
424  int options, void *user_data,
425  const char *callback_name,
426  void (*callback)(stonith_t *st,
428 
439  int (*remove_callback)(stonith_t *stonith, int call_id, bool all_callbacks);
440 
462  int (*remove_level_full)(stonith_t *st, int options,
463  const char *node, const char *pattern,
464  const char *attr, const char *value, int level);
465 
489  int (*register_level_full)(stonith_t *st, int options,
490  const char *node, const char *pattern,
491  const char *attr, const char *value, int level,
492  const stonith_key_value_t *device_list);
493 
514  int (*validate)(stonith_t *st, int call_options, const char *rsc_id,
515  const char *namespace_s, const char *agent,
516  const stonith_key_value_t *params, int timeout,
517  char **output, char **error_output);
518 
537  int (*fence_with_delay)(stonith_t *stonith, int call_options,
538  const char *node, const char *action, int timeout,
539  int tolerance, int delay);
540 
542 
543 struct stonith_s
544 {
546 
547  int call_id;
549  void *st_private;
550 
552 };
553 /* *INDENT-ON* */
554 
555 /* Core functions */
558 
560 
562 
564  const char *value);
565 void stonith_key_value_freeall(stonith_key_value_t * kvp, int keys, int values);
566 
568 
569 // Convenience functions
570 int stonith_api_connect_retry(stonith_t *st, const char *name,
571  int max_attempts);
572 const char *stonith_op_state_str(enum op_state state);
573 
574 /* Basic helpers that allows nodes to be fenced and the history to be
575  * queried without mainloop or the caller understanding the full API
576  *
577  * At least one of nodeid and uname are required
578  *
579  * NOTE: DLM uses both of these
580  */
581 int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off);
582 time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress);
583 
584 /*
585  * Helpers for using the above functions without install-time dependencies
586  *
587  * Usage:
588  * #include <crm/stonith-ng.h>
589  *
590  * To turn a node off by corosync nodeid:
591  * stonith_api_kick_helper(nodeid, 120, 1);
592  *
593  * To check the last fence date/time (also by nodeid):
594  * last = stonith_api_time_helper(nodeid, 0);
595  *
596  * To check if fencing is in progress:
597  * if(stonith_api_time_helper(nodeid, 1) > 0) { ... }
598  *
599  * eg.
600 
601  #include <stdio.h>
602  #include <time.h>
603  #include <crm/stonith-ng.h>
604  int
605  main(int argc, char ** argv)
606  {
607  int rc = 0;
608  int nodeid = 102;
609 
610  rc = stonith_api_time_helper(nodeid, 0);
611  printf("%d last fenced at %s\n", nodeid, ctime(rc));
612 
613  rc = stonith_api_kick_helper(nodeid, 120, 1);
614  printf("%d fence result: %d\n", nodeid, rc);
615 
616  rc = stonith_api_time_helper(nodeid, 0);
617  printf("%d last fenced at %s\n", nodeid, ctime(rc));
618 
619  return 0;
620  }
621 
622  */
623 
624 # define STONITH_LIBRARY "libstonithd.so.26"
625 
626 typedef int (*st_api_kick_fn) (int nodeid, const char *uname, int timeout, bool off);
627 typedef time_t (*st_api_time_fn) (int nodeid, const char *uname, bool in_progress);
628 
629 static inline int
630 stonith_api_kick_helper(uint32_t nodeid, int timeout, bool off)
631 {
632  static void *st_library = NULL;
633  static st_api_kick_fn st_kick_fn;
634 
635  if (st_library == NULL) {
636  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
637  }
638  if (st_library && st_kick_fn == NULL) {
639  st_kick_fn = (st_api_kick_fn) dlsym(st_library, "stonith_api_kick");
640  }
641  if (st_kick_fn == NULL) {
642 #ifdef ELIBACC
643  return -ELIBACC;
644 #else
645  return -ENOSYS;
646 #endif
647  }
648 
649  return (*st_kick_fn) (nodeid, NULL, timeout, off);
650 }
651 
652 static inline time_t
653 stonith_api_time_helper(uint32_t nodeid, bool in_progress)
654 {
655  static void *st_library = NULL;
656  static st_api_time_fn st_time_fn;
657 
658  if (st_library == NULL) {
659  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
660  }
661  if (st_library && st_time_fn == NULL) {
662  st_time_fn = (st_api_time_fn) dlsym(st_library, "stonith_api_time");
663  }
664  if (st_time_fn == NULL) {
665  return 0;
666  }
667 
668  return (*st_time_fn) (nodeid, NULL, in_progress);
669 }
670 
680 bool stonith_agent_exists(const char *agent, int timeout);
681 
687 const char *stonith_action_str(const char *action);
688 
689 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
690 /* Normally we'd put this section in a separate file (crm/fencing/compat.h), but
691  * we can't do that for the reason noted at the top of this file. That does mean
692  * we have to duplicate these declarations where they're implemented.
693  */
694 
696 #define T_STONITH_NOTIFY_DISCONNECT "st_notify_disconnect"
697 
699 #define T_STONITH_NOTIFY_FENCE "st_notify_fence"
700 
702 #define T_STONITH_NOTIFY_HISTORY "st_notify_history"
703 
705 #define T_STONITH_NOTIFY_HISTORY_SYNCED "st_notify_history_synced"
706 
708 const char *get_stonith_provider(const char *agent, const char *provider);
709 
710 #endif
711 
712 #ifdef __cplusplus
713 }
714 #endif
715 
716 #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:537
struct stonith_history_s * next
Definition: stonith-ng.h:107
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
int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off)
Definition: st_client.c:1976
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:489
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:423
struct stonith_key_value_s * next
Definition: stonith-ng.h:96
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:392
const char * get_stonith_provider(const char *agent, const char *provider)
Definition: st_client.c:2713
stonith_namespace
Definition: stonith-ng.h:76
bool stonith_dispatch(stonith_t *st)
Definition: st_client.c:1666
int(* confirm)(stonith_t *stonith, int call_options, const char *target)
Manually confirm that a node has been fenced.
Definition: stonith-ng.h:367
stonith_t * stonith_api_new(void)
Definition: st_client.c:1833
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:1911
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:274
stonith_key_value_t * stonith_key_value_add(stonith_key_value_t *kvp, const char *key, const char *value)
Definition: st_client.c:1932
int(* remove_callback)(stonith_t *stonith, int call_id, bool all_callbacks)
Unregister callbacks for asynchronous fencing results.
Definition: stonith-ng.h:439
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:514
int(* free)(stonith_t *st)
Destroy a fencer connection.
Definition: stonith-ng.h:152
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:2082
const char * stonith_op_state_str(enum op_state state)
Return string equivalent of an operation state value.
Definition: st_client.c:2359
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:319
enum stonith_state state
Definition: stonith-ng.h:545
unsigned int tolerance
Definition: pcmk_fence.c:33
const char * stonith_action_str(const char *action)
Turn fence action into a more readable string.
Definition: st_client.c:2113
time_t(* st_api_time_fn)(int nodeid, const char *uname, bool in_progress)
Definition: stonith-ng.h:627
op_state
Definition: stonith-ng.h:66
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:233
int(* disconnect)(stonith_t *st)
Disconnect from the local stonith daemon.
Definition: stonith-ng.h:173
void stonith_key_value_freeall(stonith_key_value_t *kvp, int keys, int values)
Definition: st_client.c:1955
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:164
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:253
uint32_t id
Definition: cpg.c:48
int call_timeout
Definition: stonith-ng.h:548
int(* remove_device)(stonith_t *st, int options, const char *name)
Unregister a fence device with the local fencer.
Definition: stonith-ng.h:185
const char * target
Definition: pcmk_fence.c:29
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:380
#define ELIBACC
Definition: portability.h:91
stonith_call_options
Definition: stonith-ng.h:42
char * client_origin
Definition: stonith-ng.h:130
void stonith_api_delete(stonith_t *st)
Definition: st_client.c:1726
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:462
stonith_api_operations_t * cmds
Definition: stonith-ng.h:551
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:218
int delay
Definition: pcmk_fence.c:34
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:203
void stonith_history_free(stonith_history_t *history)
Definition: st_client.c:762
char * executioner
Definition: stonith-ng.h:125
char * operation
Definition: stonith-ng.h:119
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:626
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:304
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:336
time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress)
Definition: st_client.c:2018
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:290
#define STONITH_LIBRARY
Definition: stonith-ng.h:624
void * st_private
Definition: stonith-ng.h:549
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:354
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:404
const char * stonith_namespace2text(enum stonith_namespace st_namespace)
Get agent namespace name.
Definition: st_client.c:130
unsigned int timeout
Definition: pcmk_fence.c:32
int call_id
Definition: stonith-ng.h:547