cpg.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * Copyright (c) 2006-2009 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Christine Caulfield (ccaulfi@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 COROSYNC_CPG_H_DEFINED
  35. #define COROSYNC_CPG_H_DEFINED
  36. #include <netinet/in.h>
  37. #include <corosync/corotypes.h>
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /**
  42. * @addtogroup cpg_corosync
  43. *
  44. * @{
  45. */
  46. typedef uint64_t cpg_handle_t;
  47. typedef enum {
  48. CPG_TYPE_UNORDERED, /* not implemented */
  49. CPG_TYPE_FIFO, /* same as agreed */
  50. CPG_TYPE_AGREED,
  51. CPG_TYPE_SAFE /* not implemented */
  52. } cpg_guarantee_t;
  53. typedef enum {
  54. CPG_FLOW_CONTROL_DISABLED, /* flow control is disabled - new messages may be sent */
  55. CPG_FLOW_CONTROL_ENABLED /* flow control is enabled - new messages should not be sent */
  56. } cpg_flow_control_state_t;
  57. typedef enum {
  58. CPG_REASON_JOIN = 1,
  59. CPG_REASON_LEAVE = 2,
  60. CPG_REASON_NODEDOWN = 3,
  61. CPG_REASON_NODEUP = 4,
  62. CPG_REASON_PROCDOWN = 5
  63. } cpg_reason_t;
  64. struct cpg_address {
  65. uint32_t nodeid;
  66. uint32_t pid;
  67. uint32_t reason;
  68. };
  69. #define CPG_MAX_NAME_LENGTH 128
  70. struct cpg_name {
  71. uint32_t length;
  72. char value[CPG_MAX_NAME_LENGTH];
  73. };
  74. #define CPG_MEMBERS_MAX 128
  75. typedef void (*cpg_deliver_fn_t) (
  76. cpg_handle_t handle,
  77. const struct cpg_name *group_name,
  78. uint32_t nodeid,
  79. uint32_t pid,
  80. const void *msg,
  81. size_t msg_len);
  82. typedef void (*cpg_confchg_fn_t) (
  83. cpg_handle_t handle,
  84. const struct cpg_name *group_name,
  85. const struct cpg_address *member_list, size_t member_list_entries,
  86. const struct cpg_address *left_list, size_t left_list_entries,
  87. const struct cpg_address *joined_list, size_t joined_list_entries);
  88. typedef struct {
  89. cpg_deliver_fn_t cpg_deliver_fn;
  90. cpg_confchg_fn_t cpg_confchg_fn;
  91. } cpg_callbacks_t;
  92. /** @} */
  93. /*
  94. * Create a new cpg connection
  95. */
  96. cs_error_t cpg_initialize (
  97. cpg_handle_t *handle,
  98. cpg_callbacks_t *callbacks);
  99. /*
  100. * Close the cpg handle
  101. */
  102. cs_error_t cpg_finalize (
  103. cpg_handle_t handle);
  104. /*
  105. * Get a file descriptor on which to poll. cpg_handle_t is NOT a
  106. * file descriptor and may not be used directly.
  107. */
  108. cs_error_t cpg_fd_get (
  109. cpg_handle_t handle,
  110. int *fd);
  111. /*
  112. * Get and set contexts for a CPG handle
  113. */
  114. cs_error_t cpg_context_get (
  115. cpg_handle_t handle,
  116. void **context);
  117. cs_error_t cpg_context_set (
  118. cpg_handle_t handle,
  119. void *context);
  120. /*
  121. * Dispatch messages and configuration changes
  122. */
  123. cs_error_t cpg_dispatch (
  124. cpg_handle_t handle,
  125. cs_dispatch_flags_t dispatch_types);
  126. /*
  127. * Join one or more groups.
  128. * messages multicasted with cpg_mcast_joined will be sent to every
  129. * group that has been joined on handle handle. Any message multicasted
  130. * to a group that has been previously joined will be delivered in cpg_dispatch
  131. */
  132. cs_error_t cpg_join (
  133. cpg_handle_t handle,
  134. const struct cpg_name *group);
  135. /*
  136. * Leave one or more groups
  137. */
  138. cs_error_t cpg_leave (
  139. cpg_handle_t handle,
  140. const struct cpg_name *group);
  141. /*
  142. * Multicast to groups joined with cpg_join.
  143. * The iovec described by iovec will be multicasted to all groups joined with
  144. * the cpg_join interface for handle.
  145. */
  146. cs_error_t cpg_mcast_joined (
  147. cpg_handle_t handle,
  148. cpg_guarantee_t guarantee,
  149. const struct iovec *iovec,
  150. unsigned int iov_len);
  151. /*
  152. * Get membership information from cpg
  153. */
  154. cs_error_t cpg_membership_get (
  155. cpg_handle_t handle,
  156. struct cpg_name *groupName,
  157. struct cpg_address *member_list,
  158. int *member_list_entries);
  159. cs_error_t cpg_local_get (
  160. cpg_handle_t handle,
  161. unsigned int *local_nodeid);
  162. cs_error_t cpg_flow_control_state_get (
  163. cpg_handle_t handle,
  164. cpg_flow_control_state_t *flow_control_enabled);
  165. cs_error_t cpg_zcb_alloc (
  166. cpg_handle_t handle,
  167. size_t size,
  168. void **buffer);
  169. cs_error_t cpg_zcb_free (
  170. cpg_handle_t handle,
  171. void *buffer);
  172. cs_error_t cpg_zcb_mcast_joined (
  173. cpg_handle_t handle,
  174. cpg_guarantee_t guarantee,
  175. void *msg,
  176. size_t msg_len);
  177. #ifdef __cplusplus
  178. }
  179. #endif
  180. #endif /* COROSYNC_CPG_H_DEFINED */