coroapi.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  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. void *group;
  44. int 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. int object_len;
  119. };
  120. struct object_key_valid {
  121. char *key_name;
  122. int key_len;
  123. int (*validate_callback) (const void *key, int key_len,
  124. const void *value, int 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, int object_name_len,
  146. const void *key_name_pt, int key_len,
  147. const void *key_value_pt, int key_value_len,
  148. 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. uint8_t *name_pt, int name_len,
  153. void *priv_data_pt);
  154. typedef void (*object_destroy_notify_fn_t) (
  155. hdb_handle_t parent_object_handle,
  156. uint8_t *name_pt, int name_len,
  157. void *priv_data_pt);
  158. typedef void (*object_notify_callback_fn_t)(
  159. hdb_handle_t object_handle,
  160. const void *key_name, int key_len,
  161. const void *value, int value_len,
  162. object_change_type_t type,
  163. void * priv_data_pt);
  164. typedef void (*object_reload_notify_fn_t) (
  165. objdb_reload_notify_type_t,
  166. int flush,
  167. 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. unsigned int *view_list,
  179. int 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, unsigned int object_name_len);
  191. int (*object_priv_set) (
  192. hdb_handle_t object_handle,
  193. void *priv);
  194. int (*object_key_create) (
  195. hdb_handle_t object_handle,
  196. const void *key_name,
  197. int key_len,
  198. const void *value,
  199. int value_len);
  200. int (*object_destroy) (
  201. hdb_handle_t object_handle);
  202. int (*object_valid_set) (
  203. hdb_handle_t object_handle,
  204. struct object_valid *object_valid_list,
  205. unsigned int object_valid_list_entries);
  206. int (*object_key_valid_set) (
  207. hdb_handle_t object_handle,
  208. struct object_key_valid *object_key_valid_list,
  209. unsigned int object_key_valid_list_entries);
  210. int (*object_find_create) (
  211. hdb_handle_t parent_object_handle,
  212. const void *object_name,
  213. int object_name_len,
  214. hdb_handle_t *object_find_handle);
  215. int (*object_find_next) (
  216. hdb_handle_t object_find_handle,
  217. hdb_handle_t *object_handle);
  218. int (*object_find_destroy) (
  219. hdb_handle_t object_find_handle);
  220. int (*object_key_get) (
  221. hdb_handle_t object_handle,
  222. const void *key_name,
  223. int key_len,
  224. void **value,
  225. int *value_len);
  226. int (*object_priv_get) (
  227. hdb_handle_t jobject_handle,
  228. void **priv);
  229. int (*object_key_replace) (
  230. hdb_handle_t object_handle,
  231. const void *key_name,
  232. int key_len,
  233. const void *new_value,
  234. int new_value_len);
  235. int (*object_key_delete) (
  236. hdb_handle_t object_handle,
  237. const void *key_name,
  238. int key_len);
  239. int (*object_iter_reset) (
  240. hdb_handle_t parent_object_handle);
  241. int (*object_iter) (
  242. hdb_handle_t parent_object_handle,
  243. void **object_name,
  244. int *name_len,
  245. hdb_handle_t *object_handle);
  246. int (*object_key_iter_reset) (
  247. hdb_handle_t object_handle);
  248. int (*object_key_iter) (
  249. hdb_handle_t parent_object_handle,
  250. void **key_name,
  251. int *key_len,
  252. void **value,
  253. int *value_len);
  254. int (*object_parent_get) (
  255. hdb_handle_t object_handle,
  256. hdb_handle_t *parent_handle);
  257. int (*object_name_get) (
  258. hdb_handle_t object_handle,
  259. char *object_name,
  260. int *object_name_len);
  261. int (*object_dump) (
  262. hdb_handle_t object_handle,
  263. FILE *file);
  264. int (*object_key_iter_from) (
  265. hdb_handle_t parent_object_handle,
  266. hdb_handle_t start_pos,
  267. void **key_name,
  268. int *key_len,
  269. void **value,
  270. int *value_len);
  271. int (*object_track_start) (
  272. hdb_handle_t object_handle,
  273. object_track_depth_t depth,
  274. object_key_change_notify_fn_t key_change_notify_fn,
  275. object_create_notify_fn_t object_create_notify_fn,
  276. object_destroy_notify_fn_t object_destroy_notify_fn,
  277. object_reload_notify_fn_t object_reload_notify_fn,
  278. void * priv_data_pt);
  279. void (*object_track_stop) (
  280. object_key_change_notify_fn_t key_change_notify_fn,
  281. object_create_notify_fn_t object_create_notify_fn,
  282. object_destroy_notify_fn_t object_destroy_notify_fn,
  283. object_reload_notify_fn_t object_reload_notify_fn,
  284. void * priv_data_pt);
  285. int (*object_write_config) (char **error_string);
  286. int (*object_reload_config) (int flush,
  287. char **error_string);
  288. int (*object_key_increment) (
  289. hdb_handle_t object_handle,
  290. const void *key_name,
  291. int key_len,
  292. unsigned int *value);
  293. int (*object_key_decrement) (
  294. hdb_handle_t object_handle,
  295. const void *key_name,
  296. int key_len,
  297. unsigned int *value);
  298. /*
  299. * Time and timer APIs
  300. */
  301. int (*timer_add_duration) (
  302. unsigned long long nanoseconds_in_future,
  303. void *data,
  304. void (*timer_nf) (void *data),
  305. corosync_timer_handle_t *handle);
  306. int (*timer_add_absolute) (
  307. unsigned long long nanoseconds_from_epoch,
  308. void *data,
  309. void (*timer_fn) (void *data),
  310. corosync_timer_handle_t *handle);
  311. void (*timer_delete) (
  312. corosync_timer_handle_t timer_handle);
  313. unsigned long long (*timer_time_get) (void);
  314. unsigned long long (*timer_expire_time_get) (
  315. corosync_timer_handle_t timer_handle);
  316. /*
  317. * IPC APIs
  318. */
  319. void (*ipc_source_set) (mar_message_source_t *source, void *conn);
  320. int (*ipc_source_is_local) (const mar_message_source_t *source);
  321. void *(*ipc_private_data_get) (void *conn);
  322. int (*ipc_response_send) (void *conn, const void *msg, int mlen);
  323. int (*ipc_response_iov_send) (void *conn,
  324. const struct iovec *iov, int iov_len);
  325. int (*ipc_dispatch_send) (void *conn, const void *msg, int mlen);
  326. int (*ipc_dispatch_iov_send) (void *conn,
  327. const struct iovec *iov, int iov_len);
  328. void (*ipc_refcnt_inc) (void *conn);
  329. void (*ipc_refcnt_dec) (void *conn);
  330. /*
  331. * Totem APIs
  332. */
  333. unsigned int (*totem_nodeid_get) (void);
  334. int (*totem_family_get) (void);
  335. int (*totem_ring_reenable) (void);
  336. int (*totem_mcast) (struct iovec *iovec, int iov_len, unsigned int guarantee);
  337. int (*totem_ifaces_get) (
  338. unsigned int nodeid,
  339. struct totem_ip_address *interfaces,
  340. char ***status,
  341. unsigned int *iface_count);
  342. char *(*totem_ifaces_print) (unsigned int nodeid);
  343. char *(*totem_ip_print) (struct totem_ip_address *addr);
  344. int (*totem_callback_token_create) (
  345. void **handle_out,
  346. enum totem_callback_token_type type,
  347. int delete,
  348. int (*callback_fn) (enum totem_callback_token_type type, void *),
  349. void *data);
  350. /*
  351. * Totem open process groups API for those service engines
  352. * wanting their own groups
  353. */
  354. int (*tpg_init) (
  355. hdb_handle_t *handle,
  356. void (*deliver_fn) (
  357. unsigned int nodeid,
  358. struct iovec *iovec,
  359. int iov_len,
  360. int endian_conversion_required),
  361. void (*confchg_fn) (
  362. enum totem_configuration_type configuration_type,
  363. unsigned int *member_list, int member_list_entries,
  364. unsigned int *left_list, int left_list_entries,
  365. unsigned int *joined_list, int joined_list_entries,
  366. struct memb_ring_id *ring_id));
  367. int (*tpg_exit) (
  368. hdb_handle_t handle);
  369. int (*tpg_join) (
  370. hdb_handle_t handle,
  371. struct corosync_tpg_group *groups,
  372. int gruop_cnt);
  373. int (*tpg_leave) (
  374. hdb_handle_t handle,
  375. struct corosync_tpg_group *groups,
  376. int gruop_cnt);
  377. int (*tpg_joined_mcast) (
  378. hdb_handle_t handle,
  379. const struct iovec *iovec,
  380. int iov_len,
  381. int guarantee);
  382. int (*tpg_joined_reserve) (
  383. hdb_handle_t handle,
  384. const struct iovec *iovec,
  385. int iov_len);
  386. int (*tpg_joined_release) (
  387. int reserved_msgs);
  388. int (*tpg_groups_mcast) (
  389. hdb_handle_t handle,
  390. int guarantee,
  391. const struct corosync_tpg_group *groups,
  392. int groups_cnt,
  393. const struct iovec *iovec,
  394. int iov_len);
  395. int (*tpg_groups_reserve) (
  396. hdb_handle_t handle,
  397. const struct corosync_tpg_group *groups,
  398. int groups_cnt,
  399. const struct iovec *iovec,
  400. int iov_len);
  401. int (*tpg_groups_release) (
  402. int reserved_msgs);
  403. int (*sync_request) (
  404. char *service_name);
  405. /*
  406. * User plugin-callable functions for quorum
  407. */
  408. int (*quorum_is_quorate) (void);
  409. int (*quorum_register_callback) (quorum_callback_fn_t callback_fn, void *context);
  410. int (*quorum_unregister_callback) (quorum_callback_fn_t callback_fn, void *context);
  411. /*
  412. * This one is for the quorum management plugin's use
  413. */
  414. int (*quorum_initialize)(struct quorum_callin_functions *fns,
  415. sync_callback_fn_t *sync_callback_fn);
  416. /*
  417. * Plugin loading and unloading
  418. */
  419. int (*plugin_interface_reference) (
  420. hdb_handle_t *handle,
  421. const char *iface_name,
  422. int version,
  423. void **interface,
  424. void *context);
  425. int (*plugin_interface_release) (hdb_handle_t handle);
  426. /*
  427. * Service loading and unloading APIs
  428. */
  429. unsigned int (*service_link_and_init) (
  430. struct corosync_api_v1 *corosync_api_v1,
  431. const char *service_name,
  432. unsigned int service_ver);
  433. unsigned int (*service_unlink_and_exit) (
  434. struct corosync_api_v1 *corosync_api_v1,
  435. const char *service_name,
  436. unsigned int service_ver);
  437. /*
  438. * Error handling APIs
  439. */
  440. void (*error_memory_failure) (void);
  441. #define corosync_fatal_error(err) api->fatal_error ((err), __FILE__, __LINE__)
  442. void (*fatal_error) (cs_fatal_error_t err, const char *file, unsigned int line);
  443. };
  444. #define SERVICE_ID_MAKE(a,b) ( ((a)<<16) | (b) )
  445. #define SERVICE_HANDLER_MAXIMUM_COUNT 64
  446. struct corosync_lib_handler {
  447. void (*lib_handler_fn) (void *conn, void *msg);
  448. int response_size;
  449. int response_id;
  450. enum cs_lib_flow_control flow_control;
  451. };
  452. struct corosync_exec_handler {
  453. void (*exec_handler_fn) (const void *msg, unsigned int nodeid);
  454. void (*exec_endian_convert_fn) (void *msg);
  455. };
  456. struct corosync_service_engine_iface_ver0 {
  457. struct corosync_service_engine *(*corosync_get_service_engine_ver0) (void);
  458. };
  459. struct corosync_service_engine {
  460. char *name;
  461. unsigned short id;
  462. unsigned int private_data_size;
  463. enum cs_lib_flow_control flow_control;
  464. enum cs_lib_allow_inquorate allow_inquorate;
  465. int (*exec_init_fn) (struct corosync_api_v1 *);
  466. int (*exec_exit_fn) (void);
  467. void (*exec_dump_fn) (void);
  468. int (*lib_init_fn) (void *conn);
  469. int (*lib_exit_fn) (void *conn);
  470. struct corosync_lib_handler *lib_engine;
  471. int lib_engine_count;
  472. struct corosync_exec_handler *exec_engine;
  473. int exec_engine_count;
  474. int (*config_init_fn) (struct corosync_api_v1 *);
  475. void (*confchg_fn) (
  476. enum totem_configuration_type configuration_type,
  477. unsigned int *member_list, int member_list_entries,
  478. unsigned int *left_list, int left_list_entries,
  479. unsigned int *joined_list, int joined_list_entries,
  480. struct memb_ring_id *ring_id);
  481. void (*sync_init) (void);
  482. int (*sync_process) (void);
  483. void (*sync_activate) (void);
  484. void (*sync_abort) (void);
  485. };
  486. #endif /* COROAPI_H_DEFINED */