coroapi.h 13 KB

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