45#include <qb/qbipc_common.h>
75static uint8_t qdevice_can_operate = 1;
76static void *qdevice_reg_conn = NULL;
77static uint8_t qdevice_master_wins = 0;
79static uint8_t two_node = 0;
81static uint8_t wait_for_all = 0;
82static uint8_t wait_for_all_status = 0;
83static uint8_t wait_for_all_autoset = 0;
86static int lowest_node_id = -1;
87static int highest_node_id = -1;
89#define DEFAULT_LMS_WIN 10000
90static uint8_t last_man_standing = 0;
93static uint8_t allow_downscale = 0;
94static uint32_t ev_barrier = 0;
96static uint8_t ev_tracking = 0;
97static uint32_t ev_tracking_barrier = 0;
98static 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
149static void votequorum_exec_send_expectedvotes_notification(
void);
150static int votequorum_exec_send_quorum_notification(
void *conn, uint64_t context);
151static 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
157static 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
197static uint8_t quorum;
198static uint8_t cluster_is_quorate;
205static struct qb_list_head cluster_members_list;
209static int quorum_members_entries = 0;
210static int previous_quorum_members_entries = 0;
211static int atb_nodelist_entries = 0;
218static int cluster_nodes_entries = 0;
231static struct qb_list_head trackers_list;
238static int qdevice_timer_set = 0;
240static int last_man_standing_timer_set = 0;
241static int sync_nodeinfo_sent = 0;
242static int sync_wait_for_poll_or_timeout = 0;
248static int sync_in_progress = 0;
250static 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,
257static int votequorum_sync_process (
void);
258static void votequorum_sync_activate (
void);
259static void votequorum_sync_abort (
void);
268static int votequorum_exec_exit_fn (
void);
269static int votequorum_exec_send_nodeinfo(uint32_t
nodeid);
271static void message_handler_req_exec_votequorum_nodeinfo (
274static void exec_votequorum_nodeinfo_endian_convert (
void *message);
276static void message_handler_req_exec_votequorum_reconfigure (
279static void exec_votequorum_reconfigure_endian_convert (
void *message);
281static void message_handler_req_exec_votequorum_qdevice_reg (
284static void exec_votequorum_qdevice_reg_endian_convert (
void *message);
286static void message_handler_req_exec_votequorum_qdevice_reconfigure (
289static 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
315static int quorum_lib_init_fn (
void *conn);
317static int quorum_lib_exit_fn (
void *conn);
319static void qdevice_timer_fn(
void *arg);
321static void message_handler_req_lib_votequorum_getinfo (
void *conn,
322 const void *message);
324static void message_handler_req_lib_votequorum_setexpected (
void *conn,
325 const void *message);
327static void message_handler_req_lib_votequorum_setvotes (
void *conn,
328 const void *message);
330static void message_handler_req_lib_votequorum_trackstart (
void *conn,
331 const void *message);
333static void message_handler_req_lib_votequorum_trackstop (
void *conn,
334 const void *message);
336static void message_handler_req_lib_votequorum_qdevice_register (
void *conn,
337 const void *message);
339static void message_handler_req_lib_votequorum_qdevice_unregister (
void *conn,
340 const void *message);
342static void message_handler_req_lib_votequorum_qdevice_update (
void *conn,
343 const void *message);
345static void message_handler_req_lib_votequorum_qdevice_poll (
void *conn,
346 const void *message);
348static 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))
435static 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) {
526static 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;
548static 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;
570static 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)) {
590static 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)) {
610static int is_in_nodelist(
int nodeid,
unsigned int *members,
int entries)
615 for (i=0; i<entries; i++) {
616 if (
nodeid == members[i]) {
638static 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)) {
694static 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");
735static int check_qdevice_master(
void)
738 struct qb_list_head *tmp;
743 qb_list_for_each(tmp, &cluster_members_list) {
756static 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",
777static 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);
817static void update_wait_for_all_status(uint8_t wfa_status)
821 wait_for_all_status = wfa_status;
822 if (wait_for_all_status) {
825 us->
flags &= ~NODE_FLAGS_WFASTATUS;
828 wait_for_all_status);
833static void update_two_node(
void)
852static 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);
862static 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);
872static 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!!!");
894 fdatasync(ev_tracking_fd);
896 fsync(ev_tracking_fd);
906static 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;
979static 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) {
995static 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) {
1055 us->
flags &= ~NODE_FLAGS_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);
1076static 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;
1107static 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);
1146static 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;
1210static 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
1243static 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;
1323 (void)
icmap_get_uint8(
"quorum.last_man_standing", &last_man_standing);
1324 (void)
icmap_get_uint32(
"quorum.last_man_standing_window", &last_man_standing_window);
1325 (void)
icmap_get_uint8(
"quorum.expected_votes_tracking", &ev_tracking);
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);
1566static void votequorum_refresh_config(
1568 const char *key_name,
1573 int old_votes, old_expected_votes;
1576 int32_t reload_status;
1584 if (
icmap_get_uint8(
"config.totemconfig_reload_in_progress", &reloading) ==
CS_OK && reloading) {
1589 if ( (strcmp(key_name,
"config.totemconfig_reload_in_progress") == 0) &&
1591 (reload_status !=
CS_OK) ) {
1596 if (strcmp(key_name,
"quorum.cancel_wait_for_all") == 0 &&
1606 old_votes = us->
votes;
1617 votequorum_exec_send_nodeinfo(us->
node_id);
1619 if (us->
votes != old_votes) {
1635static void votequorum_exec_add_config_notification(
void)
1645 votequorum_refresh_config,
1647 &icmap_track_nodelist);
1651 votequorum_refresh_config,
1653 &icmap_track_quorum);
1657 votequorum_refresh_config,
1659 &icmap_track_reload);
1668static int votequorum_exec_send_reconfigure(uint8_t
param,
unsigned int nodeid, uint32_t
value)
1671 struct iovec iov[1];
1695static int votequorum_exec_send_nodeinfo(uint32_t
nodeid)
1698 struct iovec iov[1];
1704 node = find_node_by_nodeid(
nodeid);
1715 decode_flags(node->
flags);
1730static int votequorum_exec_send_qdevice_reconfigure(
const char *
oldname,
const char *
newname)
1733 struct iovec iov[1];
1756static int votequorum_exec_send_qdevice_reg(uint32_t
operation,
const char *qdevice_name_req)
1759 struct iovec iov[1];
1780static int votequorum_exec_send_quorum_notification(
void *conn, uint64_t context)
1783 struct qb_list_head *tmp;
1786 int cluster_members = 0;
1794 qb_list_for_each(tmp, &cluster_members_list) {
1805 res_lib_votequorum_notification->quorate = cluster_is_quorate;
1806 res_lib_votequorum_notification->context = context;
1807 res_lib_votequorum_notification->node_list_entries = cluster_members;
1809 res_lib_votequorum_notification->header.size = size;
1810 res_lib_votequorum_notification->header.error =
CS_OK;
1813 qb_list_for_each(tmp, &cluster_members_list) {
1815 res_lib_votequorum_notification->node_list[i].nodeid = node->
node_id;
1816 res_lib_votequorum_notification->node_list[i++].state = node->
state;
1820 res_lib_votequorum_notification->node_list[i++].state = qdevice->
state;
1831 qb_list_for_each(tmp, &trackers_list) {
1843static int votequorum_exec_send_nodelist_notification(
void *
conn, uint64_t context)
1848 struct qb_list_head *tmp;
1858 res_lib_votequorum_notification->node_list_entries = quorum_members_entries;
1859 res_lib_votequorum_notification->ring_id.nodeid = quorum_ringid.
nodeid;
1860 res_lib_votequorum_notification->ring_id.seq = quorum_ringid.
seq;
1861 res_lib_votequorum_notification->context = context;
1863 for (i=0; i<quorum_members_entries; i++) {
1864 res_lib_votequorum_notification->node_list[i] = quorum_members[i];
1868 res_lib_votequorum_notification->header.size = size;
1869 res_lib_votequorum_notification->header.error =
CS_OK;
1879 qb_list_for_each(tmp, &trackers_list) {
1891static void votequorum_exec_send_expectedvotes_notification(
void)
1895 struct qb_list_head *tmp;
1906 qb_list_for_each(tmp, &trackers_list) {
1907 qpd = qb_list_entry(tmp,
struct quorum_pd, list);
1916static void exec_votequorum_qdevice_reconfigure_endian_convert (
void *message)
1923static void message_handler_req_exec_votequorum_qdevice_reconfigure (
1924 const void *message,
1950static void exec_votequorum_qdevice_reg_endian_convert (
void *message)
1961static void message_handler_req_exec_votequorum_qdevice_reg (
1962 const void *message,
1967 int wipe_qdevice_name = 1;
1969 struct qb_list_head *tmp;
1982 if (!strlen(qdevice_name)) {
2003 if (!qdevice_reg_conn) {
2012 if (!strlen(qdevice_name)) {
2023 votequorum_exec_send_nodeinfo(us->
node_id);
2026 "A new qdevice with different name (new: %s old: %s) is trying to register!",
2035 qdevice_reg_conn = NULL;
2038 qb_list_for_each(tmp, &cluster_members_list) {
2042 wipe_qdevice_name = 0;
2046 if (wipe_qdevice_name) {
2055static void exec_votequorum_nodeinfo_endian_convert (
void *message)
2069static void message_handler_req_exec_votequorum_nodeinfo (
2070 const void *message,
2071 unsigned int sender_nodeid)
2080 int allow_downgrade = 0;
2097 node = find_node_by_nodeid(
nodeid);
2099 node = allocate_node(
nodeid);
2114 old_votes = node->
votes;
2116 old_state = node->
state;
2117 old_flags = node->
flags;
2121 struct cluster_node *sender_node = find_node_by_nodeid(sender_nodeid);
2123 assert(sender_node != NULL);
2125 if ((!cluster_is_quorate) &&
2141 allow_downgrade = 1;
2145 if ((!cluster_is_quorate) &&
2147 allow_downgrade = 1;
2157 if ((last_man_standing) && (node->
votes > 1)) {
2159 "cluster nodes votes are set to 1. Disabling LMS.");
2160 last_man_standing = 0;
2161 if (last_man_standing_timer_set) {
2163 last_man_standing_timer_set = 0;
2171 (old_votes != node->
votes) ||
2173 (old_flags != node->
flags) ||
2174 (old_state != node->
state)) {
2175 recalculate_quorum(allow_downgrade, by_node);
2178 if ((wait_for_all) &&
2181 update_wait_for_all_status(0);
2187static void exec_votequorum_reconfigure_endian_convert (
void *message)
2199static void message_handler_req_exec_votequorum_reconfigure (
2200 const void *message,
2215 votequorum_exec_send_expectedvotes_notification();
2220 recalculate_quorum(1, 0);
2230 recalculate_quorum(1, 0);
2234 update_wait_for_all_status(0);
2237 recalculate_quorum(0, 0);
2246static int votequorum_exec_exit_fn (
void)
2256 if (allow_downscale) {
2258 ret = votequorum_exec_send_nodeinfo(us->
node_id);
2261 if ((ev_tracking) && (ev_tracking_fd != -1)) {
2262 close(ev_tracking_fd);
2270static void votequorum_set_icmap_ro_keys(
void)
2290 qb_list_init(&cluster_members_list);
2291 qb_list_init(&trackers_list);
2294 memset(cluster_nodes, 0,
sizeof(cluster_nodes));
2302 return ((
char *)
"Could not allocate node.");
2313 return ((
char *)
"Could not allocate node.");
2326 recalculate_quorum(0, 0);
2331 votequorum_set_icmap_ro_keys();
2336 votequorum_exec_add_config_notification();
2341 votequorum_exec_send_nodeinfo(us->
node_id);
2352static void votequorum_last_man_standing_timer_fn(
void *arg)
2356 last_man_standing_timer_set = 0;
2357 if (cluster_is_quorate) {
2358 recalculate_quorum(1,1);
2364static void votequorum_sync_init (
2365 const unsigned int *trans_list,
size_t trans_list_entries,
2366 const unsigned int *member_list,
size_t member_list_entries,
2376 sync_in_progress = 1;
2377 sync_nodeinfo_sent = 0;
2378 sync_wait_for_poll_or_timeout = 0;
2380 if (member_list_entries > 1) {
2381 us->
flags &= ~NODE_FLAGS_FIRST;
2390 for (i = 0; i < quorum_members_entries; i++) {
2392 for (j = 0; j < member_list_entries; j++) {
2393 if (quorum_members[i] == member_list[j]) {
2400 node = find_node_by_nodeid(quorum_members[i]);
2407 if (last_man_standing) {
2408 if (((member_list_entries >= quorum) && (left_nodes)) ||
2409 ((member_list_entries <= quorum) && (auto_tie_breaker !=
ATB_NONE) && (check_low_node_id_partition() == 1))) {
2410 if (last_man_standing_timer_set) {
2412 last_man_standing_timer_set = 0;
2414 corosync_api->
timer_add_duration((
unsigned long long)last_man_standing_window*1000000,
2415 NULL, votequorum_last_man_standing_timer_fn,
2416 &last_man_standing_timer);
2417 last_man_standing_timer_set = 1;
2421 memcpy(previous_quorum_members, quorum_members,
sizeof(
unsigned int) * quorum_members_entries);
2422 previous_quorum_members_entries = quorum_members_entries;
2424 memcpy(quorum_members, member_list,
sizeof(
unsigned int) * member_list_entries);
2425 quorum_members_entries = member_list_entries;
2432 if (qdevice_timer_set) {
2435 corosync_api->
timer_add_duration((
unsigned long long)qdevice_sync_timeout*1000000, qdevice,
2436 qdevice_timer_fn, &qdevice_timer);
2437 qdevice_timer_set = 1;
2438 sync_wait_for_poll_or_timeout = 1;
2441 qdevice_name, qdevice_sync_timeout);
2447static int votequorum_sync_process (
void)
2449 if (!sync_nodeinfo_sent) {
2450 votequorum_exec_send_nodeinfo(us->
node_id);
2452 if (strlen(qdevice_name)) {
2456 votequorum_exec_send_nodelist_notification(NULL, 0LL);
2457 sync_nodeinfo_sent = 1;
2471static void votequorum_sync_activate (
void)
2473 recalculate_quorum(0, 0);
2474 quorum_callback(quorum_members, quorum_members_entries,
2475 cluster_is_quorate, &quorum_ringid);
2476 votequorum_exec_send_quorum_notification(NULL, 0L);
2478 sync_in_progress = 0;
2481static void votequorum_sync_abort (
void)
2493 if (q_set_quorate_fn == NULL) {
2494 return ((
char *)
"Quorate function not set");
2498 quorum_callback = q_set_quorate_fn;
2501 &votequorum_service[0]);
2515static int quorum_lib_init_fn (
void *conn)
2521 qb_list_init (&pd->
list);
2528static int quorum_lib_exit_fn (
void *
conn)
2548static void qdevice_timer_fn(
void *arg)
2553 (!qdevice_timer_set)) {
2558 us->
flags &= ~NODE_FLAGS_QDEVICE_ALIVE;
2559 us->
flags &= ~NODE_FLAGS_QDEVICE_CAST_VOTE;
2561 votequorum_exec_send_nodeinfo(us->
node_id);
2563 qdevice_timer_set = 0;
2564 sync_wait_for_poll_or_timeout = 0;
2573static void message_handler_req_lib_votequorum_getinfo (
void *
conn,
const void *message)
2578 unsigned int highest_expected = 0;
2579 unsigned int total_votes = 0;
2591 node = find_node_by_nodeid(
nodeid);
2594 struct qb_list_head *nodelist;
2596 qb_list_for_each(nodelist, &cluster_members_list) {
2597 iternode = qb_list_entry(nodelist,
struct cluster_node, list);
2602 total_votes += iternode->
votes;
2607 total_votes += qdevice->
votes;
2610 switch(node->
state) {
2637 if (cluster_is_quorate) {
2643 if (last_man_standing) {
2646 if (auto_tie_breaker !=
ATB_NONE) {
2649 if (allow_downscale) {
2682static void message_handler_req_lib_votequorum_setexpected (
void *conn,
const void *message)
2687 unsigned int newquorum;
2688 unsigned int total_votes;
2689 uint8_t allow_downscale_status = 0;
2693 allow_downscale_status = allow_downscale;
2694 allow_downscale = 0;
2700 allow_downscale = allow_downscale_status;
2706 (cluster_is_quorate && (newquorum > total_votes))) {
2726static void message_handler_req_lib_votequorum_setvotes (
void *conn,
const void *message)
2731 unsigned int newquorum;
2732 unsigned int total_votes;
2733 unsigned int saved_votes;
2740 node = find_node_by_nodeid(
nodeid);
2749 saved_votes = node->
votes;
2752 newquorum = calculate_quorum(1, 0, &total_votes);
2754 if (newquorum < total_votes / 2 ||
2755 newquorum > total_votes) {
2756 node->
votes = saved_votes;
2775static void message_handler_req_lib_votequorum_trackstart (
void *conn,
2776 const void *message)
2823static void message_handler_req_lib_votequorum_trackstop (
void *
conn,
2824 const void *message)
2849static void message_handler_req_lib_votequorum_qdevice_register (
void *
conn,
2850 const void *message)
2858 if (!qdevice_can_operate) {
2859 log_printf(
LOGSYS_LEVEL_INFO,
"Registration of quorum device is disabled by incorrect corosync.conf. See logs for more information");
2870 "A new qdevice with different name (new: %s old: %s) is trying to re-register!",
2876 if (qdevice_reg_conn != NULL) {
2878 "Registration request already in progress");
2882 qdevice_reg_conn = conn;
2886 "Unable to send qdevice registration request to cluster");
2888 qdevice_reg_conn = NULL;
2905static void message_handler_req_lib_votequorum_qdevice_unregister (
void *conn,
2906 const void *message)
2919 if (qdevice_timer_set) {
2921 qdevice_timer_set = 0;
2922 sync_wait_for_poll_or_timeout = 0;
2924 us->
flags &= ~NODE_FLAGS_QDEVICE_REGISTERED;
2925 us->
flags &= ~NODE_FLAGS_QDEVICE_ALIVE;
2926 us->
flags &= ~NODE_FLAGS_QDEVICE_CAST_VOTE;
2927 us->
flags &= ~NODE_FLAGS_QDEVICE_MASTER_WINS;
2928 votequorum_exec_send_nodeinfo(us->
node_id);
2944static void message_handler_req_lib_votequorum_qdevice_update (
void *conn,
2945 const void *message)
2973static void message_handler_req_lib_votequorum_qdevice_poll (
void *conn,
2974 const void *message)
2983 if (!qdevice_can_operate) {
2994 quorum_ringid.
nodeid, quorum_ringid.
seq);
3003 if (qdevice_timer_set) {
3005 qdevice_timer_set = 0;
3008 oldflags = us->
flags;
3015 us->
flags &= ~NODE_FLAGS_QDEVICE_CAST_VOTE;
3018 if (us->
flags != oldflags) {
3019 votequorum_exec_send_nodeinfo(us->
node_id);
3022 corosync_api->
timer_add_duration((
unsigned long long)qdevice_timeout*1000000, qdevice,
3023 qdevice_timer_fn, &qdevice_timer);
3024 qdevice_timer_set = 1;
3025 sync_wait_for_poll_or_timeout = 0;
3039static void message_handler_req_lib_votequorum_qdevice_master_wins (
void *conn,
3040 const void *message)
3045 uint32_t oldflags = us->
flags;
3049 if (!qdevice_can_operate) {
3063 us->
flags &= ~NODE_FLAGS_QDEVICE_MASTER_WINS;
3066 if (us->
flags != oldflags) {
3067 votequorum_exec_send_nodeinfo(us->
node_id);
#define SERVICE_ID_MAKE(a, b)
qb_loop_timer_handle corosync_timer_handle_t
corosync_timer_handle_t
#define COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
#define COROSYNC_LIB_FLOW_CONTROL_REQUIRED
#define PROCESSOR_COUNT_MAX
#define CS_TRACK_CHANGES_ONLY
cs_error_t
The cs_error_t enum.
void(* quorum_set_quorate_fn_t)(const unsigned int *view_list, size_t view_list_entries, int quorate, struct memb_ring_id *)
struct corosync_service_engine * votequorum_get_service_engine_ver0(void)
#define VOTEQUORUM_RECONFIG_PARAM_CANCEL_WFA
#define NODE_FLAGS_QUORATE
#define VOTEQUORUM_RECONFIG_PARAM_NODE_VOTES
char * votequorum_init(struct corosync_api_v1 *api, quorum_set_quorate_fn_t q_set_quorate_fn)
#define VOTEQUORUM_RECONFIG_PARAM_EXPECTED_VOTES
#define VOTEQUORUM_QDEVICE_OPERATION_UNREGISTER
char oldname[VOTEQUORUM_QDEVICE_MAX_NAME_LEN]
#define NODE_FLAGS_QDEVICE_REGISTERED
#define MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_RECONFIGURE
char newname[VOTEQUORUM_QDEVICE_MAX_NAME_LEN]
#define NODE_FLAGS_QDEVICE_CAST_VOTE
#define MESSAGE_REQ_EXEC_VOTEQUORUM_RECONFIGURE
#define NODE_FLAGS_QDEVICE_MASTER_WINS
#define VOTEQUORUM_READCONFIG_STARTUP
#define NODE_FLAGS_LEAVING
#define NODE_FLAGS_QDEVICE_ALIVE
#define NODE_FLAGS_WFASTATUS
#define MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_REG
LOGSYS_DECLARE_SUBSYS("VOTEQ")
#define VOTEQUORUM_QDEVICE_OPERATION_REGISTER
#define MESSAGE_REQ_EXEC_VOTEQUORUM_NODEINFO
#define VOTEQUORUM_READCONFIG_RUNTIME
cs_error_t icmap_get_uint8(const char *key_name, uint8_t *u8)
#define ICMAP_TRACK_MODIFY
cs_error_t icmap_get_uint32(const char *key_name, uint32_t *u32)
cs_error_t icmap_set_uint8(const char *key_name, uint8_t value)
cs_error_t icmap_set_ro_access(const char *key_name, int prefix, int ro_access)
Set read-only access for given key (key_name) or prefix, If prefix is set.
#define ICMAP_TRACK_DELETE
cs_error_t icmap_track_add(const char *key_name, int32_t track_type, icmap_notify_fn_t notify_fn, void *user_data, icmap_track_t *icmap_track)
Add tracking function for given key_name.
#define ICMAP_TRACK_PREFIX
Whole prefix is tracked, instead of key only (so "totem." tracking means that "totem....
icmap_iter_t icmap_iter_init(const char *prefix)
Initialize iterator with given prefix.
const char * icmap_iter_next(icmap_iter_t iter, size_t *value_len, icmap_value_types_t *type)
Return next item in iterator iter.
qb_map_iter_t * icmap_iter_t
Itterator type.
void icmap_iter_finalize(icmap_iter_t iter)
Finalize iterator.
cs_error_t icmap_get_int32(const char *key_name, int32_t *i32)
#define ICMAP_KEYNAME_MAXLEN
Maximum length of key in icmap.
cs_error_t icmap_set_uint32(const char *key_name, uint32_t value)
cs_error_t icmap_get_string(const char *key_name, char **str)
Shortcut for icmap_get for string type.
#define VOTEQUORUM_QDEVICE_DEFAULT_SYNC_TIMEOUT
#define VOTEQUORUM_INFO_AUTO_TIE_BREAKER
#define VOTEQUORUM_INFO_QDEVICE_ALIVE
#define VOTEQUORUM_NODESTATE_MEMBER
#define VOTEQUORUM_NODESTATE_DEAD
#define VOTEQUORUM_INFO_ALLOW_DOWNSCALE
@ MESSAGE_RES_VOTEQUORUM_NODELIST_NOTIFICATION
@ MESSAGE_RES_VOTEQUORUM_EXPECTEDVOTES_NOTIFICATION
@ MESSAGE_RES_VOTEQUORUM_STATUS
@ MESSAGE_RES_VOTEQUORUM_QUORUM_NOTIFICATION
@ MESSAGE_RES_VOTEQUORUM_GETINFO
#define VOTEQUORUM_INFO_QDEVICE_MASTER_WINS
#define VOTEQUORUM_NODESTATE_LEAVING
#define VOTEQUORUM_INFO_TWONODE
#define VOTEQUORUM_INFO_WAIT_FOR_ALL
#define VOTEQUORUM_INFO_QUORATE
#define VOTEQUORUM_INFO_QDEVICE_REGISTERED
#define VOTEQUORUM_INFO_LAST_MAN_STANDING
#define VOTEQUORUM_QDEVICE_MAX_NAME_LEN
#define VOTEQUORUM_QDEVICE_NODEID
#define VOTEQUORUM_INFO_QDEVICE_CAST_VOTE
#define VOTEQUORUM_QDEVICE_DEFAULT_TIMEOUT
#define LOGSYS_LEVEL_ERROR
#define log_printf(level, format, args...)
#define LOGSYS_LEVEL_INFO
#define LOGSYS_LEVEL_CRIT
#define LOGSYS_LEVEL_NOTICE
#define LOGSYS_LEVEL_WARNING
#define LOGSYS_LEVEL_DEBUG
char * corosync_service_link_and_init(struct corosync_api_v1 *corosync_api, struct default_service *service)
Link and initialize a service.
The corosync_api_v1 struct.
int(* timer_add_duration)(unsigned long long nanoseconds_in_future, void *data, void(*timer_nf)(void *data), corosync_timer_handle_t *handle)
int(* totem_mcast)(const struct iovec *iovec, unsigned int iov_len, unsigned int guarantee)
void *(* ipc_private_data_get)(void *conn)
void(* timer_delete)(corosync_timer_handle_t timer_handle)
unsigned int(* totem_nodeid_get)(void)
int(* ipc_dispatch_send)(void *conn, const void *msg, size_t mlen)
int(* ipc_response_send)(void *conn, const void *msg, size_t mlen)
void(* error_memory_failure)(void) __attribute__((noreturn))
The corosync_exec_handler struct.
void(* exec_handler_fn)(const void *msg, unsigned int nodeid)
The corosync_lib_handler struct.
void(* lib_handler_fn)(void *conn, const void *msg)
The corosync_service_engine struct.
Structure passed as new_value and old_value in change callback.
unsigned char track_flags
uint64_t tracking_context
struct qb_ipc_request_header header __attribute__((aligned(8)))
struct qb_ipc_request_header header __attribute__((aligned(8)))
char qdevice_name[VOTEQUORUM_QDEVICE_MAX_NAME_LEN]
The req_lib_votequorum_getinfo struct.
The req_lib_votequorum_qdevice_master_wins struct.
char name[VOTEQUORUM_QDEVICE_MAX_NAME_LEN]
The req_lib_votequorum_qdevice_poll struct.
char name[VOTEQUORUM_QDEVICE_MAX_NAME_LEN]
The req_lib_votequorum_qdevice_register struct.
char name[VOTEQUORUM_QDEVICE_MAX_NAME_LEN]
The req_lib_votequorum_qdevice_unregister struct.
char name[VOTEQUORUM_QDEVICE_MAX_NAME_LEN]
The req_lib_votequorum_qdevice_update struct.
char newname[VOTEQUORUM_QDEVICE_MAX_NAME_LEN]
char oldname[VOTEQUORUM_QDEVICE_MAX_NAME_LEN]
The req_lib_votequorum_setexpected struct.
unsigned int expected_votes
The req_lib_votequorum_setvotes struct.
The req_lib_votequorum_trackstart struct.
The res_lib_votequorum_expectedvotes_notification struct.
The res_lib_votequorum_getinfo struct.
unsigned int highest_expected
char qdevice_name[VOTEQUORUM_QDEVICE_MAX_NAME_LEN]
unsigned int expected_votes
unsigned int qdevice_votes
The res_lib_votequorum_quorum_notification struct.
The res_lib_votequorum_status struct.
The votequorum_node struct.
#define swab32(x)
The swab32 macro.
struct memb_ring_id ring_id
struct totem_message_header header
const char * get_state_dir(void)