coroapi.h 12 KB

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