votequorum.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. * Copyright (c) 2009-2012 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Authors: Christine Caulfield (ccaulfie@redhat.com)
  7. * Fabio M. Di Nitto (fdinitto@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 CONTIBUTORS "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_VOTEQUORUM_H_DEFINED
  36. #define COROSYNC_VOTEQUORUM_H_DEFINED
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. typedef uint64_t votequorum_handle_t;
  41. #define VOTEQUORUM_INFO_FLAG_TWONODE 1
  42. #define VOTEQUORUM_INFO_FLAG_QUORATE 2
  43. #define VOTEQUORUM_INFO_WAIT_FOR_ALL 4
  44. #define VOTEQUORUM_INFO_LAST_MAN_STANDING 8
  45. #define VOTEQUORUM_INFO_AUTO_TIE_BREAKER 16
  46. #define VOTEQUORUM_INFO_LEAVE_REMOVE 32
  47. #define VOTEQUORUM_INFO_QDEVICE 64
  48. #define VOTEQUORUM_NODEID_QDEVICE 0
  49. #define VOTEQUORUM_MAX_QDEVICE_NAME_LEN 255
  50. #define NODESTATE_MEMBER 1
  51. #define NODESTATE_DEAD 2
  52. #define NODESTATE_LEAVING 3
  53. /** @} */
  54. struct votequorum_info {
  55. unsigned int node_id;
  56. unsigned int node_state;
  57. unsigned int node_votes;
  58. unsigned int node_expected_votes;
  59. unsigned int highest_expected;
  60. unsigned int total_votes;
  61. unsigned int quorum;
  62. unsigned int flags;
  63. };
  64. #ifdef EXPERIMENTAL_QUORUM_DEVICE_API
  65. struct votequorum_qdevice_info {
  66. unsigned int votes;
  67. unsigned int state;
  68. char name[VOTEQUORUM_MAX_QDEVICE_NAME_LEN];
  69. };
  70. #endif
  71. typedef struct {
  72. uint32_t nodeid;
  73. uint32_t state;
  74. } votequorum_node_t;
  75. typedef void (*votequorum_notification_fn_t) (
  76. votequorum_handle_t handle,
  77. uint64_t context,
  78. uint32_t quorate,
  79. uint32_t node_list_entries,
  80. votequorum_node_t node_list[]);
  81. typedef void (*votequorum_expectedvotes_notification_fn_t) (
  82. votequorum_handle_t handle,
  83. uint64_t context,
  84. uint32_t expected_votes);
  85. typedef struct {
  86. votequorum_notification_fn_t votequorum_notify_fn;
  87. votequorum_expectedvotes_notification_fn_t votequorum_expectedvotes_notify_fn;
  88. } votequorum_callbacks_t;
  89. /**
  90. * Create a new quorum connection
  91. */
  92. cs_error_t votequorum_initialize (
  93. votequorum_handle_t *handle,
  94. votequorum_callbacks_t *callbacks);
  95. /**
  96. * Close the quorum handle
  97. */
  98. cs_error_t votequorum_finalize (
  99. votequorum_handle_t handle);
  100. /**
  101. * Dispatch messages and configuration changes
  102. */
  103. cs_error_t votequorum_dispatch (
  104. votequorum_handle_t handle,
  105. cs_dispatch_flags_t dispatch_types);
  106. /**
  107. * Get a file descriptor on which to poll.
  108. *
  109. * @note votequorum_handle_t is NOT a file descriptor and may not be
  110. * used directly.
  111. */
  112. cs_error_t votequorum_fd_get (
  113. votequorum_handle_t handle,
  114. int *fd);
  115. /**
  116. * Get quorum information.
  117. */
  118. cs_error_t votequorum_getinfo (
  119. votequorum_handle_t handle,
  120. unsigned int nodeid,
  121. struct votequorum_info *info);
  122. /**
  123. * set expected_votes
  124. */
  125. cs_error_t votequorum_setexpected (
  126. votequorum_handle_t handle,
  127. unsigned int expected_votes);
  128. /**
  129. * set votes for a node
  130. */
  131. cs_error_t votequorum_setvotes (
  132. votequorum_handle_t handle,
  133. unsigned int nodeid,
  134. unsigned int votes);
  135. /**
  136. * Track node and quorum changes
  137. */
  138. cs_error_t votequorum_trackstart (
  139. votequorum_handle_t handle,
  140. uint64_t context,
  141. unsigned int flags );
  142. cs_error_t votequorum_trackstop (
  143. votequorum_handle_t handle);
  144. /**
  145. * Save and retrieve private data/context
  146. */
  147. cs_error_t votequorum_context_get (
  148. votequorum_handle_t handle,
  149. void **context);
  150. cs_error_t votequorum_context_set (
  151. votequorum_handle_t handle,
  152. void *context);
  153. #ifdef EXPERIMENTAL_QUORUM_DEVICE_API
  154. /**
  155. * Register a quorum device
  156. *
  157. * it will be DEAD until polled
  158. */
  159. cs_error_t votequorum_qdevice_register (
  160. votequorum_handle_t handle,
  161. const char *name);
  162. /**
  163. * Unregister a quorum device
  164. */
  165. cs_error_t votequorum_qdevice_unregister (
  166. votequorum_handle_t handle,
  167. const char *name);
  168. /**
  169. * Update registered name of a quorum device
  170. */
  171. cs_error_t votequorum_qdevice_update (
  172. votequorum_handle_t handle,
  173. const char *oldname,
  174. const char *newname);
  175. /**
  176. * Poll a quorum device
  177. */
  178. cs_error_t votequorum_qdevice_poll (
  179. votequorum_handle_t handle,
  180. const char *name,
  181. unsigned int state);
  182. /**
  183. * Get quorum device information
  184. */
  185. cs_error_t votequorum_qdevice_getinfo (
  186. votequorum_handle_t handle,
  187. unsigned int nodeid,
  188. struct votequorum_qdevice_info *info);
  189. #endif
  190. #ifdef __cplusplus
  191. }
  192. #endif
  193. #endif /* COROSYNC_VOTEQUORUM_H_DEFINED */