coroapi.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. /*
  2. * Copyright (c) 2008, 2009 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. enum cs_sync_mode {
  127. CS_SYNC_V1 = 0,
  128. CS_SYNC_V2 = 1,
  129. CS_SYNC_V1_APIV2 = 2
  130. };
  131. typedef enum {
  132. COROSYNC_FATAL_ERROR_EXIT = -1,
  133. COROSYNC_LIBAIS_SOCKET = -6,
  134. COROSYNC_LIBAIS_BIND = -7,
  135. COROSYNC_READKEY = -8,
  136. COROSYNC_INVALID_CONFIG = -9,
  137. COROSYNC_DYNAMICLOAD = -12,
  138. COROSYNC_OUT_OF_MEMORY = -15,
  139. COROSYNC_FATAL_ERR = -16
  140. } cs_fatal_error_t;
  141. #define corosync_fatal_error_t cs_fatal_error_t;
  142. #ifndef QUORUM_H_DEFINED
  143. typedef void (*quorum_callback_fn_t) (int quorate, void *context);
  144. struct quorum_callin_functions
  145. {
  146. int (*quorate) (void);
  147. int (*register_callback) (quorum_callback_fn_t callback_fn, void *context);
  148. int (*unregister_callback) (quorum_callback_fn_t callback_fn, void *context);
  149. };
  150. typedef void (*sync_callback_fn_t) (
  151. const unsigned int *view_list,
  152. size_t view_list_entries,
  153. int primary_designated,
  154. struct memb_ring_id *ring_id);
  155. #endif /* QUORUM_H_DEFINED */
  156. struct corosync_api_v1 {
  157. /*
  158. * Time and timer APIs
  159. */
  160. int (*timer_add_duration) (
  161. unsigned long long nanoseconds_in_future,
  162. void *data,
  163. void (*timer_nf) (void *data),
  164. corosync_timer_handle_t *handle);
  165. int (*timer_add_absolute) (
  166. unsigned long long nanoseconds_from_epoch,
  167. void *data,
  168. void (*timer_fn) (void *data),
  169. corosync_timer_handle_t *handle);
  170. void (*timer_delete) (
  171. corosync_timer_handle_t timer_handle);
  172. unsigned long long (*timer_time_get) (void);
  173. unsigned long long (*timer_expire_time_get) (
  174. corosync_timer_handle_t timer_handle);
  175. /*
  176. * IPC APIs
  177. */
  178. void (*ipc_source_set) (mar_message_source_t *source, void *conn);
  179. int (*ipc_source_is_local) (const mar_message_source_t *source);
  180. void *(*ipc_private_data_get) (void *conn);
  181. int (*ipc_response_send) (void *conn, const void *msg, size_t mlen);
  182. int (*ipc_response_iov_send) (void *conn,
  183. const struct iovec *iov, unsigned int iov_len);
  184. int (*ipc_dispatch_send) (void *conn, const void *msg, size_t mlen);
  185. int (*ipc_dispatch_iov_send) (void *conn,
  186. const struct iovec *iov, unsigned int iov_len);
  187. void (*ipc_refcnt_inc) (void *conn);
  188. void (*ipc_refcnt_dec) (void *conn);
  189. /*
  190. * Totem APIs
  191. */
  192. unsigned int (*totem_nodeid_get) (void);
  193. int (*totem_family_get) (void);
  194. int (*totem_ring_reenable) (void);
  195. int (*totem_mcast) (const struct iovec *iovec,
  196. unsigned int iov_len, unsigned int guarantee);
  197. int (*totem_ifaces_get) (
  198. unsigned int nodeid,
  199. struct totem_ip_address *interfaces,
  200. char ***status,
  201. unsigned int *iface_count);
  202. const char *(*totem_ifaces_print) (unsigned int nodeid);
  203. const char *(*totem_ip_print) (const struct totem_ip_address *addr);
  204. int (*totem_crypto_set) (unsigned int type);
  205. int (*totem_callback_token_create) (
  206. void **handle_out,
  207. enum totem_callback_token_type type,
  208. int delete,
  209. int (*callback_fn) (enum totem_callback_token_type type,
  210. const void *),
  211. const void *data);
  212. /*
  213. * Totem open process groups API for those service engines
  214. * wanting their own groups
  215. */
  216. int (*tpg_init) (
  217. void **instance,
  218. void (*deliver_fn) (
  219. unsigned int nodeid,
  220. const void *msg,
  221. unsigned int msg_len,
  222. int endian_conversion_required),
  223. void (*confchg_fn) (
  224. enum totem_configuration_type configuration_type,
  225. const unsigned int *member_list,
  226. size_t member_list_entries,
  227. const unsigned int *left_list,
  228. size_t left_list_entries,
  229. const unsigned int *joined_list,
  230. size_t joined_list_entries,
  231. const struct memb_ring_id *ring_id));
  232. int (*tpg_exit) (
  233. void *instance);
  234. int (*tpg_join) (
  235. void *instance,
  236. const struct corosync_tpg_group *groups,
  237. size_t group_cnt);
  238. int (*tpg_leave) (
  239. void *instance,
  240. const struct corosync_tpg_group *groups,
  241. size_t group_cnt);
  242. int (*tpg_joined_mcast) (
  243. void *totempg_groups_instance,
  244. const struct iovec *iovec,
  245. unsigned int iov_len,
  246. int guarantee);
  247. int (*tpg_joined_reserve) (
  248. void *totempg_groups_instance,
  249. const struct iovec *iovec,
  250. unsigned int iov_len);
  251. int (*tpg_joined_release) (
  252. int reserved_msgs);
  253. int (*tpg_groups_mcast) (
  254. void *instance,
  255. int guarantee,
  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_reserve) (
  261. void *instance,
  262. const struct corosync_tpg_group *groups,
  263. size_t groups_cnt,
  264. const struct iovec *iovec,
  265. unsigned int iov_len);
  266. int (*tpg_groups_release) (
  267. int reserved_msgs);
  268. int (*schedwrk_create) (
  269. hdb_handle_t *handle,
  270. int (schedwrk_fn) (const void *),
  271. const void *context);
  272. void (*schedwrk_destroy) (hdb_handle_t handle);
  273. int (*sync_request) (
  274. const char *service_name);
  275. /*
  276. * User plugin-callable functions for quorum
  277. */
  278. int (*quorum_is_quorate) (void);
  279. int (*quorum_register_callback) (quorum_callback_fn_t callback_fn, void *context);
  280. int (*quorum_unregister_callback) (quorum_callback_fn_t callback_fn, void *context);
  281. /*
  282. * This one is for the quorum management plugin's use
  283. */
  284. int (*quorum_initialize)(struct quorum_callin_functions *fns);
  285. /*
  286. * Plugin loading and unloading
  287. */
  288. int (*plugin_interface_reference) (
  289. hdb_handle_t *handle,
  290. const char *iface_name,
  291. int version,
  292. void **interface,
  293. void *context);
  294. int (*plugin_interface_release) (hdb_handle_t handle);
  295. /*
  296. * Service loading and unloading APIs
  297. */
  298. unsigned int (*service_link_and_init) (
  299. struct corosync_api_v1 *corosync_api_v1,
  300. const char *service_name,
  301. unsigned int service_ver);
  302. unsigned int (*service_unlink_and_exit) (
  303. struct corosync_api_v1 *corosync_api_v1,
  304. const char *service_name,
  305. unsigned int service_ver);
  306. /*
  307. * Error handling APIs
  308. */
  309. void (*error_memory_failure) (void) __attribute__ ((noreturn));
  310. #define corosync_fatal_error(err) api->fatal_error ((err), __FILE__, __LINE__)
  311. void (*fatal_error) (cs_fatal_error_t err,
  312. const char *file,
  313. unsigned int line) __attribute__ ((noreturn));
  314. void (*shutdown_request) (void);
  315. void (*state_dump) (void);
  316. qb_loop_t *(*poll_handle_get) (void);
  317. void *(*totem_get_stats)(void);
  318. int (*schedwrk_create_nolock) (
  319. hdb_handle_t *handle,
  320. int (schedwrk_fn) (const void *),
  321. const void *context);
  322. int (*poll_dispatch_add) (qb_loop_t * handle,
  323. int fd,
  324. int events,
  325. void *data,
  326. int (*dispatch_fn) (int fd,
  327. int revents,
  328. void *data));
  329. int (*poll_dispatch_delete) (
  330. qb_loop_t * handle,
  331. int fd);
  332. };
  333. #define SERVICE_ID_MAKE(a,b) ( ((a)<<16) | (b) )
  334. #define SERVICE_HANDLER_MAXIMUM_COUNT 64
  335. struct corosync_lib_handler {
  336. void (*lib_handler_fn) (void *conn, const void *msg);
  337. enum cs_lib_flow_control flow_control;
  338. };
  339. struct corosync_exec_handler {
  340. void (*exec_handler_fn) (const void *msg, unsigned int nodeid);
  341. void (*exec_endian_convert_fn) (void *msg);
  342. };
  343. struct corosync_service_engine_iface_ver0 {
  344. struct corosync_service_engine *(*corosync_get_service_engine_ver0) (void);
  345. };
  346. typedef void (*sync_init_v1_fn_t) (
  347. const unsigned int *member_list,
  348. size_t member_list_entries,
  349. const struct memb_ring_id *ring_id) ;
  350. struct corosync_service_engine {
  351. const char *name;
  352. unsigned short id;
  353. unsigned short priority; /* Lower priority are loaded first, unloaded last.
  354. * 0 is a special case which always loaded _and_ unloaded last
  355. */
  356. unsigned int private_data_size;
  357. enum cs_lib_flow_control flow_control;
  358. enum cs_lib_allow_inquorate allow_inquorate;
  359. int (*exec_init_fn) (struct corosync_api_v1 *);
  360. int (*exec_exit_fn) (void);
  361. void (*exec_dump_fn) (void);
  362. int (*lib_init_fn) (void *conn);
  363. int (*lib_exit_fn) (void *conn);
  364. struct corosync_lib_handler *lib_engine;
  365. int lib_engine_count;
  366. struct corosync_exec_handler *exec_engine;
  367. int exec_engine_count;
  368. int (*config_init_fn) (struct corosync_api_v1 *);
  369. void (*confchg_fn) (
  370. enum totem_configuration_type configuration_type,
  371. const unsigned int *member_list, size_t member_list_entries,
  372. const unsigned int *left_list, size_t left_list_entries,
  373. const unsigned int *joined_list, size_t joined_list_entries,
  374. const struct memb_ring_id *ring_id);
  375. enum cs_sync_mode sync_mode;
  376. sync_init_v1_fn_t sync_init;
  377. int (*sync_process) (void);
  378. void (*sync_activate) (void);
  379. void (*sync_abort) (void);
  380. };
  381. #endif /* COROAPI_H_DEFINED */