qdevice-net-algo-ffsplit.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /*
  2. * Copyright (c) 2015-2019 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Jan Friesse (jfriesse@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 Red Hat, 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 CONTRIBUTORS "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. #include <sys/types.h>
  35. #include <string.h>
  36. #include "qdevice-net-algo-ffsplit.h"
  37. #include "qdevice-log.h"
  38. #include "qdevice-net-send.h"
  39. #include "qdevice-net-cast-vote-timer.h"
  40. #include "qdevice-votequorum.h"
  41. #include "utils.h"
  42. static int
  43. check_vqinfo_validity(struct qdevice_net_instance *instance)
  44. {
  45. struct qdevice_instance *qdev_instance;
  46. struct votequorum_info vq_info;
  47. cs_error_t cs_res;
  48. struct node_list_entry *node;
  49. uint32_t node_id;
  50. qdev_instance = instance->qdevice_instance_ptr;
  51. TAILQ_FOREACH(node, &qdev_instance->config_node_list, entries) {
  52. node_id = node->node_id;
  53. cs_res = votequorum_getinfo(qdev_instance->votequorum_handle, node_id, &vq_info);
  54. if (cs_res == CS_ERR_NOT_EXIST) {
  55. continue;
  56. } else if (cs_res != CS_OK) {
  57. log(LOG_CRIT, "Can't get votequorum information for node "
  58. UTILS_PRI_NODE_ID ". Error %s", node_id, cs_strerror(cs_res));
  59. return (-1);
  60. }
  61. if (vq_info.node_votes != 1) {
  62. log(LOG_CRIT, "50:50 split algorithm works only if all nodes have "
  63. "exactly 1 vote. Node " UTILS_PRI_NODE_ID " has %u votes!",
  64. node_id, vq_info.node_votes);
  65. return (-1);
  66. }
  67. if (vq_info.qdevice_votes != 1) {
  68. log(LOG_CRIT, "50:50 split algorithm works only if qdevice has "
  69. "exactly 1 vote. Node "UTILS_PRI_NODE_ID" has %u votes!",
  70. node_id, vq_info.qdevice_votes);
  71. return (-1);
  72. }
  73. }
  74. return (0);
  75. }
  76. static int
  77. check_cmap_validity(struct qdevice_net_instance *instance)
  78. {
  79. struct qdevice_instance *qdev_instance;
  80. uint32_t qdevice_votes;
  81. qdev_instance = instance->qdevice_instance_ptr;
  82. if (cmap_get_uint32(qdev_instance->cmap_handle, "quorum.device.votes", &qdevice_votes) != CS_OK ||
  83. qdevice_votes != 1) {
  84. log(LOG_CRIT, "50:50 split algorithm works only if quorum.device.votes"
  85. " configuration key is set to 1!");
  86. return (-1);
  87. }
  88. return (0);
  89. }
  90. int
  91. qdevice_net_algo_ffsplit_init(struct qdevice_net_instance *instance)
  92. {
  93. if (check_cmap_validity(instance) != 0 ||
  94. check_vqinfo_validity(instance) != 0) {
  95. return (-1);
  96. }
  97. return (0);
  98. }
  99. int
  100. qdevice_net_algo_ffsplit_connected(struct qdevice_net_instance *instance, enum tlv_heuristics *heuristics,
  101. int *send_config_node_list, int *send_membership_node_list, int *send_quorum_node_list, enum tlv_vote *vote)
  102. {
  103. return (0);
  104. }
  105. int
  106. qdevice_net_algo_ffsplit_config_node_list_changed(struct qdevice_net_instance *instance,
  107. const struct node_list *nlist, int config_version_set, uint64_t config_version,
  108. int *send_node_list, enum tlv_vote *vote)
  109. {
  110. if (check_vqinfo_validity(instance) != 0) {
  111. return (-1);
  112. }
  113. return (0);
  114. }
  115. int
  116. qdevice_net_algo_ffsplit_votequorum_node_list_notify(struct qdevice_net_instance *instance,
  117. const struct tlv_ring_id *ring_id, uint32_t node_list_entries, uint32_t node_list[],
  118. int *pause_cast_vote_timer, enum tlv_vote *vote)
  119. {
  120. return (0);
  121. }
  122. int
  123. qdevice_net_algo_ffsplit_votequorum_node_list_heuristics_notify(struct qdevice_net_instance *instance,
  124. const struct tlv_ring_id *ring_id, uint32_t node_list_entries, uint32_t node_list[],
  125. int *send_node_list, enum tlv_vote *vote, enum tlv_heuristics *heuristics)
  126. {
  127. return (0);
  128. }
  129. int
  130. qdevice_net_algo_ffsplit_votequorum_quorum_notify(struct qdevice_net_instance *instance,
  131. uint32_t quorate, uint32_t node_list_entries, votequorum_node_t node_list[], int *send_node_list,
  132. enum tlv_vote *vote)
  133. {
  134. return (0);
  135. }
  136. int
  137. qdevice_net_algo_ffsplit_votequorum_expected_votes_notify(struct qdevice_net_instance *instance,
  138. uint32_t expected_votes, enum tlv_vote *vote)
  139. {
  140. if (check_vqinfo_validity(instance) != 0) {
  141. return (-1);
  142. }
  143. return (0);
  144. }
  145. int
  146. qdevice_net_algo_ffsplit_config_node_list_reply_received(struct qdevice_net_instance *instance,
  147. uint32_t seq_number, int initial, const struct tlv_ring_id *ring_id, int ring_id_is_valid,
  148. enum tlv_vote *vote)
  149. {
  150. if (!ring_id_is_valid) {
  151. *vote = TLV_VOTE_NO_CHANGE;
  152. }
  153. return (0);
  154. }
  155. int
  156. qdevice_net_algo_ffsplit_membership_node_list_reply_received(struct qdevice_net_instance *instance,
  157. uint32_t seq_number, const struct tlv_ring_id *ring_id, int ring_id_is_valid, enum tlv_vote *vote)
  158. {
  159. if (!ring_id_is_valid) {
  160. *vote = TLV_VOTE_NO_CHANGE;
  161. }
  162. return (0);
  163. }
  164. int
  165. qdevice_net_algo_ffsplit_quorum_node_list_reply_received(struct qdevice_net_instance *instance,
  166. uint32_t seq_number, const struct tlv_ring_id *ring_id, int ring_id_is_valid, enum tlv_vote *vote)
  167. {
  168. if (!ring_id_is_valid) {
  169. *vote = TLV_VOTE_NO_CHANGE;
  170. }
  171. return (0);
  172. }
  173. int
  174. qdevice_net_algo_ffsplit_ask_for_vote_reply_received(struct qdevice_net_instance *instance,
  175. uint32_t seq_number, const struct tlv_ring_id *ring_id, int ring_id_is_valid, enum tlv_vote *vote)
  176. {
  177. if (!ring_id_is_valid) {
  178. *vote = TLV_VOTE_NO_CHANGE;
  179. }
  180. return (0);
  181. }
  182. int
  183. qdevice_net_algo_ffsplit_vote_info_received(struct qdevice_net_instance *instance,
  184. uint32_t seq_number, const struct tlv_ring_id *ring_id, int ring_id_is_valid, enum tlv_vote *vote)
  185. {
  186. if (!ring_id_is_valid) {
  187. *vote = TLV_VOTE_NO_CHANGE;
  188. }
  189. return (0);
  190. }
  191. int
  192. qdevice_net_algo_ffsplit_echo_reply_received(struct qdevice_net_instance *instance,
  193. uint32_t seq_number, int is_expected_seq_number)
  194. {
  195. return (is_expected_seq_number ? 0 : -1);
  196. }
  197. int
  198. qdevice_net_algo_ffsplit_echo_reply_not_received(struct qdevice_net_instance *instance)
  199. {
  200. return (-1);
  201. }
  202. int
  203. qdevice_net_algo_ffsplit_heuristics_change(struct qdevice_net_instance *instance,
  204. enum tlv_heuristics *heuristics, int *send_msg, enum tlv_vote *vote)
  205. {
  206. return (0);
  207. }
  208. int
  209. qdevice_net_algo_ffsplit_heuristics_change_reply_received(struct qdevice_net_instance *instance,
  210. uint32_t seq_number, const struct tlv_ring_id *ring_id, int ring_id_is_valid,
  211. enum tlv_heuristics heuristics, enum tlv_vote *vote)
  212. {
  213. if (!ring_id_is_valid) {
  214. *vote = TLV_VOTE_NO_CHANGE;
  215. }
  216. return (0);
  217. }
  218. int
  219. qdevice_net_algo_ffsplit_disconnected(struct qdevice_net_instance *instance,
  220. enum qdevice_net_disconnect_reason disconnect_reason, int *try_reconnect, enum tlv_vote *vote)
  221. {
  222. /*
  223. * We cannot depend on default behavior (until there is no change -> use old vote).
  224. * This could create two quorate clusters (2:2 -> first half get ACK -> first half
  225. * disconnects from qnetd -> second half get ACK -> two quorate clusters)
  226. */
  227. *vote = TLV_VOTE_NACK;
  228. return (0);
  229. }
  230. void
  231. qdevice_net_algo_ffsplit_destroy(struct qdevice_net_instance *instance)
  232. {
  233. }
  234. static struct qdevice_net_algorithm qdevice_net_algo_ffsplit = {
  235. .init = qdevice_net_algo_ffsplit_init,
  236. .connected = qdevice_net_algo_ffsplit_connected,
  237. .config_node_list_changed = qdevice_net_algo_ffsplit_config_node_list_changed,
  238. .votequorum_node_list_notify = qdevice_net_algo_ffsplit_votequorum_node_list_notify,
  239. .votequorum_node_list_heuristics_notify = qdevice_net_algo_ffsplit_votequorum_node_list_heuristics_notify,
  240. .votequorum_quorum_notify = qdevice_net_algo_ffsplit_votequorum_quorum_notify,
  241. .votequorum_expected_votes_notify = qdevice_net_algo_ffsplit_votequorum_expected_votes_notify,
  242. .config_node_list_reply_received = qdevice_net_algo_ffsplit_config_node_list_reply_received,
  243. .membership_node_list_reply_received = qdevice_net_algo_ffsplit_membership_node_list_reply_received,
  244. .quorum_node_list_reply_received = qdevice_net_algo_ffsplit_quorum_node_list_reply_received,
  245. .ask_for_vote_reply_received = qdevice_net_algo_ffsplit_ask_for_vote_reply_received,
  246. .vote_info_received = qdevice_net_algo_ffsplit_vote_info_received,
  247. .echo_reply_received = qdevice_net_algo_ffsplit_echo_reply_received,
  248. .echo_reply_not_received = qdevice_net_algo_ffsplit_echo_reply_not_received,
  249. .heuristics_change = qdevice_net_algo_ffsplit_heuristics_change,
  250. .heuristics_change_reply_received = qdevice_net_algo_ffsplit_heuristics_change_reply_received,
  251. .disconnected = qdevice_net_algo_ffsplit_disconnected,
  252. .destroy = qdevice_net_algo_ffsplit_destroy,
  253. };
  254. int
  255. qdevice_net_algo_ffsplit_register(void)
  256. {
  257. return (qdevice_net_algorithm_register(TLV_DECISION_ALGORITHM_TYPE_FFSPLIT, &qdevice_net_algo_ffsplit));
  258. }