38 #include <sys/types.h>
44 #include <qb/qblist.h>
45 #include <qb/qbipc_common.h>
75 static uint8_t qdevice_can_operate = 1;
76 static void *qdevice_reg_conn = NULL;
77 static uint8_t qdevice_master_wins = 0;
79 static uint8_t two_node = 0;
81 static uint8_t wait_for_all = 0;
82 static uint8_t wait_for_all_status = 0;
83 static uint8_t wait_for_all_autoset = 0;
86 static int lowest_node_id = -1;
87 static int highest_node_id = -1;
89 #define DEFAULT_LMS_WIN 10000
90 static uint8_t last_man_standing = 0;
93 static uint8_t allow_downscale = 0;
94 static uint32_t ev_barrier = 0;
96 static uint8_t ev_tracking = 0;
97 static uint32_t ev_tracking_barrier = 0;
98 static int ev_tracking_fd = -1;
144 #define MESSAGE_REQ_EXEC_VOTEQUORUM_NODEINFO 0
145 #define MESSAGE_REQ_EXEC_VOTEQUORUM_RECONFIGURE 1
146 #define MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_REG 2
147 #define MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_RECONFIGURE 3
149 static void votequorum_exec_send_expectedvotes_notification(
void);
150 static int votequorum_exec_send_quorum_notification(
void *conn, uint64_t context);
151 static int votequorum_exec_send_nodelist_notification(
void *conn, uint64_t context);
153 #define VOTEQUORUM_RECONFIG_PARAM_EXPECTED_VOTES 1
154 #define VOTEQUORUM_RECONFIG_PARAM_NODE_VOTES 2
155 #define VOTEQUORUM_RECONFIG_PARAM_CANCEL_WFA 3
157 static int votequorum_exec_send_reconfigure(uint8_t
param,
unsigned int nodeid, uint32_t
value);
162 #define VOTEQUORUM_QDEVICE_OPERATION_UNREGISTER 0
163 #define VOTEQUORUM_QDEVICE_OPERATION_REGISTER 1
169 #define NODE_FLAGS_QUORATE 1
170 #define NODE_FLAGS_LEAVING 2
171 #define NODE_FLAGS_WFASTATUS 4
172 #define NODE_FLAGS_FIRST 8
173 #define NODE_FLAGS_QDEVICE_REGISTERED 16
174 #define NODE_FLAGS_QDEVICE_ALIVE 32
175 #define NODE_FLAGS_QDEVICE_CAST_VOTE 64
176 #define NODE_FLAGS_QDEVICE_MASTER_WINS 128
197 static uint8_t quorum;
198 static uint8_t cluster_is_quorate;
205 static struct qb_list_head cluster_members_list;
209 static int quorum_members_entries = 0;
210 static int previous_quorum_members_entries = 0;
211 static int atb_nodelist_entries = 0;
218 static int cluster_nodes_entries = 0;
231 static struct qb_list_head trackers_list;
238 static int qdevice_timer_set = 0;
240 static int last_man_standing_timer_set = 0;
241 static int sync_nodeinfo_sent = 0;
242 static int sync_wait_for_poll_or_timeout = 0;
248 static int sync_in_progress = 0;
250 static void votequorum_sync_init (
251 const unsigned int *trans_list,
252 size_t trans_list_entries,
253 const unsigned int *member_list,
254 size_t member_list_entries,
257 static int votequorum_sync_process (
void);
258 static void votequorum_sync_activate (
void);
259 static void votequorum_sync_abort (
void);
268 static int votequorum_exec_exit_fn (
void);
269 static int votequorum_exec_send_nodeinfo(uint32_t
nodeid);
271 static void message_handler_req_exec_votequorum_nodeinfo (
274 static void exec_votequorum_nodeinfo_endian_convert (
void *message);
276 static void message_handler_req_exec_votequorum_reconfigure (
279 static void exec_votequorum_reconfigure_endian_convert (
void *message);
281 static void message_handler_req_exec_votequorum_qdevice_reg (
284 static void exec_votequorum_qdevice_reg_endian_convert (
void *message);
286 static void message_handler_req_exec_votequorum_qdevice_reconfigure (
289 static void exec_votequorum_qdevice_reconfigure_endian_convert (
void *message);
295 .exec_endian_convert_fn = exec_votequorum_nodeinfo_endian_convert
298 .exec_handler_fn = message_handler_req_exec_votequorum_reconfigure,
299 .exec_endian_convert_fn = exec_votequorum_reconfigure_endian_convert
302 .exec_handler_fn = message_handler_req_exec_votequorum_qdevice_reg,
303 .exec_endian_convert_fn = exec_votequorum_qdevice_reg_endian_convert
306 .exec_handler_fn = message_handler_req_exec_votequorum_qdevice_reconfigure,
307 .exec_endian_convert_fn = exec_votequorum_qdevice_reconfigure_endian_convert
315 static int quorum_lib_init_fn (
void *conn);
317 static int quorum_lib_exit_fn (
void *conn);
319 static void qdevice_timer_fn(
void *arg);
321 static void message_handler_req_lib_votequorum_getinfo (
void *conn,
322 const void *message);
324 static void message_handler_req_lib_votequorum_setexpected (
void *conn,
325 const void *message);
327 static void message_handler_req_lib_votequorum_setvotes (
void *conn,
328 const void *message);
330 static void message_handler_req_lib_votequorum_trackstart (
void *conn,
331 const void *message);
333 static void message_handler_req_lib_votequorum_trackstop (
void *conn,
334 const void *message);
336 static void message_handler_req_lib_votequorum_qdevice_register (
void *conn,
337 const void *message);
339 static void message_handler_req_lib_votequorum_qdevice_unregister (
void *conn,
340 const void *message);
342 static void message_handler_req_lib_votequorum_qdevice_update (
void *conn,
343 const void *message);
345 static void message_handler_req_lib_votequorum_qdevice_poll (
void *conn,
346 const void *message);
348 static void message_handler_req_lib_votequorum_qdevice_master_wins (
void *conn,
349 const void *message);
358 .lib_handler_fn = message_handler_req_lib_votequorum_setexpected,
362 .lib_handler_fn = message_handler_req_lib_votequorum_setvotes,
366 .lib_handler_fn = message_handler_req_lib_votequorum_trackstart,
370 .lib_handler_fn = message_handler_req_lib_votequorum_trackstop,
374 .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_register,
378 .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_unregister,
382 .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_update,
386 .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_poll,
390 .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_master_wins,
396 .
name =
"corosync vote quorum service v1.0",
399 .private_data_size =
sizeof (
struct quorum_pd),
402 .lib_init_fn = quorum_lib_init_fn,
403 .lib_exit_fn = quorum_lib_exit_fn,
404 .lib_engine = quorum_lib_service,
406 .exec_init_fn = votequorum_exec_init_fn,
407 .exec_exit_fn = votequorum_exec_exit_fn,
408 .exec_engine = votequorum_exec_engine,
410 .sync_init = votequorum_sync_init,
411 .sync_process = votequorum_sync_process,
412 .sync_activate = votequorum_sync_activate,
413 .sync_abort = votequorum_sync_abort
418 return (&votequorum_service_engine);
423 .
name =
"corosync_votequorum",
433 #define max(a,b) (((a) > (b)) ? (a) : (b))
435 static void node_add_ordered(
struct cluster_node *newnode)
438 struct qb_list_head *tmp;
442 qb_list_for_each(tmp, &cluster_members_list) {
450 qb_list_add(&newnode->
list, &cluster_members_list);
452 qb_list_add_tail(&newnode->
list, &node->
list);
461 struct qb_list_head *tmp;
466 cl = (
struct cluster_node *)&cluster_nodes[cluster_nodes_entries];
467 cluster_nodes_entries++;
469 qb_list_for_each(tmp, &cluster_members_list) {
488 node_add_ordered(cl);
500 struct qb_list_head *tmp;
514 qb_list_for_each(tmp, &cluster_members_list) {
526 static void get_lowest_node_id(
void)
529 struct qb_list_head *tmp;
535 qb_list_for_each(tmp, &cluster_members_list) {
538 (node->
node_id < lowest_node_id)) {
539 lowest_node_id = node->
node_id;
548 static void get_highest_node_id(
void)
551 struct qb_list_head *tmp;
557 qb_list_for_each(tmp, &cluster_members_list) {
560 (node->
node_id > highest_node_id)) {
561 highest_node_id = node->
node_id;
570 static int check_low_node_id_partition(
void)
573 struct qb_list_head *tmp;
578 qb_list_for_each(tmp, &cluster_members_list) {
581 (node->
node_id == lowest_node_id)) {
590 static int check_high_node_id_partition(
void)
593 struct qb_list_head *tmp;
598 qb_list_for_each(tmp, &cluster_members_list) {
601 (node->
node_id == highest_node_id)) {
610 static int is_in_nodelist(
int nodeid,
unsigned int *members,
int entries)
615 for (i=0; i<entries; i++) {
616 if (
nodeid == members[i]) {
638 static int check_auto_tie_breaker(
void)
645 res = check_low_node_id_partition();
651 res = check_high_node_id_partition();
658 for (i=0; i < atb_nodelist_entries; i++) {
659 if (is_in_nodelist(atb_nodelist[i], quorum_members, quorum_members_entries)) {
666 for (j=0; j<i; j++) {
667 if (is_in_nodelist(atb_nodelist[j], previous_quorum_members, previous_quorum_members_entries)) {
694 static void parse_atb_string(
char *atb_string)
702 if (!strcmp(atb_string,
"lowest"))
705 if (!strcmp(atb_string,
"highest"))
708 if (atoi(atb_string)) {
710 atb_nodelist_entries = 0;
713 num = strtol(ptr, &ptr, 10);
716 atb_nodelist[atb_nodelist_entries++] = num;
720 if (atb_nodelist_entries) {
729 log_printf(
LOGSYS_LEVEL_WARNING,
"auto_tie_breaker_nodes is not valid. It must be 'lowest', 'highest' or a space-separated list of node IDs. auto_tie_breaker is disabled");
735 static int check_qdevice_master(
void)
738 struct qb_list_head *tmp;
743 qb_list_for_each(tmp, &cluster_members_list) {
756 static void decode_flags(uint32_t
flags)
761 "flags: quorate: %s Leaving: %s WFA Status: %s First: %s Qdevice: %s QdeviceAlive: %s QdeviceCastVote: %s QdeviceMasterWins: %s",
777 static int load_ev_tracking_barrier(
void)
780 char filename[PATH_MAX];
784 snprintf(filename,
sizeof(filename) - 1,
"%s/ev_tracking",
get_state_dir());
786 ev_tracking_fd = open(filename, O_RDWR, 0700);
787 if (ev_tracking_fd != -1) {
788 res = read (ev_tracking_fd, &ev_tracking_barrier,
sizeof(uint32_t));
789 close(ev_tracking_fd);
790 if (res ==
sizeof (uint32_t)) {
796 ev_tracking_barrier = 0;
798 ev_tracking_fd = open (filename, O_CREAT|O_RDWR, 0700);
799 if (ev_tracking_fd != -1) {
800 res = write (ev_tracking_fd, &ev_tracking_barrier,
sizeof (uint32_t));
801 if ((res == -1) || (res !=
sizeof (uint32_t))) {
803 "Unable to write to %s", filename);
805 close(ev_tracking_fd);
810 "Unable to create %s file", filename);
817 static void update_wait_for_all_status(uint8_t wfa_status)
821 wait_for_all_status = wfa_status;
822 if (wait_for_all_status) {
828 wait_for_all_status);
833 static void update_two_node(
void)
852 static void update_qdevice_can_operate(uint8_t status)
856 qdevice_can_operate = status;
857 icmap_set_uint8(
"runtime.votequorum.qdevice_can_operate", qdevice_can_operate);
862 static void update_qdevice_master_wins(uint8_t allow)
866 qdevice_master_wins = allow;
867 icmap_set_uint8(
"runtime.votequorum.qdevice_master_wins", qdevice_master_wins);
872 static void update_ev_tracking_barrier(uint32_t ev_t_barrier)
878 ev_tracking_barrier = ev_t_barrier;
879 icmap_set_uint32(
"runtime.votequorum.ev_tracking_barrier", ev_tracking_barrier);
881 if (lseek (ev_tracking_fd, 0, SEEK_SET) != 0) {
883 "Unable to update ev_tracking_barrier on disk data!!!");
888 res = write (ev_tracking_fd, &ev_tracking_barrier,
sizeof (uint32_t));
889 if (res !=
sizeof (uint32_t)) {
891 "Unable to update ev_tracking_barrier on disk data!!!");
893 #ifdef HAVE_FDATASYNC
894 fdatasync(ev_tracking_fd);
896 fsync(ev_tracking_fd);
906 static int calculate_quorum(
int allow_decrease,
unsigned int max_expected,
unsigned int *ret_total_votes)
908 struct qb_list_head *nodelist;
910 unsigned int total_votes = 0;
911 unsigned int highest_expected = 0;
912 unsigned int newquorum, q1, q2;
913 unsigned int total_nodes = 0;
917 if ((allow_downscale) && (allow_decrease) && (max_expected)) {
918 max_expected =
max(ev_barrier, max_expected);
921 qb_list_for_each(nodelist, &cluster_members_list) {
929 total_votes += node->
votes;
936 total_votes += qdevice->
votes;
940 if (max_expected > 0) {
941 highest_expected = max_expected;
948 q1 = (highest_expected + 2) / 2;
949 q2 = (total_votes + 2) / 2;
950 newquorum =
max(q1, q2);
956 if (!allow_decrease) {
957 newquorum =
max(quorum, newquorum);
967 if (two_node && total_nodes <= 2) {
971 if (ret_total_votes) {
972 *ret_total_votes = total_votes;
979 static void update_node_expected_votes(
int new_expected_votes)
981 struct qb_list_head *nodelist;
984 if (new_expected_votes) {
985 qb_list_for_each(nodelist, &cluster_members_list) {
995 static void are_we_quorate(
unsigned int total_votes)
998 int quorum_change = 0;
1006 if ((wait_for_all) && (wait_for_all_status)) {
1009 "Waiting for all cluster members. "
1010 "Current votes: %d expected_votes: %d",
1012 assert(!cluster_is_quorate);
1015 update_wait_for_all_status(0);
1018 if (quorum > total_votes) {
1022 get_lowest_node_id();
1023 get_highest_node_id();
1026 if ((auto_tie_breaker !=
ATB_NONE) &&
1030 (previous_quorum_members_entries - quorum_members_entries < quorum) &&
1031 (check_auto_tie_breaker() == 1)) {
1035 if ((qdevice_master_wins) &&
1037 (check_qdevice_master() == 1)) {
1042 if (cluster_is_quorate && !
quorate) {
1046 if (!cluster_is_quorate &&
quorate) {
1052 if (cluster_is_quorate) {
1060 update_wait_for_all_status(0);
1062 update_wait_for_all_status(1);
1066 if ((quorum_change) &&
1067 (sync_in_progress == 0)) {
1068 quorum_callback(quorum_members, quorum_members_entries,
1069 cluster_is_quorate, &quorum_ringid);
1070 votequorum_exec_send_quorum_notification(NULL, 0L);
1076 static void get_total_votes(
unsigned int *totalvotes,
unsigned int *current_members)
1078 unsigned int total_votes = 0;
1079 unsigned int cluster_members = 0;
1080 struct qb_list_head *nodelist;
1085 qb_list_for_each(nodelist, &cluster_members_list) {
1089 total_votes += node->
votes;
1093 if (qdevice->
votes) {
1094 total_votes += qdevice->
votes;
1098 *totalvotes = total_votes;
1099 *current_members = cluster_members;
1107 static void recalculate_quorum(
int allow_decrease,
int by_current_nodes)
1109 unsigned int total_votes = 0;
1110 unsigned int cluster_members = 0;
1114 get_total_votes(&total_votes, &cluster_members);
1116 if (!by_current_nodes) {
1117 cluster_members = 0;
1126 votequorum_exec_send_expectedvotes_notification();
1129 if ((ev_tracking) &&
1134 quorum = calculate_quorum(allow_decrease, cluster_members, &total_votes);
1135 update_node_expected_votes(cluster_members);
1137 are_we_quorate(total_votes);
1146 static int votequorum_read_nodelist_configuration(uint32_t *
votes,
1151 const char *iter_key;
1153 uint32_t our_pos, node_pos, last_node_pos=-1;
1154 uint32_t nodecount = 0;
1155 uint32_t nodelist_expected_votes = 0;
1156 uint32_t node_votes = 0;
1163 "No nodelist defined or our node is not in the nodelist");
1171 res = sscanf(iter_key,
"nodelist.node.%u.%s", &node_pos, tmp_key);
1181 if (last_node_pos == node_pos) {
1184 last_node_pos = node_pos;
1193 nodelist_expected_votes = nodelist_expected_votes + node_votes;
1195 if (node_pos == our_pos) {
1196 *
votes = node_votes;
1210 static int votequorum_qdevice_is_configured(uint32_t *qdevice_votes)
1212 char *qdevice_model = NULL;
1218 if (strlen(qdevice_model)) {
1220 *qdevice_votes = -1;
1228 update_qdevice_can_operate(1);
1232 free(qdevice_model);
1240 #define VOTEQUORUM_READCONFIG_STARTUP 0
1241 #define VOTEQUORUM_READCONFIG_RUNTIME 1
1243 static char *votequorum_readconfig(
int runtime)
1245 uint32_t node_votes = 0, qdevice_votes = 0;
1247 uint32_t node_count = 0;
1249 int have_nodelist, have_qdevice;
1250 char *atb_string = NULL;
1268 auto_tie_breaker = initial_auto_tie_breaker;
1276 have_nodelist = votequorum_read_nodelist_configuration(&node_votes, &node_count, &node_expected_votes);
1277 have_qdevice = votequorum_qdevice_is_configured(&qdevice_votes);
1286 error = (
char *)
"configuration error: nodelist or quorum.expected_votes must be configured!";
1299 if ((two_node) && (have_qdevice)) {
1301 error = (
char *)
"configuration error: two_node and quorum device cannot be configured at the same time!";
1310 update_qdevice_can_operate(0);
1321 wait_for_all_autoset = 1;
1324 icmap_get_uint32(
"quorum.last_man_standing_window", &last_man_standing_window);
1338 "auto_tie_breaker_node: is meaningless if auto_tie_breaker is set to 0");
1342 if (atb && atb_string) {
1343 parse_atb_string(atb_string);
1346 initial_auto_tie_breaker = auto_tie_breaker;
1349 if (allow_downscale) {
1354 if (load_ev_tracking_barrier() < 0) {
1356 return ((
char *)
"Unable to load ev_tracking file!");
1358 update_ev_tracking_barrier(ev_tracking_barrier);
1368 if (wait_for_all_autoset) {
1369 wait_for_all = two_node;
1375 if (two_node && auto_tie_breaker !=
ATB_NONE) {
1385 if ((auto_tie_breaker !=
ATB_NONE) && (node_expected_votes % 2) &&
1387 if (last_man_standing) {
1396 error = (
char *)
"configuration error: auto_tie_breaker & last_man_standing not available in odd sized cluster";
1415 if ((have_qdevice) && (last_man_standing)) {
1417 error = (
char *)
"configuration error: quorum.device is not compatible with last_man_standing";
1422 update_qdevice_can_operate(0);
1426 if ((have_qdevice) && (auto_tie_breaker !=
ATB_NONE)) {
1428 error = (
char *)
"configuration error: quorum.device is not compatible with auto_tie_breaker";
1433 update_qdevice_can_operate(0);
1437 if ((have_qdevice) && (allow_downscale)) {
1439 error = (
char *)
"configuration error: quorum.device is not compatible with allow_downscale";
1444 update_qdevice_can_operate(0);
1453 if ((
expected_votes) && (have_qdevice) && (qdevice_votes == -1)) {
1455 error = (
char *)
"configuration error: quorum.device.votes must be specified when quorum.expected_votes is set";
1460 update_qdevice_can_operate(0);
1469 if ((have_qdevice) &&
1470 (qdevice_votes == -1) &&
1472 (node_count != node_expected_votes)) {
1474 error = (
char *)
"configuration error: quorum.device.votes must be specified when not all nodes votes 1";
1479 update_qdevice_can_operate(0);
1491 error = (
char *)
"configuration error: quorum.device.votes is too high or expected_votes is too low";
1496 update_qdevice_can_operate(0);
1505 if ((have_qdevice) &&
1506 (qdevice_votes == -1) &&
1509 (node_count == node_expected_votes)) {
1510 qdevice_votes = node_expected_votes - 1;
1511 node_expected_votes = node_expected_votes + qdevice_votes;
1523 if (have_nodelist) {
1524 us->
votes = node_votes;
1539 if (!have_qdevice) {
1543 if (qdevice_votes != -1) {
1544 qdevice->
votes = qdevice_votes;
1551 update_wait_for_all_status(1);
1553 }
else if (wait_for_all_autoset && wait_for_all_status) {
1558 update_wait_for_all_status(0);
1566 static void votequorum_refresh_config(
1568 const char *key_name,
1573 int old_votes, old_expected_votes;
1583 if (
icmap_get_uint8(
"config.totemconfig_reload_in_progress", &reloading) ==
CS_OK && reloading) {
1588 if (strcmp(key_name,
"quorum.cancel_wait_for_all") == 0 &&
1598 old_votes = us->
votes;
1609 votequorum_exec_send_nodeinfo(us->
node_id);
1611 if (us->
votes != old_votes) {
1627 static void votequorum_exec_add_config_notification(
void)
1637 votequorum_refresh_config,
1639 &icmap_track_nodelist);
1643 votequorum_refresh_config,
1645 &icmap_track_quorum);
1649 votequorum_refresh_config,
1651 &icmap_track_reload);
1660 static int votequorum_exec_send_reconfigure(uint8_t
param,
unsigned int nodeid, uint32_t
value)
1663 struct iovec iov[1];
1687 static int votequorum_exec_send_nodeinfo(uint32_t
nodeid)
1690 struct iovec iov[1];
1696 node = find_node_by_nodeid(
nodeid);
1707 decode_flags(node->
flags);
1722 static int votequorum_exec_send_qdevice_reconfigure(
const char *
oldname,
const char *
newname)
1725 struct iovec iov[1];
1748 static int votequorum_exec_send_qdevice_reg(uint32_t
operation,
const char *qdevice_name_req)
1751 struct iovec iov[1];
1772 static int votequorum_exec_send_quorum_notification(
void *conn, uint64_t context)
1775 struct qb_list_head *tmp;
1778 int cluster_members = 0;
1786 qb_list_for_each(tmp, &cluster_members_list) {
1797 res_lib_votequorum_notification->quorate = cluster_is_quorate;
1798 res_lib_votequorum_notification->context = context;
1799 res_lib_votequorum_notification->node_list_entries = cluster_members;
1801 res_lib_votequorum_notification->header.size = size;
1802 res_lib_votequorum_notification->header.error =
CS_OK;
1805 qb_list_for_each(tmp, &cluster_members_list) {
1807 res_lib_votequorum_notification->node_list[i].nodeid = node->
node_id;
1808 res_lib_votequorum_notification->node_list[i++].state = node->
state;
1812 res_lib_votequorum_notification->node_list[i++].state = qdevice->
state;
1823 qb_list_for_each(tmp, &trackers_list) {
1835 static int votequorum_exec_send_nodelist_notification(
void *
conn, uint64_t context)
1840 struct qb_list_head *tmp;
1850 res_lib_votequorum_notification->node_list_entries = quorum_members_entries;
1851 res_lib_votequorum_notification->ring_id.nodeid = quorum_ringid.
nodeid;
1852 res_lib_votequorum_notification->ring_id.seq = quorum_ringid.
seq;
1853 res_lib_votequorum_notification->context = context;
1855 for (i=0; i<quorum_members_entries; i++) {
1856 res_lib_votequorum_notification->node_list[i] = quorum_members[i];
1860 res_lib_votequorum_notification->header.size = size;
1861 res_lib_votequorum_notification->header.error =
CS_OK;
1871 qb_list_for_each(tmp, &trackers_list) {
1883 static void votequorum_exec_send_expectedvotes_notification(
void)
1887 struct qb_list_head *tmp;
1898 qb_list_for_each(tmp, &trackers_list) {
1899 qpd = qb_list_entry(tmp,
struct quorum_pd, list);
1908 static void exec_votequorum_qdevice_reconfigure_endian_convert (
void *message)
1915 static void message_handler_req_exec_votequorum_qdevice_reconfigure (
1916 const void *message,
1942 static void exec_votequorum_qdevice_reg_endian_convert (
void *message)
1953 static void message_handler_req_exec_votequorum_qdevice_reg (
1954 const void *message,
1959 int wipe_qdevice_name = 1;
1961 struct qb_list_head *tmp;
1974 if (!strlen(qdevice_name)) {
1995 if (!qdevice_reg_conn) {
2004 if (!strlen(qdevice_name)) {
2015 votequorum_exec_send_nodeinfo(us->
node_id);
2018 "A new qdevice with different name (new: %s old: %s) is trying to register!",
2027 qdevice_reg_conn = NULL;
2030 qb_list_for_each(tmp, &cluster_members_list) {
2034 wipe_qdevice_name = 0;
2038 if (wipe_qdevice_name) {
2047 static void exec_votequorum_nodeinfo_endian_convert (
void *message)
2061 static void message_handler_req_exec_votequorum_nodeinfo (
2062 const void *message,
2063 unsigned int sender_nodeid)
2072 int allow_downgrade = 0;
2089 node = find_node_by_nodeid(
nodeid);
2091 node = allocate_node(
nodeid);
2106 old_votes = node->
votes;
2108 old_state = node->
state;
2109 old_flags = node->
flags;
2113 struct cluster_node *sender_node = find_node_by_nodeid(sender_nodeid);
2115 assert(sender_node != NULL);
2117 if ((!cluster_is_quorate) &&
2133 allow_downgrade = 1;
2137 if ((!cluster_is_quorate) &&
2139 allow_downgrade = 1;
2149 if ((last_man_standing) && (node->
votes > 1)) {
2151 "cluster nodes votes are set to 1. Disabling LMS.");
2152 last_man_standing = 0;
2153 if (last_man_standing_timer_set) {
2155 last_man_standing_timer_set = 0;
2163 (old_votes != node->
votes) ||
2165 (old_flags != node->
flags) ||
2166 (old_state != node->
state)) {
2167 recalculate_quorum(allow_downgrade, by_node);
2170 if ((wait_for_all) &&
2173 update_wait_for_all_status(0);
2179 static void exec_votequorum_reconfigure_endian_convert (
void *message)
2191 static void message_handler_req_exec_votequorum_reconfigure (
2192 const void *message,
2207 votequorum_exec_send_expectedvotes_notification();
2212 recalculate_quorum(1, 0);
2222 recalculate_quorum(1, 0);
2226 update_wait_for_all_status(0);
2229 recalculate_quorum(0, 0);
2238 static int votequorum_exec_exit_fn (
void)
2248 if (allow_downscale) {
2250 ret = votequorum_exec_send_nodeinfo(us->
node_id);
2253 if ((ev_tracking) && (ev_tracking_fd != -1)) {
2254 close(ev_tracking_fd);
2262 static void votequorum_set_icmap_ro_keys(
void)
2282 qb_list_init(&cluster_members_list);
2283 qb_list_init(&trackers_list);
2286 memset(cluster_nodes, 0,
sizeof(cluster_nodes));
2294 return ((
char *)
"Could not allocate node.");
2305 return ((
char *)
"Could not allocate node.");
2318 recalculate_quorum(0, 0);
2323 votequorum_set_icmap_ro_keys();
2328 votequorum_exec_add_config_notification();
2333 votequorum_exec_send_nodeinfo(us->
node_id);
2344 static void votequorum_last_man_standing_timer_fn(
void *arg)
2348 last_man_standing_timer_set = 0;
2349 if (cluster_is_quorate) {
2350 recalculate_quorum(1,1);
2356 static void votequorum_sync_init (
2357 const unsigned int *trans_list,
size_t trans_list_entries,
2358 const unsigned int *member_list,
size_t member_list_entries,
2368 sync_in_progress = 1;
2369 sync_nodeinfo_sent = 0;
2370 sync_wait_for_poll_or_timeout = 0;
2372 if (member_list_entries > 1) {
2382 for (i = 0; i < quorum_members_entries; i++) {
2384 for (j = 0; j < member_list_entries; j++) {
2385 if (quorum_members[i] == member_list[j]) {
2392 node = find_node_by_nodeid(quorum_members[i]);
2399 if (last_man_standing) {
2400 if (((member_list_entries >= quorum) && (left_nodes)) ||
2401 ((member_list_entries <= quorum) && (auto_tie_breaker !=
ATB_NONE) && (check_low_node_id_partition() == 1))) {
2402 if (last_man_standing_timer_set) {
2404 last_man_standing_timer_set = 0;
2406 corosync_api->
timer_add_duration((
unsigned long long)last_man_standing_window*1000000,
2407 NULL, votequorum_last_man_standing_timer_fn,
2408 &last_man_standing_timer);
2409 last_man_standing_timer_set = 1;
2413 memcpy(previous_quorum_members, quorum_members,
sizeof(
unsigned int) * quorum_members_entries);
2414 previous_quorum_members_entries = quorum_members_entries;
2416 memcpy(quorum_members, member_list,
sizeof(
unsigned int) * member_list_entries);
2417 quorum_members_entries = member_list_entries;
2424 if (qdevice_timer_set) {
2427 corosync_api->
timer_add_duration((
unsigned long long)qdevice_sync_timeout*1000000, qdevice,
2428 qdevice_timer_fn, &qdevice_timer);
2429 qdevice_timer_set = 1;
2430 sync_wait_for_poll_or_timeout = 1;
2433 qdevice_name, qdevice_sync_timeout);
2439 static int votequorum_sync_process (
void)
2441 if (!sync_nodeinfo_sent) {
2442 votequorum_exec_send_nodeinfo(us->
node_id);
2444 if (strlen(qdevice_name)) {
2448 votequorum_exec_send_nodelist_notification(NULL, 0LL);
2449 sync_nodeinfo_sent = 1;
2463 static void votequorum_sync_activate (
void)
2465 recalculate_quorum(0, 0);
2466 quorum_callback(quorum_members, quorum_members_entries,
2467 cluster_is_quorate, &quorum_ringid);
2468 votequorum_exec_send_quorum_notification(NULL, 0L);
2470 sync_in_progress = 0;
2473 static void votequorum_sync_abort (
void)
2485 if (q_set_quorate_fn == NULL) {
2486 return ((
char *)
"Quorate function not set");
2490 quorum_callback = q_set_quorate_fn;
2493 &votequorum_service[0]);
2507 static int quorum_lib_init_fn (
void *conn)
2513 qb_list_init (&pd->
list);
2520 static int quorum_lib_exit_fn (
void *
conn)
2540 static void qdevice_timer_fn(
void *arg)
2545 (!qdevice_timer_set)) {
2553 votequorum_exec_send_nodeinfo(us->
node_id);
2555 qdevice_timer_set = 0;
2556 sync_wait_for_poll_or_timeout = 0;
2565 static void message_handler_req_lib_votequorum_getinfo (
void *
conn,
const void *message)
2570 unsigned int highest_expected = 0;
2571 unsigned int total_votes = 0;
2583 node = find_node_by_nodeid(
nodeid);
2586 struct qb_list_head *nodelist;
2588 qb_list_for_each(nodelist, &cluster_members_list) {
2589 iternode = qb_list_entry(nodelist,
struct cluster_node, list);
2594 total_votes += iternode->
votes;
2599 total_votes += qdevice->
votes;
2602 switch(node->
state) {
2629 if (cluster_is_quorate) {
2635 if (last_man_standing) {
2638 if (auto_tie_breaker !=
ATB_NONE) {
2641 if (allow_downscale) {
2674 static void message_handler_req_lib_votequorum_setexpected (
void *conn,
const void *message)
2679 unsigned int newquorum;
2680 unsigned int total_votes;
2681 uint8_t allow_downscale_status = 0;
2685 allow_downscale_status = allow_downscale;
2686 allow_downscale = 0;
2692 allow_downscale = allow_downscale_status;
2698 (cluster_is_quorate && (newquorum > total_votes))) {
2718 static void message_handler_req_lib_votequorum_setvotes (
void *conn,
const void *message)
2723 unsigned int newquorum;
2724 unsigned int total_votes;
2725 unsigned int saved_votes;
2732 node = find_node_by_nodeid(
nodeid);
2741 saved_votes = node->
votes;
2744 newquorum = calculate_quorum(1, 0, &total_votes);
2746 if (newquorum < total_votes / 2 ||
2747 newquorum > total_votes) {
2748 node->
votes = saved_votes;
2767 static void message_handler_req_lib_votequorum_trackstart (
void *conn,
2768 const void *message)
2815 static void message_handler_req_lib_votequorum_trackstop (
void *
conn,
2816 const void *message)
2841 static void message_handler_req_lib_votequorum_qdevice_register (
void *
conn,
2842 const void *message)
2850 if (!qdevice_can_operate) {
2851 log_printf(
LOGSYS_LEVEL_INFO,
"Registration of quorum device is disabled by incorrect corosync.conf. See logs for more information");
2862 "A new qdevice with different name (new: %s old: %s) is trying to re-register!",
2868 if (qdevice_reg_conn != NULL) {
2870 "Registration request already in progress");
2874 qdevice_reg_conn = conn;
2878 "Unable to send qdevice registration request to cluster");
2880 qdevice_reg_conn = NULL;
2897 static void message_handler_req_lib_votequorum_qdevice_unregister (
void *conn,
2898 const void *message)
2911 if (qdevice_timer_set) {
2913 qdevice_timer_set = 0;
2914 sync_wait_for_poll_or_timeout = 0;
2920 votequorum_exec_send_nodeinfo(us->
node_id);
2936 static void message_handler_req_lib_votequorum_qdevice_update (
void *conn,
2937 const void *message)
2965 static void message_handler_req_lib_votequorum_qdevice_poll (
void *conn,
2966 const void *message)
2975 if (!qdevice_can_operate) {
2986 quorum_ringid.
nodeid, quorum_ringid.
seq);
2995 if (qdevice_timer_set) {
2997 qdevice_timer_set = 0;
3000 oldflags = us->
flags;
3010 if (us->
flags != oldflags) {
3011 votequorum_exec_send_nodeinfo(us->
node_id);
3014 corosync_api->
timer_add_duration((
unsigned long long)qdevice_timeout*1000000, qdevice,
3015 qdevice_timer_fn, &qdevice_timer);
3016 qdevice_timer_set = 1;
3017 sync_wait_for_poll_or_timeout = 0;
3031 static void message_handler_req_lib_votequorum_qdevice_master_wins (
void *conn,
3032 const void *message)
3037 uint32_t oldflags = us->
flags;
3041 if (!qdevice_can_operate) {
3058 if (us->
flags != oldflags) {
3059 votequorum_exec_send_nodeinfo(us->
node_id);