pacemaker  1.1.14-70404b0
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 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 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 <stdbool.h>
30 
31 /* TO-DO: Work out how to drop this requirement */
32 # include <libxml/tree.h>
33 
34 # define T_STONITH_NOTIFY_DISCONNECT "st_notify_disconnect"
35 # define T_STONITH_NOTIFY_FENCE "st_notify_fence"
36 
37 /* *INDENT-OFF* */
42 };
43 
45  st_opt_none = 0x00000000,
46  st_opt_verbose = 0x00000001,
47  st_opt_allow_suicide = 0x00000002,
48 
49  st_opt_manual_ack = 0x00000008,
50  st_opt_discard_reply = 0x00000010,
51 /* st_opt_all_replies = 0x00000020, */
52  st_opt_topology = 0x00000040,
53  st_opt_scope_local = 0x00000100,
54  st_opt_cs_nodeid = 0x00000200,
55  st_opt_sync_call = 0x00001000,
58  st_opt_timeout_updates = 0x00002000,
61 };
62 
65 {
71 };
72 
73 typedef struct stonith_key_value_s {
74  char *key;
75  char *value;
78 
79 typedef struct stonith_history_s {
80  char *target;
81  char *action;
82  char *origin;
83  char *delegate;
84  int completed;
85  int state;
86 
88  char *client;
90 
91 typedef struct stonith_s stonith_t;
92 
93 typedef struct stonith_event_s
94 {
95  char *id;
96  char *type;
97  char *message;
98  char *operation;
99 
100  int result;
101  char *origin;
102  char *target;
103  char *action;
104  char *executioner;
105 
106  char *device;
107 
110 
112 
114 {
115  int rc;
116  int call_id;
117  void *userdata;
119 
121 {
125  int (*free) (stonith_t *st);
126 
133  int (*connect) (stonith_t *st, const char *name, int *stonith_fd);
134 
141  int (*disconnect)(stonith_t *st);
142 
152  stonith_t *st, int options, const char *name);
153 
163  stonith_t *st, int options, const char *id,
164  const char *namespace, const char *agent, stonith_key_value_t *params);
165 
174  int (*remove_level)(
175  stonith_t *st, int options, const char *node, int level);
176 
187  stonith_t *st, int options, const char *node, int level, stonith_key_value_t *device_list);
188 
197  int (*metadata)(stonith_t *st, int options,
198  const char *device, const char *namespace, char **output, int timeout);
199 
210  int (*list_agents)(stonith_t *stonith, int call_options, const char *namespace,
211  stonith_key_value_t **devices, int timeout);
212 
219  int (*list)(stonith_t *st, int options, const char *id, char **list_output, int timeout);
220 
227  int (*monitor)(stonith_t *st, int options, const char *id, int timeout);
228 
235  int (*status)(stonith_t *st, int options, const char *id, const char *port, int timeout);
236 
246  int (*query)(stonith_t *st, int options, const char *node,
247  stonith_key_value_t **devices, int timeout);
248 
264  int (*fence)(stonith_t *st, int options, const char *node, const char *action,
265  int timeout, int tolerance);
266 
273  int (*confirm)(stonith_t *st, int options, const char *node);
274 
283  int (*history)(stonith_t *st, int options, const char *node, stonith_history_t **output, int timeout);
284 
286  stonith_t *st, const char *event,
287  void (*notify)(stonith_t *st, stonith_event_t *e));
288  int (*remove_notification)(stonith_t *st, const char *event);
289 
305  int call_id,
306  int timeout,
307  int options,
308  void *userdata,
309  const char *callback_name,
310  void (*callback)(stonith_t *st, stonith_callback_data_t *data));
311 
315  int (*remove_callback)(stonith_t *st, int call_id, bool all_callbacks);
316 
333  int (*remove_level_full)(stonith_t *st, int options,
334  const char *node, const char *pattern,
335  const char *attr, const char *value, int level);
336 
354  int (*register_level_full)(stonith_t *st, int options,
355  const char *node, const char *pattern,
356  const char *attr, const char *value,
357  int level, stonith_key_value_t *device_list);
358 
360 
361 struct stonith_s
362 {
364 
365  int call_id;
367  void *private;
368 
370 };
371 /* *INDENT-ON* */
372 
373 /* Core functions */
375 void stonith_api_delete(stonith_t * st);
376 
378 
379 const char *get_stonith_provider(const char *agent, const char *provider);
380 
381 bool stonith_dispatch(stonith_t * st);
382 
384  const char *value);
385 void stonith_key_value_freeall(stonith_key_value_t * kvp, int keys, int values);
386 
387 /* Basic helpers that allows nodes to be fenced and the history to be
388  * queried without mainloop or the caller understanding the full API
389  *
390  * At least one of nodeid and uname are required
391  */
392 int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off);
393 time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress);
394 
395 /*
396  * Helpers for using the above functions without install-time dependencies
397  *
398  * Usage:
399  * #include <crm/stonith-ng.h>
400  *
401  * To turn a node off by corosync nodeid:
402  * stonith_api_kick_helper(nodeid, 120, 1);
403  *
404  * To check the last fence date/time (also by nodeid):
405  * last = stonith_api_time_helper(nodeid, 0);
406  *
407  * To check if fencing is in progress:
408  * if(stonith_api_time_helper(nodeid, 1) > 0) { ... }
409  *
410  * eg.
411 
412  #include <stdio.h>
413  #include <time.h>
414  #include <crm/stonith-ng.h>
415  int
416  main(int argc, char ** argv)
417  {
418  int rc = 0;
419  int nodeid = 102;
420 
421  rc = stonith_api_time_helper(nodeid, 0);
422  printf("%d last fenced at %s\n", nodeid, ctime(rc));
423 
424  rc = stonith_api_kick_helper(nodeid, 120, 1);
425  printf("%d fence result: %d\n", nodeid, rc);
426 
427  rc = stonith_api_time_helper(nodeid, 0);
428  printf("%d last fenced at %s\n", nodeid, ctime(rc));
429 
430  return 0;
431  }
432 
433  */
434 
435 # define STONITH_LIBRARY "libstonithd.so.2"
436 
437 static inline int
438 stonith_api_kick_helper(uint32_t nodeid, int timeout, bool off)
439 {
440  static void *st_library = NULL;
441  static int (*st_kick_fn) (int nodeid, const char *uname, int timeout, bool off) = NULL;
442 
443  if (st_library == NULL) {
444  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
445  }
446  if (st_library && st_kick_fn == NULL) {
447  st_kick_fn = dlsym(st_library, "stonith_api_kick");
448  }
449  if (st_kick_fn == NULL) {
450  return -ELIBACC;
451  }
452 
453  return (*st_kick_fn) (nodeid, NULL, timeout, off);
454 }
455 
456 static inline time_t
457 stonith_api_time_helper(uint32_t nodeid, bool in_progress)
458 {
459  static void *st_library = NULL;
460  static time_t(*st_time_fn) (int nodeid, const char *uname, bool in_progress) = NULL;
461 
462  if (st_library == NULL) {
463  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
464  }
465  if (st_library && st_time_fn == NULL) {
466  st_time_fn = dlsym(st_library, "stonith_api_time");
467  }
468  if (st_time_fn == NULL) {
469  return 0;
470  }
471 
472  return (*st_time_fn) (nodeid, NULL, in_progress);
473 }
474 
475 #endif
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:246
struct stonith_history_s * next
Definition: stonith-ng.h:87
int(* register_notification)(stonith_t *st, const char *event, void(*notify)(stonith_t *st, stonith_event_t *e))
Definition: stonith-ng.h:285
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:354
const char * get_stonith_provider(const char *agent, const char *provider)
Definition: st_client.c:1609
struct stonith_api_operations_s stonith_api_operations_t
int(* metadata)(stonith_t *st, int options, const char *device, const char *namespace, char **output, int timeout)
Get the metadata documentation for a resource.
Definition: stonith-ng.h:197
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:2562
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:283
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:186
struct stonith_history_s stonith_history_t
struct stonith_key_value_s * next
Definition: stonith-ng.h:76
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:227
int(* free)(stonith_t *st)
Destroy the stonith api structure.
Definition: stonith-ng.h:125
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:219
int(* confirm)(stonith_t *st, int options, const char *node)
Manually confirm that a node is down.
Definition: stonith-ng.h:273
bool stonith_dispatch(stonith_t *st)
Definition: st_client.c:2350
stonith_t * stonith_api_new(void)
Definition: st_client.c:2462
stonith_key_value_t * stonith_key_value_add(stonith_key_value_t *kvp, const char *key, const char *value)
Definition: st_client.c:2514
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:315
char uname[MAX_NAME]
Definition: internal.h:53
struct stonith_callback_data_s stonith_callback_data_t
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 async call id.
Definition: stonith-ng.h:304
uint32_t id
Definition: internal.h:48
enum stonith_state state
Definition: stonith-ng.h:363
op_state
Definition: stonith-ng.h:64
char * message
Definition: stonith-ng.h:97
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:235
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:174
void stonith_key_value_freeall(stonith_key_value_t *kvp, int keys, int values)
Definition: st_client.c:2541
void stonith_dump_pending_callbacks(stonith_t *st)
Definition: st_client.c:2070
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:333
int call_timeout
Definition: stonith-ng.h:366
stonith_state
Definition: stonith-ng.h:38
#define ELIBACC
Definition: portability.h:235
stonith_call_options
Definition: stonith-ng.h:44
char * client_origin
Definition: stonith-ng.h:109
void stonith_api_delete(stonith_t *st)
Definition: st_client.c:2453
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:264
stonith_api_operations_t * cmds
Definition: stonith-ng.h:369
char * executioner
Definition: stonith-ng.h:104
int(* connect)(stonith_t *st, const char *name, int *stonith_fd)
Connect to the local stonith daemon.
Definition: stonith-ng.h:133
char * operation
Definition: stonith-ng.h:98
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:151
#define uint32_t
Definition: stdint.in.h:158
struct stonith_event_s stonith_event_t
char data[0]
Definition: internal.h:58
int(* disconnect)(stonith_t *st)
Disconnect from the local stonith daemon.
Definition: stonith-ng.h:141
time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress)
Definition: st_client.c:2611
#define STONITH_LIBRARY
Definition: stonith-ng.h:435
int(* register_device)(stonith_t *st, int options, const char *id, const char *namespace, const char *agent, stonith_key_value_t *params)
Register a stonith device with the local stonith daemon.
Definition: stonith-ng.h:162
int(* list_agents)(stonith_t *stonith, int call_options, const char *namespace, stonith_key_value_t **devices, int timeout)
Retrieve a list of installed stonith agents.
Definition: stonith-ng.h:210
int call_id
Definition: stonith-ng.h:365
int(* remove_notification)(stonith_t *st, const char *event)
Definition: stonith-ng.h:288