votequorum.h 5.5 KB

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