pacemaker  1.1.18-2b07d5c5a9
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 typedef struct stonith_key_value_s {
75  char *key;
76  char *value;
79 
80 typedef struct stonith_history_s {
81  char *target;
82  char *action;
83  char *origin;
84  char *delegate;
85  int completed;
86  int state;
87 
89  char *client;
91 
92 typedef struct stonith_s stonith_t;
93 
94 typedef struct stonith_event_s
95 {
96  char *id;
97  char *type;
98  char *message;
99  char *operation;
100 
101  int result;
102  char *origin;
103  char *target;
104  char *action;
105  char *executioner;
106 
107  char *device;
108 
111 
113 
115 {
116  int rc;
117  int call_id;
118  void *userdata;
120 
122 {
126  int (*free) (stonith_t *st);
127 
134  int (*connect) (stonith_t *st, const char *name, int *stonith_fd);
135 
142  int (*disconnect)(stonith_t *st);
143 
152  int (*remove_device)(
153  stonith_t *st, int options, const char *name);
154 
163  int (*register_device)(
164  stonith_t *st, int options, const char *id,
165  const char *namespace, const char *agent, stonith_key_value_t *params);
166 
175  int (*remove_level)(
176  stonith_t *st, int options, const char *node, int level);
177 
187  int (*register_level)(
188  stonith_t *st, int options, const char *node, int level, stonith_key_value_t *device_list);
189 
198  int (*metadata)(stonith_t *st, int options,
199  const char *device, const char *namespace, char **output, int timeout);
200 
211  int (*list_agents)(stonith_t *stonith, int call_options, const char *namespace,
212  stonith_key_value_t **devices, int timeout);
213 
220  int (*list)(stonith_t *st, int options, const char *id, char **list_output, int timeout);
221 
228  int (*monitor)(stonith_t *st, int options, const char *id, int timeout);
229 
236  int (*status)(stonith_t *st, int options, const char *id, const char *port, int timeout);
237 
247  int (*query)(stonith_t *st, int options, const char *node,
248  stonith_key_value_t **devices, int timeout);
249 
265  int (*fence)(stonith_t *st, int options, const char *node, const char *action,
266  int timeout, int tolerance);
267 
274  int (*confirm)(stonith_t *st, int options, const char *node);
275 
284  int (*history)(stonith_t *st, int options, const char *node, stonith_history_t **output, int timeout);
285 
286  int (*register_notification)(
287  stonith_t *st, const char *event,
288  void (*notify)(stonith_t *st, stonith_event_t *e));
289  int (*remove_notification)(stonith_t *st, const char *event);
290 
305  int (*register_callback)(stonith_t *st,
306  int call_id,
307  int timeout,
308  int options,
309  void *userdata,
310  const char *callback_name,
311  void (*callback)(stonith_t *st, stonith_callback_data_t *data));
312 
316  int (*remove_callback)(stonith_t *st, int call_id, bool all_callbacks);
317 
334  int (*remove_level_full)(stonith_t *st, int options,
335  const char *node, const char *pattern,
336  const char *attr, const char *value, int level);
337 
355  int (*register_level_full)(stonith_t *st, int options,
356  const char *node, const char *pattern,
357  const char *attr, const char *value,
358  int level, stonith_key_value_t *device_list);
359 
361 
362 struct stonith_s
363 {
364  enum stonith_state state;
365 
366  int call_id;
368  void *private;
369 
371 };
372 /* *INDENT-ON* */
373 
374 /* Core functions */
376 void stonith_api_delete(stonith_t * st);
377 
379 
380 const char *get_stonith_provider(const char *agent, const char *provider);
381 
382 bool stonith_dispatch(stonith_t * st);
383 
385  const char *value);
386 void stonith_key_value_freeall(stonith_key_value_t * kvp, int keys, int values);
387 
388 /* Basic helpers that allows nodes to be fenced and the history to be
389  * queried without mainloop or the caller understanding the full API
390  *
391  * At least one of nodeid and uname are required
392  */
393 int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off);
394 time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress);
395 
396 /*
397  * Helpers for using the above functions without install-time dependencies
398  *
399  * Usage:
400  * #include <crm/stonith-ng.h>
401  *
402  * To turn a node off by corosync nodeid:
403  * stonith_api_kick_helper(nodeid, 120, 1);
404  *
405  * To check the last fence date/time (also by nodeid):
406  * last = stonith_api_time_helper(nodeid, 0);
407  *
408  * To check if fencing is in progress:
409  * if(stonith_api_time_helper(nodeid, 1) > 0) { ... }
410  *
411  * eg.
412 
413  #include <stdio.h>
414  #include <time.h>
415  #include <crm/stonith-ng.h>
416  int
417  main(int argc, char ** argv)
418  {
419  int rc = 0;
420  int nodeid = 102;
421 
422  rc = stonith_api_time_helper(nodeid, 0);
423  printf("%d last fenced at %s\n", nodeid, ctime(rc));
424 
425  rc = stonith_api_kick_helper(nodeid, 120, 1);
426  printf("%d fence result: %d\n", nodeid, rc);
427 
428  rc = stonith_api_time_helper(nodeid, 0);
429  printf("%d last fenced at %s\n", nodeid, ctime(rc));
430 
431  return 0;
432  }
433 
434  */
435 
436 # define STONITH_LIBRARY "libstonithd.so.2"
437 
438 static inline int
439 stonith_api_kick_helper(uint32_t nodeid, int timeout, bool off)
440 {
441  static void *st_library = NULL;
442  static int (*st_kick_fn) (int nodeid, const char *uname, int timeout, bool off) = NULL;
443 
444  if (st_library == NULL) {
445  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
446  }
447  if (st_library && st_kick_fn == NULL) {
448  st_kick_fn = dlsym(st_library, "stonith_api_kick");
449  }
450  if (st_kick_fn == NULL) {
451 #ifdef ELIBACC
452  return -ELIBACC;
453 #else
454  return -ENOSYS;
455 #endif
456  }
457 
458  return (*st_kick_fn) (nodeid, NULL, timeout, off);
459 }
460 
461 static inline time_t
462 stonith_api_time_helper(uint32_t nodeid, bool in_progress)
463 {
464  static void *st_library = NULL;
465  static time_t(*st_time_fn) (int nodeid, const char *uname, bool in_progress) = NULL;
466 
467  if (st_library == NULL) {
468  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
469  }
470  if (st_library && st_time_fn == NULL) {
471  st_time_fn = dlsym(st_library, "stonith_api_time");
472  }
473  if (st_time_fn == NULL) {
474  return 0;
475  }
476 
477  return (*st_time_fn) (nodeid, NULL, in_progress);
478 }
479 
480 #endif
struct stonith_history_s * next
Definition: stonith-ng.h:88
const char * get_stonith_provider(const char *agent, const char *provider)
Definition: st_client.c:1599
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:2552
struct stonith_history_s stonith_history_t
struct stonith_key_value_s * next
Definition: stonith-ng.h:77
bool stonith_dispatch(stonith_t *st)
Definition: st_client.c:2340
stonith_t * stonith_api_new(void)
Definition: st_client.c:2452
stonith_key_value_t * stonith_key_value_add(stonith_key_value_t *kvp, const char *key, const char *value)
Definition: st_client.c:2504
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
char * message
Definition: stonith-ng.h:98
void stonith_key_value_freeall(stonith_key_value_t *kvp, int keys, int values)
Definition: st_client.c:2531
void stonith_dump_pending_callbacks(stonith_t *st)
Definition: st_client.c:2060
int call_timeout
Definition: stonith-ng.h:367
stonith_state
Definition: stonith-ng.h:39
#define ELIBACC
Definition: portability.h:237
stonith_call_options
Definition: stonith-ng.h:45
char * client_origin
Definition: stonith-ng.h:110
void stonith_api_delete(stonith_t *st)
Definition: st_client.c:2443
stonith_api_operations_t * cmds
Definition: stonith-ng.h:370
char * executioner
Definition: stonith-ng.h:105
char * operation
Definition: stonith-ng.h:99
#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:2601
#define STONITH_LIBRARY
Definition: stonith-ng.h:436
int call_id
Definition: stonith-ng.h:366