coroapi.h 9.1 KB

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