votequorum.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 struct {
  74. votequorum_notification_fn_t votequorum_notify_fn;
  75. } votequorum_callbacks_t;
  76. /*
  77. * Create a new quorum connection
  78. */
  79. cs_error_t votequorum_initialize (
  80. votequorum_handle_t *handle,
  81. votequorum_callbacks_t *callbacks);
  82. /*
  83. * Close the quorum handle
  84. */
  85. cs_error_t votequorum_finalize (
  86. votequorum_handle_t handle);
  87. /*
  88. * Dispatch messages and configuration changes
  89. */
  90. cs_error_t votequorum_dispatch (
  91. votequorum_handle_t handle,
  92. cs_dispatch_flags_t dispatch_types);
  93. /*
  94. * Get a file descriptor on which to poll. votequorum_handle_t is NOT a
  95. * file descriptor and may not be used directly.
  96. */
  97. cs_error_t votequorum_fd_get (
  98. votequorum_handle_t handle,
  99. int *fd);
  100. /*
  101. * Get quorum information.
  102. */
  103. cs_error_t votequorum_getinfo (
  104. votequorum_handle_t handle,
  105. unsigned int nodeid,
  106. struct votequorum_info *info);
  107. /*
  108. * set expected_votes
  109. */
  110. cs_error_t votequorum_setexpected (
  111. votequorum_handle_t handle,
  112. unsigned int expected_votes);
  113. /*
  114. * set votes for a node
  115. */
  116. cs_error_t votequorum_setvotes (
  117. votequorum_handle_t handle,
  118. unsigned int nodeid,
  119. unsigned int votes);
  120. /*
  121. * Register a quorum device
  122. * it will be DEAD until polled
  123. */
  124. cs_error_t votequorum_qdisk_register (
  125. votequorum_handle_t handle,
  126. char *name,
  127. unsigned int votes);
  128. /*
  129. * Unregister a quorum device
  130. */
  131. cs_error_t votequorum_qdisk_unregister (
  132. votequorum_handle_t handle);
  133. /*
  134. * Poll a quorum device
  135. */
  136. cs_error_t votequorum_qdisk_poll (
  137. votequorum_handle_t handle,
  138. unsigned int state);
  139. /*
  140. * Get quorum device information
  141. */
  142. cs_error_t votequorum_qdisk_getinfo (
  143. votequorum_handle_t handle,
  144. struct votequorum_qdisk_info *info);
  145. /*
  146. * Set the "hasstate" bit for this node
  147. */
  148. cs_error_t votequorum_setstate (
  149. votequorum_handle_t handle);
  150. /* Track node and quorum changes */
  151. cs_error_t votequorum_trackstart (
  152. votequorum_handle_t handle,
  153. uint64_t context,
  154. unsigned int flags );
  155. cs_error_t votequorum_trackstop (
  156. votequorum_handle_t handle);
  157. /*
  158. * Set our LEAVING flag. we should exit soon after this
  159. */
  160. cs_error_t votequorum_leaving (
  161. votequorum_handle_t handle);
  162. /*
  163. * Save and retrieve private data/context
  164. */
  165. cs_error_t votequorum_context_get (
  166. votequorum_handle_t handle,
  167. void **context);
  168. cs_error_t votequorum_context_set (
  169. votequorum_handle_t handle,
  170. void *context);
  171. #endif /* COROSYNC_VOTEQUORUM_H_DEFINED */