coroapi.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  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 corosync_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. enum corosync_lib_flow_control {
  78. COROSYNC_LIB_FLOW_CONTROL_REQUIRED = 1,
  79. COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED = 2
  80. };
  81. #if !defined (COROSYNC_FLOW_CONTROL_STATE)
  82. enum corosync_flow_control_state {
  83. COROSYNC_FLOW_CONTROL_STATE_DISABLED,
  84. COROSYNC_FLOW_CONTROL_STATE_ENABLED
  85. };
  86. #endif
  87. typedef enum {
  88. COROSYNC_FATAL_ERROR_EXIT = -1,
  89. COROSYNC_LIBAIS_SOCKET = -6,
  90. COROSYNC_LIBAIS_BIND = -7,
  91. COROSYNC_READKEY = -8,
  92. COROSYNC_INVALID_CONFIG = -9,
  93. COROSYNC_DYNAMICLOAD = -12,
  94. COROSYNC_OUT_OF_MEMORY = -15,
  95. COROSYNC_FATAL_ERR = -16
  96. } corosync_fatal_error_t;
  97. #ifndef OBJECT_PARENT_HANDLE
  98. #define OBJECT_PARENT_HANDLE 0
  99. struct object_valid {
  100. char *object_name;
  101. int object_len;
  102. };
  103. struct object_key_valid {
  104. char *key_name;
  105. int key_len;
  106. int (*validate_callback) (void *key, int key_len, void *value, int value_len);
  107. };
  108. typedef enum {
  109. OBJECT_TRACK_DEPTH_ONE,
  110. OBJECT_TRACK_DEPTH_RECURSIVE
  111. } object_track_depth_t;
  112. typedef enum {
  113. OBJECT_KEY_CREATED,
  114. OBJECT_KEY_REPLACED,
  115. OBJECT_KEY_DELETED
  116. } object_change_type_t;
  117. typedef void (*object_key_change_notify_fn_t)(object_change_type_t change_type,
  118. unsigned int parent_object_handle,
  119. unsigned int object_handle,
  120. void *object_name_pt, int object_name_len,
  121. void *key_name_pt, int key_len,
  122. void *key_value_pt, int key_value_len,
  123. void *priv_data_pt);
  124. typedef void (*object_create_notify_fn_t) (unsigned int parent_object_handle,
  125. unsigned int object_handle,
  126. uint8_t *name_pt, int name_len,
  127. void *priv_data_pt);
  128. typedef void (*object_destroy_notify_fn_t) (unsigned int parent_object_handle,
  129. uint8_t *name_pt, int name_len,
  130. void *priv_data_pt);
  131. typedef void (*object_notify_callback_fn_t)(unsigned int object_handle,
  132. void *key_name, int key_len,
  133. void *value, int value_len,
  134. object_change_type_t type,
  135. void * priv_data_pt);
  136. #endif /* OBJECT_PARENT_HANDLE_DEFINED */
  137. struct corosync_api_v1 {
  138. /*
  139. * Object and configuration APIs
  140. */
  141. int (*object_create) (
  142. unsigned int parent_object_handle,
  143. unsigned int *object_handle,
  144. void *object_name, unsigned int object_name_len);
  145. int (*object_priv_set) (
  146. unsigned int object_handle,
  147. void *priv);
  148. int (*object_key_create) (
  149. unsigned int object_handle,
  150. void *key_name,
  151. int key_len,
  152. void *value,
  153. int value_len);
  154. int (*object_destroy) (
  155. unsigned int object_handle);
  156. int (*object_valid_set) (
  157. unsigned int object_handle,
  158. struct object_valid *object_valid_list,
  159. unsigned int object_valid_list_entries);
  160. int (*object_key_valid_set) (
  161. unsigned int object_handle,
  162. struct object_key_valid *object_key_valid_list,
  163. unsigned int object_key_valid_list_entries);
  164. int (*object_find_create) (
  165. unsigned int parent_object_handle,
  166. void *object_name,
  167. int object_name_len,
  168. unsigned int *object_find_handle);
  169. int (*object_find_next) (
  170. unsigned int object_find_handle,
  171. unsigned int *object_handle);
  172. int (*object_find_destroy) (
  173. unsigned int object_find_handle);
  174. int (*object_key_get) (
  175. unsigned int object_handle,
  176. void *key_name,
  177. int key_len,
  178. void **value,
  179. int *value_len);
  180. int (*object_priv_get) (
  181. unsigned int jobject_handle,
  182. void **priv);
  183. int (*object_key_replace) (
  184. unsigned int object_handle,
  185. void *key_name,
  186. int key_len,
  187. void *old_value,
  188. int old_value_len,
  189. void *new_value,
  190. int new_value_len);
  191. int (*object_key_delete) (
  192. unsigned int object_handle,
  193. void *key_name,
  194. int key_len,
  195. void *value,
  196. int value_len);
  197. int (*object_iter_reset) (
  198. unsigned int parent_object_handle);
  199. int (*object_iter) (
  200. unsigned int parent_object_handle,
  201. void **object_name,
  202. int *name_len,
  203. unsigned int *object_handle);
  204. int (*object_key_iter_reset) (
  205. unsigned int object_handle);
  206. int (*object_key_iter) (
  207. unsigned int parent_object_handle,
  208. void **key_name,
  209. int *key_len,
  210. void **value,
  211. int *value_len);
  212. int (*object_parent_get) (
  213. unsigned int object_handle,
  214. unsigned int *parent_handle);
  215. int (*object_name_get) (
  216. unsigned int object_handle,
  217. char *object_name,
  218. int *object_name_len);
  219. int (*object_dump) (
  220. unsigned int object_handle,
  221. FILE *file);
  222. int (*object_key_iter_from) (
  223. unsigned int parent_object_handle,
  224. unsigned int start_pos,
  225. void **key_name,
  226. int *key_len,
  227. void **value,
  228. int *value_len);
  229. int (*object_track_start) (
  230. unsigned int object_handle,
  231. object_track_depth_t depth,
  232. object_key_change_notify_fn_t key_change_notify_fn,
  233. object_create_notify_fn_t object_create_notify_fn,
  234. object_destroy_notify_fn_t object_destroy_notify_fn,
  235. void * priv_data_pt);
  236. void (*object_track_stop) (
  237. object_key_change_notify_fn_t key_change_notify_fn,
  238. object_create_notify_fn_t object_create_notify_fn,
  239. object_destroy_notify_fn_t object_destroy_notify_fn,
  240. void * priv_data_pt);
  241. int (*object_write_config) (char **error_string);
  242. int (*object_reload_config) (int flush,
  243. char **error_string);
  244. int (*object_key_increment) (
  245. unsigned int object_handle,
  246. void *key_name,
  247. int key_len,
  248. unsigned int *value);
  249. int (*object_key_decrement) (
  250. unsigned int object_handle,
  251. void *key_name,
  252. int key_len,
  253. unsigned int *value);
  254. /*
  255. * Time and timer APIs
  256. */
  257. int (*timer_add_duration) (
  258. unsigned long long nanoseconds_in_future,
  259. void *data,
  260. void (*timer_nf) (void *data),
  261. corosync_timer_handle_t *handle);
  262. int (*timer_add_absolute) (
  263. unsigned long long nanoseconds_from_epoch,
  264. void *data,
  265. void (*timer_fn) (void *data),
  266. corosync_timer_handle_t *handle);
  267. void (*timer_delete) (
  268. corosync_timer_handle_t timer_handle);
  269. unsigned long long (*timer_time_get) (void);
  270. /*
  271. * IPC APIs
  272. */
  273. void (*ipc_source_set) (mar_message_source_t *source, void *conn);
  274. int (*ipc_source_is_local) (mar_message_source_t *source);
  275. void *(*ipc_private_data_get) (void *conn);
  276. int (*ipc_response_send) (void *conn, void *msg, int mlen);
  277. int (*ipc_response_no_fcc) (void *conn, void *msg, int mlen);
  278. int (*ipc_dispatch_send) (void *conn, void *msg, int mlen);
  279. /*
  280. * DEPRECATED
  281. */
  282. int (*ipc_conn_send_response) (void *conn, void *msg, int mlen);
  283. /*
  284. * DEPRECATED
  285. */
  286. void *(*ipc_conn_partner_get) (void *conn);
  287. void (*ipc_fc_create) (
  288. void *conn,
  289. unsigned int service,
  290. char *id,
  291. int id_len,
  292. void (*flow_control_state_set_fn)
  293. (void *context,
  294. enum corosync_flow_control_state flow_control_state_set),
  295. void *context);
  296. void (*ipc_fc_destroy) (
  297. void *conn,
  298. unsigned int service,
  299. unsigned char *id,
  300. int id_len);
  301. void (*ipc_refcnt_inc) (void *conn);
  302. void (*ipc_refcnt_dec) (void *conn);
  303. /*
  304. * Totem APIs
  305. */
  306. int (*totem_nodeid_get) (void);
  307. int (*totem_family_get) (void);
  308. int (*totem_ring_reenable) (void);
  309. int (*totem_mcast) (struct iovec *iovec, int iov_len, unsigned int guarantee);
  310. int (*totem_send_ok) (struct iovec *iovec, int iov_len);
  311. int (*totem_ifaces_get) (
  312. unsigned int nodeid,
  313. struct totem_ip_address *interfaces,
  314. char ***status,
  315. unsigned int *iface_count);
  316. char *(*totem_ifaces_print) (unsigned int nodeid);
  317. char *(*totem_ip_print) (struct totem_ip_address *addr);
  318. /*
  319. * Totem open process groups API for those service engines
  320. * wanting their own groups
  321. */
  322. int (*tpg_init) (
  323. corosync_tpg_handle *handle,
  324. void (*deliver_fn) (
  325. unsigned int nodeid,
  326. struct iovec *iovec,
  327. int iov_len,
  328. int endian_conversion_required),
  329. void (*confchg_fn) (
  330. enum totem_configuration_type configuration_type,
  331. unsigned int *member_list, int member_list_entries,
  332. unsigned int *left_list, int left_list_entries,
  333. unsigned int *joined_list, int joined_list_entries,
  334. struct memb_ring_id *ring_id));
  335. int (*tpg_exit) (
  336. corosync_tpg_handle handle);
  337. int (*tpg_join) (
  338. corosync_tpg_handle handle,
  339. struct corosync_tpg_group *groups,
  340. int gruop_cnt);
  341. int (*tpg_leave) (
  342. corosync_tpg_handle handle,
  343. struct corosync_tpg_group *groups,
  344. int gruop_cnt);
  345. int (*tpg_joined_mcast) (
  346. corosync_tpg_handle handle,
  347. struct iovec *iovec,
  348. int iov_len,
  349. int guarantee);
  350. int (*tpg_joined_send_ok) (
  351. corosync_tpg_handle handle,
  352. struct iovec *iovec,
  353. int iov_len);
  354. int (*tpg_groups_mcast) (
  355. corosync_tpg_handle handle,
  356. int guarantee,
  357. struct corosync_tpg_group *groups,
  358. int groups_cnt,
  359. struct iovec *iovec,
  360. int iov_len);
  361. int (*tpg_groups_send_ok) (
  362. corosync_tpg_handle handle,
  363. struct corosync_tpg_group *groups,
  364. int groups_cnt,
  365. struct iovec *iovec,
  366. int iov_len);
  367. int (*sync_request) (
  368. char *service_name);
  369. /*
  370. * Plugin loading and unloading
  371. */
  372. int (*plugin_interface_reference) (
  373. unsigned int *handle,
  374. char *iface_name,
  375. int version,
  376. void **interface,
  377. void *context);
  378. int (*plugin_interface_release) (unsigned int handle);
  379. /*
  380. * Service loading and unloading APIs
  381. */
  382. unsigned int (*service_link_and_init) (
  383. struct corosync_api_v1 *corosync_api_v1,
  384. char *service_name,
  385. unsigned int service_ver);
  386. unsigned int (*service_unlink_and_exit) (
  387. struct corosync_api_v1 *corosync_api_v1,
  388. char *service_name,
  389. unsigned int service_ver);
  390. /*
  391. * Error handling APIs
  392. */
  393. void (*error_memory_failure) (void);
  394. #define corosync_fatal_error(err) api->fatal_error ((err), __FILE__, __LINE__)
  395. void (*fatal_error) (corosync_fatal_error_t err, const char *file, unsigned int line);
  396. };
  397. #define SERVICE_ID_MAKE(a,b) ( ((a)<<16) | (b) )
  398. #define SERVICE_HANDLER_MAXIMUM_COUNT 64
  399. struct corosync_lib_handler {
  400. void (*lib_handler_fn) (void *conn, void *msg);
  401. int response_size;
  402. int response_id;
  403. enum corosync_lib_flow_control flow_control;
  404. };
  405. struct corosync_exec_handler {
  406. void (*exec_handler_fn) (void *msg, unsigned int nodeid);
  407. void (*exec_endian_convert_fn) (void *msg);
  408. };
  409. struct corosync_service_engine_iface_ver0 {
  410. struct corosync_service_engine *(*corosync_get_service_engine_ver0) (void);
  411. };
  412. struct corosync_service_engine {
  413. char *name;
  414. unsigned short id;
  415. unsigned int private_data_size;
  416. enum corosync_lib_flow_control flow_control;
  417. int (*exec_init_fn) (struct corosync_api_v1 *);
  418. int (*exec_exit_fn) (void);
  419. void (*exec_dump_fn) (void);
  420. int (*lib_init_fn) (void *conn);
  421. int (*lib_exit_fn) (void *conn);
  422. struct corosync_lib_handler *lib_engine;
  423. int lib_engine_count;
  424. struct corosync_exec_handler *exec_engine;
  425. int exec_engine_count;
  426. int (*config_init_fn) (struct corosync_api_v1 *);
  427. void (*confchg_fn) (
  428. enum totem_configuration_type configuration_type,
  429. unsigned int *member_list, int member_list_entries,
  430. unsigned int *left_list, int left_list_entries,
  431. unsigned int *joined_list, int joined_list_entries,
  432. struct memb_ring_id *ring_id);
  433. void (*sync_init) (void);
  434. int (*sync_process) (void);
  435. void (*sync_activate) (void);
  436. void (*sync_abort) (void);
  437. };
  438. #endif /* COROAPI_H_DEFINED */