corosync  2.4.4
coroapi.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2012 Red Hat, Inc.
3  *
4  * All rights reserved.
5  *
6  * Author: Steven Dake (sdake@redhat.com)
7  *
8  * This software licensed under BSD license, the text of which follows:
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  *
13  * - Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  * - Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  * - Neither the name of the MontaVista Software, Inc. nor the names of its
19  * contributors may be used to endorse or promote products derived from this
20  * software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32  * THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 #ifndef COROAPI_H_DEFINED
35 #define COROAPI_H_DEFINED
36 
37 #include <config.h>
38 
39 #include <stdio.h>
40 #ifdef HAVE_SYS_UIO_H
41 #include <sys/uio.h>
42 #endif
43 #include <corosync/hdb.h>
44 #include <qb/qbloop.h>
45 #include <corosync/swab.h>
46 
50 typedef struct {
51  uint32_t nodeid __attribute__((aligned(8)));
52  void *conn __attribute__((aligned(8)));
53 } mar_message_source_t __attribute__((aligned(8)));
54 
59 static inline void swab_mar_message_source_t (mar_message_source_t *to_swab)
60 {
61  swab32 (to_swab->nodeid);
62  /*
63  * if it is from a byteswapped machine, then we can safely
64  * ignore its conn info data structure since this is only
65  * local to the machine
66  */
67  to_swab->conn = NULL;
68 }
69 
70 #ifndef TIMER_HANDLE_T
71 
74 typedef qb_loop_timer_handle corosync_timer_handle_t;
75 #define TIMER_HANDLE_T 1
76 #endif
77 
82  const void *group;
83  size_t group_len;
84 };
85 
86 #define TOTEMIP_ADDRLEN (sizeof(struct in6_addr))
87 
88 #define INTERFACE_MAX 2
89 
90 #ifndef MESSAGE_QUEUE_MAX
91 #ifdef HAVE_SMALL_MEMORY_FOOTPRINT
92 #define PROCESSOR_COUNT_MAX 16
93 #define MESSAGE_SIZE_MAX 1024*64
94 #define MESSAGE_QUEUE_MAX 512
95 #else
96 #define PROCESSOR_COUNT_MAX 384
97 #define MESSAGE_SIZE_MAX 1024*1024
98 #define MESSAGE_QUEUE_MAX ((4 * MESSAGE_SIZE_MAX) / totem_config->net_mtu)
99 #endif /* HAVE_SMALL_MEMORY_FOOTPRINT */
100 #endif /* MESSAGE_QUEUE_MAX */
101 
102 #define TOTEM_AGREED 0
103 #define TOTEM_SAFE 1
104 
105 #define MILLI_2_NANO_SECONDS 1000000ULL
106 
107 #if !defined(TOTEM_IP_ADDRESS)
108 
112  unsigned int nodeid;
113  unsigned short family;
114  unsigned char addr[TOTEMIP_ADDRLEN];
115 } __attribute__((packed));
116 #endif
117 
118 #if !defined(MEMB_RING_ID)
119 
122 struct memb_ring_id {
124  unsigned long long seq;
125 } __attribute__((packed));
126 #endif
127 
128 #if !defined(TOTEM_CONFIGURATION_TYPE)
129 
135 };
136 #endif
137 
138 #if !defined(TOTEM_CALLBACK_TOKEN_TYPE)
139 
145 };
146 #endif
147 
154 };
155 #define corosync_lib_flow_control cs_lib_flow_control
156 #define COROSYNC_LIB_FLOW_CONTROL_REQUIRED CS_LIB_FLOW_CONTROL_REQUIRED
157 #define COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED CS_LIB_FLOW_CONTROL_NOT_REQUIRED
158 
163  CS_LIB_DISALLOW_INQUORATE = 0, /* default */
165 };
166 
167 #if !defined (COROSYNC_FLOW_CONTROL_STATE)
168 
174 };
175 #define corosync_flow_control_state cs_flow_control_state
176 #define CS_FLOW_CONTROL_STATE_DISABLED CS_FLOW_CONTROL_STATE_DISABLED
177 #define CS_FLOW_CONTROL_STATE_ENABLED CS_FLOW_CONTROL_STATE_ENABLED
178 
179 #endif /* COROSYNC_FLOW_CONTROL_STATE */
180 
183 typedef enum {
193 #define corosync_fatal_error_t cs_fatal_error_t;
194 
195 #ifndef QUORUM_H_DEFINED
196 
199 typedef void (*quorum_callback_fn_t) (int quorate, void *context);
200 
205  int (*quorate) (void);
206  int (*register_callback) (quorum_callback_fn_t callback_fn, void *contexxt);
207  int (*unregister_callback) (quorum_callback_fn_t callback_fn, void *context);
208 };
209 
213 typedef void (*sync_callback_fn_t) (
214  const unsigned int *view_list,
215  size_t view_list_entries,
216  int primary_designated,
217  struct memb_ring_id *ring_id);
218 
219 #endif /* QUORUM_H_DEFINED */
220 
221 
226  /*
227  * Time and timer APIs
228  */
229  int (*timer_add_duration) (
230  unsigned long long nanoseconds_in_future,
231  void *data,
232  void (*timer_nf) (void *data),
233  corosync_timer_handle_t *handle);
234 
235  int (*timer_add_absolute) (
236  unsigned long long nanoseconds_from_epoch,
237  void *data,
238  void (*timer_fn) (void *data),
239  corosync_timer_handle_t *handle);
240 
241  void (*timer_delete) (
242  corosync_timer_handle_t timer_handle);
243 
244  unsigned long long (*timer_time_get) (void);
245 
246  unsigned long long (*timer_expire_time_get) (
247  corosync_timer_handle_t timer_handle);
248 
249  /*
250  * IPC APIs
251  */
252  void (*ipc_source_set) (mar_message_source_t *source, void *conn);
253 
254  int (*ipc_source_is_local) (const mar_message_source_t *source);
255 
256  void *(*ipc_private_data_get) (void *conn);
257 
258  int (*ipc_response_send) (void *conn, const void *msg, size_t mlen);
259 
260  int (*ipc_response_iov_send) (void *conn,
261  const struct iovec *iov, unsigned int iov_len);
262 
263  int (*ipc_dispatch_send) (void *conn, const void *msg, size_t mlen);
264 
265  int (*ipc_dispatch_iov_send) (void *conn,
266  const struct iovec *iov, unsigned int iov_len);
267 
268  void (*ipc_refcnt_inc) (void *conn);
269 
270  void (*ipc_refcnt_dec) (void *conn);
271 
272  /*
273  * Totem APIs
274  */
275  unsigned int (*totem_nodeid_get) (void);
276 
277  int (*totem_family_get) (void);
278 
279  int (*totem_ring_reenable) (void);
280 
281  int (*totem_mcast) (const struct iovec *iovec,
282  unsigned int iov_len, unsigned int guarantee);
283 
284  int (*totem_ifaces_get) (
285  unsigned int nodeid,
286  struct totem_ip_address *interfaces,
287  unsigned int interfaces_size,
288  char ***status,
289  unsigned int *iface_count);
290 
291  const char *(*totem_ifaces_print) (unsigned int nodeid);
292 
293  const char *(*totem_ip_print) (const struct totem_ip_address *addr);
294 
295  int (*totem_crypto_set) (const char *cipher_type, const char *hash_type);
296 
297  int (*totem_callback_token_create) (
298  void **handle_out,
300  int delete,
301  int (*callback_fn) (enum totem_callback_token_type type,
302  const void *),
303  const void *data);
304 
305  /*
306  * Totem open process groups API for those service engines
307  * wanting their own groups
308  */
309  int (*tpg_init) (
310  void **instance,
311 
312  void (*deliver_fn) (
313  unsigned int nodeid,
314  const void *msg,
315  unsigned int msg_len,
316  int endian_conversion_required),
317 
318  void (*confchg_fn) (
319  enum totem_configuration_type configuration_type,
320  const unsigned int *member_list,
321  size_t member_list_entries,
322  const unsigned int *left_list,
323  size_t left_list_entries,
324  const unsigned int *joined_list,
325  size_t joined_list_entries,
326  const struct memb_ring_id *ring_id));
327 
328  int (*tpg_exit) (
329  void *instance);
330 
331  int (*tpg_join) (
332  void *instance,
333  const struct corosync_tpg_group *groups,
334  size_t group_cnt);
335 
336  int (*tpg_leave) (
337  void *instance,
338  const struct corosync_tpg_group *groups,
339  size_t group_cnt);
340 
341  int (*tpg_joined_mcast) (
342  void *totempg_groups_instance,
343  const struct iovec *iovec,
344  unsigned int iov_len,
345  int guarantee);
346 
347  int (*tpg_joined_reserve) (
348  void *totempg_groups_instance,
349  const struct iovec *iovec,
350  unsigned int iov_len);
351 
352  int (*tpg_joined_release) (
353  int reserved_msgs);
354 
355  int (*tpg_groups_mcast) (
356  void *instance,
357  int guarantee,
358  const struct corosync_tpg_group *groups,
359  size_t groups_cnt,
360  const struct iovec *iovec,
361  unsigned int iov_len);
362 
363  int (*tpg_groups_reserve) (
364  void *instance,
365  const struct corosync_tpg_group *groups,
366  size_t groups_cnt,
367  const struct iovec *iovec,
368  unsigned int iov_len);
369 
370  int (*tpg_groups_release) (
371  int reserved_msgs);
372 
374  hdb_handle_t *handle,
375  int (schedwrk_fn) (const void *),
376  const void *context);
377 
378  void (*schedwrk_destroy) (hdb_handle_t handle);
379 
380  int (*sync_request) (
381  const char *service_name);
382 
383  /*
384  * User plugin-callable functions for quorum
385  */
386  int (*quorum_is_quorate) (void);
387  int (*quorum_register_callback) (quorum_callback_fn_t callback_fn, void *context);
388  int (*quorum_unregister_callback) (quorum_callback_fn_t callback_fn, void *context);
389 
390  /*
391  * This one is for the quorum management plugin's use
392  */
394 
395  /*
396  * Plugin loading and unloading
397  */
398  int (*plugin_interface_reference) (
399  hdb_handle_t *handle,
400  const char *iface_name,
401  int version,
402  void **interface,
403  void *context);
404 
405  int (*plugin_interface_release) (hdb_handle_t handle);
406 
407  /*
408  * Service loading and unloading APIs
409  */
410  unsigned int (*service_link_and_init) (
412  const char *service_name,
413  unsigned int service_ver);
414 
415  unsigned int (*service_unlink_and_exit) (
416  struct corosync_api_v1 *corosync_api_v1,
417  const char *service_name,
418  unsigned int service_ver);
419 
420  /*
421  * Error handling APIs
422  */
423  void (*error_memory_failure) (void) __attribute__ ((noreturn));
424 
425 #define corosync_fatal_error(err) api->fatal_error ((err), __FILE__, __LINE__)
427  const char *file,
428  unsigned int line) __attribute__ ((noreturn));
429 
430  void (*shutdown_request) (void);
431 
432  void (*state_dump) (void);
433 
434  qb_loop_t *(*poll_handle_get) (void);
435 
436  void *(*totem_get_stats)(void);
437 
439  hdb_handle_t *handle,
440  int (schedwrk_fn) (const void *),
441  const void *context);
442 
443  int (*poll_dispatch_add) (qb_loop_t * handle,
444  int fd,
445  int events,
446  void *data,
447 
448  int (*dispatch_fn) (int fd,
449  int revents,
450  void *data));
451 
452 
454  qb_loop_t * handle,
455  int fd);
456 
457 };
458 
459 #define SERVICE_ID_MAKE(a,b) ( ((a)<<16) | (b) )
460 
461 #define SERVICE_HANDLER_MAXIMUM_COUNT 64
462 
463 #define SERVICES_COUNT_MAX 64
464 
469  void (*lib_handler_fn) (void *conn, const void *msg);
470  enum cs_lib_flow_control flow_control;
471 };
472 
477  void (*exec_handler_fn) (const void *msg, unsigned int nodeid);
478  void (*exec_endian_convert_fn) (void *msg);
479 };
480 
485  struct corosync_service_engine *(*corosync_get_service_engine_ver0) (void);
486 };
487 
492  const char *name;
493  unsigned short id;
494  unsigned short priority; /* Lower priority are loaded first, unloaded last.
495  * 0 is a special case which always loaded _and_ unloaded last
496  */
497  unsigned int private_data_size;
498  enum cs_lib_flow_control flow_control;
499  enum cs_lib_allow_inquorate allow_inquorate;
500  char *(*exec_init_fn) (struct corosync_api_v1 *);
501  int (*exec_exit_fn) (void);
502  void (*exec_dump_fn) (void);
503  int (*lib_init_fn) (void *conn);
504  int (*lib_exit_fn) (void *conn);
509  int (*config_init_fn) (struct corosync_api_v1 *);
510  void (*confchg_fn) (
511  enum totem_configuration_type configuration_type,
512  const unsigned int *member_list, size_t member_list_entries,
513  const unsigned int *left_list, size_t left_list_entries,
514  const unsigned int *joined_list, size_t joined_list_entries,
515  const struct memb_ring_id *ring_id);
516  void (*sync_init) (
517  const unsigned int *trans_list,
518  size_t trans_list_entries,
519  const unsigned int *member_list,
520  size_t member_list_entries,
521  const struct memb_ring_id *ring_id);
522  int (*sync_process) (void);
523  void (*sync_activate) (void);
524  void (*sync_abort) (void);
525 };
526 
527 #endif /* COROAPI_H_DEFINED */
const char * name
Definition: coroapi.h:492
unsigned short family
Definition: coroapi.h:113
void(* state_dump)(void)
Definition: coroapi.h:432
enum totem_configuration_type __attribute__
#define CS_FLOW_CONTROL_STATE_DISABLED
Definition: coroapi.h:176
cmap_value_types_t type
Definition: cmap.h:112
void sync_abort(void)
Definition: sync.c:528
The totem_ip_address struct.
Definition: coroapi.h:111
The corosync_service_engine struct.
Definition: coroapi.h:491
int sync_init(int(*sync_callbacks_retrieve)(int service_id, struct sync_callbacks *callbacks), void(*synchronization_completed)(void))
Definition: sync.c:158
void(* shutdown_request)(void)
Definition: coroapi.h:430
void(* fatal_error)(cs_fatal_error_t err, const char *file, unsigned int line) __attribute__((noreturn))
Definition: coroapi.h:426
totem_configuration_type
The totem_configuration_type enum.
Definition: coroapi.h:132
cs_fatal_error_t
The cs_fatal_error_t enum.
Definition: coroapi.h:183
The corosync_lib_handler struct.
Definition: coroapi.h:468
int guarantee
Definition: totemsrp.c:66
unsigned char addr[TOTEMIP_ADDRLEN]
Definition: coroapi.h:77
The corosync_exec_handler struct.
Definition: coroapi.h:476
const void * group
Definition: coroapi.h:82
The quorum_callin_functions struct.
Definition: coroapi.h:204
unsigned short priority
Definition: coroapi.h:494
The corosync_service_engine_iface_ver0 struct.
Definition: coroapi.h:484
The corosync_tpg_group struct.
Definition: coroapi.h:81
void schedwrk_destroy(hdb_handle_t handle)
Definition: schedwrk.c:154
#define CS_FLOW_CONTROL_STATE_ENABLED
Definition: coroapi.h:177
void(* error_memory_failure)(void) __attribute__((noreturn))
Definition: coroapi.h:423
size_t group_len
Definition: coroapi.h:83
const void * data
Definition: cmap.h:114
struct corosync_exec_handler * exec_engine
Definition: coroapi.h:507
struct corosync_lib_handler * lib_engine
Definition: coroapi.h:505
cs_flow_control_state
The cs_flow_control_state enum.
Definition: coroapi.h:171
int schedwrk_create_nolock(hdb_handle_t *handle, int(schedwrk_fn)(const void *), const void *context)
Definition: schedwrk.c:146
unsigned int nodeid
Definition: coroapi.h:112
The corosync_api_v1 struct.
Definition: coroapi.h:225
void(* quorum_callback_fn_t)(int quorate, void *context)
The quorum_callback_fn_t callback.
Definition: coroapi.h:199
uint32_t quorate
Definition: sam.c:134
#define swab32(x)
The swab32 macro.
Definition: swab.h:51
int(* poll_dispatch_add)(qb_loop_t *handle, int fd, int events, void *data, int(*dispatch_fn)(int fd, int revents, void *data))
Definition: coroapi.h:443
#define TOTEMIP_ADDRLEN
Definition: coroapi.h:86
void(* sync_callback_fn_t)(const unsigned int *view_list, size_t view_list_entries, int primary_designated, struct memb_ring_id *ring_id)
The sync_callback_fn_t callback.
Definition: coroapi.h:213
qb_handle_t hdb_handle_t
Definition: hdb.h:52
The memb_ring_id struct.
Definition: coroapi.h:122
unsigned short id
Definition: coroapi.h:493
cs_lib_allow_inquorate
The cs_lib_allow_inquorate enum.
Definition: coroapi.h:162
qb_loop_timer_handle corosync_timer_handle_t
corosync_timer_handle_t
Definition: coroapi.h:74
cs_lib_flow_control
The cs_lib_flow_control enum.
Definition: coroapi.h:151
unsigned long long seq
Definition: coroapi.h:124
unsigned int nodeid
Definition: coroapi.h:75
unsigned int private_data_size
Definition: coroapi.h:497
struct memb_ring_id ring_id
Definition: totemsrp.c:64
int(* poll_dispatch_delete)(qb_loop_t *handle, int fd)
Definition: coroapi.h:453
unsigned int(* service_unlink_and_exit)(struct corosync_api_v1 *corosync_api_v1, const char *service_name, unsigned int service_ver)
Definition: coroapi.h:415
int schedwrk_create(hdb_handle_t *handle, int(schedwrk_fn)(const void *), const void *context)
Definition: schedwrk.c:138
cs_error_t quorum_initialize(quorum_handle_t *handle, quorum_callbacks_t *callbacks, uint32_t *quorum_type)
Create a new quorum connection.
Definition: lib/quorum.c:69
totem_callback_token_type
The totem_callback_token_type enum.
Definition: coroapi.h:142
The mar_message_source_t struct.
Definition: coroapi.h:50
struct totem_ip_address rep
Definition: coroapi.h:75