votequorum.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /*
  2. * Copyright (c) 2009-2012 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Authors: Christine Caulfield (ccaulfie@redhat.com)
  7. * Fabio M. Di Nitto (fdinitto@redhat.com)
  8. *
  9. * This software licensed under BSD license, the text of which follows:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  33. * THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #ifndef COROSYNC_VOTEQUORUM_H_DEFINED
  36. #define COROSYNC_VOTEQUORUM_H_DEFINED
  37. #include <corosync/corotypes.h>
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /**
  42. * @brief votequorum_handle_t
  43. */
  44. typedef uint64_t votequorum_handle_t;
  45. #define VOTEQUORUM_INFO_TWONODE 1
  46. #define VOTEQUORUM_INFO_QUORATE 2
  47. #define VOTEQUORUM_INFO_WAIT_FOR_ALL 4
  48. #define VOTEQUORUM_INFO_LAST_MAN_STANDING 8
  49. #define VOTEQUORUM_INFO_AUTO_TIE_BREAKER 16
  50. #define VOTEQUORUM_INFO_ALLOW_DOWNSCALE 32
  51. #define VOTEQUORUM_INFO_QDEVICE_REGISTERED 64
  52. #define VOTEQUORUM_INFO_QDEVICE_ALIVE 128
  53. #define VOTEQUORUM_INFO_QDEVICE_CAST_VOTE 256
  54. #define VOTEQUORUM_INFO_QDEVICE_MASTER_WINS 512
  55. #define VOTEQUORUM_QDEVICE_NODEID 0
  56. #define VOTEQUORUM_QDEVICE_MAX_NAME_LEN 255
  57. #define VOTEQUORUM_QDEVICE_DEFAULT_TIMEOUT 10000
  58. #define VOTEQUORUM_QDEVICE_DEFAULT_SYNC_TIMEOUT 30000
  59. #define VOTEQUORUM_NODESTATE_MEMBER 1
  60. #define VOTEQUORUM_NODESTATE_DEAD 2
  61. #define VOTEQUORUM_NODESTATE_LEAVING 3
  62. /** @} */
  63. /**
  64. * @brief The votequorum_info struct
  65. */
  66. struct votequorum_info {
  67. unsigned int node_id;
  68. unsigned int node_state;
  69. unsigned int node_votes;
  70. unsigned int node_expected_votes;
  71. unsigned int highest_expected;
  72. unsigned int total_votes;
  73. unsigned int quorum;
  74. unsigned int flags;
  75. unsigned int qdevice_votes;
  76. char qdevice_name[VOTEQUORUM_QDEVICE_MAX_NAME_LEN];
  77. };
  78. /**
  79. * @brief The votequorum_node_t struct
  80. */
  81. typedef struct {
  82. uint32_t nodeid;
  83. uint32_t state;
  84. } votequorum_node_t;
  85. /**
  86. * @brief The votequorum_ring_id_t struct
  87. */
  88. typedef struct {
  89. uint32_t nodeid;
  90. uint64_t seq;
  91. } votequorum_ring_id_t;
  92. /**
  93. * @brief The votequorum_quorum_notification_fn_t callback
  94. */
  95. typedef void (*votequorum_quorum_notification_fn_t) (
  96. votequorum_handle_t handle,
  97. uint64_t context,
  98. uint32_t quorate,
  99. uint32_t node_list_entries,
  100. votequorum_node_t node_list[]);
  101. typedef void (*votequorum_nodelist_notification_fn_t) (
  102. votequorum_handle_t handle,
  103. uint64_t context,
  104. votequorum_ring_id_t ring_id,
  105. uint32_t node_list_entries,
  106. uint32_t node_list[]);
  107. /**
  108. * @brief The votequorum_expectedvotes_notification_fn_t callback
  109. */
  110. typedef void (*votequorum_expectedvotes_notification_fn_t) (
  111. votequorum_handle_t handle,
  112. uint64_t context,
  113. uint32_t expected_votes);
  114. /**
  115. * @brief The votequorum_callbacks_t struct
  116. */
  117. typedef struct {
  118. votequorum_quorum_notification_fn_t votequorum_quorum_notify_fn;
  119. votequorum_expectedvotes_notification_fn_t votequorum_expectedvotes_notify_fn;
  120. votequorum_nodelist_notification_fn_t votequorum_nodelist_notify_fn;
  121. } votequorum_callbacks_t;
  122. /**
  123. * @brief Create a new quorum connection
  124. * @param handle
  125. * @param callbacks
  126. * @return
  127. */
  128. cs_error_t votequorum_initialize (
  129. votequorum_handle_t *handle,
  130. votequorum_callbacks_t *callbacks);
  131. /**
  132. * @brief Close the quorum handle
  133. * @param handle
  134. * @return
  135. */
  136. cs_error_t votequorum_finalize (
  137. votequorum_handle_t handle);
  138. /**
  139. * @brief Dispatch messages and configuration changes
  140. * @param handle
  141. * @param dispatch_types
  142. * @return
  143. */
  144. cs_error_t votequorum_dispatch (
  145. votequorum_handle_t handle,
  146. cs_dispatch_flags_t dispatch_types);
  147. /**
  148. * @brief Get a file descriptor on which to poll.
  149. *
  150. * @note votequorum_handle_t is NOT a file descriptor and may not be used directly.
  151. *
  152. * @param handle
  153. * @param fd
  154. * @return
  155. */
  156. cs_error_t votequorum_fd_get (
  157. votequorum_handle_t handle,
  158. int *fd);
  159. /**
  160. * @brief Get quorum information.
  161. * @param handle
  162. * @param nodeid
  163. * @param info
  164. * @return
  165. */
  166. cs_error_t votequorum_getinfo (
  167. votequorum_handle_t handle,
  168. unsigned int nodeid,
  169. struct votequorum_info *info);
  170. /**
  171. * @brief set expected_votes
  172. * @param handle
  173. * @param expected_votes
  174. * @return
  175. */
  176. cs_error_t votequorum_setexpected (
  177. votequorum_handle_t handle,
  178. unsigned int expected_votes);
  179. /**
  180. * @brief set votes for a node
  181. * @param handle
  182. * @param nodeid
  183. * @param votes
  184. * @return
  185. */
  186. cs_error_t votequorum_setvotes (
  187. votequorum_handle_t handle,
  188. unsigned int nodeid,
  189. unsigned int votes);
  190. /**
  191. * @brief Track node and quorum changes
  192. * @param handle
  193. * @param context
  194. * @param flags
  195. * @return
  196. */
  197. cs_error_t votequorum_trackstart (
  198. votequorum_handle_t handle,
  199. uint64_t context,
  200. unsigned int flags);
  201. /**
  202. * @brief votequorum_trackstop
  203. * @param handle
  204. * @return
  205. */
  206. cs_error_t votequorum_trackstop (
  207. votequorum_handle_t handle);
  208. /**
  209. * @brief Save and retrieve private data/context
  210. * @param handle
  211. * @param context
  212. * @return
  213. */
  214. cs_error_t votequorum_context_get (
  215. votequorum_handle_t handle,
  216. void **context);
  217. /**
  218. * @brief votequorum_context_set
  219. * @param handle
  220. * @param context
  221. * @return
  222. */
  223. cs_error_t votequorum_context_set (
  224. votequorum_handle_t handle,
  225. void *context);
  226. /**
  227. * @brief Register a quorum device
  228. *
  229. * it will be DEAD until polled
  230. *
  231. * @param handle
  232. * @param name
  233. * @return
  234. */
  235. cs_error_t votequorum_qdevice_register (
  236. votequorum_handle_t handle,
  237. const char *name);
  238. /**
  239. * @brief Unregister a quorum device
  240. * @param handle
  241. * @param name
  242. * @return
  243. */
  244. cs_error_t votequorum_qdevice_unregister (
  245. votequorum_handle_t handle,
  246. const char *name);
  247. /**
  248. * @brief Update registered name of a quorum device
  249. * @param handle
  250. * @param oldname
  251. * @param newname
  252. * @return
  253. */
  254. cs_error_t votequorum_qdevice_update (
  255. votequorum_handle_t handle,
  256. const char *oldname,
  257. const char *newname);
  258. /**
  259. * @brief Poll a quorum device
  260. * @param handle
  261. * @param name
  262. * @param cast_vote
  263. * @param ring_id
  264. * @return
  265. */
  266. cs_error_t votequorum_qdevice_poll (
  267. votequorum_handle_t handle,
  268. const char *name,
  269. unsigned int cast_vote,
  270. votequorum_ring_id_t ring_id);
  271. /**
  272. * @brief Allow qdevice to tell votequorum if master_wins can be enabled or not
  273. * @param handle
  274. * @param name
  275. * @param allow
  276. * @return
  277. */
  278. cs_error_t votequorum_qdevice_master_wins (
  279. votequorum_handle_t handle,
  280. const char *name,
  281. unsigned int allow);
  282. #ifdef __cplusplus
  283. }
  284. #endif
  285. #endif /* COROSYNC_VOTEQUORUM_H_DEFINED */