coroapi.h 9.2 KB

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