coroapi.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  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. typedef void * corosync_timer_handle_t;
  42. struct corosync_tpg_group {
  43. const void *group;
  44. size_t group_len;
  45. };
  46. #define TOTEMIP_ADDRLEN (sizeof(struct in6_addr))
  47. #define PROCESSOR_COUNT_MAX 384
  48. #define INTERFACE_MAX 2
  49. #ifndef MESSAGE_SIZE_MAX
  50. #define MESSAGE_SIZE_MAX 1024*1024 /* (1MB) */
  51. #endif /* MESSAGE_SIZE_MAX */
  52. #ifndef MESSAGE_QUEUE_MAX
  53. #define MESSAGE_QUEUE_MAX MESSAGE_SIZE_MAX / totem_config->net_mtu
  54. #endif /* MESSAGE_QUEUE_MAX */
  55. #define TOTEM_AGREED 0
  56. #define TOTEM_SAFE 1
  57. #define MILLI_2_NANO_SECONDS 1000000ULL
  58. #if !defined(TOTEM_IP_ADDRESS)
  59. struct totem_ip_address {
  60. unsigned int nodeid;
  61. unsigned short family;
  62. unsigned char addr[TOTEMIP_ADDRLEN];
  63. } __attribute__((packed));
  64. #endif
  65. #if !defined(MEMB_RING_ID)
  66. struct memb_ring_id {
  67. struct totem_ip_address rep;
  68. unsigned long long seq;
  69. } __attribute__((packed));
  70. #endif
  71. #if !defined(TOTEM_CONFIGURATION_TYPE)
  72. enum totem_configuration_type {
  73. TOTEM_CONFIGURATION_REGULAR,
  74. TOTEM_CONFIGURATION_TRANSITIONAL
  75. };
  76. #endif
  77. #if !defined(TOTEM_CALLBACK_TOKEN_TYPE)
  78. enum totem_callback_token_type {
  79. TOTEM_CALLBACK_TOKEN_RECEIVED = 1,
  80. TOTEM_CALLBACK_TOKEN_SENT = 2
  81. };
  82. #endif
  83. enum cs_lib_flow_control {
  84. CS_LIB_FLOW_CONTROL_REQUIRED = 1,
  85. CS_LIB_FLOW_CONTROL_NOT_REQUIRED = 2
  86. };
  87. #define corosync_lib_flow_control cs_lib_flow_control
  88. #define COROSYNC_LIB_FLOW_CONTROL_REQUIRED CS_LIB_FLOW_CONTROL_REQUIRED
  89. #define COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  90. enum cs_lib_allow_inquorate {
  91. CS_LIB_DISALLOW_INQUORATE = 0, /* default */
  92. CS_LIB_ALLOW_INQUORATE = 1
  93. };
  94. #if !defined (COROSYNC_FLOW_CONTROL_STATE)
  95. enum cs_flow_control_state {
  96. CS_FLOW_CONTROL_STATE_DISABLED,
  97. CS_FLOW_CONTROL_STATE_ENABLED
  98. };
  99. #define corosync_flow_control_state cs_flow_control_state
  100. #define CS_FLOW_CONTROL_STATE_DISABLED CS_FLOW_CONTROL_STATE_DISABLED
  101. #define CS_FLOW_CONTROL_STATE_ENABLED CS_FLOW_CONTROL_STATE_ENABLED
  102. #endif /* COROSYNC_FLOW_CONTROL_STATE */
  103. typedef enum {
  104. COROSYNC_FATAL_ERROR_EXIT = -1,
  105. COROSYNC_LIBAIS_SOCKET = -6,
  106. COROSYNC_LIBAIS_BIND = -7,
  107. COROSYNC_READKEY = -8,
  108. COROSYNC_INVALID_CONFIG = -9,
  109. COROSYNC_DYNAMICLOAD = -12,
  110. COROSYNC_OUT_OF_MEMORY = -15,
  111. COROSYNC_FATAL_ERR = -16
  112. } cs_fatal_error_t;
  113. #define corosync_fatal_error_t cs_fatal_error_t;
  114. #ifndef OBJECT_PARENT_HANDLE
  115. #define OBJECT_PARENT_HANDLE 0xffffffff00000000ULL
  116. struct object_valid {
  117. char *object_name;
  118. size_t object_len;
  119. };
  120. struct object_key_valid {
  121. char *key_name;
  122. size_t key_len;
  123. int (*validate_callback) (const void *key, size_t key_len,
  124. const void *value, size_t value_len);
  125. };
  126. /* deprecated */
  127. typedef enum {
  128. OBJECT_TRACK_DEPTH_ONE,
  129. OBJECT_TRACK_DEPTH_RECURSIVE
  130. } object_track_depth_t;
  131. typedef enum {
  132. OBJECT_KEY_CREATED,
  133. OBJECT_KEY_REPLACED,
  134. OBJECT_KEY_DELETED
  135. } object_change_type_t;
  136. typedef enum {
  137. OBJDB_RELOAD_NOTIFY_START,
  138. OBJDB_RELOAD_NOTIFY_END,
  139. OBJDB_RELOAD_NOTIFY_FAILED
  140. } objdb_reload_notify_type_t;
  141. typedef void (*object_key_change_notify_fn_t)(
  142. object_change_type_t change_type,
  143. hdb_handle_t parent_object_handle,
  144. hdb_handle_t object_handle,
  145. const void *object_name_pt, size_t object_name_len,
  146. const void *key_name_pt, size_t key_len,
  147. const void *key_value_pt, size_t key_value_len,
  148. const void *priv_data_pt);
  149. typedef void (*object_create_notify_fn_t) (
  150. hdb_handle_t parent_object_handle,
  151. hdb_handle_t object_handle,
  152. const uint8_t *name_pt, size_t name_len,
  153. const void *priv_data_pt);
  154. typedef void (*object_destroy_notify_fn_t) (
  155. hdb_handle_t parent_object_handle,
  156. const uint8_t *name_pt, size_t name_len,
  157. const void *priv_data_pt);
  158. typedef void (*object_notify_callback_fn_t)(
  159. hdb_handle_t object_handle,
  160. const void *key_name, size_t key_len,
  161. const void *value, size_t value_len,
  162. object_change_type_t type,
  163. const void * priv_data_pt);
  164. typedef void (*object_reload_notify_fn_t) (
  165. objdb_reload_notify_type_t,
  166. int flush,
  167. const void *priv_data_pt);
  168. #endif /* OBJECT_PARENT_HANDLE_DEFINED */
  169. #ifndef QUORUM_H_DEFINED
  170. typedef void (*quorum_callback_fn_t) (int quorate, void *context);
  171. struct quorum_callin_functions
  172. {
  173. int (*quorate) (void);
  174. int (*register_callback) (quorum_callback_fn_t callback_fn, void *context);
  175. int (*unregister_callback) (quorum_callback_fn_t callback_fn, void *context);
  176. };
  177. typedef void (*sync_callback_fn_t) (
  178. const unsigned int *view_list,
  179. size_t view_list_entries,
  180. int primary_designated,
  181. struct memb_ring_id *ring_id);
  182. #endif /* QUORUM_H_DEFINED */
  183. struct corosync_api_v1 {
  184. /*
  185. * Object and configuration APIs
  186. */
  187. int (*object_create) (
  188. hdb_handle_t parent_object_handle,
  189. hdb_handle_t *object_handle,
  190. const void *object_name,
  191. size_t object_name_len);
  192. int (*object_priv_set) (
  193. hdb_handle_t object_handle,
  194. void *priv);
  195. int (*object_key_create) (
  196. hdb_handle_t object_handle,
  197. const void *key_name,
  198. size_t key_len,
  199. const void *value,
  200. size_t value_len);
  201. int (*object_destroy) (
  202. hdb_handle_t object_handle);
  203. int (*object_valid_set) (
  204. hdb_handle_t object_handle,
  205. struct object_valid *object_valid_list,
  206. unsigned int object_valid_list_entries);
  207. int (*object_key_valid_set) (
  208. hdb_handle_t object_handle,
  209. struct object_key_valid *object_key_valid_list,
  210. unsigned int object_key_valid_list_entries);
  211. int (*object_find_create) (
  212. hdb_handle_t parent_object_handle,
  213. const void *object_name,
  214. size_t object_name_len,
  215. hdb_handle_t *object_find_handle);
  216. int (*object_find_next) (
  217. hdb_handle_t object_find_handle,
  218. hdb_handle_t *object_handle);
  219. int (*object_find_destroy) (
  220. hdb_handle_t object_find_handle);
  221. int (*object_key_get) (
  222. hdb_handle_t object_handle,
  223. const void *key_name,
  224. size_t key_len,
  225. void **value,
  226. size_t *value_len);
  227. int (*object_priv_get) (
  228. hdb_handle_t jobject_handle,
  229. void **priv);
  230. int (*object_key_replace) (
  231. hdb_handle_t object_handle,
  232. const void *key_name,
  233. size_t key_len,
  234. const void *new_value,
  235. size_t new_value_len);
  236. int (*object_key_delete) (
  237. hdb_handle_t object_handle,
  238. const void *key_name,
  239. size_t key_len);
  240. int (*object_iter_reset) (
  241. hdb_handle_t parent_object_handle);
  242. int (*object_iter) (
  243. hdb_handle_t parent_object_handle,
  244. void **object_name,
  245. size_t *name_len,
  246. hdb_handle_t *object_handle);
  247. int (*object_key_iter_reset) (
  248. hdb_handle_t object_handle);
  249. int (*object_key_iter) (
  250. hdb_handle_t parent_object_handle,
  251. void **key_name,
  252. size_t *key_len,
  253. void **value,
  254. size_t *value_len);
  255. int (*object_parent_get) (
  256. hdb_handle_t object_handle,
  257. hdb_handle_t *parent_handle);
  258. int (*object_name_get) (
  259. hdb_handle_t object_handle,
  260. char *object_name,
  261. size_t *object_name_len);
  262. int (*object_dump) (
  263. hdb_handle_t object_handle,
  264. FILE *file);
  265. int (*object_key_iter_from) (
  266. hdb_handle_t parent_object_handle,
  267. hdb_handle_t start_pos,
  268. void **key_name,
  269. size_t *key_len,
  270. void **value,
  271. size_t *value_len);
  272. int (*object_track_start) (
  273. hdb_handle_t object_handle,
  274. object_track_depth_t depth,
  275. object_key_change_notify_fn_t key_change_notify_fn,
  276. object_create_notify_fn_t object_create_notify_fn,
  277. object_destroy_notify_fn_t object_destroy_notify_fn,
  278. object_reload_notify_fn_t object_reload_notify_fn,
  279. void * priv_data_pt);
  280. void (*object_track_stop) (
  281. object_key_change_notify_fn_t key_change_notify_fn,
  282. object_create_notify_fn_t object_create_notify_fn,
  283. object_destroy_notify_fn_t object_destroy_notify_fn,
  284. object_reload_notify_fn_t object_reload_notify_fn,
  285. void * priv_data_pt);
  286. int (*object_write_config) (const char **error_string);
  287. int (*object_reload_config) (int flush,
  288. const char **error_string);
  289. int (*object_key_increment) (
  290. hdb_handle_t object_handle,
  291. const void *key_name,
  292. size_t key_len,
  293. unsigned int *value);
  294. int (*object_key_decrement) (
  295. hdb_handle_t object_handle,
  296. const void *key_name,
  297. size_t key_len,
  298. unsigned int *value);
  299. /*
  300. * Time and timer APIs
  301. */
  302. int (*timer_add_duration) (
  303. unsigned long long nanoseconds_in_future,
  304. void *data,
  305. void (*timer_nf) (void *data),
  306. corosync_timer_handle_t *handle);
  307. int (*timer_add_absolute) (
  308. unsigned long long nanoseconds_from_epoch,
  309. void *data,
  310. void (*timer_fn) (void *data),
  311. corosync_timer_handle_t *handle);
  312. void (*timer_delete) (
  313. corosync_timer_handle_t timer_handle);
  314. unsigned long long (*timer_time_get) (void);
  315. unsigned long long (*timer_expire_time_get) (
  316. corosync_timer_handle_t timer_handle);
  317. /*
  318. * IPC APIs
  319. */
  320. void (*ipc_source_set) (mar_message_source_t *source, void *conn);
  321. int (*ipc_source_is_local) (const mar_message_source_t *source);
  322. void *(*ipc_private_data_get) (void *conn);
  323. int (*ipc_response_send) (void *conn, const void *msg, int mlen);
  324. int (*ipc_response_iov_send) (void *conn,
  325. const struct iovec *iov, unsigned int iov_len);
  326. int (*ipc_dispatch_send) (void *conn, const void *msg, int mlen);
  327. int (*ipc_dispatch_iov_send) (void *conn,
  328. const struct iovec *iov, unsigned int iov_len);
  329. void (*ipc_refcnt_inc) (void *conn);
  330. void (*ipc_refcnt_dec) (void *conn);
  331. /*
  332. * Totem APIs
  333. */
  334. unsigned int (*totem_nodeid_get) (void);
  335. int (*totem_family_get) (void);
  336. int (*totem_ring_reenable) (void);
  337. int (*totem_mcast) (struct iovec *iovec, unsigned int iov_len, unsigned int guarantee);
  338. int (*totem_ifaces_get) (
  339. unsigned int nodeid,
  340. struct totem_ip_address *interfaces,
  341. char ***status,
  342. unsigned int *iface_count);
  343. const char *(*totem_ifaces_print) (unsigned int nodeid);
  344. const char *(*totem_ip_print) (const struct totem_ip_address *addr);
  345. int (*totem_callback_token_create) (
  346. void **handle_out,
  347. enum totem_callback_token_type type,
  348. int delete,
  349. int (*callback_fn) (enum totem_callback_token_type type,
  350. const void *),
  351. const void *data);
  352. /*
  353. * Totem open process groups API for those service engines
  354. * wanting their own groups
  355. */
  356. int (*tpg_init) (
  357. hdb_handle_t *handle,
  358. void (*deliver_fn) (
  359. unsigned int nodeid,
  360. struct iovec *iovec,
  361. unsigned int iov_len,
  362. int endian_conversion_required),
  363. void (*confchg_fn) (
  364. enum totem_configuration_type configuration_type,
  365. const unsigned int *member_list,
  366. size_t member_list_entries,
  367. const unsigned int *left_list,
  368. size_t left_list_entries,
  369. const unsigned int *joined_list,
  370. size_t joined_list_entries,
  371. const struct memb_ring_id *ring_id));
  372. int (*tpg_exit) (
  373. hdb_handle_t handle);
  374. int (*tpg_join) (
  375. hdb_handle_t handle,
  376. struct corosync_tpg_group *groups,
  377. int group_cnt);
  378. int (*tpg_leave) (
  379. hdb_handle_t handle,
  380. struct corosync_tpg_group *groups,
  381. int group_cnt);
  382. int (*tpg_joined_mcast) (
  383. hdb_handle_t handle,
  384. const struct iovec *iovec,
  385. unsigned int iov_len,
  386. int guarantee);
  387. int (*tpg_joined_reserve) (
  388. hdb_handle_t handle,
  389. const struct iovec *iovec,
  390. unsigned int iov_len);
  391. int (*tpg_joined_release) (
  392. int reserved_msgs);
  393. int (*tpg_groups_mcast) (
  394. hdb_handle_t handle,
  395. int guarantee,
  396. const struct corosync_tpg_group *groups,
  397. int groups_cnt,
  398. const struct iovec *iovec,
  399. unsigned int iov_len);
  400. int (*tpg_groups_reserve) (
  401. hdb_handle_t handle,
  402. const struct corosync_tpg_group *groups,
  403. int groups_cnt,
  404. const struct iovec *iovec,
  405. unsigned int iov_len);
  406. int (*tpg_groups_release) (
  407. int reserved_msgs);
  408. int (*sync_request) (
  409. const char *service_name);
  410. /*
  411. * User plugin-callable functions for quorum
  412. */
  413. int (*quorum_is_quorate) (void);
  414. int (*quorum_register_callback) (quorum_callback_fn_t callback_fn, void *context);
  415. int (*quorum_unregister_callback) (quorum_callback_fn_t callback_fn, void *context);
  416. /*
  417. * This one is for the quorum management plugin's use
  418. */
  419. int (*quorum_initialize)(struct quorum_callin_functions *fns);
  420. /*
  421. * Plugin loading and unloading
  422. */
  423. int (*plugin_interface_reference) (
  424. hdb_handle_t *handle,
  425. const char *iface_name,
  426. int version,
  427. void **interface,
  428. void *context);
  429. int (*plugin_interface_release) (hdb_handle_t handle);
  430. /*
  431. * Service loading and unloading APIs
  432. */
  433. unsigned int (*service_link_and_init) (
  434. struct corosync_api_v1 *corosync_api_v1,
  435. const char *service_name,
  436. unsigned int service_ver);
  437. unsigned int (*service_unlink_and_exit) (
  438. struct corosync_api_v1 *corosync_api_v1,
  439. const char *service_name,
  440. unsigned int service_ver);
  441. /*
  442. * Error handling APIs
  443. */
  444. void (*error_memory_failure) (void);
  445. #define corosync_fatal_error(err) api->fatal_error ((err), __FILE__, __LINE__)
  446. void (*fatal_error) (cs_fatal_error_t err, const char *file, unsigned int line);
  447. };
  448. #define SERVICE_ID_MAKE(a,b) ( ((a)<<16) | (b) )
  449. #define SERVICE_HANDLER_MAXIMUM_COUNT 64
  450. struct corosync_lib_handler {
  451. void (*lib_handler_fn) (void *conn, void *msg);
  452. int response_size;
  453. int response_id;
  454. enum cs_lib_flow_control flow_control;
  455. };
  456. struct corosync_exec_handler {
  457. void (*exec_handler_fn) (const void *msg, unsigned int nodeid);
  458. void (*exec_endian_convert_fn) (void *msg);
  459. };
  460. struct corosync_service_engine_iface_ver0 {
  461. struct corosync_service_engine *(*corosync_get_service_engine_ver0) (void);
  462. };
  463. struct corosync_service_engine {
  464. const char *name;
  465. unsigned short id;
  466. unsigned int private_data_size;
  467. enum cs_lib_flow_control flow_control;
  468. enum cs_lib_allow_inquorate allow_inquorate;
  469. int (*exec_init_fn) (struct corosync_api_v1 *);
  470. int (*exec_exit_fn) (void);
  471. void (*exec_dump_fn) (void);
  472. int (*lib_init_fn) (void *conn);
  473. int (*lib_exit_fn) (void *conn);
  474. struct corosync_lib_handler *lib_engine;
  475. int lib_engine_count;
  476. struct corosync_exec_handler *exec_engine;
  477. int exec_engine_count;
  478. int (*config_init_fn) (struct corosync_api_v1 *);
  479. void (*confchg_fn) (
  480. enum totem_configuration_type configuration_type,
  481. const unsigned int *member_list, size_t member_list_entries,
  482. const unsigned int *left_list, size_t left_list_entries,
  483. const unsigned int *joined_list, size_t joined_list_entries,
  484. const struct memb_ring_id *ring_id);
  485. void (*sync_init) (void);
  486. int (*sync_process) (void);
  487. void (*sync_activate) (void);
  488. void (*sync_abort) (void);
  489. };
  490. #endif /* COROAPI_H_DEFINED */