cpg.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. cpg_handle_t is NOT a
  153. * file descriptor and may not be used directly.
  154. */
  155. cs_error_t cpg_fd_get (
  156. cpg_handle_t handle,
  157. int *fd);
  158. /*
  159. * Get and set contexts for a CPG handle
  160. */
  161. cs_error_t cpg_context_get (
  162. cpg_handle_t handle,
  163. void **context);
  164. cs_error_t cpg_context_set (
  165. cpg_handle_t handle,
  166. void *context);
  167. /*
  168. * Dispatch messages and configuration changes
  169. */
  170. cs_error_t cpg_dispatch (
  171. cpg_handle_t handle,
  172. cs_dispatch_flags_t dispatch_types);
  173. /*
  174. * Join one or more groups.
  175. * messages multicasted with cpg_mcast_joined will be sent to every
  176. * group that has been joined on handle handle. Any message multicasted
  177. * to a group that has been previously joined will be delivered in cpg_dispatch
  178. */
  179. cs_error_t cpg_join (
  180. cpg_handle_t handle,
  181. const struct cpg_name *group);
  182. /*
  183. * Leave one or more groups
  184. */
  185. cs_error_t cpg_leave (
  186. cpg_handle_t handle,
  187. const struct cpg_name *group);
  188. /*
  189. * Multicast to groups joined with cpg_join.
  190. * The iovec described by iovec will be multicasted to all groups joined with
  191. * the cpg_join interface for handle.
  192. */
  193. cs_error_t cpg_mcast_joined (
  194. cpg_handle_t handle,
  195. cpg_guarantee_t guarantee,
  196. const struct iovec *iovec,
  197. unsigned int iov_len);
  198. /*
  199. * Get membership information from cpg
  200. */
  201. cs_error_t cpg_membership_get (
  202. cpg_handle_t handle,
  203. struct cpg_name *groupName,
  204. struct cpg_address *member_list,
  205. int *member_list_entries);
  206. cs_error_t cpg_local_get (
  207. cpg_handle_t handle,
  208. unsigned int *local_nodeid);
  209. cs_error_t cpg_flow_control_state_get (
  210. cpg_handle_t handle,
  211. cpg_flow_control_state_t *flow_control_enabled);
  212. cs_error_t cpg_zcb_alloc (
  213. cpg_handle_t handle,
  214. size_t size,
  215. void **buffer);
  216. cs_error_t cpg_zcb_free (
  217. cpg_handle_t handle,
  218. void *buffer);
  219. cs_error_t cpg_zcb_mcast_joined (
  220. cpg_handle_t handle,
  221. cpg_guarantee_t guarantee,
  222. void *msg,
  223. size_t msg_len);
  224. /*
  225. * Iteration
  226. */
  227. cs_error_t cpg_iteration_initialize(
  228. cpg_handle_t handle,
  229. cpg_iteration_type_t iteration_type,
  230. const struct cpg_name *group,
  231. cpg_iteration_handle_t *cpg_iteration_handle);
  232. cs_error_t cpg_iteration_next(
  233. cpg_iteration_handle_t handle,
  234. struct cpg_iteration_description_t *description);
  235. cs_error_t cpg_iteration_finalize (
  236. cpg_iteration_handle_t handle);
  237. #ifdef __cplusplus
  238. }
  239. #endif
  240. #endif /* COROSYNC_CPG_H_DEFINED */