votequorum.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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_TWONODE 1
  42. #define VOTEQUORUM_INFO_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_ALLOW_DOWNSCALE 32
  47. #define VOTEQUORUM_INFO_QDEVICE_REGISTERED 64
  48. #define VOTEQUORUM_INFO_QDEVICE_ALIVE 128
  49. #define VOTEQUORUM_INFO_QDEVICE_CAST_VOTE 256
  50. #define VOTEQUORUM_INFO_QDEVICE_MASTER_WINS 512
  51. #define VOTEQUORUM_QDEVICE_NODEID 0
  52. #define VOTEQUORUM_QDEVICE_MAX_NAME_LEN 255
  53. #define VOTEQUORUM_QDEVICE_DEFAULT_TIMEOUT 10000
  54. #define VOTEQUORUM_NODESTATE_MEMBER 1
  55. #define VOTEQUORUM_NODESTATE_DEAD 2
  56. #define VOTEQUORUM_NODESTATE_LEAVING 3
  57. /** @} */
  58. struct votequorum_info {
  59. unsigned int node_id;
  60. unsigned int node_state;
  61. unsigned int node_votes;
  62. unsigned int node_expected_votes;
  63. unsigned int highest_expected;
  64. unsigned int total_votes;
  65. unsigned int quorum;
  66. unsigned int flags;
  67. unsigned int qdevice_votes;
  68. char qdevice_name[VOTEQUORUM_QDEVICE_MAX_NAME_LEN];
  69. };
  70. typedef struct {
  71. uint32_t nodeid;
  72. uint32_t state;
  73. } votequorum_node_t;
  74. typedef void (*votequorum_notification_fn_t) (
  75. votequorum_handle_t handle,
  76. uint64_t context,
  77. uint32_t quorate,
  78. uint32_t node_list_entries,
  79. votequorum_node_t node_list[]);
  80. typedef void (*votequorum_expectedvotes_notification_fn_t) (
  81. votequorum_handle_t handle,
  82. uint64_t context,
  83. uint32_t expected_votes);
  84. typedef struct {
  85. votequorum_notification_fn_t votequorum_notify_fn;
  86. votequorum_expectedvotes_notification_fn_t votequorum_expectedvotes_notify_fn;
  87. } votequorum_callbacks_t;
  88. /**
  89. * Create a new quorum connection
  90. */
  91. cs_error_t votequorum_initialize (
  92. votequorum_handle_t *handle,
  93. votequorum_callbacks_t *callbacks);
  94. /**
  95. * Close the quorum handle
  96. */
  97. cs_error_t votequorum_finalize (
  98. votequorum_handle_t handle);
  99. /**
  100. * Dispatch messages and configuration changes
  101. */
  102. cs_error_t votequorum_dispatch (
  103. votequorum_handle_t handle,
  104. cs_dispatch_flags_t dispatch_types);
  105. /**
  106. * Get a file descriptor on which to poll.
  107. *
  108. * @note votequorum_handle_t is NOT a file descriptor and may not be
  109. * used directly.
  110. */
  111. cs_error_t votequorum_fd_get (
  112. votequorum_handle_t handle,
  113. int *fd);
  114. /**
  115. * Get quorum information.
  116. */
  117. cs_error_t votequorum_getinfo (
  118. votequorum_handle_t handle,
  119. unsigned int nodeid,
  120. struct votequorum_info *info);
  121. /**
  122. * set expected_votes
  123. */
  124. cs_error_t votequorum_setexpected (
  125. votequorum_handle_t handle,
  126. unsigned int expected_votes);
  127. /**
  128. * set votes for a node
  129. */
  130. cs_error_t votequorum_setvotes (
  131. votequorum_handle_t handle,
  132. unsigned int nodeid,
  133. unsigned int votes);
  134. /**
  135. * Track node and quorum changes
  136. */
  137. cs_error_t votequorum_trackstart (
  138. votequorum_handle_t handle,
  139. uint64_t context,
  140. unsigned int flags );
  141. cs_error_t votequorum_trackstop (
  142. votequorum_handle_t handle);
  143. /**
  144. * Save and retrieve private data/context
  145. */
  146. cs_error_t votequorum_context_get (
  147. votequorum_handle_t handle,
  148. void **context);
  149. cs_error_t votequorum_context_set (
  150. votequorum_handle_t handle,
  151. void *context);
  152. /**
  153. * Register a quorum device
  154. *
  155. * it will be DEAD until polled
  156. */
  157. cs_error_t votequorum_qdevice_register (
  158. votequorum_handle_t handle,
  159. const char *name);
  160. /**
  161. * Unregister a quorum device
  162. */
  163. cs_error_t votequorum_qdevice_unregister (
  164. votequorum_handle_t handle,
  165. const char *name);
  166. /**
  167. * Update registered name of a quorum device
  168. */
  169. cs_error_t votequorum_qdevice_update (
  170. votequorum_handle_t handle,
  171. const char *oldname,
  172. const char *newname);
  173. /**
  174. * Poll a quorum device
  175. */
  176. cs_error_t votequorum_qdevice_poll (
  177. votequorum_handle_t handle,
  178. const char *name,
  179. unsigned int cast_vote);
  180. /**
  181. * Allow qdevice to tell votequorum if master_wins can be enabled or not
  182. */
  183. cs_error_t votequorum_qdevice_master_wins (
  184. votequorum_handle_t handle,
  185. const char *name,
  186. unsigned int allow);
  187. #ifdef __cplusplus
  188. }
  189. #endif
  190. #endif /* COROSYNC_VOTEQUORUM_H_DEFINED */