pacemaker  1.1.19-c3c624ea3d
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 
38 /* *INDENT-OFF* */
43 };
44 
46  st_opt_none = 0x00000000,
47  st_opt_verbose = 0x00000001,
48  st_opt_allow_suicide = 0x00000002,
49 
50  st_opt_manual_ack = 0x00000008,
51  st_opt_discard_reply = 0x00000010,
52 /* st_opt_all_replies = 0x00000020, */
53  st_opt_topology = 0x00000040,
54  st_opt_scope_local = 0x00000100,
55  st_opt_cs_nodeid = 0x00000200,
56  st_opt_sync_call = 0x00001000,
59  st_opt_timeout_updates = 0x00002000,
62 };
63 
66 {
72 };
73 
74 // Supported fence agent interface standards
78  st_namespace_internal, // Implemented internally by Pacemaker
79 
80  /* Neither of these projects are active any longer, but the fence agent
81  * interfaces they created are still in use and supported by Pacemaker.
82  */
83  st_namespace_rhcs, // Red Hat Cluster Suite compatible
84  st_namespace_lha, // Linux-HA compatible
85 };
86 
87 enum stonith_namespace stonith_text2namespace(const char *namespace_s);
88 const char *stonith_namespace2text(enum stonith_namespace namespace);
89 enum stonith_namespace stonith_get_namespace(const char *agent,
90  const char *namespace_s);
91 
92 typedef struct stonith_key_value_s {
93  char *key;
94  char *value;
97 
98 typedef struct stonith_history_s {
99  char *target;
100  char *action;
101  char *origin;
102  char *delegate;
104  int state;
105 
107  char *client;
109 
110 typedef struct stonith_s stonith_t;
111 
112 typedef struct stonith_event_s
113 {
114  char *id;
115  char *type;
116  char *message;
117  char *operation;
118 
119  int result;
120  char *origin;
121  char *target;
122  char *action;
123  char *executioner;
124 
125  char *device;
126 
129 
131 
133 {
134  int rc;
135  int call_id;
136  void *userdata;
138 
140 {
144  int (*free) (stonith_t *st);
145 
152  int (*connect) (stonith_t *st, const char *name, int *stonith_fd);
153 
160  int (*disconnect)(stonith_t *st);
161 
170  int (*remove_device)(
171  stonith_t *st, int options, const char *name);
172 
181  int (*register_device)(
182  stonith_t *st, int options, const char *id,
183  const char *namespace, const char *agent, stonith_key_value_t *params);
184 
193  int (*remove_level)(
194  stonith_t *st, int options, const char *node, int level);
195 
205  int (*register_level)(
206  stonith_t *st, int options, const char *node, int level, stonith_key_value_t *device_list);
207 
216  int (*metadata)(stonith_t *st, int options,
217  const char *device, const char *namespace, char **output, int timeout);
218 
229  int (*list_agents)(stonith_t *stonith, int call_options, const char *namespace,
230  stonith_key_value_t **devices, int timeout);
231 
238  int (*list)(stonith_t *st, int options, const char *id, char **list_output, int timeout);
239 
246  int (*monitor)(stonith_t *st, int options, const char *id, int timeout);
247 
254  int (*status)(stonith_t *st, int options, const char *id, const char *port, int timeout);
255 
265  int (*query)(stonith_t *st, int options, const char *node,
266  stonith_key_value_t **devices, int timeout);
267 
283  int (*fence)(stonith_t *st, int options, const char *node, const char *action,
284  int timeout, int tolerance);
285 
292  int (*confirm)(stonith_t *st, int options, const char *node);
293 
302  int (*history)(stonith_t *st, int options, const char *node, stonith_history_t **output, int timeout);
303 
304  int (*register_notification)(
305  stonith_t *st, const char *event,
306  void (*notify)(stonith_t *st, stonith_event_t *e));
307  int (*remove_notification)(stonith_t *st, const char *event);
308 
323  int (*register_callback)(stonith_t *st,
324  int call_id,
325  int timeout,
326  int options,
327  void *userdata,
328  const char *callback_name,
329  void (*callback)(stonith_t *st, stonith_callback_data_t *data));
330 
334  int (*remove_callback)(stonith_t *st, int call_id, bool all_callbacks);
335 
352  int (*remove_level_full)(stonith_t *st, int options,
353  const char *node, const char *pattern,
354  const char *attr, const char *value, int level);
355 
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 
402 
403 struct stonith_s
404 {
405  enum stonith_state state;
406 
407  int call_id;
409  void *private;
410 
412 };
413 /* *INDENT-ON* */
414 
415 /* Core functions */
417 void stonith_api_delete(stonith_t * st);
418 
420 
421 // deprecated (use stonith_get_namespace() instead)
422 const char *get_stonith_provider(const char *agent, const char *provider);
423 
424 bool stonith_dispatch(stonith_t * st);
425 
427  const char *value);
428 void stonith_key_value_freeall(stonith_key_value_t * kvp, int keys, int values);
429 
431 
432 /* Basic helpers that allows nodes to be fenced and the history to be
433  * queried without mainloop or the caller understanding the full API
434  *
435  * At least one of nodeid and uname are required
436  */
437 int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off);
438 time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress);
439 
440 /*
441  * Helpers for using the above functions without install-time dependencies
442  *
443  * Usage:
444  * #include <crm/stonith-ng.h>
445  *
446  * To turn a node off by corosync nodeid:
447  * stonith_api_kick_helper(nodeid, 120, 1);
448  *
449  * To check the last fence date/time (also by nodeid):
450  * last = stonith_api_time_helper(nodeid, 0);
451  *
452  * To check if fencing is in progress:
453  * if(stonith_api_time_helper(nodeid, 1) > 0) { ... }
454  *
455  * eg.
456 
457  #include <stdio.h>
458  #include <time.h>
459  #include <crm/stonith-ng.h>
460  int
461  main(int argc, char ** argv)
462  {
463  int rc = 0;
464  int nodeid = 102;
465 
466  rc = stonith_api_time_helper(nodeid, 0);
467  printf("%d last fenced at %s\n", nodeid, ctime(rc));
468 
469  rc = stonith_api_kick_helper(nodeid, 120, 1);
470  printf("%d fence result: %d\n", nodeid, rc);
471 
472  rc = stonith_api_time_helper(nodeid, 0);
473  printf("%d last fenced at %s\n", nodeid, ctime(rc));
474 
475  return 0;
476  }
477 
478  */
479 
480 # define STONITH_LIBRARY "libstonithd.so.2"
481 
482 static inline int
483 stonith_api_kick_helper(uint32_t nodeid, int timeout, bool off)
484 {
485  static void *st_library = NULL;
486  static int (*st_kick_fn) (int nodeid, const char *uname, int timeout, bool off) = NULL;
487 
488  if (st_library == NULL) {
489  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
490  }
491  if (st_library && st_kick_fn == NULL) {
492  st_kick_fn = dlsym(st_library, "stonith_api_kick");
493  }
494  if (st_kick_fn == NULL) {
495 #ifdef ELIBACC
496  return -ELIBACC;
497 #else
498  return -ENOSYS;
499 #endif
500  }
501 
502  return (*st_kick_fn) (nodeid, NULL, timeout, off);
503 }
504 
505 static inline time_t
506 stonith_api_time_helper(uint32_t nodeid, bool in_progress)
507 {
508  static void *st_library = NULL;
509  static time_t(*st_time_fn) (int nodeid, const char *uname, bool in_progress) = NULL;
510 
511  if (st_library == NULL) {
512  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
513  }
514  if (st_library && st_time_fn == NULL) {
515  st_time_fn = dlsym(st_library, "stonith_api_time");
516  }
517  if (st_time_fn == NULL) {
518  return 0;
519  }
520 
521  return (*st_time_fn) (nodeid, NULL, in_progress);
522 }
523 
524 #endif
struct stonith_history_s * next
Definition: stonith-ng.h:106
const char * get_stonith_provider(const char *agent, const char *provider)
Deprecated (use stonith_get_namespace() instead)
Definition: st_client.c:1461
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:2454
const char * stonith_namespace2text(enum stonith_namespace namespace)
Get agent namespace name.
Definition: st_client.c:168
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:95
stonith_namespace
Definition: stonith-ng.h:75
bool stonith_dispatch(stonith_t *st)
Definition: st_client.c:2165
stonith_t * stonith_api_new(void)
Definition: st_client.c:2352
stonith_key_value_t * stonith_key_value_add(stonith_key_value_t *kvp, const char *key, const char *value)
Definition: st_client.c:2406
char uname[MAX_NAME]
Definition: internal.h:53
struct stonith_callback_data_s stonith_callback_data_t
uint32_t id
Definition: internal.h:48
op_state
Definition: stonith-ng.h:65
void stonith_key_value_freeall(stonith_key_value_t *kvp, int keys, int values)
Definition: st_client.c:2433
void stonith_dump_pending_callbacks(stonith_t *st)
Definition: st_client.c:1885
int call_timeout
Definition: stonith-ng.h:408
stonith_state
Definition: stonith-ng.h:39
#define ELIBACC
Definition: portability.h:230
stonith_call_options
Definition: stonith-ng.h:45
char * client_origin
Definition: stonith-ng.h:128
void stonith_api_delete(stonith_t *st)
Definition: st_client.c:2268
stonith_api_operations_t * cmds
Definition: stonith-ng.h:411
void stonith_history_free(stonith_history_t *history)
Definition: st_client.c:1444
char * executioner
Definition: stonith-ng.h:123
char * operation
Definition: stonith-ng.h:117
#define uint32_t
Definition: stdint.in.h:158
struct stonith_event_s stonith_event_t
char data[0]
Definition: internal.h:58
time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress)
Definition: st_client.c:2503
#define STONITH_LIBRARY
Definition: stonith-ng.h:480
enum stonith_namespace stonith_text2namespace(const char *namespace_s)
Get agent namespace by name.
Definition: st_client.c:142
int call_id
Definition: stonith-ng.h:407