votequorum.h 5.2 KB

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