cpg.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. struct cpg_address {
  72. uint32_t nodeid;
  73. uint32_t pid;
  74. uint32_t reason;
  75. };
  76. #define CPG_MAX_NAME_LENGTH 128
  77. struct cpg_name {
  78. uint32_t length;
  79. char value[CPG_MAX_NAME_LENGTH];
  80. };
  81. #define CPG_MEMBERS_MAX 128
  82. struct cpg_iteration_description_t {
  83. struct cpg_name group;
  84. uint32_t nodeid;
  85. uint32_t pid;
  86. };
  87. typedef void (*cpg_deliver_fn_t) (
  88. cpg_handle_t handle,
  89. const struct cpg_name *group_name,
  90. uint32_t nodeid,
  91. uint32_t pid,
  92. /*
  93. * Unlike many "msg" pointers, this one is deliberately *not*
  94. * declared const in order to permit in-place endian conversion.
  95. */
  96. void *msg,
  97. size_t msg_len);
  98. typedef void (*cpg_confchg_fn_t) (
  99. cpg_handle_t handle,
  100. const struct cpg_name *group_name,
  101. const struct cpg_address *member_list, size_t member_list_entries,
  102. const struct cpg_address *left_list, size_t left_list_entries,
  103. const struct cpg_address *joined_list, size_t joined_list_entries);
  104. typedef struct {
  105. cpg_deliver_fn_t cpg_deliver_fn;
  106. cpg_confchg_fn_t cpg_confchg_fn;
  107. } cpg_callbacks_t;
  108. /** @} */
  109. /*
  110. * Create a new cpg connection
  111. */
  112. cs_error_t cpg_initialize (
  113. cpg_handle_t *handle,
  114. cpg_callbacks_t *callbacks);
  115. /*
  116. * Close the cpg handle
  117. */
  118. cs_error_t cpg_finalize (
  119. cpg_handle_t handle);
  120. /*
  121. * Get a file descriptor on which to poll. cpg_handle_t is NOT a
  122. * file descriptor and may not be used directly.
  123. */
  124. cs_error_t cpg_fd_get (
  125. cpg_handle_t handle,
  126. int *fd);
  127. /*
  128. * Get and set contexts for a CPG handle
  129. */
  130. cs_error_t cpg_context_get (
  131. cpg_handle_t handle,
  132. void **context);
  133. cs_error_t cpg_context_set (
  134. cpg_handle_t handle,
  135. void *context);
  136. /*
  137. * Dispatch messages and configuration changes
  138. */
  139. cs_error_t cpg_dispatch (
  140. cpg_handle_t handle,
  141. cs_dispatch_flags_t dispatch_types);
  142. /*
  143. * Join one or more groups.
  144. * messages multicasted with cpg_mcast_joined will be sent to every
  145. * group that has been joined on handle handle. Any message multicasted
  146. * to a group that has been previously joined will be delivered in cpg_dispatch
  147. */
  148. cs_error_t cpg_join (
  149. cpg_handle_t handle,
  150. const struct cpg_name *group);
  151. /*
  152. * Leave one or more groups
  153. */
  154. cs_error_t cpg_leave (
  155. cpg_handle_t handle,
  156. const struct cpg_name *group);
  157. /*
  158. * Multicast to groups joined with cpg_join.
  159. * The iovec described by iovec will be multicasted to all groups joined with
  160. * the cpg_join interface for handle.
  161. */
  162. cs_error_t cpg_mcast_joined (
  163. cpg_handle_t handle,
  164. cpg_guarantee_t guarantee,
  165. const struct iovec *iovec,
  166. unsigned int iov_len);
  167. /*
  168. * Get membership information from cpg
  169. */
  170. cs_error_t cpg_membership_get (
  171. cpg_handle_t handle,
  172. struct cpg_name *groupName,
  173. struct cpg_address *member_list,
  174. int *member_list_entries);
  175. cs_error_t cpg_local_get (
  176. cpg_handle_t handle,
  177. unsigned int *local_nodeid);
  178. cs_error_t cpg_flow_control_state_get (
  179. cpg_handle_t handle,
  180. cpg_flow_control_state_t *flow_control_enabled);
  181. cs_error_t cpg_zcb_alloc (
  182. cpg_handle_t handle,
  183. size_t size,
  184. void **buffer);
  185. cs_error_t cpg_zcb_free (
  186. cpg_handle_t handle,
  187. void *buffer);
  188. cs_error_t cpg_zcb_mcast_joined (
  189. cpg_handle_t handle,
  190. cpg_guarantee_t guarantee,
  191. void *msg,
  192. size_t msg_len);
  193. /*
  194. * Iteration
  195. */
  196. cs_error_t cpg_iteration_initialize(
  197. cpg_handle_t handle,
  198. cpg_iteration_type_t iteration_type,
  199. const struct cpg_name *group,
  200. cpg_iteration_handle_t *cpg_iteration_handle);
  201. cs_error_t cpg_iteration_next(
  202. cpg_iteration_handle_t handle,
  203. struct cpg_iteration_description_t *description);
  204. cs_error_t cpg_iteration_finalize (
  205. cpg_iteration_handle_t handle);
  206. #ifdef __cplusplus
  207. }
  208. #endif
  209. #endif /* COROSYNC_CPG_H_DEFINED */