coroapi.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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. #include <stdio.h>
  37. #ifdef COROSYNC_BSD
  38. #include <sys/uio.h>
  39. #endif
  40. #include <corosync/hdb.h>
  41. #include <qb/qbloop.h>
  42. #include <corosync/swab.h>
  43. typedef struct {
  44. uint32_t nodeid __attribute__((aligned(8)));
  45. void *conn __attribute__((aligned(8)));
  46. } mar_message_source_t __attribute__((aligned(8)));
  47. static inline void swab_mar_message_source_t (mar_message_source_t *to_swab)
  48. {
  49. swab32 (to_swab->nodeid);
  50. /*
  51. * if it is from a byteswapped machine, then we can safely
  52. * ignore its conn info data structure since this is only
  53. * local to the machine
  54. */
  55. to_swab->conn = NULL;
  56. }
  57. #ifndef TIMER_HANDLE_T
  58. typedef qb_loop_timer_handle corosync_timer_handle_t;
  59. #define TIMER_HANDLE_T 1
  60. #endif
  61. struct corosync_tpg_group {
  62. const void *group;
  63. size_t group_len;
  64. };
  65. #define TOTEMIP_ADDRLEN (sizeof(struct in6_addr))
  66. #define INTERFACE_MAX 2
  67. #ifndef MESSAGE_QUEUE_MAX
  68. #ifdef HAVE_SMALL_MEMORY_FOOTPRINT
  69. #define PROCESSOR_COUNT_MAX 16
  70. #define MESSAGE_SIZE_MAX 1024*64
  71. #define MESSAGE_QUEUE_MAX 512
  72. #else
  73. #define PROCESSOR_COUNT_MAX 384
  74. #define MESSAGE_SIZE_MAX 1024*1024
  75. #define MESSAGE_QUEUE_MAX ((4 * MESSAGE_SIZE_MAX) / totem_config->net_mtu)
  76. #endif /* HAVE_SMALL_MEMORY_FOOTPRINT */
  77. #endif /* MESSAGE_QUEUE_MAX */
  78. #define TOTEM_AGREED 0
  79. #define TOTEM_SAFE 1
  80. #define MILLI_2_NANO_SECONDS 1000000ULL
  81. #if !defined(TOTEM_IP_ADDRESS)
  82. struct totem_ip_address {
  83. unsigned int nodeid;
  84. unsigned short family;
  85. unsigned char addr[TOTEMIP_ADDRLEN];
  86. } __attribute__((packed));
  87. #endif
  88. #if !defined(MEMB_RING_ID)
  89. struct memb_ring_id {
  90. struct totem_ip_address rep;
  91. unsigned long long seq;
  92. } __attribute__((packed));
  93. #endif
  94. #if !defined(TOTEM_CONFIGURATION_TYPE)
  95. enum totem_configuration_type {
  96. TOTEM_CONFIGURATION_REGULAR,
  97. TOTEM_CONFIGURATION_TRANSITIONAL
  98. };
  99. #endif
  100. #if !defined(TOTEM_CALLBACK_TOKEN_TYPE)
  101. enum totem_callback_token_type {
  102. TOTEM_CALLBACK_TOKEN_RECEIVED = 1,
  103. TOTEM_CALLBACK_TOKEN_SENT = 2
  104. };
  105. #endif
  106. enum cs_lib_flow_control {
  107. CS_LIB_FLOW_CONTROL_REQUIRED = 1,
  108. CS_LIB_FLOW_CONTROL_NOT_REQUIRED = 2
  109. };
  110. #define corosync_lib_flow_control cs_lib_flow_control
  111. #define COROSYNC_LIB_FLOW_CONTROL_REQUIRED CS_LIB_FLOW_CONTROL_REQUIRED
  112. #define COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  113. enum cs_lib_allow_inquorate {
  114. CS_LIB_DISALLOW_INQUORATE = 0, /* default */
  115. CS_LIB_ALLOW_INQUORATE = 1
  116. };
  117. #if !defined (COROSYNC_FLOW_CONTROL_STATE)
  118. enum cs_flow_control_state {
  119. CS_FLOW_CONTROL_STATE_DISABLED,
  120. CS_FLOW_CONTROL_STATE_ENABLED
  121. };
  122. #define corosync_flow_control_state cs_flow_control_state
  123. #define CS_FLOW_CONTROL_STATE_DISABLED CS_FLOW_CONTROL_STATE_DISABLED
  124. #define CS_FLOW_CONTROL_STATE_ENABLED CS_FLOW_CONTROL_STATE_ENABLED
  125. #endif /* COROSYNC_FLOW_CONTROL_STATE */
  126. typedef enum {
  127. COROSYNC_FATAL_ERROR_EXIT = -1,
  128. COROSYNC_LIBAIS_SOCKET = -6,
  129. COROSYNC_LIBAIS_BIND = -7,
  130. COROSYNC_READKEY = -8,
  131. COROSYNC_INVALID_CONFIG = -9,
  132. COROSYNC_DYNAMICLOAD = -12,
  133. COROSYNC_OUT_OF_MEMORY = -15,
  134. COROSYNC_FATAL_ERR = -16
  135. } cs_fatal_error_t;
  136. #define corosync_fatal_error_t cs_fatal_error_t;
  137. #ifndef QUORUM_H_DEFINED
  138. typedef void (*quorum_callback_fn_t) (int quorate, void *context);
  139. struct quorum_callin_functions {
  140. int (*quorate) (void);
  141. int (*register_callback) (quorum_callback_fn_t callback_fn, void *contexxt);
  142. int (*unregister_callback) (quorum_callback_fn_t callback_fn, void *context);
  143. };
  144. typedef void (*sync_callback_fn_t) (
  145. const unsigned int *view_list,
  146. size_t view_list_entries,
  147. int primary_designated,
  148. struct memb_ring_id *ring_id);
  149. #endif /* QUORUM_H_DEFINED */
  150. struct corosync_api_v1 {
  151. /*
  152. * Time and timer APIs
  153. */
  154. int (*timer_add_duration) (
  155. unsigned long long nanoseconds_in_future,
  156. void *data,
  157. void (*timer_nf) (void *data),
  158. corosync_timer_handle_t *handle);
  159. int (*timer_add_absolute) (
  160. unsigned long long nanoseconds_from_epoch,
  161. void *data,
  162. void (*timer_fn) (void *data),
  163. corosync_timer_handle_t *handle);
  164. void (*timer_delete) (
  165. corosync_timer_handle_t timer_handle);
  166. unsigned long long (*timer_time_get) (void);
  167. unsigned long long (*timer_expire_time_get) (
  168. corosync_timer_handle_t timer_handle);
  169. /*
  170. * IPC APIs
  171. */
  172. void (*ipc_source_set) (mar_message_source_t *source, void *conn);
  173. int (*ipc_source_is_local) (const mar_message_source_t *source);
  174. void *(*ipc_private_data_get) (void *conn);
  175. int (*ipc_response_send) (void *conn, const void *msg, size_t mlen);
  176. int (*ipc_response_iov_send) (void *conn,
  177. const struct iovec *iov, unsigned int iov_len);
  178. int (*ipc_dispatch_send) (void *conn, const void *msg, size_t mlen);
  179. int (*ipc_dispatch_iov_send) (void *conn,
  180. const struct iovec *iov, unsigned int iov_len);
  181. void (*ipc_refcnt_inc) (void *conn);
  182. void (*ipc_refcnt_dec) (void *conn);
  183. /*
  184. * Totem APIs
  185. */
  186. unsigned int (*totem_nodeid_get) (void);
  187. int (*totem_family_get) (void);
  188. int (*totem_ring_reenable) (void);
  189. int (*totem_mcast) (const struct iovec *iovec,
  190. unsigned int iov_len, unsigned int guarantee);
  191. int (*totem_ifaces_get) (
  192. unsigned int nodeid,
  193. struct totem_ip_address *interfaces,
  194. char ***status,
  195. unsigned int *iface_count);
  196. const char *(*totem_ifaces_print) (unsigned int nodeid);
  197. const char *(*totem_ip_print) (const struct totem_ip_address *addr);
  198. int (*totem_crypto_set) (const char *cipher_type, const char *hash_type);
  199. int (*totem_callback_token_create) (
  200. void **handle_out,
  201. enum totem_callback_token_type type,
  202. int delete,
  203. int (*callback_fn) (enum totem_callback_token_type type,
  204. const void *),
  205. const void *data);
  206. /*
  207. * Totem open process groups API for those service engines
  208. * wanting their own groups
  209. */
  210. int (*tpg_init) (
  211. void **instance,
  212. void (*deliver_fn) (
  213. unsigned int nodeid,
  214. const void *msg,
  215. unsigned int msg_len,
  216. int endian_conversion_required),
  217. void (*confchg_fn) (
  218. enum totem_configuration_type configuration_type,
  219. const unsigned int *member_list,
  220. size_t member_list_entries,
  221. const unsigned int *left_list,
  222. size_t left_list_entries,
  223. const unsigned int *joined_list,
  224. size_t joined_list_entries,
  225. const struct memb_ring_id *ring_id));
  226. int (*tpg_exit) (
  227. void *instance);
  228. int (*tpg_join) (
  229. void *instance,
  230. const struct corosync_tpg_group *groups,
  231. size_t group_cnt);
  232. int (*tpg_leave) (
  233. void *instance,
  234. const struct corosync_tpg_group *groups,
  235. size_t group_cnt);
  236. int (*tpg_joined_mcast) (
  237. void *totempg_groups_instance,
  238. const struct iovec *iovec,
  239. unsigned int iov_len,
  240. int guarantee);
  241. int (*tpg_joined_reserve) (
  242. void *totempg_groups_instance,
  243. const struct iovec *iovec,
  244. unsigned int iov_len);
  245. int (*tpg_joined_release) (
  246. int reserved_msgs);
  247. int (*tpg_groups_mcast) (
  248. void *instance,
  249. int guarantee,
  250. const struct corosync_tpg_group *groups,
  251. size_t groups_cnt,
  252. const struct iovec *iovec,
  253. unsigned int iov_len);
  254. int (*tpg_groups_reserve) (
  255. void *instance,
  256. const struct corosync_tpg_group *groups,
  257. size_t groups_cnt,
  258. const struct iovec *iovec,
  259. unsigned int iov_len);
  260. int (*tpg_groups_release) (
  261. int reserved_msgs);
  262. int (*schedwrk_create) (
  263. hdb_handle_t *handle,
  264. int (schedwrk_fn) (const void *),
  265. const void *context);
  266. void (*schedwrk_destroy) (hdb_handle_t handle);
  267. int (*sync_request) (
  268. const char *service_name);
  269. /*
  270. * User plugin-callable functions for quorum
  271. */
  272. int (*quorum_is_quorate) (void);
  273. int (*quorum_register_callback) (quorum_callback_fn_t callback_fn, void *context);
  274. int (*quorum_unregister_callback) (quorum_callback_fn_t callback_fn, void *context);
  275. /*
  276. * This one is for the quorum management plugin's use
  277. */
  278. int (*quorum_initialize)(struct quorum_callin_functions *fns);
  279. /*
  280. * Plugin loading and unloading
  281. */
  282. int (*plugin_interface_reference) (
  283. hdb_handle_t *handle,
  284. const char *iface_name,
  285. int version,
  286. void **interface,
  287. void *context);
  288. int (*plugin_interface_release) (hdb_handle_t handle);
  289. /*
  290. * Service loading and unloading APIs
  291. */
  292. unsigned int (*service_link_and_init) (
  293. struct corosync_api_v1 *corosync_api_v1,
  294. const char *service_name,
  295. unsigned int service_ver);
  296. unsigned int (*service_unlink_and_exit) (
  297. struct corosync_api_v1 *corosync_api_v1,
  298. const char *service_name,
  299. unsigned int service_ver);
  300. /*
  301. * Error handling APIs
  302. */
  303. void (*error_memory_failure) (void) __attribute__ ((noreturn));
  304. #define corosync_fatal_error(err) api->fatal_error ((err), __FILE__, __LINE__)
  305. void (*fatal_error) (cs_fatal_error_t err,
  306. const char *file,
  307. unsigned int line) __attribute__ ((noreturn));
  308. void (*shutdown_request) (void);
  309. void (*state_dump) (void);
  310. qb_loop_t *(*poll_handle_get) (void);
  311. void *(*totem_get_stats)(void);
  312. int (*schedwrk_create_nolock) (
  313. hdb_handle_t *handle,
  314. int (schedwrk_fn) (const void *),
  315. const void *context);
  316. int (*poll_dispatch_add) (qb_loop_t * handle,
  317. int fd,
  318. int events,
  319. void *data,
  320. int (*dispatch_fn) (int fd,
  321. int revents,
  322. void *data));
  323. int (*poll_dispatch_delete) (
  324. qb_loop_t * handle,
  325. int fd);
  326. };
  327. #define SERVICE_ID_MAKE(a,b) ( ((a)<<16) | (b) )
  328. #define SERVICE_HANDLER_MAXIMUM_COUNT 64
  329. struct corosync_lib_handler {
  330. void (*lib_handler_fn) (void *conn, const void *msg);
  331. enum cs_lib_flow_control flow_control;
  332. };
  333. struct corosync_exec_handler {
  334. void (*exec_handler_fn) (const void *msg, unsigned int nodeid);
  335. void (*exec_endian_convert_fn) (void *msg);
  336. };
  337. struct corosync_service_engine_iface_ver0 {
  338. struct corosync_service_engine *(*corosync_get_service_engine_ver0) (void);
  339. };
  340. struct corosync_service_engine {
  341. const char *name;
  342. unsigned short id;
  343. unsigned short priority; /* Lower priority are loaded first, unloaded last.
  344. * 0 is a special case which always loaded _and_ unloaded last
  345. */
  346. unsigned int private_data_size;
  347. enum cs_lib_flow_control flow_control;
  348. enum cs_lib_allow_inquorate allow_inquorate;
  349. char *(*exec_init_fn) (struct corosync_api_v1 *);
  350. int (*exec_exit_fn) (void);
  351. void (*exec_dump_fn) (void);
  352. int (*lib_init_fn) (void *conn);
  353. int (*lib_exit_fn) (void *conn);
  354. struct corosync_lib_handler *lib_engine;
  355. int lib_engine_count;
  356. struct corosync_exec_handler *exec_engine;
  357. int exec_engine_count;
  358. int (*config_init_fn) (struct corosync_api_v1 *);
  359. void (*confchg_fn) (
  360. enum totem_configuration_type configuration_type,
  361. const unsigned int *member_list, size_t member_list_entries,
  362. const unsigned int *left_list, size_t left_list_entries,
  363. const unsigned int *joined_list, size_t joined_list_entries,
  364. const struct memb_ring_id *ring_id);
  365. void (*sync_init) (
  366. const unsigned int *trans_list,
  367. size_t trans_list_entries,
  368. const unsigned int *member_list,
  369. size_t member_list_entries,
  370. const struct memb_ring_id *ring_id);
  371. int (*sync_process) (void);
  372. void (*sync_activate) (void);
  373. void (*sync_abort) (void);
  374. };
  375. #endif /* COROAPI_H_DEFINED */