corosync  3.1.2
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 8
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 {
123  unsigned int nodeid;
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_mcast) (const struct iovec *iovec,
280  unsigned int iov_len, unsigned int guarantee);
281 
282  int (*totem_ifaces_get) (
283  unsigned int nodeid,
284  unsigned int *interface_ids,
285  struct totem_ip_address *interfaces,
286  unsigned int interfaces_size,
287  char ***status,
288  unsigned int *iface_count);
289 
290  const char *(*totem_ifaces_print) (unsigned int nodeid);
291 
292  const char *(*totem_ip_print) (const struct totem_ip_address *addr);
293 
294  int (*totem_crypto_set) (const char *cipher_type, const char *hash_type);
295 
296  int (*totem_callback_token_create) (
297  void **handle_out,
299  int delete,
300  int (*callback_fn) (enum totem_callback_token_type type,
301  const void *),
302  const void *data);
303 
304  /*
305  * Totem open process groups API for those service engines
306  * wanting their own groups
307  */
308  int (*tpg_init) (
309  void **instance,
310 
311  void (*deliver_fn) (
312  unsigned int nodeid,
313  const void *msg,
314  unsigned int msg_len,
315  int endian_conversion_required),
316 
317  void (*confchg_fn) (
318  enum totem_configuration_type configuration_type,
319  const unsigned int *member_list,
320  size_t member_list_entries,
321  const unsigned int *left_list,
322  size_t left_list_entries,
323  const unsigned int *joined_list,
324  size_t joined_list_entries,
325  const struct memb_ring_id *ring_id));
326 
327  int (*tpg_exit) (
328  void *instance);
329 
330  int (*tpg_join) (
331  void *instance,
332  const struct corosync_tpg_group *groups,
333  size_t group_cnt);
334 
335  int (*tpg_leave) (
336  void *instance,
337  const struct corosync_tpg_group *groups,
338  size_t group_cnt);
339 
340  int (*tpg_joined_mcast) (
341  void *totempg_groups_instance,
342  const struct iovec *iovec,
343  unsigned int iov_len,
344  int guarantee);
345 
346  int (*tpg_joined_reserve) (
347  void *totempg_groups_instance,
348  const struct iovec *iovec,
349  unsigned int iov_len);
350 
351  int (*tpg_joined_release) (
352  int reserved_msgs);
353 
354  int (*tpg_groups_mcast) (
355  void *instance,
356  int guarantee,
357  const struct corosync_tpg_group *groups,
358  size_t groups_cnt,
359  const struct iovec *iovec,
360  unsigned int iov_len);
361 
362  int (*tpg_groups_reserve) (
363  void *instance,
364  const struct corosync_tpg_group *groups,
365  size_t groups_cnt,
366  const struct iovec *iovec,
367  unsigned int iov_len);
368 
369  int (*tpg_groups_release) (
370  int reserved_msgs);
371 
373  hdb_handle_t *handle,
374  int (schedwrk_fn) (const void *),
375  const void *context);
376 
377  void (*schedwrk_destroy) (hdb_handle_t handle);
378 
379  int (*sync_request) (
380  const char *service_name);
381 
382  /*
383  * User plugin-callable functions for quorum
384  */
385  int (*quorum_is_quorate) (void);
386  int (*quorum_register_callback) (quorum_callback_fn_t callback_fn, void *context);
387  int (*quorum_unregister_callback) (quorum_callback_fn_t callback_fn, void *context);
388 
389  /*
390  * This one is for the quorum management plugin's use
391  */
393 
394  /*
395  * Plugin loading and unloading
396  */
397  int (*plugin_interface_reference) (
398  hdb_handle_t *handle,
399  const char *iface_name,
400  int version,
401  void **interface,
402  void *context);
403 
404  int (*plugin_interface_release) (hdb_handle_t handle);
405 
406  /*
407  * Service loading and unloading APIs
408  */
409  unsigned int (*service_link_and_init) (
411  const char *service_name,
412  unsigned int service_ver);
413 
414  unsigned int (*service_unlink_and_exit) (
415  struct corosync_api_v1 *corosync_api_v1,
416  const char *service_name,
417  unsigned int service_ver);
418 
419  /*
420  * Error handling APIs
421  */
422  void (*error_memory_failure) (void) __attribute__ ((noreturn));
423 
424 #define corosync_fatal_error(err) api->fatal_error ((err), __FILE__, __LINE__)
426  const char *file,
427  unsigned int line) __attribute__ ((noreturn));
428 
429  void (*shutdown_request) (void);
430 
431  void (*state_dump) (void);
432 
433  qb_loop_t *(*poll_handle_get) (void);
434 
435  void *(*totem_get_stats)(void);
436 
438  hdb_handle_t *handle,
439  int (schedwrk_fn) (const void *),
440  const void *context);
441 
442  int (*poll_dispatch_add) (qb_loop_t * handle,
443  int fd,
444  int events,
445  void *data,
446 
447  int (*dispatch_fn) (int fd,
448  int revents,
449  void *data));
450 
451 
453  qb_loop_t * handle,
454  int fd);
455 
456 };
457 
458 #define SERVICE_ID_MAKE(a,b) ( ((a)<<16) | (b) )
459 
460 #define SERVICE_HANDLER_MAXIMUM_COUNT 64
461 
462 #define SERVICES_COUNT_MAX 64
463 
468  void (*lib_handler_fn) (void *conn, const void *msg);
469  enum cs_lib_flow_control flow_control;
470 };
471 
476  void (*exec_handler_fn) (const void *msg, unsigned int nodeid);
477  void (*exec_endian_convert_fn) (void *msg);
478 };
479 
484  struct corosync_service_engine *(*corosync_get_service_engine_ver0) (void);
485 };
486 
491  const char *name;
492  unsigned short id;
493  unsigned short priority; /* Lower priority are loaded first, unloaded last.
494  * 0 is a special case which always loaded _and_ unloaded last
495  */
497  enum cs_lib_flow_control flow_control;
498  enum cs_lib_allow_inquorate allow_inquorate;
499  char *(*exec_init_fn) (struct corosync_api_v1 *);
500  int (*exec_exit_fn) (void);
501  void (*exec_dump_fn) (void);
502  int (*lib_init_fn) (void *conn);
503  int (*lib_exit_fn) (void *conn);
508  int (*config_init_fn) (struct corosync_api_v1 *);
509  void (*confchg_fn) (
510  enum totem_configuration_type configuration_type,
511  const unsigned int *member_list, size_t member_list_entries,
512  const unsigned int *left_list, size_t left_list_entries,
513  const unsigned int *joined_list, size_t joined_list_entries,
514  const struct memb_ring_id *ring_id);
515  void (*sync_init) (
516  const unsigned int *trans_list,
517  size_t trans_list_entries,
518  const unsigned int *member_list,
519  size_t member_list_entries,
520  const struct memb_ring_id *ring_id);
521  int (*sync_process) (void);
522  void (*sync_activate) (void);
523  void (*sync_abort) (void);
524 };
525 
526 #endif /* COROAPI_H_DEFINED */
const char * name
Definition: coroapi.h:491
unsigned short family
Definition: coroapi.h:113
char version
Definition: totem.h:54
void(* state_dump)(void)
Definition: coroapi.h:431
enum totem_configuration_type __attribute__
#define CS_FLOW_CONTROL_STATE_DISABLED
Definition: coroapi.h:176
cmap_value_types_t type
Definition: cmap.h:118
void sync_abort(void)
Definition: sync.c:535
The totem_ip_address struct.
Definition: coroapi.h:111
The corosync_service_engine struct.
Definition: coroapi.h:490
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:429
void(* fatal_error)(cs_fatal_error_t err, const char *file, unsigned int line) __attribute__((noreturn))
Definition: coroapi.h:425
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:467
int guarantee
Definition: totemsrp.c:266
unsigned char addr[TOTEMIP_ADDRLEN]
Definition: coroapi.h:77
The corosync_exec_handler struct.
Definition: coroapi.h:475
const void * group
Definition: coroapi.h:82
The quorum_callin_functions struct.
Definition: coroapi.h:204
unsigned short priority
Definition: coroapi.h:493
The corosync_service_engine_iface_ver0 struct.
Definition: coroapi.h:483
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:422
size_t group_len
Definition: coroapi.h:83
const void * data
Definition: cmap.h:120
struct corosync_exec_handler * exec_engine
Definition: coroapi.h:506
struct corosync_lib_handler * lib_engine
Definition: coroapi.h:504
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:442
#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 int nodeid
Definition: coroapi.h:123
unsigned short id
Definition: coroapi.h:492
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
struct memb_ring_id ring_id
Definition: totemsrp.c:264
int(* poll_dispatch_delete)(qb_loop_t *handle, int fd)
Definition: coroapi.h:452
unsigned int(* service_unlink_and_exit)(struct corosync_api_v1 *corosync_api_v1, const char *service_name, unsigned int service_ver)
Definition: coroapi.h:414
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:73
totem_callback_token_type
The totem_callback_token_type enum.
Definition: coroapi.h:142
The mar_message_source_t struct.
Definition: coroapi.h:50