coroapi.h 15 KB

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