pacemaker  1.1.18-7fdfbbe
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups 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 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 
153  stonith_t *st, int options, const char *name);
154 
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 
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 
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 
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 {
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
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:247
struct stonith_history_s * next
Definition: stonith-ng.h:88
int(* register_notification)(stonith_t *st, const char *event, void(*notify)(stonith_t *st, stonith_event_t *e))
Definition: stonith-ng.h:286
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:355
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
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:198
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
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:284
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:187
struct stonith_history_s stonith_history_t
struct stonith_key_value_s * next
Definition: stonith-ng.h:77
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:228
int(* free)(stonith_t *st)
Destroy the stonith api structure.
Definition: stonith-ng.h:126
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:220
int(* confirm)(stonith_t *st, int options, const char *node)
Manually confirm that a node is down.
Definition: stonith-ng.h:274
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
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:316
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:305
uint32_t id
Definition: internal.h:48
enum stonith_state state
Definition: stonith-ng.h:364
op_state
Definition: stonith-ng.h:65
char * message
Definition: stonith-ng.h:98
int(* status)(stonith_t *st, int options, const char *id, const char *port, int timeout)
Check to see if a local stonith device&#39;s port is reachable.
Definition: stonith-ng.h:236
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:175
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(* 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:334
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
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:265
stonith_api_operations_t * cmds
Definition: stonith-ng.h:370
char * executioner
Definition: stonith-ng.h:105
int(* connect)(stonith_t *st, const char *name, int *stonith_fd)
Connect to the local stonith daemon.
Definition: stonith-ng.h:134
char * operation
Definition: stonith-ng.h:99
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:152
#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:142
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(* 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:163
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:211
int call_id
Definition: stonith-ng.h:366
int(* remove_notification)(stonith_t *st, const char *event)
Definition: stonith-ng.h:289