coroapi.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  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. int (*object_reload_config) (int flush,
  233. char **error_string);
  234. /*
  235. * Time and timer APIs
  236. */
  237. int (*timer_add_duration) (
  238. unsigned long long nanoseconds_in_future,
  239. void *data,
  240. void (*timer_nf) (void *data),
  241. corosync_timer_handle_t *handle);
  242. int (*timer_add_absolute) (
  243. unsigned long long nanoseconds_from_epoch,
  244. void *data,
  245. void (*timer_fn) (void *data),
  246. corosync_timer_handle_t *handle);
  247. void (*timer_delete) (
  248. corosync_timer_handle_t timer_handle);
  249. unsigned long long (*timer_time_get) (void);
  250. /*
  251. * IPC APIs
  252. */
  253. void (*ipc_source_set) (mar_message_source_t *source, void *conn);
  254. int (*ipc_source_is_local) (mar_message_source_t *source);
  255. void *(*ipc_private_data_get) (void *conn);
  256. int (*ipc_response_send) (void *conn, void *msg, int mlen);
  257. int (*ipc_dispatch_send) (void *conn, void *msg, int mlen);
  258. /*
  259. * DEPRECATED
  260. */
  261. int (*ipc_conn_send_response) (void *conn, void *msg, int mlen);
  262. /*
  263. * DEPRECATED
  264. */
  265. void *(*ipc_conn_partner_get) (void *conn);
  266. void (*ipc_fc_create) (
  267. void *conn,
  268. unsigned int service,
  269. char *id,
  270. int id_len,
  271. void (*flow_control_state_set_fn)
  272. (void *context,
  273. enum corosync_flow_control_state flow_control_state_set),
  274. void *context);
  275. void (*ipc_fc_destroy) (
  276. void *conn,
  277. unsigned int service,
  278. unsigned char *id,
  279. int id_len);
  280. void (*ipc_refcnt_inc) (void *conn);
  281. void (*ipc_refcnt_dec) (void *conn);
  282. /*
  283. * Totem APIs
  284. */
  285. int (*totem_nodeid_get) (void);
  286. int (*totem_family_get) (void);
  287. int (*totem_ring_reenable) (void);
  288. int (*totem_mcast) (struct iovec *iovec, int iov_len, unsigned int guarantee);
  289. int (*totem_send_ok) (struct iovec *iovec, int iov_len);
  290. int (*totem_ifaces_get) (
  291. unsigned int nodeid,
  292. struct totem_ip_address *interfaces,
  293. char ***status,
  294. unsigned int *iface_count);
  295. char *(*totem_ifaces_print) (unsigned int nodeid);
  296. char *(*totem_ip_print) (struct totem_ip_address *addr);
  297. /*
  298. * Totem open process groups API for those service engines
  299. * wanting their own groups
  300. */
  301. int (*tpg_init) (
  302. corosync_tpg_handle *handle,
  303. void (*deliver_fn) (
  304. unsigned int nodeid,
  305. struct iovec *iovec,
  306. int iov_len,
  307. int endian_conversion_required),
  308. void (*confchg_fn) (
  309. enum totem_configuration_type configuration_type,
  310. unsigned int *member_list, int member_list_entries,
  311. unsigned int *left_list, int left_list_entries,
  312. unsigned int *joined_list, int joined_list_entries,
  313. struct memb_ring_id *ring_id));
  314. int (*tpg_exit) (
  315. corosync_tpg_handle handle);
  316. int (*tpg_join) (
  317. corosync_tpg_handle handle,
  318. struct corosync_tpg_group *groups,
  319. int gruop_cnt);
  320. int (*tpg_leave) (
  321. corosync_tpg_handle handle,
  322. struct corosync_tpg_group *groups,
  323. int gruop_cnt);
  324. int (*tpg_joined_mcast) (
  325. corosync_tpg_handle handle,
  326. struct iovec *iovec,
  327. int iov_len,
  328. int guarantee);
  329. int (*tpg_joined_send_ok) (
  330. corosync_tpg_handle handle,
  331. struct iovec *iovec,
  332. int iov_len);
  333. int (*tpg_groups_mcast) (
  334. corosync_tpg_handle handle,
  335. int guarantee,
  336. struct corosync_tpg_group *groups,
  337. int groups_cnt,
  338. struct iovec *iovec,
  339. int iov_len);
  340. int (*tpg_groups_send_ok) (
  341. corosync_tpg_handle handle,
  342. struct corosync_tpg_group *groups,
  343. int groups_cnt,
  344. struct iovec *iovec,
  345. int iov_len);
  346. /*
  347. * Plugin loading and unloading
  348. */
  349. int (*plugin_interface_reference) (
  350. unsigned int *handle,
  351. char *iface_name,
  352. int version,
  353. void **interface,
  354. void *context);
  355. int (*plugin_interface_release) (unsigned int handle);
  356. /*
  357. * Service loading and unloading APIs
  358. */
  359. unsigned int (*service_link_and_init) (
  360. struct corosync_api_v1 *corosync_api_v1,
  361. char *service_name,
  362. unsigned int service_ver);
  363. unsigned int (*service_unlink_and_exit) (
  364. struct corosync_api_v1 *corosync_api_v1,
  365. char *service_name,
  366. unsigned int service_ver);
  367. /*
  368. * Error handling APIs
  369. */
  370. void (*error_memory_failure) (void);
  371. };
  372. #define SERVICE_ID_MAKE(a,b) ( ((a)<<16) | (b) )
  373. #define SERVICE_HANDLER_MAXIMUM_COUNT 64
  374. struct corosync_lib_handler {
  375. void (*lib_handler_fn) (void *conn, void *msg);
  376. int response_size;
  377. int response_id;
  378. enum corosync_lib_flow_control flow_control;
  379. };
  380. struct corosync_exec_handler {
  381. void (*exec_handler_fn) (void *msg, unsigned int nodeid);
  382. void (*exec_endian_convert_fn) (void *msg);
  383. };
  384. struct corosync_service_engine_iface_ver0 {
  385. struct corosync_service_engine *(*corosync_get_service_engine_ver0) (void);
  386. };
  387. struct corosync_service_engine {
  388. char *name;
  389. unsigned short id;
  390. unsigned int private_data_size;
  391. enum corosync_lib_flow_control flow_control;
  392. int (*exec_init_fn) (struct corosync_api_v1 *);
  393. int (*exec_exit_fn) (void);
  394. void (*exec_dump_fn) (void);
  395. int (*lib_init_fn) (void *conn);
  396. int (*lib_exit_fn) (void *conn);
  397. struct corosync_lib_handler *lib_engine;
  398. int lib_engine_count;
  399. struct corosync_exec_handler *exec_engine;
  400. int exec_engine_count;
  401. int (*config_init_fn) (struct corosync_api_v1 *);
  402. void (*confchg_fn) (
  403. enum totem_configuration_type configuration_type,
  404. unsigned int *member_list, int member_list_entries,
  405. unsigned int *left_list, int left_list_entries,
  406. unsigned int *joined_list, int joined_list_entries,
  407. struct memb_ring_id *ring_id);
  408. void (*sync_init) (void);
  409. int (*sync_process) (void);
  410. void (*sync_activate) (void);
  411. void (*sync_abort) (void);
  412. };
  413. #endif /* COROAPI_H_DEFINED */