votequorum.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. votequorum_handle_t is NOT a
  106. * file descriptor and may not be used directly.
  107. */
  108. cs_error_t votequorum_fd_get (
  109. votequorum_handle_t handle,
  110. int *fd);
  111. /*
  112. * Get quorum information.
  113. */
  114. cs_error_t votequorum_getinfo (
  115. votequorum_handle_t handle,
  116. unsigned int nodeid,
  117. struct votequorum_info *info);
  118. /*
  119. * set expected_votes
  120. */
  121. cs_error_t votequorum_setexpected (
  122. votequorum_handle_t handle,
  123. unsigned int expected_votes);
  124. /*
  125. * set votes for a node
  126. */
  127. cs_error_t votequorum_setvotes (
  128. votequorum_handle_t handle,
  129. unsigned int nodeid,
  130. unsigned int votes);
  131. /*
  132. * Register a quorum device
  133. * it will be DEAD until polled
  134. */
  135. cs_error_t votequorum_qdisk_register (
  136. votequorum_handle_t handle,
  137. const char *name,
  138. unsigned int votes);
  139. /*
  140. * Unregister a quorum device
  141. */
  142. cs_error_t votequorum_qdisk_unregister (
  143. votequorum_handle_t handle);
  144. /*
  145. * Poll a quorum device
  146. */
  147. cs_error_t votequorum_qdisk_poll (
  148. votequorum_handle_t handle,
  149. unsigned int state);
  150. /*
  151. * Get quorum device information
  152. */
  153. cs_error_t votequorum_qdisk_getinfo (
  154. votequorum_handle_t handle,
  155. struct votequorum_qdisk_info *info);
  156. /*
  157. * Set the "hasstate" bit for this node
  158. */
  159. cs_error_t votequorum_setstate (
  160. votequorum_handle_t handle);
  161. /* Track node and quorum changes */
  162. cs_error_t votequorum_trackstart (
  163. votequorum_handle_t handle,
  164. uint64_t context,
  165. unsigned int flags );
  166. cs_error_t votequorum_trackstop (
  167. votequorum_handle_t handle);
  168. /*
  169. * Set our LEAVING flag. we should exit soon after this
  170. */
  171. cs_error_t votequorum_leaving (
  172. votequorum_handle_t handle);
  173. /*
  174. * Save and retrieve private data/context
  175. */
  176. cs_error_t votequorum_context_get (
  177. votequorum_handle_t handle,
  178. void **context);
  179. cs_error_t votequorum_context_set (
  180. votequorum_handle_t handle,
  181. void *context);
  182. #ifdef __cplusplus
  183. }
  184. #endif
  185. #endif /* COROSYNC_VOTEQUORUM_H_DEFINED */