pacemaker  1.1.12-561c4cf
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 
63 #define stonith_default_options = stonith_none
64 
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 
319 
320 struct stonith_s
321 {
323 
324  int call_id;
326  void *private;
327 
329 };
330 /* *INDENT-ON* */
331 
332 /* Core functions */
334 void stonith_api_delete(stonith_t * st);
335 
337 
338 const char *get_stonith_provider(const char *agent, const char *provider);
339 
340 bool stonith_dispatch(stonith_t * st);
341 
343  const char *value);
344 void stonith_key_value_freeall(stonith_key_value_t * kvp, int keys, int values);
345 
346 /* Basic helpers that allows nodes to be fenced and the history to be
347  * queried without mainloop or the caller understanding the full API
348  *
349  * At least one of nodeid and uname are required
350  */
351 int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off);
352 time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress);
353 
354 /*
355  * Helpers for using the above functions without install-time dependancies
356  *
357  * Usage:
358  * #include <crm/stonith-ng.h>
359  *
360  * To turn a node off by corosync nodeid:
361  * stonith_api_kick_helper(nodeid, 120, 1);
362  *
363  * To check the last fence date/time (also by nodeid):
364  * last = stonith_api_time_helper(nodeid, 0);
365  *
366  * To check if fencing is in progress:
367  * if(stonith_api_time_helper(nodeid, 1) > 0) { ... }
368  *
369  * eg.
370 
371  #include <stdio.h>
372  #include <time.h>
373  #include <crm/stonith-ng.h>
374  int
375  main(int argc, char ** argv)
376  {
377  int rc = 0;
378  int nodeid = 102;
379 
380  rc = stonith_api_time_helper(nodeid, 0);
381  printf("%d last fenced at %s\n", nodeid, ctime(rc));
382 
383  rc = stonith_api_kick_helper(nodeid, 120, 1);
384  printf("%d fence result: %d\n", nodeid, rc);
385 
386  rc = stonith_api_time_helper(nodeid, 0);
387  printf("%d last fenced at %s\n", nodeid, ctime(rc));
388 
389  return 0;
390  }
391 
392  */
393 
394 # define STONITH_LIBRARY "libstonithd.so.2"
395 
396 static inline int
397 stonith_api_kick_helper(uint32_t nodeid, int timeout, bool off)
398 {
399  static void *st_library = NULL;
400  static int (*st_kick_fn) (int nodeid, const char *uname, int timeout, bool off) = NULL;
401 
402  if (st_library == NULL) {
403  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
404  }
405  if (st_library && st_kick_fn == NULL) {
406  st_kick_fn = dlsym(st_library, "stonith_api_kick");
407  }
408  if (st_kick_fn == NULL) {
409  return -ELIBACC;
410  }
411 
412  return (*st_kick_fn) (nodeid, NULL, timeout, off);
413 }
414 
415 static inline time_t
416 stonith_api_time_helper(uint32_t nodeid, bool in_progress)
417 {
418  static void *st_library = NULL;
419  static time_t(*st_time_fn) (int nodeid, const char *uname, bool in_progress) = NULL;
420 
421  if (st_library == NULL) {
422  st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY);
423  }
424  if (st_library && st_time_fn == NULL) {
425  st_time_fn = dlsym(st_library, "stonith_api_time");
426  }
427  if (st_time_fn == NULL) {
428  return 0;
429  }
430 
431  return (*st_time_fn) (nodeid, NULL, in_progress);
432 }
433 
434 #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
const char * get_stonith_provider(const char *agent, const char *provider)
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)
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)
stonith_t * stonith_api_new(void)
stonith_key_value_t * stonith_key_value_add(stonith_key_value_t *kvp, const char *key, const char *value)
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:322
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'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)
void stonith_dump_pending_callbacks(stonith_t *st)
int call_timeout
Definition: stonith-ng.h:325
stonith_state
Definition: stonith-ng.h:38
stonith_call_options
Definition: stonith-ng.h:44
char * client_origin
Definition: stonith-ng.h:110
void stonith_api_delete(stonith_t *st)
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:328
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
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)
#define STONITH_LIBRARY
Definition: stonith-ng.h:394
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:324
int(* remove_notification)(stonith_t *st, const char *event)
Definition: stonith-ng.h:289