votequorum.h 5.3 KB

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