pacemaker 2.1.1-77db578727
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
stonith-ng.h
Go to the documentation of this file.
1/*
2 * Copyright 2004-2021 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 STONITH_NG__H
11# define STONITH_NG__H
12
13#ifdef __cplusplus
14extern "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* */
46
48 st_opt_none = 0x00000000,
49 st_opt_verbose = 0x00000001,
51
52 st_opt_manual_ack = 0x00000008,
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,
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
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
93enum stonith_namespace stonith_text2namespace(const char *namespace_s);
94const char *stonith_namespace2text(enum stonith_namespace st_namespace);
95enum stonith_namespace stonith_get_namespace(const char *agent,
96 const char *namespace_s);
97
103
114
115typedef struct stonith_s stonith_t;
116
117typedef struct stonith_event_s
118{
119 char *id;
120 char *type;
121 char *message;
123
125 char *origin;
126 char *target;
127 char *action;
129
130 char *device;
131
134
136
143
145{
149 int (*free) (stonith_t *st);
150
157 int (*connect) (stonith_t *st, const char *name, int *stonith_fd);
158
166
176 stonith_t *st, int options, const char *name);
177
187 stonith_t *st, int options, const char *id,
188 const char *provider, const char *agent, stonith_key_value_t *params);
189
197 stonith_t *st, int options, const char *node, int level);
198
207 stonith_t *st, int options, const char *node, int level, stonith_key_value_t *device_list);
208
217 int (*metadata)(stonith_t *st, int options,
218 const char *device, const char *provider, char **output, int timeout);
219
230 int (*list_agents)(stonith_t *stonith, int call_options, const char *provider,
231 stonith_key_value_t **devices, int timeout);
232
239 int (*list)(stonith_t *st, int options, const char *id, char **list_output, int timeout);
240
247 int (*monitor)(stonith_t *st, int options, const char *id, int timeout);
248
255 int (*status)(stonith_t *st, int options, const char *id, const char *port, int timeout);
256
266 int (*query)(stonith_t *st, int options, const char *node,
267 stonith_key_value_t **devices, int timeout);
268
284 int (*fence)(stonith_t *st, int options, const char *node, const char *action,
285 int timeout, int tolerance);
286
293 int (*confirm)(stonith_t *st, int options, const char *node);
294
301 int (*history)(stonith_t *st, int options, const char *node, stonith_history_t **output, int timeout);
302
304 stonith_t *st, const char *event,
305 void (*notify)(stonith_t *st, stonith_event_t *e));
306 int (*remove_notification)(stonith_t *st, const char *event);
307
326 int call_id,
327 int timeout,
328 int options,
329 void *userdata,
330 const char *callback_name,
331 void (*callback)(stonith_t *st, stonith_callback_data_t *data));
332
336 int (*remove_callback)(stonith_t *st, int call_id, bool all_callbacks);
337
353 int (*remove_level_full)(stonith_t *st, int options,
354 const char *node, const char *pattern,
355 const char *attr, const char *value, int level);
356
373 int (*register_level_full)(stonith_t *st, int options,
374 const char *node, const char *pattern,
375 const char *attr, const char *value,
376 int level, stonith_key_value_t *device_list);
377
396 int (*validate)(stonith_t *st, int call_options, const char *rsc_id,
397 const char *namespace_s, const char *agent,
398 stonith_key_value_t *params, int timeout, char **output,
399 char **error_output);
400
418 int (*fence_with_delay)(stonith_t *st, int options, const char *node, const char *action,
419 int timeout, int tolerance, int delay);
420
422
433/* *INDENT-ON* */
434
435/* Core functions */
438
440
442
444 const char *value);
445void stonith_key_value_freeall(stonith_key_value_t * kvp, int keys, int values);
446
448
449// Convenience functions
451 int max_attempts);
452const char *stonith_op_state_str(enum op_state state);
453
454/* Basic helpers that allows nodes to be fenced and the history to be
455 * queried without mainloop or the caller understanding the full API
456 *
457 * At least one of nodeid and uname are required
458 */
459int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off);
460time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress);
461
462/*
463 * Helpers for using the above functions without install-time dependencies
464 *
465 * Usage:
466 * #include <crm/stonith-ng.h>
467 *
468 * To turn a node off by corosync nodeid:
469 * stonith_api_kick_helper(nodeid, 120, 1);
470 *
471 * To check the last fence date/time (also by nodeid):
472 * last = stonith_api_time_helper(nodeid, 0);
473 *
474 * To check if fencing is in progress:
475 * if(stonith_api_time_helper(nodeid, 1) > 0) { ... }
476 *
477 * eg.
478
479 #include <stdio.h>
480 #include <time.h>
481 #include <crm/stonith-ng.h>
482 int
483 main(int argc, char ** argv)
484 {
485 int rc = 0;
486 int nodeid = 102;
487
488 rc = stonith_api_time_helper(nodeid, 0);
489 printf("%d last fenced at %s\n", nodeid, ctime(rc));
490
491 rc = stonith_api_kick_helper(nodeid, 120, 1);
492 printf("%d fence result: %d\n", nodeid, rc);
493
494 rc = stonith_api_time_helper(nodeid, 0);
495 printf("%d last fenced at %s\n", nodeid, ctime(rc));
496
497 return 0;
498 }
499
500 */
501
502# define STONITH_LIBRARY "libstonithd.so.26"
503
504typedef int (*st_api_kick_fn) (int nodeid, const char *uname, int timeout, bool off);
505typedef time_t (*st_api_time_fn) (int nodeid, const char *uname, bool in_progress);
506
507static inline int
508stonith_api_kick_helper(uint32_t nodeid, int timeout, bool off)
509{
510 static void *st_library = NULL;
511 static st_api_kick_fn st_kick_fn;
512
513 if (st_library == NULL) {
514 st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
515 }
516 if (st_library && st_kick_fn == NULL) {
517 st_kick_fn = (st_api_kick_fn) dlsym(st_library, "stonith_api_kick");
518 }
519 if (st_kick_fn == NULL) {
520#ifdef ELIBACC
521 return -ELIBACC;
522#else
523 return -ENOSYS;
524#endif
525 }
526
527 return (*st_kick_fn) (nodeid, NULL, timeout, off);
528}
529
530static inline time_t
531stonith_api_time_helper(uint32_t nodeid, bool in_progress)
532{
533 static void *st_library = NULL;
534 static st_api_time_fn st_time_fn;
535
536 if (st_library == NULL) {
537 st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
538 }
539 if (st_library && st_time_fn == NULL) {
540 st_time_fn = (st_api_time_fn) dlsym(st_library, "stonith_api_time");
541 }
542 if (st_time_fn == NULL) {
543 return 0;
544 }
545
546 return (*st_time_fn) (nodeid, NULL, in_progress);
547}
548
558bool stonith_agent_exists(const char *agent, int timeout);
559
565const char *stonith_action_str(const char *action);
566
567#if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
568/* Normally we'd put this section in a separate file (crm/fencing/compat.h), but
569 * we can't do that for the reason noted at the top of this file. That does mean
570 * we have to duplicate these declarations where they're implemented.
571 */
572
574const char *get_stonith_provider(const char *agent, const char *provider);
575
576#endif
577
578#ifdef __cplusplus
579}
580#endif
581
582#endif
char uname[MAX_NAME]
Definition cpg.c:5
char data[0]
Definition cpg.c:10
uint32_t id
Definition cpg.c:0
unsigned int timeout
Definition pcmk_fence.c:32
char * name
Definition pcmk_fence.c:31
int delay
Definition pcmk_fence.c:34
unsigned int tolerance
Definition pcmk_fence.c:33
stonith_t * st
Definition pcmk_fence.c:28
const char * action
Definition pcmk_fence.c:30
#define ELIBACC
const char * stonith_namespace2text(enum stonith_namespace st_namespace)
Get agent namespace name.
Definition st_client.c:157
struct stonith_api_operations_s stonith_api_operations_t
time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress)
Definition st_client.c:2286
struct stonith_callback_data_s stonith_callback_data_t
enum stonith_namespace stonith_get_namespace(const char *agent, const char *namespace_s)
Determine namespace of a fence agent.
Definition st_client.c:178
struct stonith_key_value_s stonith_key_value_t
void stonith_history_free(stonith_history_t *history)
Definition st_client.c:1158
#define STONITH_LIBRARY
Definition stonith-ng.h:502
enum stonith_namespace stonith_text2namespace(const char *namespace_s)
Get agent namespace by name.
Definition st_client.c:131
stonith_call_options
Definition stonith-ng.h:47
@ st_opt_scope_local
Definition stonith-ng.h:56
@ st_opt_cleanup
Definition stonith-ng.h:65
@ st_opt_timeout_updates
Definition stonith-ng.h:61
@ st_opt_broadcast
Definition stonith-ng.h:67
@ st_opt_cs_nodeid
Definition stonith-ng.h:57
@ st_opt_discard_reply
Definition stonith-ng.h:53
@ st_opt_manual_ack
Definition stonith-ng.h:52
@ st_opt_allow_suicide
Definition stonith-ng.h:50
@ st_opt_verbose
Definition stonith-ng.h:49
@ st_opt_report_only_success
Definition stonith-ng.h:63
@ st_opt_none
Definition stonith-ng.h:48
@ st_opt_topology
Definition stonith-ng.h:55
@ st_opt_sync_call
Definition stonith-ng.h:58
const char * stonith_action_str(const char *action)
Turn stonith action into a more readable string.
Definition st_client.c:2381
stonith_namespace
Definition stonith-ng.h:81
@ st_namespace_invalid
Definition stonith-ng.h:82
@ st_namespace_rhcs
Definition stonith-ng.h:89
@ st_namespace_internal
Definition stonith-ng.h:84
@ st_namespace_any
Definition stonith-ng.h:83
@ st_namespace_lha
Definition stonith-ng.h:90
bool stonith_dispatch(stonith_t *st)
Definition st_client.c:1953
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:2175
time_t(* st_api_time_fn)(int nodeid, const char *uname, bool in_progress)
Definition stonith-ng.h:505
int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off)
Definition st_client.c:2244
const char * get_stonith_provider(const char *agent, const char *provider)
Definition st_client.c:2703
stonith_state
Definition stonith-ng.h:41
@ stonith_disconnected
Definition stonith-ng.h:44
@ stonith_connected_command
Definition stonith-ng.h:42
@ stonith_connected_query
Definition stonith-ng.h:43
void stonith_key_value_freeall(stonith_key_value_t *kvp, int keys, int values)
Definition st_client.c:2223
struct stonith_history_s stonith_history_t
op_state
Definition stonith-ng.h:72
@ st_duplicate
Definition stonith-ng.h:76
@ st_query
Definition stonith-ng.h:73
@ st_failed
Definition stonith-ng.h:77
@ st_done
Definition stonith-ng.h:75
@ st_exec
Definition stonith-ng.h:74
void stonith_api_delete(stonith_t *st)
Definition st_client.c:2011
struct stonith_event_s stonith_event_t
stonith_t * stonith_api_new(void)
Definition st_client.c:2097
int(* st_api_kick_fn)(int nodeid, const char *uname, int timeout, bool off)
Definition stonith-ng.h:504
bool stonith_agent_exists(const char *agent, int timeout)
Definition st_client.c:2350
void stonith_dump_pending_callbacks(stonith_t *st)
Definition st_client.c:1702
const char * stonith_op_state_str(enum op_state state)
Return string equivalent of an operation state value.
Definition st_client.c:2612
stonith_key_value_t * stonith_key_value_add(stonith_key_value_t *kvp, const char *key, const char *value)
Definition st_client.c:2196
int(* fence_with_delay)(stonith_t *st, int options, const char *node, const char *action, int timeout, int tolerance, int delay)
Issue a fencing action against a node with requested fencing delay.
Definition stonith-ng.h:418
int(* free)(stonith_t *st)
Destroy the stonith api structure.
Definition stonith-ng.h:149
int(* register_level_full)(stonith_t *st, int options, const char *node, const char *pattern, const char *attr, const char *value, int level, stonith_key_value_t *device_list)
Register fencing level for specific node, node regex or attribute.
Definition stonith-ng.h:373
int(* remove_callback)(stonith_t *st, int call_id, bool all_callbacks)
Remove a registered callback for a given call id.
Definition stonith-ng.h:336
int(* register_level)(stonith_t *st, int options, const char *node, int level, stonith_key_value_t *device_list)
Register a fencing level containing the fencing devices to be used at that level for a specific node.
Definition stonith-ng.h:206
int(* status)(stonith_t *st, int options, const char *id, const char *port, int timeout)
Check to see if a local stonith device's port is reachable.
Definition stonith-ng.h:255
int(* metadata)(stonith_t *st, int options, const char *device, const char *provider, char **output, int timeout)
Get the metadata documentation for a resource.
Definition stonith-ng.h:217
int(* fence)(stonith_t *st, int options, const char *node, const char *action, int timeout, int tolerance)
Issue a fencing action against a node.
Definition stonith-ng.h:284
int(* register_notification)(stonith_t *st, const char *event, void(*notify)(stonith_t *st, stonith_event_t *e))
Definition stonith-ng.h:303
int(* connect)(stonith_t *st, const char *name, int *stonith_fd)
Connect to the local stonith daemon.
Definition stonith-ng.h:157
int(* register_callback)(stonith_t *st, int call_id, int timeout, int options, void *userdata, const char *callback_name, void(*callback)(stonith_t *st, stonith_callback_data_t *data))
Register a callback to receive the result of an asynchronous call.
Definition stonith-ng.h:325
int(* list_agents)(stonith_t *stonith, int call_options, const char *provider, stonith_key_value_t **devices, int timeout)
Retrieve a list of installed stonith agents.
Definition stonith-ng.h:230
int(* register_device)(stonith_t *st, int options, const char *id, const char *provider, const char *agent, stonith_key_value_t *params)
Register a stonith device with the local stonith daemon.
Definition stonith-ng.h:186
int(* remove_level)(stonith_t *st, int options, const char *node, int level)
Remove a fencing level for a specific node.
Definition stonith-ng.h:196
int(* list)(stonith_t *st, int options, const char *id, char **list_output, int timeout)
Retrieve string listing hosts and port assignments from a local stonith device.
Definition stonith-ng.h:239
int(* query)(stonith_t *st, int options, const char *node, stonith_key_value_t **devices, int timeout)
Retrieve a list of registered stonith devices.
Definition stonith-ng.h:266
int(* disconnect)(stonith_t *st)
Disconnect from the local stonith daemon.
Definition stonith-ng.h:165
int(* validate)(stonith_t *st, int call_options, const char *rsc_id, const char *namespace_s, const char *agent, stonith_key_value_t *params, int timeout, char **output, char **error_output)
Validate an arbitrary stonith device configuration.
Definition stonith-ng.h:396
int(* remove_level_full)(stonith_t *st, int options, const char *node, const char *pattern, const char *attr, const char *value, int level)
Remove fencing level for specific node, node regex or attribute.
Definition stonith-ng.h:353
int(* monitor)(stonith_t *st, int options, const char *id, int timeout)
Check to see if a local stonith device is reachable.
Definition stonith-ng.h:247
int(* history)(stonith_t *st, int options, const char *node, stonith_history_t **output, int timeout)
Retrieve a list of fencing operations that have occurred for a specific node.
Definition stonith-ng.h:301
int(* remove_notification)(stonith_t *st, const char *event)
Definition stonith-ng.h:306
int(* confirm)(stonith_t *st, int options, const char *node)
Manually confirm that a node is down.
Definition stonith-ng.h:293
int(* remove_device)(stonith_t *st, int options, const char *name)
Remove a registered stonith device with the local stonith daemon.
Definition stonith-ng.h:175
char * client_origin
Definition stonith-ng.h:133
struct stonith_history_s * next
Definition stonith-ng.h:112
struct stonith_key_value_s * next
Definition stonith-ng.h:101
enum stonith_state state
Definition stonith-ng.h:425
void * st_private
Definition stonith-ng.h:429
int call_timeout
Definition stonith-ng.h:428
stonith_api_operations_t * cmds
Definition stonith-ng.h:431