votequorum.h 5.4 KB

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