coroapi.h 13 KB

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