coroapi.h 13 KB

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