coroapi.h 11 KB

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