pacemaker  2.1.6-802a72226b
Scalable High-Availability cluster resource manager
stonith-ng.h
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2022 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 # 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;
114  char *exit_reason;
116 
117 typedef struct stonith_s stonith_t;
118 
119 typedef struct stonith_event_s
120 {
121  char *id;
122  char *type;
123  char *message;
124  char *operation;
125 
126  int result;
127  char *origin;
128  char *target;
129  char *action;
130  char *executioner;
131 
132  char *device;
133 
136 
138  void *opaque;
140 
141 typedef struct stonith_callback_data_s {
142  int rc;
143  int call_id;
144  void *userdata;
145 
147  void *opaque;
149 
151 {
157  int (*free) (stonith_t *st);
158 
169  int (*connect) (stonith_t *st, const char *name, int *stonith_fd);
170 
179 
190  int (*remove_device)(stonith_t *st, int options, const char *name);
191 
208  int (*register_device)(stonith_t *st, int options, const char *id,
209  const char *namespace, const char *agent,
210  const stonith_key_value_t *params);
211 
223  int (*remove_level)(stonith_t *st, int options, const char *node,
224  int level);
225 
238  int (*register_level)(stonith_t *st, int options, const char *node,
239  int level, const stonith_key_value_t *device_list);
240 
258  int (*metadata)(stonith_t *stonith, int call_options, const char *agent,
259  const char *namespace, char **output, int timeout_sec);
260 
279  int (*list_agents)(stonith_t *stonith, int call_options,
280  const char *namespace, stonith_key_value_t **devices,
281  int timeout);
282 
295  int (*list)(stonith_t *stonith, int call_options, const char *id,
296  char **list_info, int timeout);
297 
309  int (*monitor)(stonith_t *stonith, int call_options, const char *id,
310  int timeout);
311 
324  int (*status)(stonith_t *stonith, int call_options, const char *id,
325  const char *port, int timeout);
326 
341  int (*query)(stonith_t *stonith, int call_options, const char *target,
342  stonith_key_value_t **devices, int timeout);
343 
359  int (*fence)(stonith_t *stonith, int call_options, const char *node,
360  const char *action, int timeout, int tolerance);
361 
372  int (*confirm)(stonith_t *stonith, int call_options, const char *target);
373 
385  int (*history)(stonith_t *stonith, int call_options, const char *node,
387 
397  int (*register_notification)(stonith_t *stonith, const char *event,
398  void (*callback)(stonith_t *st,
399  stonith_event_t *e));
400 
409  int (*remove_notification)(stonith_t *stonith, const char *event);
410 
428  int (*register_callback)(stonith_t *stonith, int call_id, int timeout,
429  int options, void *user_data,
430  const char *callback_name,
431  void (*callback)(stonith_t *st,
433 
444  int (*remove_callback)(stonith_t *stonith, int call_id, bool all_callbacks);
445 
467  int (*remove_level_full)(stonith_t *st, int options,
468  const char *node, const char *pattern,
469  const char *attr, const char *value, int level);
470 
494  int (*register_level_full)(stonith_t *st, int options,
495  const char *node, const char *pattern,
496  const char *attr, const char *value, int level,
497  const stonith_key_value_t *device_list);
498 
519  int (*validate)(stonith_t *st, int call_options, const char *rsc_id,
520  const char *namespace_s, const char *agent,
521  const stonith_key_value_t *params, int timeout,
522  char **output, char **error_output);
523 
542  int (*fence_with_delay)(stonith_t *stonith, int call_options,
543  const char *node, const char *action, int timeout,
544  int tolerance, int delay);
545 
547 
548 struct stonith_s
549 {
551 
552  int call_id;
554  void *st_private;
555 
557 };
558 /* *INDENT-ON* */
559 
560 /* Core functions */
563 
565 
567 
569  const char *value);
570 void stonith_key_value_freeall(stonith_key_value_t * kvp, int keys, int values);
571 
573 
574 // Convenience functions
575 int stonith_api_connect_retry(stonith_t *st, const char *name,
576  int max_attempts);
577 const char *stonith_op_state_str(enum op_state state);
578 
579 /* Basic helpers that allows nodes to be fenced and the history to be
580  * queried without mainloop or the caller understanding the full API
581  *
582  * At least one of nodeid and uname are required
583  */
584 int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off);
585 time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress);
586 
587 /*
588  * Helpers for using the above functions without install-time dependencies
589  *
590  * Usage:
591  * #include <crm/stonith-ng.h>
592  *
593  * To turn a node off by corosync nodeid:
594  * stonith_api_kick_helper(nodeid, 120, 1);
595  *
596  * To check the last fence date/time (also by nodeid):
597  * last = stonith_api_time_helper(nodeid, 0);
598  *
599  * To check if fencing is in progress:
600  * if(stonith_api_time_helper(nodeid, 1) > 0) { ... }
601  *
602  * eg.
603 
604  #include <stdio.h>
605  #include <time.h>
606  #include <crm/stonith-ng.h>
607  int
608  main(int argc, char ** argv)
609  {
610  int rc = 0;
611  int nodeid = 102;
612 
613  rc = stonith_api_time_helper(nodeid, 0);
614  printf("%d last fenced at %s\n", nodeid, ctime(rc));
615 
616  rc = stonith_api_kick_helper(nodeid, 120, 1);
617  printf("%d fence result: %d\n", nodeid, rc);
618 
619  rc = stonith_api_time_helper(nodeid, 0);
620  printf("%d last fenced at %s\n", nodeid, ctime(rc));
621 
622  return 0;
623  }
624 
625  */
626 
627 # define STONITH_LIBRARY "libstonithd.so.26"
628 
629 typedef int (*st_api_kick_fn) (int nodeid, const char *uname, int timeout, bool off);
630 typedef time_t (*st_api_time_fn) (int nodeid, const char *uname, bool in_progress);
631 
632 static inline int
633 stonith_api_kick_helper(uint32_t nodeid, int timeout, bool off)
634 {
635  static void *st_library = NULL;
636  static st_api_kick_fn st_kick_fn;
637 
638  if (st_library == NULL) {
639  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
640  }
641  if (st_library && st_kick_fn == NULL) {
642  st_kick_fn = (st_api_kick_fn) dlsym(st_library, "stonith_api_kick");
643  }
644  if (st_kick_fn == NULL) {
645 #ifdef ELIBACC
646  return -ELIBACC;
647 #else
648  return -ENOSYS;
649 #endif
650  }
651 
652  return (*st_kick_fn) (nodeid, NULL, timeout, off);
653 }
654 
655 static inline time_t
656 stonith_api_time_helper(uint32_t nodeid, bool in_progress)
657 {
658  static void *st_library = NULL;
659  static st_api_time_fn st_time_fn;
660 
661  if (st_library == NULL) {
662  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
663  }
664  if (st_library && st_time_fn == NULL) {
665  st_time_fn = (st_api_time_fn) dlsym(st_library, "stonith_api_time");
666  }
667  if (st_time_fn == NULL) {
668  return 0;
669  }
670 
671  return (*st_time_fn) (nodeid, NULL, in_progress);
672 }
673 
683 bool stonith_agent_exists(const char *agent, int timeout);
684 
690 const char *stonith_action_str(const char *action);
691 
692 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
693 /* Normally we'd put this section in a separate file (crm/fencing/compat.h), but
694  * we can't do that for the reason noted at the top of this file. That does mean
695  * we have to duplicate these declarations where they're implemented.
696  */
697 
699 const char *get_stonith_provider(const char *agent, const char *provider);
700 
701 #endif
702 
703 #ifdef __cplusplus
704 }
705 #endif
706 
707 #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:542
struct stonith_history_s * next
Definition: stonith-ng.h:112
char data[0]
Definition: cpg.c:55
struct stonith_api_operations_s stonith_api_operations_t
int(* list_agents)(stonith_t *stonith, int call_options, const char *namespace, stonith_key_value_t **devices, int timeout)
Retrieve a list of installed fence agents.
Definition: stonith-ng.h:279
struct stonith_key_value_s stonith_key_value_t
const char * name
Definition: cib.c:24
int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off)
Definition: st_client.c:1960
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:494
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:428
struct stonith_key_value_s * next
Definition: stonith-ng.h:101
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:397
int(* register_device)(stonith_t *st, int options, const char *id, const char *namespace, const char *agent, const stonith_key_value_t *params)
Register a fence device with the local fencer.
Definition: stonith-ng.h:208
const char * get_stonith_provider(const char *agent, const char *provider)
Definition: st_client.c:2696
stonith_namespace
Definition: stonith-ng.h:81
bool stonith_dispatch(stonith_t *st)
Definition: st_client.c:1649
int(* confirm)(stonith_t *stonith, int call_options, const char *target)
Manually confirm that a node has been fenced.
Definition: stonith-ng.h:372
stonith_t * stonith_api_new(void)
Definition: st_client.c:1817
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:1895
stonith_key_value_t * stonith_key_value_add(stonith_key_value_t *kvp, const char *key, const char *value)
Definition: st_client.c:1916
int(* remove_callback)(stonith_t *stonith, int call_id, bool all_callbacks)
Unregister callbacks for asynchronous fencing results.
Definition: stonith-ng.h:444
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:519
int(* free)(stonith_t *st)
Destroy a fencer connection.
Definition: stonith-ng.h:157
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:2066
const char * stonith_op_state_str(enum op_state state)
Return string equivalent of an operation state value.
Definition: st_client.c:2343
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:324
enum stonith_state state
Definition: stonith-ng.h:550
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:2097
time_t(* st_api_time_fn)(int nodeid, const char *uname, bool in_progress)
Definition: stonith-ng.h:630
op_state
Definition: stonith-ng.h:71
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:238
int(* disconnect)(stonith_t *st)
Disconnect from the local stonith daemon.
Definition: stonith-ng.h:178
void stonith_key_value_freeall(stonith_key_value_t *kvp, int keys, int values)
Definition: st_client.c:1939
void stonith_dump_pending_callbacks(stonith_t *st)
Definition: st_client.c:1353
int(* connect)(stonith_t *st, const char *name, int *stonith_fd)
Connect to the local fencer.
Definition: stonith-ng.h:169
uint32_t id
Definition: cpg.c:45
int call_timeout
Definition: stonith-ng.h:553
int(* remove_device)(stonith_t *st, int options, const char *name)
Unregister a fence device with the local fencer.
Definition: stonith-ng.h:190
const char * target
Definition: pcmk_fence.c:29
stonith_state
Definition: stonith-ng.h:41
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:385
#define ELIBACC
Definition: portability.h:130
stonith_call_options
Definition: stonith-ng.h:47
char * client_origin
Definition: stonith-ng.h:135
void stonith_api_delete(stonith_t *st)
Definition: st_client.c:1709
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:467
stonith_api_operations_t * cmds
Definition: stonith-ng.h:556
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:223
int delay
Definition: pcmk_fence.c:34
int(* metadata)(stonith_t *stonith, int call_options, const char *agent, const char *namespace, char **output, int timeout_sec)
Retrieve a fence agent&#39;s metadata.
Definition: stonith-ng.h:258
void stonith_history_free(stonith_history_t *history)
Definition: st_client.c:755
char * executioner
Definition: stonith-ng.h:130
char * operation
Definition: stonith-ng.h:124
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:629
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:309
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:341
time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress)
Definition: st_client.c:2002
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:295
#define STONITH_LIBRARY
Definition: stonith-ng.h:627
void * st_private
Definition: stonith-ng.h:554
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:359
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:409
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:552