pacemaker  1.1.24-3850484742
Scalable High-Availability cluster resource manager
stonith-ng.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2004 Andrew Beekhof <andrew@beekhof.net>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This software is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
25 #ifndef STONITH_NG__H
26 # define STONITH_NG__H
27 
28 # include <dlfcn.h>
29 # include <errno.h>
30 # include <stdbool.h>
31 
32 /* TO-DO: Work out how to drop this requirement */
33 # include <libxml/tree.h>
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;
110  int state;
111 
113  char *client;
115 
116 typedef struct stonith_s stonith_t;
117 
118 typedef struct stonith_event_s
119 {
120  char *id;
121  char *type;
122  char *message;
123  char *operation;
124 
125  int result;
126  char *origin;
127  char *target;
128  char *action;
129  char *executioner;
130 
131  char *device;
132 
135 
137 
139 {
140  int rc;
141  int call_id;
142  void *userdata;
144 
146 {
150  int (*free) (stonith_t *st);
151 
158  int (*connect) (stonith_t *st, const char *name, int *stonith_fd);
159 
166  int (*disconnect)(stonith_t *st);
167 
176  int (*remove_device)(
177  stonith_t *st, int options, const char *name);
178 
187  int (*register_device)(
188  stonith_t *st, int options, const char *id,
189  const char *namespace, const char *agent, stonith_key_value_t *params);
190 
199  int (*remove_level)(
200  stonith_t *st, int options, const char *node, int level);
201 
211  int (*register_level)(
212  stonith_t *st, int options, const char *node, int level, stonith_key_value_t *device_list);
213 
222  int (*metadata)(stonith_t *st, int options,
223  const char *device, const char *namespace, char **output, int timeout);
224 
235  int (*list_agents)(stonith_t *stonith, int call_options, const char *namespace,
236  stonith_key_value_t **devices, int timeout);
237 
244  int (*list)(stonith_t *st, int options, const char *id, char **list_output, int timeout);
245 
252  int (*monitor)(stonith_t *st, int options, const char *id, int timeout);
253 
260  int (*status)(stonith_t *st, int options, const char *id, const char *port, int timeout);
261 
271  int (*query)(stonith_t *st, int options, const char *node,
272  stonith_key_value_t **devices, int timeout);
273 
289  int (*fence)(stonith_t *st, int options, const char *node, const char *action,
290  int timeout, int tolerance);
291 
298  int (*confirm)(stonith_t *st, int options, const char *node);
299 
308  int (*history)(stonith_t *st, int options, const char *node, stonith_history_t **output, int timeout);
309 
310  int (*register_notification)(
311  stonith_t *st, const char *event,
312  void (*notify)(stonith_t *st, stonith_event_t *e));
313  int (*remove_notification)(stonith_t *st, const char *event);
314 
329  int (*register_callback)(stonith_t *st,
330  int call_id,
331  int timeout,
332  int options,
333  void *userdata,
334  const char *callback_name,
335  void (*callback)(stonith_t *st, stonith_callback_data_t *data));
336 
340  int (*remove_callback)(stonith_t *st, int call_id, bool all_callbacks);
341 
358  int (*remove_level_full)(stonith_t *st, int options,
359  const char *node, const char *pattern,
360  const char *attr, const char *value, int level);
361 
379  int (*register_level_full)(stonith_t *st, int options,
380  const char *node, const char *pattern,
381  const char *attr, const char *value,
382  int level, stonith_key_value_t *device_list);
383 
402  int (*validate)(stonith_t *st, int call_options, const char *rsc_id,
403  const char *namespace_s, const char *agent,
404  stonith_key_value_t *params, int timeout, char **output,
405  char **error_output);
406 
424  int (*fence_with_delay)(stonith_t *st, int options, const char *node, const char *action,
425  int timeout, int tolerance, int delay);
426 
428 
429 struct stonith_s
430 {
431  enum stonith_state state;
432 
433  int call_id;
435  void *private;
436 
438 };
439 /* *INDENT-ON* */
440 
441 /* Core functions */
443 void stonith_api_delete(stonith_t * st);
444 
446 
447 // deprecated (use stonith_get_namespace() instead)
448 const char *get_stonith_provider(const char *agent, const char *provider);
449 
450 bool stonith_dispatch(stonith_t * st);
451 
453  const char *value);
454 void stonith_key_value_freeall(stonith_key_value_t * kvp, int keys, int values);
455 
457 
458 /* Basic helpers that allows nodes to be fenced and the history to be
459  * queried without mainloop or the caller understanding the full API
460  *
461  * At least one of nodeid and uname are required
462  */
463 int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off);
464 time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress);
465 
466 /*
467  * Helpers for using the above functions without install-time dependencies
468  *
469  * Usage:
470  * #include <crm/stonith-ng.h>
471  *
472  * To turn a node off by corosync nodeid:
473  * stonith_api_kick_helper(nodeid, 120, 1);
474  *
475  * To check the last fence date/time (also by nodeid):
476  * last = stonith_api_time_helper(nodeid, 0);
477  *
478  * To check if fencing is in progress:
479  * if(stonith_api_time_helper(nodeid, 1) > 0) { ... }
480  *
481  * eg.
482 
483  #include <stdio.h>
484  #include <time.h>
485  #include <crm/stonith-ng.h>
486  int
487  main(int argc, char ** argv)
488  {
489  int rc = 0;
490  int nodeid = 102;
491 
492  rc = stonith_api_time_helper(nodeid, 0);
493  printf("%d last fenced at %s\n", nodeid, ctime(rc));
494 
495  rc = stonith_api_kick_helper(nodeid, 120, 1);
496  printf("%d fence result: %d\n", nodeid, rc);
497 
498  rc = stonith_api_time_helper(nodeid, 0);
499  printf("%d last fenced at %s\n", nodeid, ctime(rc));
500 
501  return 0;
502  }
503 
504  */
505 
506 # define STONITH_LIBRARY "libstonithd.so.2"
507 
508 static inline int
509 stonith_api_kick_helper(uint32_t nodeid, int timeout, bool off)
510 {
511  static void *st_library = NULL;
512  static int (*st_kick_fn) (int nodeid, const char *uname, int timeout, bool off) = NULL;
513 
514  if (st_library == NULL) {
515  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
516  }
517  if (st_library && st_kick_fn == NULL) {
518  st_kick_fn = dlsym(st_library, "stonith_api_kick");
519  }
520  if (st_kick_fn == NULL) {
521 #ifdef ELIBACC
522  return -ELIBACC;
523 #else
524  return -ENOSYS;
525 #endif
526  }
527 
528  return (*st_kick_fn) (nodeid, NULL, timeout, off);
529 }
530 
531 static inline time_t
532 stonith_api_time_helper(uint32_t nodeid, bool in_progress)
533 {
534  static void *st_library = NULL;
535  static time_t(*st_time_fn) (int nodeid, const char *uname, bool in_progress) = NULL;
536 
537  if (st_library == NULL) {
538  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
539  }
540  if (st_library && st_time_fn == NULL) {
541  st_time_fn = dlsym(st_library, "stonith_api_time");
542  }
543  if (st_time_fn == NULL) {
544  return 0;
545  }
546 
547  return (*st_time_fn) (nodeid, NULL, in_progress);
548 }
549 
550 #endif
struct stonith_history_s * next
Definition: stonith-ng.h:112
const char * get_stonith_provider(const char *agent, const char *provider)
Deprecated (use stonith_get_namespace() instead)
Definition: st_client.c:1291
struct stonith_api_operations_s stonith_api_operations_t
struct stonith_key_value_s stonith_key_value_t
int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off)
Definition: st_client.c:2313
struct stonith_history_s stonith_history_t
enum stonith_namespace stonith_get_namespace(const char *agent, const char *namespace_s)
Determine namespace of a fence agent.
Definition: st_client.c:189
struct stonith_key_value_s * next
Definition: stonith-ng.h:101
stonith_namespace
Definition: stonith-ng.h:81
bool stonith_dispatch(stonith_t *st)
Definition: st_client.c:2017
stonith_t * stonith_api_new(void)
Definition: st_client.c:2208
stonith_key_value_t * stonith_key_value_add(stonith_key_value_t *kvp, const char *key, const char *value)
Definition: st_client.c:2265
char uname[MAX_NAME]
Definition: internal.h:81
struct stonith_callback_data_s stonith_callback_data_t
uint32_t id
Definition: internal.h:76
op_state
Definition: stonith-ng.h:71
void stonith_key_value_freeall(stonith_key_value_t *kvp, int keys, int values)
Definition: st_client.c:2292
void stonith_dump_pending_callbacks(stonith_t *st)
Definition: st_client.c:1724
int call_timeout
Definition: stonith-ng.h:434
stonith_state
Definition: stonith-ng.h:41
#define ELIBACC
Definition: portability.h:230
stonith_call_options
Definition: stonith-ng.h:47
char * client_origin
Definition: stonith-ng.h:134
void stonith_api_delete(stonith_t *st)
Definition: st_client.c:2120
stonith_api_operations_t * cmds
Definition: stonith-ng.h:437
void stonith_history_free(stonith_history_t *history)
Definition: st_client.c:1274
char * executioner
Definition: stonith-ng.h:129
char * operation
Definition: stonith-ng.h:123
#define uint32_t
Definition: stdint.in.h:158
struct stonith_event_s stonith_event_t
char data[0]
Definition: internal.h:86
time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress)
Definition: st_client.c:2362
#define STONITH_LIBRARY
Definition: stonith-ng.h:506
enum stonith_namespace stonith_text2namespace(const char *namespace_s)
Get agent namespace by name.
Definition: st_client.c:142
const char * stonith_namespace2text(enum stonith_namespace st_namespace)
Get agent namespace name.
Definition: st_client.c:168
int call_id
Definition: stonith-ng.h:433