cpg.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*
  2. * Copyright (c) 2006-2009 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Christine Caulfield (ccaulfi@redhat.com)
  7. * Author: Jan Friesse (jfriesse@redhat.com)
  8. *
  9. * This software licensed under BSD license, the text of which follows:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  33. * THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #ifndef COROSYNC_CPG_H_DEFINED
  36. #define COROSYNC_CPG_H_DEFINED
  37. #include <netinet/in.h>
  38. #include <corosync/corotypes.h>
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. /**
  43. * @addtogroup cpg_corosync
  44. *
  45. * @{
  46. */
  47. typedef uint64_t cpg_handle_t;
  48. typedef uint64_t cpg_iteration_handle_t;
  49. typedef enum {
  50. CPG_TYPE_UNORDERED, /**< not implemented */
  51. CPG_TYPE_FIFO, /**< same as agreed */
  52. CPG_TYPE_AGREED,
  53. CPG_TYPE_SAFE /**< not implemented */
  54. } cpg_guarantee_t;
  55. typedef enum {
  56. CPG_FLOW_CONTROL_DISABLED, /**< flow control is disabled - new messages may be sent */
  57. CPG_FLOW_CONTROL_ENABLED /**< flow control is enabled - new messages should not be sent */
  58. } cpg_flow_control_state_t;
  59. typedef enum {
  60. CPG_REASON_JOIN = 1,
  61. CPG_REASON_LEAVE = 2,
  62. CPG_REASON_NODEDOWN = 3,
  63. CPG_REASON_NODEUP = 4,
  64. CPG_REASON_PROCDOWN = 5
  65. } cpg_reason_t;
  66. typedef enum {
  67. CPG_ITERATION_NAME_ONLY = 1,
  68. CPG_ITERATION_ONE_GROUP = 2,
  69. CPG_ITERATION_ALL = 3,
  70. } cpg_iteration_type_t;
  71. typedef enum {
  72. CPG_MODEL_V1 = 1,
  73. } cpg_model_t;
  74. struct cpg_address {
  75. uint32_t nodeid;
  76. uint32_t pid;
  77. uint32_t reason;
  78. };
  79. #define CPG_MAX_NAME_LENGTH 128
  80. struct cpg_name {
  81. uint32_t length;
  82. char value[CPG_MAX_NAME_LENGTH];
  83. };
  84. #define CPG_MEMBERS_MAX 128
  85. struct cpg_iteration_description_t {
  86. struct cpg_name group;
  87. uint32_t nodeid;
  88. uint32_t pid;
  89. };
  90. struct cpg_ring_id {
  91. uint32_t nodeid;
  92. uint64_t seq;
  93. };
  94. typedef void (*cpg_deliver_fn_t) (
  95. cpg_handle_t handle,
  96. const struct cpg_name *group_name,
  97. uint32_t nodeid,
  98. uint32_t pid,
  99. /**
  100. * Unlike many "msg" pointers, this one is deliberately *not*
  101. * declared const in order to permit in-place endian conversion.
  102. */
  103. void *msg,
  104. size_t msg_len);
  105. typedef void (*cpg_confchg_fn_t) (
  106. cpg_handle_t handle,
  107. const struct cpg_name *group_name,
  108. const struct cpg_address *member_list, size_t member_list_entries,
  109. const struct cpg_address *left_list, size_t left_list_entries,
  110. const struct cpg_address *joined_list, size_t joined_list_entries);
  111. typedef void (*cpg_totem_confchg_fn_t) (
  112. cpg_handle_t handle,
  113. struct cpg_ring_id ring_id,
  114. uint32_t member_list_entries,
  115. const uint32_t *member_list);
  116. typedef struct {
  117. cpg_deliver_fn_t cpg_deliver_fn;
  118. cpg_confchg_fn_t cpg_confchg_fn;
  119. } cpg_callbacks_t;
  120. typedef struct {
  121. cpg_model_t model;
  122. } cpg_model_data_t;
  123. #define CPG_MODEL_V1_DELIVER_INITIAL_TOTEM_CONF 0x01
  124. typedef struct {
  125. cpg_model_t model;
  126. cpg_deliver_fn_t cpg_deliver_fn;
  127. cpg_confchg_fn_t cpg_confchg_fn;
  128. cpg_totem_confchg_fn_t cpg_totem_confchg_fn;
  129. unsigned int flags;
  130. } cpg_model_v1_data_t;
  131. /** @} */
  132. /**
  133. * Create a new cpg connection
  134. */
  135. cs_error_t cpg_initialize (
  136. cpg_handle_t *handle,
  137. cpg_callbacks_t *callbacks);
  138. /**
  139. * Create a new cpg connection, initialize with model
  140. */
  141. cs_error_t cpg_model_initialize (
  142. cpg_handle_t *handle,
  143. cpg_model_t model,
  144. cpg_model_data_t *model_data,
  145. void *context);
  146. /**
  147. * Close the cpg handle
  148. */
  149. cs_error_t cpg_finalize (
  150. cpg_handle_t handle);
  151. /**
  152. * Get a file descriptor on which to poll.
  153. *
  154. * cpg_handle_t is NOT a file descriptor and may not be used directly.
  155. */
  156. cs_error_t cpg_fd_get (
  157. cpg_handle_t handle,
  158. int *fd);
  159. /**
  160. * Get contexts for a CPG handle
  161. */
  162. cs_error_t cpg_context_get (
  163. cpg_handle_t handle,
  164. void **context);
  165. /**
  166. * Set contexts for a CPG handle
  167. */
  168. cs_error_t cpg_context_set (
  169. cpg_handle_t handle,
  170. void *context);
  171. /**
  172. * Dispatch messages and configuration changes
  173. */
  174. cs_error_t cpg_dispatch (
  175. cpg_handle_t handle,
  176. cs_dispatch_flags_t dispatch_types);
  177. /**
  178. * Join one or more groups.
  179. *
  180. * messages multicasted with cpg_mcast_joined will be sent to every
  181. * group that has been joined on handle handle. Any message multicasted
  182. * to a group that has been previously joined will be delivered in cpg_dispatch
  183. */
  184. cs_error_t cpg_join (
  185. cpg_handle_t handle,
  186. const struct cpg_name *group);
  187. /**
  188. * Leave one or more groups
  189. */
  190. cs_error_t cpg_leave (
  191. cpg_handle_t handle,
  192. const struct cpg_name *group);
  193. /**
  194. * Multicast to groups joined with cpg_join.
  195. *
  196. * @param handle
  197. * @param guarantee
  198. * @param iovec This iovec will be multicasted to all groups joined with
  199. * the cpg_join interface for handle.
  200. * @param iov_len
  201. */
  202. cs_error_t cpg_mcast_joined (
  203. cpg_handle_t handle,
  204. cpg_guarantee_t guarantee,
  205. const struct iovec *iovec,
  206. unsigned int iov_len);
  207. /**
  208. * Get membership information from cpg
  209. */
  210. cs_error_t cpg_membership_get (
  211. cpg_handle_t handle,
  212. struct cpg_name *groupName,
  213. struct cpg_address *member_list,
  214. int *member_list_entries);
  215. cs_error_t cpg_local_get (
  216. cpg_handle_t handle,
  217. unsigned int *local_nodeid);
  218. cs_error_t cpg_flow_control_state_get (
  219. cpg_handle_t handle,
  220. cpg_flow_control_state_t *flow_control_enabled);
  221. cs_error_t cpg_zcb_alloc (
  222. cpg_handle_t handle,
  223. size_t size,
  224. void **buffer);
  225. cs_error_t cpg_zcb_free (
  226. cpg_handle_t handle,
  227. void *buffer);
  228. cs_error_t cpg_zcb_mcast_joined (
  229. cpg_handle_t handle,
  230. cpg_guarantee_t guarantee,
  231. void *msg,
  232. size_t msg_len);
  233. /**
  234. * Iteration
  235. */
  236. cs_error_t cpg_iteration_initialize(
  237. cpg_handle_t handle,
  238. cpg_iteration_type_t iteration_type,
  239. const struct cpg_name *group,
  240. cpg_iteration_handle_t *cpg_iteration_handle);
  241. cs_error_t cpg_iteration_next(
  242. cpg_iteration_handle_t handle,
  243. struct cpg_iteration_description_t *description);
  244. cs_error_t cpg_iteration_finalize (
  245. cpg_iteration_handle_t handle);
  246. #ifdef __cplusplus
  247. }
  248. #endif
  249. #endif /* COROSYNC_CPG_H_DEFINED */