coroapi.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  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. #if defined(COROSYNC_BSD) || defined(COROSYNC_SOLARIS)
  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. unsigned int interfaces_size,
  195. char ***status,
  196. unsigned int *iface_count);
  197. const char *(*totem_ifaces_print) (unsigned int nodeid);
  198. const char *(*totem_ip_print) (const struct totem_ip_address *addr);
  199. int (*totem_crypto_set) (const char *cipher_type, const char *hash_type);
  200. int (*totem_callback_token_create) (
  201. void **handle_out,
  202. enum totem_callback_token_type type,
  203. int delete,
  204. int (*callback_fn) (enum totem_callback_token_type type,
  205. const void *),
  206. const void *data);
  207. /*
  208. * Totem open process groups API for those service engines
  209. * wanting their own groups
  210. */
  211. int (*tpg_init) (
  212. void **instance,
  213. void (*deliver_fn) (
  214. unsigned int nodeid,
  215. const void *msg,
  216. unsigned int msg_len,
  217. int endian_conversion_required),
  218. void (*confchg_fn) (
  219. enum totem_configuration_type configuration_type,
  220. const unsigned int *member_list,
  221. size_t member_list_entries,
  222. const unsigned int *left_list,
  223. size_t left_list_entries,
  224. const unsigned int *joined_list,
  225. size_t joined_list_entries,
  226. const struct memb_ring_id *ring_id));
  227. int (*tpg_exit) (
  228. void *instance);
  229. int (*tpg_join) (
  230. void *instance,
  231. const struct corosync_tpg_group *groups,
  232. size_t group_cnt);
  233. int (*tpg_leave) (
  234. void *instance,
  235. const struct corosync_tpg_group *groups,
  236. size_t group_cnt);
  237. int (*tpg_joined_mcast) (
  238. void *totempg_groups_instance,
  239. const struct iovec *iovec,
  240. unsigned int iov_len,
  241. int guarantee);
  242. int (*tpg_joined_reserve) (
  243. void *totempg_groups_instance,
  244. const struct iovec *iovec,
  245. unsigned int iov_len);
  246. int (*tpg_joined_release) (
  247. int reserved_msgs);
  248. int (*tpg_groups_mcast) (
  249. void *instance,
  250. int guarantee,
  251. const struct corosync_tpg_group *groups,
  252. size_t groups_cnt,
  253. const struct iovec *iovec,
  254. unsigned int iov_len);
  255. int (*tpg_groups_reserve) (
  256. void *instance,
  257. const struct corosync_tpg_group *groups,
  258. size_t groups_cnt,
  259. const struct iovec *iovec,
  260. unsigned int iov_len);
  261. int (*tpg_groups_release) (
  262. int reserved_msgs);
  263. int (*schedwrk_create) (
  264. hdb_handle_t *handle,
  265. int (schedwrk_fn) (const void *),
  266. const void *context);
  267. void (*schedwrk_destroy) (hdb_handle_t handle);
  268. int (*sync_request) (
  269. const char *service_name);
  270. /*
  271. * User plugin-callable functions for quorum
  272. */
  273. int (*quorum_is_quorate) (void);
  274. int (*quorum_register_callback) (quorum_callback_fn_t callback_fn, void *context);
  275. int (*quorum_unregister_callback) (quorum_callback_fn_t callback_fn, void *context);
  276. /*
  277. * This one is for the quorum management plugin's use
  278. */
  279. int (*quorum_initialize)(struct quorum_callin_functions *fns);
  280. /*
  281. * Plugin loading and unloading
  282. */
  283. int (*plugin_interface_reference) (
  284. hdb_handle_t *handle,
  285. const char *iface_name,
  286. int version,
  287. void **interface,
  288. void *context);
  289. int (*plugin_interface_release) (hdb_handle_t handle);
  290. /*
  291. * Service loading and unloading APIs
  292. */
  293. unsigned int (*service_link_and_init) (
  294. struct corosync_api_v1 *corosync_api_v1,
  295. const char *service_name,
  296. unsigned int service_ver);
  297. unsigned int (*service_unlink_and_exit) (
  298. struct corosync_api_v1 *corosync_api_v1,
  299. const char *service_name,
  300. unsigned int service_ver);
  301. /*
  302. * Error handling APIs
  303. */
  304. void (*error_memory_failure) (void) __attribute__ ((noreturn));
  305. #define corosync_fatal_error(err) api->fatal_error ((err), __FILE__, __LINE__)
  306. void (*fatal_error) (cs_fatal_error_t err,
  307. const char *file,
  308. unsigned int line) __attribute__ ((noreturn));
  309. void (*shutdown_request) (void);
  310. void (*state_dump) (void);
  311. qb_loop_t *(*poll_handle_get) (void);
  312. void *(*totem_get_stats)(void);
  313. int (*schedwrk_create_nolock) (
  314. hdb_handle_t *handle,
  315. int (schedwrk_fn) (const void *),
  316. const void *context);
  317. int (*poll_dispatch_add) (qb_loop_t * handle,
  318. int fd,
  319. int events,
  320. void *data,
  321. int (*dispatch_fn) (int fd,
  322. int revents,
  323. void *data));
  324. int (*poll_dispatch_delete) (
  325. qb_loop_t * handle,
  326. int fd);
  327. };
  328. #define SERVICE_ID_MAKE(a,b) ( ((a)<<16) | (b) )
  329. #define SERVICE_HANDLER_MAXIMUM_COUNT 64
  330. #define SERVICES_COUNT_MAX 64
  331. struct corosync_lib_handler {
  332. void (*lib_handler_fn) (void *conn, const void *msg);
  333. enum cs_lib_flow_control flow_control;
  334. };
  335. struct corosync_exec_handler {
  336. void (*exec_handler_fn) (const void *msg, unsigned int nodeid);
  337. void (*exec_endian_convert_fn) (void *msg);
  338. };
  339. struct corosync_service_engine_iface_ver0 {
  340. struct corosync_service_engine *(*corosync_get_service_engine_ver0) (void);
  341. };
  342. struct corosync_service_engine {
  343. const char *name;
  344. unsigned short id;
  345. unsigned short priority; /* Lower priority are loaded first, unloaded last.
  346. * 0 is a special case which always loaded _and_ unloaded last
  347. */
  348. unsigned int private_data_size;
  349. enum cs_lib_flow_control flow_control;
  350. enum cs_lib_allow_inquorate allow_inquorate;
  351. char *(*exec_init_fn) (struct corosync_api_v1 *);
  352. int (*exec_exit_fn) (void);
  353. void (*exec_dump_fn) (void);
  354. int (*lib_init_fn) (void *conn);
  355. int (*lib_exit_fn) (void *conn);
  356. struct corosync_lib_handler *lib_engine;
  357. int lib_engine_count;
  358. struct corosync_exec_handler *exec_engine;
  359. int exec_engine_count;
  360. int (*config_init_fn) (struct corosync_api_v1 *);
  361. void (*confchg_fn) (
  362. enum totem_configuration_type configuration_type,
  363. const unsigned int *member_list, size_t member_list_entries,
  364. const unsigned int *left_list, size_t left_list_entries,
  365. const unsigned int *joined_list, size_t joined_list_entries,
  366. const struct memb_ring_id *ring_id);
  367. void (*sync_init) (
  368. const unsigned int *trans_list,
  369. size_t trans_list_entries,
  370. const unsigned int *member_list,
  371. size_t member_list_entries,
  372. const struct memb_ring_id *ring_id);
  373. int (*sync_process) (void);
  374. void (*sync_activate) (void);
  375. void (*sync_abort) (void);
  376. };
  377. #endif /* COROAPI_H_DEFINED */