quorum.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * Copyright (c) 2008-2020 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 Red Hat, 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_QUORUM_H_DEFINED
  35. #define COROSYNC_QUORUM_H_DEFINED
  36. #include <corosync/corotypes.h>
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. typedef enum {
  41. QUORUM_MODEL_V0 = 0,
  42. QUORUM_MODEL_V1 = 1,
  43. } quorum_model_t;
  44. /**
  45. * @brief quorum_handle_t
  46. */
  47. typedef uint64_t quorum_handle_t;
  48. struct quorum_ring_id {
  49. uint32_t nodeid;
  50. uint64_t seq;
  51. };
  52. /**
  53. * @brief The quorum_notification_fn_t callback
  54. */
  55. typedef void (*quorum_notification_fn_t) (
  56. quorum_handle_t handle,
  57. uint32_t quorate,
  58. uint64_t ring_seq,
  59. uint32_t view_list_entries,
  60. uint32_t *view_list
  61. );
  62. typedef void (*quorum_v1_quorum_notification_fn_t) (
  63. quorum_handle_t handle,
  64. uint32_t quorate,
  65. struct quorum_ring_id ring_id,
  66. uint32_t member_list_entries, const uint32_t *member_list
  67. );
  68. typedef void (*quorum_v1_nodelist_notification_fn_t) (
  69. quorum_handle_t handle,
  70. struct quorum_ring_id ring_id,
  71. uint32_t member_list_entries, const uint32_t *member_list,
  72. uint32_t joined_list_entries, const uint32_t *joined_list,
  73. uint32_t left_list_entries, const uint32_t *left_list
  74. );
  75. /**
  76. * @brief The quorum_callbacks_t struct
  77. */
  78. typedef struct {
  79. quorum_notification_fn_t quorum_notify_fn;
  80. } quorum_callbacks_t;
  81. typedef struct {
  82. quorum_model_t model;
  83. } quorum_model_data_t;
  84. typedef struct {
  85. quorum_model_t model;
  86. quorum_notification_fn_t quorum_notify_fn;
  87. } quorum_model_v0_data_t;
  88. typedef struct {
  89. quorum_model_t model;
  90. quorum_v1_quorum_notification_fn_t quorum_notify_fn;
  91. quorum_v1_nodelist_notification_fn_t nodelist_notify_fn;
  92. } quorum_model_v1_data_t;
  93. #define QUORUM_FREE 0
  94. #define QUORUM_SET 1
  95. /**
  96. * @brief Create a new quorum connection
  97. * @param handle
  98. * @param callbacks
  99. * @param quorum_type
  100. * @return
  101. */
  102. cs_error_t quorum_initialize (
  103. quorum_handle_t *handle,
  104. quorum_callbacks_t *callbacks,
  105. uint32_t *quorum_type);
  106. cs_error_t quorum_model_initialize (
  107. quorum_handle_t *handle,
  108. quorum_model_t model,
  109. quorum_model_data_t *model_data,
  110. uint32_t *quorum_type,
  111. void *context);
  112. /**
  113. * @brief Close the quorum handle
  114. * @param handle
  115. * @return
  116. */
  117. cs_error_t quorum_finalize (
  118. quorum_handle_t handle);
  119. /**
  120. * @brief Get a file descriptor on which to poll.
  121. *
  122. * @note quorum_handle_t is NOT a file descriptor and may not be used directly.
  123. *
  124. * @param handle
  125. * @param fd
  126. * @return
  127. */
  128. cs_error_t quorum_fd_get (
  129. quorum_handle_t handle,
  130. int *fd);
  131. /**
  132. * @brief Dispatch messages and configuration changes
  133. * @param handle
  134. * @param dispatch_types
  135. * @return
  136. */
  137. cs_error_t quorum_dispatch (
  138. quorum_handle_t handle,
  139. cs_dispatch_flags_t dispatch_types);
  140. /**
  141. * @brief Get quorum information.
  142. * @param handle
  143. * @param quorate
  144. * @return
  145. */
  146. cs_error_t quorum_getquorate (
  147. quorum_handle_t handle,
  148. int *quorate);
  149. /**
  150. * @brief Track node and quorum changes
  151. * @param handle
  152. * @param flags
  153. * @return
  154. */
  155. cs_error_t quorum_trackstart (
  156. quorum_handle_t handle,
  157. unsigned int flags );
  158. /**
  159. * @brief quorum_trackstop
  160. * @param handle
  161. * @return
  162. */
  163. cs_error_t quorum_trackstop (
  164. quorum_handle_t handle);
  165. /**
  166. * @brief quorum_context_set
  167. * @param handle
  168. * @param context
  169. * @return
  170. */
  171. cs_error_t quorum_context_set (
  172. quorum_handle_t handle,
  173. const void *context);
  174. /**
  175. * @brief quorum_context_get
  176. * @param handle
  177. * @param context
  178. * @return
  179. */
  180. cs_error_t quorum_context_get (
  181. quorum_handle_t handle,
  182. const void **context);
  183. #ifdef __cplusplus
  184. }
  185. #endif
  186. #endif /* COROSYNC_QUORUM_H_DEFINED */