coroapi.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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. #endif /* OBJECT_PARENT_HANDLE_DEFINED */
  85. struct corosync_api_v1 {
  86. /*
  87. * Object and configuration APIs
  88. */
  89. int (*object_create) (
  90. unsigned int parent_object_handle,
  91. unsigned int *object_handle,
  92. void *object_name, unsigned int object_name_len);
  93. int (*object_priv_set) (
  94. unsigned int object_handle,
  95. void *priv);
  96. int (*object_key_create) (
  97. unsigned int object_handle,
  98. void *key_name,
  99. int key_len,
  100. void *value,
  101. int value_len);
  102. int (*object_destroy) (
  103. unsigned int object_handle);
  104. int (*object_valid_set) (
  105. unsigned int object_handle,
  106. struct object_valid *object_valid_list,
  107. unsigned int object_valid_list_entries);
  108. int (*object_key_valid_set) (
  109. unsigned int object_handle,
  110. struct object_key_valid *object_key_valid_list,
  111. unsigned int object_key_valid_list_entries);
  112. int (*object_find_create) (
  113. unsigned int parent_object_handle,
  114. void *object_name,
  115. int object_name_len,
  116. unsigned int *object_find_handle);
  117. int (*object_find_next) (
  118. unsigned int object_find_handle,
  119. unsigned int *object_handle);
  120. int (*object_find_destroy) (
  121. unsigned int object_find_handle);
  122. int (*object_key_get) (
  123. unsigned int object_handle,
  124. void *key_name,
  125. int key_len,
  126. void **value,
  127. int *value_len);
  128. int (*object_priv_get) (
  129. unsigned int jobject_handle,
  130. void **priv);
  131. int (*object_key_replace) (
  132. unsigned int object_handle,
  133. void *key_name,
  134. int key_len,
  135. void *old_value,
  136. int old_value_len,
  137. void *new_value,
  138. int new_value_len);
  139. int (*object_key_delete) (
  140. unsigned int object_handle,
  141. void *key_name,
  142. int key_len,
  143. void *value,
  144. int value_len);
  145. int (*object_iter_reset) (
  146. unsigned int parent_object_handle);
  147. int (*object_iter) (
  148. unsigned int parent_object_handle,
  149. void **object_name,
  150. int *name_len,
  151. unsigned int *object_handle);
  152. int (*object_key_iter_reset) (
  153. unsigned int object_handle);
  154. int (*object_key_iter) (
  155. unsigned int parent_object_handle,
  156. void **key_name,
  157. int *key_len,
  158. void **value,
  159. int *value_len);
  160. int (*object_parent_get) (
  161. unsigned int object_handle,
  162. unsigned int *parent_handle);
  163. int (*object_dump) (
  164. unsigned int object_handle,
  165. FILE *file);
  166. int (*object_find_from) (
  167. unsigned int parent_object_handle,
  168. unsigned int start_pos,
  169. void *object_name,
  170. int object_name_len,
  171. unsigned int *object_handle,
  172. unsigned int *next_pos);
  173. int (*object_iter_from) (
  174. unsigned int parent_object_handle,
  175. unsigned int start_pos,
  176. void **object_name,
  177. int *name_len,
  178. unsigned int *object_handle);
  179. int (*object_key_iter_from) (
  180. unsigned int parent_object_handle,
  181. unsigned int start_pos,
  182. void **key_name,
  183. int *key_len,
  184. void **value,
  185. int *value_len);
  186. int (*object_write_config) (char **error_string);
  187. /*
  188. * Time and timer APIs
  189. */
  190. int (*timer_add_duration) (
  191. unsigned long long nanoseconds_in_future,
  192. void *data,
  193. void (*timer_nf) (void *data),
  194. corosync_timer_handle_t *handle);
  195. int (*timer_add_absolute) (
  196. unsigned long long nanoseconds_from_epoch,
  197. void *data,
  198. void (*timer_fn) (void *data),
  199. corosync_timer_handle_t *handle);
  200. void (*timer_delete) (
  201. corosync_timer_handle_t timer_handle);
  202. unsigned long long (*timer_time_get) (void);
  203. /*
  204. * IPC APIs
  205. */
  206. void (*ipc_source_set) (mar_message_source_t *source, void *conn);
  207. int (*ipc_source_is_local) (mar_message_source_t *source);
  208. void *(*ipc_private_data_get) (void *conn);
  209. int (*ipc_response_send) (void *conn, void *msg, int mlen);
  210. int (*ipc_dispatch_send) (void *conn, void *msg, int mlen);
  211. /*
  212. * DEPRECATED
  213. */
  214. int (*ipc_conn_send_response) (void *conn, void *msg, int mlen);
  215. /*
  216. * DEPRECATED
  217. */
  218. void *(*ipc_conn_partner_get) (void *conn);
  219. void (*ipc_fc_create) (
  220. void *conn,
  221. unsigned int service,
  222. char *id,
  223. int id_len,
  224. void (*flow_control_state_set_fn)
  225. (void *context,
  226. enum corosync_flow_control_state flow_control_state_set),
  227. void *context);
  228. void (*ipc_fc_destroy) (
  229. void *conn,
  230. unsigned int service,
  231. unsigned char *id,
  232. int id_len);
  233. void (*ipc_refcnt_inc) (void *conn);
  234. void (*ipc_refcnt_dec) (void *conn);
  235. /*
  236. * Totem APIs
  237. */
  238. int (*totem_nodeid_get) (void);
  239. int (*totem_family_get) (void);
  240. int (*totem_ring_reenable) (void);
  241. int (*totem_mcast) (struct iovec *iovec, int iov_len, unsigned int guarantee);
  242. int (*totem_send_ok) (struct iovec *iovec, int iov_len);
  243. int (*totem_ifaces_get) (
  244. unsigned int nodeid,
  245. struct totem_ip_address *interfaces,
  246. char ***status,
  247. unsigned int *iface_count);
  248. char *(*totem_ifaces_print) (unsigned int nodeid);
  249. char *(*totem_ip_print) (struct totem_ip_address *addr);
  250. /*
  251. * Service loading and unloading APIs
  252. */
  253. unsigned int (*service_link_and_init) (
  254. struct corosync_api_v1 *corosync_api_v1,
  255. char *service_name,
  256. unsigned int service_ver);
  257. unsigned int (*service_unlink_and_exit) (
  258. struct corosync_api_v1 *corosync_api_v1,
  259. char *service_name,
  260. unsigned int service_ver);
  261. /*
  262. * Error handling APIs
  263. */
  264. void (*error_memory_failure) (void);
  265. };
  266. #define SERVICE_ID_MAKE(a,b) ( ((a)<<16) | (b) )
  267. #define SERVICE_HANDLER_MAXIMUM_COUNT 64
  268. struct corosync_lib_handler {
  269. void (*lib_handler_fn) (void *conn, void *msg);
  270. int response_size;
  271. int response_id;
  272. enum corosync_lib_flow_control flow_control;
  273. };
  274. struct corosync_exec_handler {
  275. void (*exec_handler_fn) (void *msg, unsigned int nodeid);
  276. void (*exec_endian_convert_fn) (void *msg);
  277. };
  278. struct corosync_service_engine_iface_ver0 {
  279. struct corosync_service_engine *(*corosync_get_service_engine_ver0) (void);
  280. };
  281. struct corosync_service_engine {
  282. char *name;
  283. unsigned short id;
  284. unsigned int private_data_size;
  285. enum corosync_lib_flow_control flow_control;
  286. int (*exec_init_fn) (struct corosync_api_v1 *);
  287. int (*exec_exit_fn) (void);
  288. void (*exec_dump_fn) (void);
  289. int (*lib_init_fn) (void *conn);
  290. int (*lib_exit_fn) (void *conn);
  291. struct corosync_lib_handler *lib_engine;
  292. int lib_engine_count;
  293. struct corosync_exec_handler *exec_engine;
  294. int exec_engine_count;
  295. int (*config_init_fn) (struct corosync_api_v1 *);
  296. void (*confchg_fn) (
  297. enum totem_configuration_type configuration_type,
  298. unsigned int *member_list, int member_list_entries,
  299. unsigned int *left_list, int left_list_entries,
  300. unsigned int *joined_list, int joined_list_entries,
  301. struct memb_ring_id *ring_id);
  302. void (*sync_init) (void);
  303. int (*sync_process) (void);
  304. void (*sync_activate) (void);
  305. void (*sync_abort) (void);
  306. };
  307. #endif /* COROAPI_H_DEFINED */