pacemaker 3.0.1-16e74fc4da
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
stonith-ng.h
Go to the documentation of this file.
1/*
2 * Copyright 2004-2025 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
14extern "C" {
15#endif
16
23/* IMPORTANT: dlm source code includes this file directly. Until dlm v4.2.0
24 * (commit 5afd9fdc), dlm did not have access to other Pacemaker headers on its
25 * include path. This file should *not* include any other Pacemaker headers
26 * until we decide that we no longer need to support dlm versions older than
27 * v4.2.0.
28 *
29 * @COMPAT Remove this restriction and take any opportunities to simplify code
30 * when possible.
31 */
32
33# include <dlfcn.h>
34# include <errno.h>
35# include <stdbool.h> // bool
36# include <stdint.h> // uint32_t
37# include <time.h> // time_t
38
39// @TODO Keep this definition but make it internal
49
50// @TODO Keep this definition but make it internal
57 // No options
60
61#if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
63 st_opt_verbose = (1 << 0),
64#endif
65
66 // The fencing target is allowed to execute the request
69
70#if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
73#endif
74
75 // Used internally to indicate that request is manual fence confirmation
76 // \internal Do not use
79
80 // Do not return any reply from server
83
84 // Used internally to indicate that request requires a fencing topology
85 // \internal Do not use
87 st_opt_topology = (1 << 6),
88
89#if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
92#endif
93
94 // Interpret target as node cluster layer ID instead of name
96 st_opt_cs_nodeid = (1 << 9),
97
98 // Wait for request to be completed before returning
100 st_opt_sync_call = (1 << 12),
101
102 // Request that server send an update with optimal callback timeout
105
106 // Invoke callback only if request succeeded
109
110 // For a fence history request, request that the history be cleared
112 st_opt_cleanup = (1 << 19),
113
114 // For a fence history request, broadcast the request to all nodes
116 st_opt_broadcast = (1 << 20),
117};
118
119// Order matters here, do not change values
120// @TODO Keep this definition but make it internal
132
133// @TODO Keep this definition but make it internal
141
142 // Implemented internally by Pacemaker
144
145 /* Neither of these projects are active any longer, but the fence agent
146 * interfaces they created are still in use and supported by Pacemaker.
147 */
148 // Red Hat Cluster Suite compatible
150
151 // Linux-HA compatible
153};
154
155/* @COMPAT Drop this and use a GList/GSList of pcmk_nvpair_t or a GHashtable as
156 * appropriate
157 */
167
168// @TODO Keep this definition but make it internal
185
186// @TODO Keep this typedef but rename it and make it internal
187typedef struct stonith_s stonith_t;
188
189// @TODO Keep this definition but make it internal
194typedef struct stonith_event_s {
195 char *id;
198 char *origin;
199 char *target;
200 char *action;
202
203 char *device;
204
205 // Name of the client that initiated the action
207
208 void *opaque;
210
211// @TODO Keep this definition but make it internal
224
225// @TODO Keep this object but make it internal
237 int (*free) (stonith_t *st);
238
250 int (*connect) (stonith_t *st, const char *name, int *stonith_fd);
251
261
273 int (*remove_device)(stonith_t *st, int options, const char *name);
274
292 int (*register_device)(stonith_t *st, int options, const char *id,
293 const char *namespace_s, const char *agent,
294 const stonith_key_value_t *params);
295
309 int (*remove_level)(stonith_t *st, int options, const char *node,
310 int level);
311
326 int (*register_level)(stonith_t *st, int options, const char *node,
327 int level, const stonith_key_value_t *device_list);
328
344 int (*metadata)(stonith_t *stonith, int call_options, const char *agent,
345 const char *namespace_s, char **output, int timeout_sec);
346
365 int (*list_agents)(stonith_t *stonith, int call_options,
366 const char *namespace_s, stonith_key_value_t **devices,
367 int timeout);
368
382 int (*list)(stonith_t *stonith, int call_options, const char *id,
383 char **list_info, int timeout);
384
397 int (*monitor)(stonith_t *stonith, int call_options, const char *id,
398 int timeout);
399
414 int (*status)(stonith_t *stonith, int call_options, const char *id,
415 const char *port, int timeout);
416
432 int (*query)(stonith_t *stonith, int call_options, const char *target,
433 stonith_key_value_t **devices, int timeout);
434
454 int (*fence)(stonith_t *stonith, int call_options, const char *node,
455 const char *action, int timeout, int tolerance);
456
468 int (*confirm)(stonith_t *stonith, int call_options, const char *target);
469
482 int (*history)(stonith_t *stonith, int call_options, const char *node,
484
495 int (*register_notification)(stonith_t *stonith, const char *event,
496 void (*callback)(stonith_t *st,
497 stonith_event_t *e));
498
508 int (*remove_notification)(stonith_t *stonith, const char *event);
509
528 int (*register_callback)(stonith_t *stonith, int call_id, int timeout,
529 int options, void *user_data,
530 const char *callback_name,
531 void (*callback)(stonith_t *st,
533
546 int (*remove_callback)(stonith_t *stonith, int call_id, bool all_callbacks);
547
570 int (*remove_level_full)(stonith_t *st, int options,
571 const char *node, const char *pattern,
572 const char *attr, const char *value, int level);
573
598 int (*register_level_full)(stonith_t *st, int options,
599 const char *node, const char *pattern,
600 const char *attr, const char *value, int level,
601 const stonith_key_value_t *device_list);
602
622 int (*validate)(stonith_t *st, int call_options, const char *rsc_id,
623 const char *namespace_s, const char *agent,
624 const stonith_key_value_t *params, int timeout,
625 char **output, char **error_output);
626
646 int (*fence_with_delay)(stonith_t *stonith, int call_options,
647 const char *node, const char *action, int timeout,
648 int tolerance, int delay);
649
651
652// @TODO Keep this object but make it internal
663
664/* Basic helpers that allows nodes to be fenced and the history to be
665 * queried without mainloop or the caller understanding the full API
666 *
667 * At least one of nodeid and uname are required
668 *
669 * NOTE: dlm (as of at least 4.3.0) uses these (via the helper functions below)
670 */
671int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off);
672time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress);
673
674/*
675 * Helpers for using the above functions without install-time dependencies
676 *
677 * Usage:
678 * #include <crm/stonith-ng.h>
679 *
680 * To turn a node off by corosync nodeid:
681 * stonith_api_kick_helper(nodeid, 120, 1);
682 *
683 * To check the last fence date/time (also by nodeid):
684 * last = stonith_api_time_helper(nodeid, 0);
685 *
686 * To check if fencing is in progress:
687 * if(stonith_api_time_helper(nodeid, 1) > 0) { ... }
688 *
689 * eg.
690
691 #include <stdio.h>
692 #include <time.h>
693 #include <crm/stonith-ng.h>
694 int
695 main(int argc, char ** argv)
696 {
697 int rc = 0;
698 int nodeid = 102;
699
700 rc = stonith_api_time_helper(nodeid, 0);
701 printf("%d last fenced at %s\n", nodeid, ctime(rc));
702
703 rc = stonith_api_kick_helper(nodeid, 120, 1);
704 printf("%d fence result: %d\n", nodeid, rc);
705
706 rc = stonith_api_time_helper(nodeid, 0);
707 printf("%d last fenced at %s\n", nodeid, ctime(rc));
708
709 return 0;
710 }
711
712 */
713
714#define STONITH_LIBRARY "libstonithd.so.56"
715
716// NOTE: dlm (as of at least 4.3.0) uses these (via the helper functions below)
717typedef int (*st_api_kick_fn) (int nodeid, const char *uname, int timeout, bool off);
718typedef time_t (*st_api_time_fn) (int nodeid, const char *uname, bool in_progress);
719
720// NOTE: dlm (as of at least 4.3.0) uses this
721static inline int
722stonith_api_kick_helper(uint32_t nodeid, int timeout, bool off)
723{
724 static void *st_library = NULL;
725 static st_api_kick_fn st_kick_fn;
726
727 if (st_library == NULL) {
728 st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
729 }
730 if (st_library && st_kick_fn == NULL) {
731 st_kick_fn = (st_api_kick_fn) dlsym(st_library, "stonith_api_kick");
732 }
733 if (st_kick_fn == NULL) {
734#ifdef ELIBACC
735 return -ELIBACC;
736#else
737 return -ENOSYS;
738#endif
739 }
740
741 return (*st_kick_fn) (nodeid, NULL, timeout, off);
742}
743
744// NOTE: dlm (as of at least 4.3.0) uses this
745static inline time_t
746stonith_api_time_helper(uint32_t nodeid, bool in_progress)
747{
748 static void *st_library = NULL;
749 static st_api_time_fn st_time_fn;
750
751 if (st_library == NULL) {
752 st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
753 }
754 if (st_library && st_time_fn == NULL) {
755 st_time_fn = (st_api_time_fn) dlsym(st_library, "stonith_api_time");
756 }
757 if (st_time_fn == NULL) {
758 return 0;
759 }
760
761 return (*st_time_fn) (nodeid, NULL, in_progress);
762}
763
764#if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
765
766/* Normally we'd put this section in a separate file (crm/fencing/compat.h), but
767 * we can't do that for the reason noted at the top of this file. That does mean
768 * we have to duplicate these declarations where they're implemented.
769 */
770
773
775void stonith_api_delete(stonith_t *stonith);
776
779
781bool stonith_dispatch(stonith_t *stonith_api);
782
785 const char *key, const char *value);
786
788void stonith_key_value_freeall(stonith_key_value_t *head, int keys, int values);
789
792
795 int max_attempts);
796
798const char *stonith_op_state_str(enum op_state state);
799
801bool stonith_agent_exists(const char *agent, int timeout);
802
804const char *stonith_action_str(const char *action);
805
807enum stonith_namespace stonith_text2namespace(const char *namespace_s);
808
810const char *stonith_namespace2text(enum stonith_namespace st_namespace);
811
813enum stonith_namespace stonith_get_namespace(const char *agent,
814 const char *namespace_s);
815
816#endif // !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
817
818#ifdef __cplusplus
819}
820#endif
821
822#endif
const char * name
Definition cib.c:26
char uname[MAX_NAME]
Definition cpg.c:5
char data[0]
Definition cpg.c:10
uint32_t id
Definition cpg.c:0
#define PCMK_ALLOW_DEPRECATED
Allow use of deprecated Pacemaker APIs.
Definition crm.h:46
unsigned int timeout
Definition pcmk_fence.c:34
int delay
Definition pcmk_fence.c:36
unsigned int tolerance
Definition pcmk_fence.c:35
stonith_t * st
Definition pcmk_fence.c:30
const char * action
Definition pcmk_fence.c:32
const char * target
Definition pcmk_fence.c:31
#define ELIBACC
Definition portability.h:46
void stonith_api_delete(stonith_t *stonith)
Definition st_client.c:2819
const char * stonith_namespace2text(enum stonith_namespace st_namespace)
Definition st_client.c:2933
struct stonith_api_operations_s stonith_api_operations_t
Fencer API operations.
time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress)
Definition st_client.c:2095
struct stonith_callback_data_s stonith_callback_data_t
Data for an asynchronous fencing request callback.
enum stonith_namespace stonith_get_namespace(const char *agent, const char *namespace_s)
Definition st_client.c:2942
struct stonith_key_value_s stonith_key_value_t
Key-value pair list node.
#define STONITH_LIBRARY
Definition stonith-ng.h:714
enum stonith_namespace stonith_text2namespace(const char *namespace_s)
Definition st_client.c:2925
stonith_call_options
Flags that can be set in call options for API requests.
Definition stonith-ng.h:56
@ st_opt_scope_local
Definition stonith-ng.h:91
@ st_opt_cleanup
Definition stonith-ng.h:112
@ st_opt_timeout_updates
Definition stonith-ng.h:104
@ st_opt_broadcast
Definition stonith-ng.h:116
@ st_opt_cs_nodeid
Definition stonith-ng.h:96
@ st_opt_allow_self_fencing
Definition stonith-ng.h:68
@ st_opt_discard_reply
Definition stonith-ng.h:82
@ st_opt_manual_ack
Definition stonith-ng.h:78
@ st_opt_allow_suicide
Definition stonith-ng.h:72
@ st_opt_verbose
Definition stonith-ng.h:63
@ st_opt_report_only_success
Definition stonith-ng.h:108
@ st_opt_none
Definition stonith-ng.h:59
@ st_opt_topology
Definition stonith-ng.h:87
@ st_opt_sync_call
Definition stonith-ng.h:100
void stonith_history_free(stonith_history_t *head)
Definition st_client.c:2876
const char * stonith_action_str(const char *action)
Definition st_client.c:2909
stonith_namespace
Supported fence agent interface standards.
Definition stonith-ng.h:138
@ st_namespace_invalid
Definition stonith-ng.h:139
@ st_namespace_rhcs
Definition stonith-ng.h:149
@ st_namespace_internal
Definition stonith-ng.h:143
@ st_namespace_any
Definition stonith-ng.h:140
@ st_namespace_lha
Definition stonith-ng.h:152
int stonith_api_connect_retry(stonith_t *st, const char *name, int max_attempts)
Definition st_client.c:2885
time_t(* st_api_time_fn)(int nodeid, const char *uname, bool in_progress)
Definition stonith-ng.h:718
int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off)
Definition st_client.c:2053
stonith_state
Fencer API connection state.
Definition stonith-ng.h:44
@ stonith_disconnected
Definition stonith-ng.h:47
@ stonith_connected_command
Definition stonith-ng.h:45
@ stonith_connected_query
Definition stonith-ng.h:46
struct stonith_history_s stonith_history_t
Fencing history entry.
op_state
Fencing operation states.
Definition stonith-ng.h:125
@ st_duplicate
Definition stonith-ng.h:129
@ st_query
Definition stonith-ng.h:126
@ st_failed
Definition stonith-ng.h:130
@ st_done
Definition stonith-ng.h:128
@ st_exec
Definition stonith-ng.h:127
bool stonith_dispatch(stonith_t *stonith_api)
Definition st_client.c:2850
struct stonith_event_s stonith_event_t
Fencing event.
stonith_t * stonith_api_new(void)
Definition st_client.c:2811
int(* st_api_kick_fn)(int nodeid, const char *uname, int timeout, bool off)
Definition stonith-ng.h:717
void stonith_key_value_freeall(stonith_key_value_t *head, int keys, int values)
Definition st_client.c:2868
bool stonith_agent_exists(const char *agent, int timeout)
Definition st_client.c:2901
void stonith_dump_pending_callbacks(stonith_t *stonith)
Definition st_client.c:2836
const char * stonith_op_state_str(enum op_state state)
Definition st_client.c:2893
stonith_key_value_t * stonith_key_value_add(stonith_key_value_t *kvp, const char *key, const char *value)
Definition st_client.c:2859
Fencer API operations.
Definition stonith-ng.h:230
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:646
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:326
int(* free)(stonith_t *st)
Destroy a fencer connection.
Definition stonith-ng.h:237
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:528
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:432
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:495
int(* connect)(stonith_t *st, const char *name, int *stonith_fd)
Connect to the local fencer.
Definition stonith-ng.h:250
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:292
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:309
int(* disconnect)(stonith_t *st)
Disconnect from the local stonith daemon.
Definition stonith-ng.h:260
int(* list)(stonith_t *stonith, int call_options, const char *id, char **list_info, int timeout)
Get the output of a fence device's list action.
Definition stonith-ng.h:382
int(* remove_callback)(stonith_t *stonith, int call_id, bool all_callbacks)
Unregister callbacks for asynchronous fencing results.
Definition stonith-ng.h:546
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:570
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:454
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:365
int(* confirm)(stonith_t *stonith, int call_options, const char *target)
Manually confirm that a node has been fenced.
Definition stonith-ng.h:468
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:414
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:598
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:622
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:397
int(* remove_notification)(stonith_t *stonith, const char *event)
Unregister callbacks for fence notifications.
Definition stonith-ng.h:508
int(* remove_device)(stonith_t *st, int options, const char *name)
Unregister a fence device with the local fencer.
Definition stonith-ng.h:273
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:482
int(* metadata)(stonith_t *stonith, int call_options, const char *agent, const char *namespace_s, char **output, int timeout_sec)
Retrieve a fence agent's metadata.
Definition stonith-ng.h:344
Data for an asynchronous fencing request callback.
Definition stonith-ng.h:216
Fencing event.
Definition stonith-ng.h:194
char * client_origin
Definition stonith-ng.h:206
Fencing history entry.
Definition stonith-ng.h:173
struct stonith_history_s * next
Definition stonith-ng.h:181
Key-value pair list node.
Definition stonith-ng.h:162
struct stonith_key_value_s * next
Definition stonith-ng.h:165
Fencer API connection object.
Definition stonith-ng.h:657
enum stonith_state state
Definition stonith-ng.h:658
void * st_private
Definition stonith-ng.h:660
stonith_api_operations_t * cmds
Definition stonith-ng.h:661