pacemaker  2.1.9-49aab99839
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 {
146  char *id;
147  char *type;
148  char *message;
149  char *operation;
150 
151  int result;
152  char *origin;
153  char *target;
154  char *action;
155  char *executioner;
156 
157  char *device;
158 
161 
163  void *opaque;
165 
166 typedef struct stonith_callback_data_s {
167  int rc;
168  int call_id;
169  void *userdata;
170 
172  void *opaque;
174 
176 {
182  int (*free) (stonith_t *st);
183 
194  int (*connect) (stonith_t *st, const char *name, int *stonith_fd);
195 
204 
215  int (*remove_device)(stonith_t *st, int options, const char *name);
216 
233  int (*register_device)(stonith_t *st, int options, const char *id,
234  const char *namespace_s, const char *agent,
235  const stonith_key_value_t *params);
236 
248  int (*remove_level)(stonith_t *st, int options, const char *node,
249  int level);
250 
263  int (*register_level)(stonith_t *st, int options, const char *node,
264  int level, const stonith_key_value_t *device_list);
265 
283  int (*metadata)(stonith_t *stonith, int call_options, const char *agent,
284  const char *namespace_s, char **output, int timeout_sec);
285 
304  int (*list_agents)(stonith_t *stonith, int call_options,
305  const char *namespace_s, stonith_key_value_t **devices,
306  int timeout);
307 
320  int (*list)(stonith_t *stonith, int call_options, const char *id,
321  char **list_info, int timeout);
322 
334  int (*monitor)(stonith_t *stonith, int call_options, const char *id,
335  int timeout);
336 
349  int (*status)(stonith_t *stonith, int call_options, const char *id,
350  const char *port, int timeout);
351 
366  int (*query)(stonith_t *stonith, int call_options, const char *target,
367  stonith_key_value_t **devices, int timeout);
368 
384  int (*fence)(stonith_t *stonith, int call_options, const char *node,
385  const char *action, int timeout, int tolerance);
386 
397  int (*confirm)(stonith_t *stonith, int call_options, const char *target);
398 
410  int (*history)(stonith_t *stonith, int call_options, const char *node,
412 
422  int (*register_notification)(stonith_t *stonith, const char *event,
423  void (*callback)(stonith_t *st,
424  stonith_event_t *e));
425 
434  int (*remove_notification)(stonith_t *stonith, const char *event);
435 
453  int (*register_callback)(stonith_t *stonith, int call_id, int timeout,
454  int options, void *user_data,
455  const char *callback_name,
456  void (*callback)(stonith_t *st,
458 
469  int (*remove_callback)(stonith_t *stonith, int call_id, bool all_callbacks);
470 
492  int (*remove_level_full)(stonith_t *st, int options,
493  const char *node, const char *pattern,
494  const char *attr, const char *value, int level);
495 
519  int (*register_level_full)(stonith_t *st, int options,
520  const char *node, const char *pattern,
521  const char *attr, const char *value, int level,
522  const stonith_key_value_t *device_list);
523 
544  int (*validate)(stonith_t *st, int call_options, const char *rsc_id,
545  const char *namespace_s, const char *agent,
546  const stonith_key_value_t *params, int timeout,
547  char **output, char **error_output);
548 
567  int (*fence_with_delay)(stonith_t *stonith, int call_options,
568  const char *node, const char *action, int timeout,
569  int tolerance, int delay);
570 
572 
573 struct stonith_s
574 {
576 
577  int call_id;
579  void *st_private;
580 
582 };
583 /* *INDENT-ON* */
584 
585 /* Core functions */
588 
590 
592 
594  const char *value);
595 void stonith_key_value_freeall(stonith_key_value_t * kvp, int keys, int values);
596 
598 
599 // Convenience functions
600 int stonith_api_connect_retry(stonith_t *st, const char *name,
601  int max_attempts);
602 const char *stonith_op_state_str(enum op_state state);
603 
604 /* Basic helpers that allows nodes to be fenced and the history to be
605  * queried without mainloop or the caller understanding the full API
606  *
607  * At least one of nodeid and uname are required
608  *
609  * NOTE: DLM uses both of these
610  */
611 int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off);
612 time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress);
613 
614 /*
615  * Helpers for using the above functions without install-time dependencies
616  *
617  * Usage:
618  * #include <crm/stonith-ng.h>
619  *
620  * To turn a node off by corosync nodeid:
621  * stonith_api_kick_helper(nodeid, 120, 1);
622  *
623  * To check the last fence date/time (also by nodeid):
624  * last = stonith_api_time_helper(nodeid, 0);
625  *
626  * To check if fencing is in progress:
627  * if(stonith_api_time_helper(nodeid, 1) > 0) { ... }
628  *
629  * eg.
630 
631  #include <stdio.h>
632  #include <time.h>
633  #include <crm/stonith-ng.h>
634  int
635  main(int argc, char ** argv)
636  {
637  int rc = 0;
638  int nodeid = 102;
639 
640  rc = stonith_api_time_helper(nodeid, 0);
641  printf("%d last fenced at %s\n", nodeid, ctime(rc));
642 
643  rc = stonith_api_kick_helper(nodeid, 120, 1);
644  printf("%d fence result: %d\n", nodeid, rc);
645 
646  rc = stonith_api_time_helper(nodeid, 0);
647  printf("%d last fenced at %s\n", nodeid, ctime(rc));
648 
649  return 0;
650  }
651 
652  */
653 
654 # define STONITH_LIBRARY "libstonithd.so.26"
655 
656 typedef int (*st_api_kick_fn) (int nodeid, const char *uname, int timeout, bool off);
657 typedef time_t (*st_api_time_fn) (int nodeid, const char *uname, bool in_progress);
658 
659 static inline int
660 stonith_api_kick_helper(uint32_t nodeid, int timeout, bool off)
661 {
662  static void *st_library = NULL;
663  static st_api_kick_fn st_kick_fn;
664 
665  if (st_library == NULL) {
666  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
667  }
668  if (st_library && st_kick_fn == NULL) {
669  st_kick_fn = (st_api_kick_fn) dlsym(st_library, "stonith_api_kick");
670  }
671  if (st_kick_fn == NULL) {
672 #ifdef ELIBACC
673  return -ELIBACC;
674 #else
675  return -ENOSYS;
676 #endif
677  }
678 
679  return (*st_kick_fn) (nodeid, NULL, timeout, off);
680 }
681 
682 static inline time_t
683 stonith_api_time_helper(uint32_t nodeid, bool in_progress)
684 {
685  static void *st_library = NULL;
686  static st_api_time_fn st_time_fn;
687 
688  if (st_library == NULL) {
689  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
690  }
691  if (st_library && st_time_fn == NULL) {
692  st_time_fn = (st_api_time_fn) dlsym(st_library, "stonith_api_time");
693  }
694  if (st_time_fn == NULL) {
695  return 0;
696  }
697 
698  return (*st_time_fn) (nodeid, NULL, in_progress);
699 }
700 
710 bool stonith_agent_exists(const char *agent, int timeout);
711 
717 const char *stonith_action_str(const char *action);
718 
719 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
720 /* Normally we'd put this section in a separate file (crm/fencing/compat.h), but
721  * we can't do that for the reason noted at the top of this file. That does mean
722  * we have to duplicate these declarations where they're implemented.
723  */
724 
726 #define T_STONITH_NOTIFY_DISCONNECT "st_notify_disconnect"
727 
729 #define T_STONITH_NOTIFY_FENCE "st_notify_fence"
730 
732 #define T_STONITH_NOTIFY_HISTORY "st_notify_history"
733 
735 #define T_STONITH_NOTIFY_HISTORY_SYNCED "st_notify_history_synced"
736 
738 const char *get_stonith_provider(const char *agent, const char *provider);
739 
740 #endif
741 
742 #ifdef __cplusplus
743 }
744 #endif
745 
746 #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:567
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:1977
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:519
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:453
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:422
const char * get_stonith_provider(const char *agent, const char *provider)
Definition: st_client.c:2714
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:1667
int(* confirm)(stonith_t *stonith, int call_options, const char *target)
Manually confirm that a node has been fenced.
Definition: stonith-ng.h:397
stonith_t * stonith_api_new(void)
Definition: st_client.c:1834
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:1912
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:304
stonith_key_value_t * stonith_key_value_add(stonith_key_value_t *kvp, const char *key, const char *value)
Definition: st_client.c:1933
int(* remove_callback)(stonith_t *stonith, int call_id, bool all_callbacks)
Unregister callbacks for asynchronous fencing results.
Definition: stonith-ng.h:469
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:544
int(* free)(stonith_t *st)
Destroy a fencer connection.
Definition: stonith-ng.h:182
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:2083
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:2360
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:349
enum stonith_state state
Definition: stonith-ng.h:575
For a fence history request, request that the history be cleared.
Definition: stonith-ng.h:89
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:2114
time_t(* st_api_time_fn)(int nodeid, const char *uname, bool in_progress)
Definition: stonith-ng.h:657
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:263
int(* disconnect)(stonith_t *st)
Disconnect from the local stonith daemon.
Definition: stonith-ng.h:203
void stonith_key_value_freeall(stonith_key_value_t *kvp, int keys, int values)
Definition: st_client.c:1956
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:194
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:283
#define PCMK_ALLOW_DEPRECATED
Allow use of deprecated Pacemaker APIs.
Definition: crm.h:46
uint32_t id
Definition: cpg.c:48
int call_timeout
Definition: stonith-ng.h:578
int(* remove_device)(stonith_t *st, int options, const char *name)
Unregister a fence device with the local fencer.
Definition: stonith-ng.h:215
Wait for request to be completed before returning.
Definition: stonith-ng.h:80
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:410
#define ELIBACC
Definition: portability.h:91
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:160
void stonith_api_delete(stonith_t *st)
Definition: st_client.c:1727
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:492
stonith_api_operations_t * cmds
Definition: stonith-ng.h:581
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:248
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:233
void stonith_history_free(stonith_history_t *history)
Definition: st_client.c:762
Request that server send an update with optimal callback timeout.
Definition: stonith-ng.h:83
char * executioner
Definition: stonith-ng.h:155
char * operation
Definition: stonith-ng.h:149
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:656
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:334
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:366
time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress)
Definition: st_client.c:2019
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:320
#define STONITH_LIBRARY
Definition: stonith-ng.h:654
void * st_private
Definition: stonith-ng.h:579
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:384
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:434
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:32
int call_id
Definition: stonith-ng.h:577