diff --git a/qdevices/corosync-qdevice.c b/qdevices/corosync-qdevice.c
index d7d8934d..fd932f10 100644
--- a/qdevices/corosync-qdevice.c
+++ b/qdevices/corosync-qdevice.c
@@ -1,255 +1,261 @@
 /*
  * Copyright (c) 2015-2016 Red Hat, Inc.
  *
  * All rights reserved.
  *
  * Author: Jan Friesse (jfriesse@redhat.com)
  *
  * This software licensed under BSD license, the text of which follows:
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
  *
  * - Redistributions of source code must retain the above copyright notice,
  *   this list of conditions and the following disclaimer.
  * - Redistributions in binary form must reproduce the above copyright notice,
  *   this list of conditions and the following disclaimer in the documentation
  *   and/or other materials provided with the distribution.
  * - Neither the name of the Red Hat, Inc. nor the names of its
  *   contributors may be used to endorse or promote products derived from this
  *   software without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #include <err.h>
 #include <signal.h>
 
 #include "dynar.h"
 #include "dynar-str.h"
 #include "dynar-getopt-lex.h"
 #include "qdevice-advanced-settings.h"
 #include "qdevice-config.h"
 #include "qdevice-cmap.h"
 #include "qdevice-ipc.h"
 #include "qdevice-log.h"
 #include "qdevice-model.h"
 #include "qdevice-votequorum.h"
 #include "utils.h"
 
 struct qdevice_instance *global_instance;
 
 static void
 signal_int_handler(int sig)
 {
 	qdevice_log(LOG_DEBUG, "SIGINT received - closing local unix socket");
 	qdevice_ipc_close(global_instance);
 }
 
 static void
 signal_term_handler(int sig)
 {
 	qdevice_log(LOG_DEBUG, "SIGTERM received - closing server socket");
 	qdevice_ipc_close(global_instance);
 }
 
 static void
 signal_handlers_register(void)
 {
 	struct sigaction act;
 
 	act.sa_handler = signal_int_handler;
 	sigemptyset(&act.sa_mask);
 	act.sa_flags = SA_RESTART;
 
 	sigaction(SIGINT, &act, NULL);
 
 	act.sa_handler = signal_term_handler;
 	sigemptyset(&act.sa_mask);
 	act.sa_flags = SA_RESTART;
 
 	sigaction(SIGTERM, &act, NULL);
 }
 
 static void
 usage(void)
 {
 
 	printf("usage: %s [-dfh] [-S option=value[,option2=value2,...]]\n", QDEVICE_PROGRAM_NAME);
 }
 
 static void
 cli_parse_long_opt(struct qdevice_advanced_settings *advanced_settings, const char *long_opt)
 {
 	struct dynar_getopt_lex lex;
 	struct dynar dynar_long_opt;
 	const char *opt;
 	const char *val;
 	int res;
 
 	dynar_init(&dynar_long_opt, strlen(long_opt) + 1);
 	if (dynar_str_cpy(&dynar_long_opt, long_opt) != 0) {
 		errx(1, "Can't alloc memory for long option");
 	}
 
 	dynar_getopt_lex_init(&lex, &dynar_long_opt);
 
 	while (dynar_getopt_lex_token_next(&lex) == 0 && strcmp(dynar_data(&lex.option), "") != 0) {
 		opt = dynar_data(&lex.option);
 		val = dynar_data(&lex.value);
 
 		res = qdevice_advanced_settings_set(advanced_settings, opt, val);
 		switch (res) {
 		case -1:
 			errx(1, "Unknown option '%s'", opt);
 			break;
 		case -2:
 			errx(1, "Invalid value '%s' for option '%s'", val, opt);
 			break;
 		}
 	}
 
 	dynar_getopt_lex_destroy(&lex);
 	dynar_destroy(&dynar_long_opt);
 }
 
 static void
 cli_parse(int argc, char * const argv[], int *foreground, int *force_debug,
     struct qdevice_advanced_settings *advanced_settings)
 {
 	int ch;
 
 	*foreground = 0;
 	*force_debug = 0;
 
 	while ((ch = getopt(argc, argv, "dfhS:")) != -1) {
 		switch (ch) {
 		case 'd':
 			*force_debug = 1;
 			break;
 		case 'f':
 			*foreground = 1;
 			break;
 		case 'S':
 			cli_parse_long_opt(advanced_settings, optarg);
 			break;
 		case 'h':
 		case '?':
 			usage();
 			exit(1);
 			break;
 		}
 	}
 }
 
 int
 main(int argc, char * const argv[])
 {
 	struct qdevice_instance instance;
 	struct qdevice_advanced_settings advanced_settings;
 	int foreground;
 	int force_debug;
 	int lock_file;
 	int another_instance_running;
 
 	if (qdevice_advanced_settings_init(&advanced_settings) != 0) {
 		errx(1, "Can't alloc memory for advanced settings");
 	}
 
 	cli_parse(argc, argv, &foreground, &force_debug, &advanced_settings);
 
 	qdevice_instance_init(&instance, &advanced_settings);
 
 	qdevice_cmap_init(&instance);
 	qdevice_log_init(&instance, force_debug);
 
 	/*
 	 * Daemonize
 	 */
 	if (!foreground) {
 		utils_tty_detach();
 	}
 
 	if ((lock_file = utils_flock(advanced_settings.lock_file, getpid(),
 	    &another_instance_running)) == -1) {
 		if (another_instance_running) {
 			qdevice_log(LOG_ERR, "Another instance is running");
 		} else {
 			qdevice_log_err(LOG_ERR, "Can't aquire lock");
 		}
 
 		exit(1);
 	}
 
 	qdevice_log(LOG_DEBUG, "Initializing votequorum");
 	qdevice_votequorum_init(&instance);
 
 	qdevice_log(LOG_DEBUG, "Initializing local socket");
 	if (qdevice_ipc_init(&instance) != 0) {
 		return (1);
 	}
 
 	qdevice_log(LOG_DEBUG, "Registering qdevice models");
 	qdevice_model_register_all();
 
 	qdevice_log(LOG_DEBUG, "Configuring qdevice");
 	if (qdevice_instance_configure_from_cmap(&instance) != 0) {
 		return (1);
 	}
 
+	qdevice_log(LOG_DEBUG, "Configuring master_wins");
+	if (qdevice_votequorum_master_wins(&instance, (advanced_settings.master_wins ==
+	    QDEVICE_ADVANCED_SETTINGS_MASTER_WINS_FORCE_ON ? 1 : 0)) != 0) {
+		return (1);
+	}
+
 	qdevice_log(LOG_DEBUG, "Getting configuration node list");
 	if (qdevice_cmap_store_config_node_list(&instance) != 0) {
 		return (1);
 	}
 
 	qdevice_log(LOG_DEBUG, "Initializing qdevice model");
 	if (qdevice_model_init(&instance) != 0) {
 		return (1);
 	}
 
 	qdevice_log(LOG_DEBUG, "Initializing cmap tracking");
 	if (qdevice_cmap_add_track(&instance) != 0) {
 		return (1);
 	}
 
 	qdevice_log(LOG_DEBUG, "Waiting for ring id");
 	if (qdevice_votequorum_wait_for_ring_id(&instance) != 0) {
 		return (1);
 	}
 
 	global_instance = &instance;
 	signal_handlers_register();
 
 	qdevice_log(LOG_DEBUG, "Running qdevice model");
 	if (qdevice_model_run(&instance) != 0) {
 		return (1);
 	}
 
 	qdevice_log(LOG_DEBUG, "Removing cmap tracking");
 	if (qdevice_cmap_del_track(&instance) != 0) {
 		return (1);
 	}
 
 	qdevice_log(LOG_DEBUG, "Destorying qdevice model");
 	qdevice_model_destroy(&instance);
 
 	qdevice_ipc_destroy(&instance);
 
 	qdevice_votequorum_destroy(&instance);
 	qdevice_cmap_destroy(&instance);
 	qdevice_log_close(&instance);
 	qdevice_instance_destroy(&instance);
 	qdevice_advanced_settings_destroy(&advanced_settings);
 
 	return (0);
 }
diff --git a/qdevices/qdevice-advanced-settings.c b/qdevices/qdevice-advanced-settings.c
index f0109601..60ee9cc9 100644
--- a/qdevices/qdevice-advanced-settings.c
+++ b/qdevices/qdevice-advanced-settings.c
@@ -1,267 +1,281 @@
 /*
  * Copyright (c) 2015-2016 Red Hat, Inc.
  *
  * All rights reserved.
  *
  * Author: Jan Friesse (jfriesse@redhat.com)
  *
  * This software licensed under BSD license, the text of which follows:
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
  *
  * - Redistributions of source code must retain the above copyright notice,
  *   this list of conditions and the following disclaimer.
  * - Redistributions in binary form must reproduce the above copyright notice,
  *   this list of conditions and the following disclaimer in the documentation
  *   and/or other materials provided with the distribution.
  * - Neither the name of the Red Hat, Inc. nor the names of its
  *   contributors may be used to endorse or promote products derived from this
  *   software without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
 
 #include "dynar.h"
 #include "dynar-getopt-lex.h"
 #include "dynar-str.h"
 #include "qdevice-config.h"
 #include "qnet-config.h"
 #include "qdevice-advanced-settings.h"
 #include "utils.h"
 
 int
 qdevice_advanced_settings_init(struct qdevice_advanced_settings *settings)
 {
 
 	memset(settings, 0, sizeof(*settings));
 	if ((settings->lock_file = strdup(QDEVICE_DEFAULT_LOCK_FILE)) == NULL) {
 		return (-1);
 	}
 	if ((settings->local_socket_file = strdup(QDEVICE_DEFAULT_LOCAL_SOCKET_FILE)) == NULL) {
 		return (-1);
 	}
 	settings->local_socket_backlog = QDEVICE_DEFAULT_LOCAL_SOCKET_BACKLOG;
 	settings->max_cs_try_again = QDEVICE_DEFAULT_MAX_CS_TRY_AGAIN;
 	if ((settings->votequorum_device_name = strdup(QDEVICE_DEFAULT_VOTEQUORUM_DEVICE_NAME)) == NULL) {
 		return (-1);
 	}
 	settings->ipc_max_clients = QDEVICE_DEFAULT_IPC_MAX_CLIENTS;
 	settings->ipc_max_receive_size = QDEVICE_DEFAULT_IPC_MAX_RECEIVE_SIZE;
 	settings->ipc_max_send_size = QDEVICE_DEFAULT_IPC_MAX_SEND_SIZE;
 	if ((settings->net_nss_db_dir = strdup(QDEVICE_NET_DEFAULT_NSS_DB_DIR)) == NULL) {
 		return (-1);
 	}
 	settings->net_initial_msg_receive_size = QDEVICE_NET_DEFAULT_INITIAL_MSG_RECEIVE_SIZE;
 	settings->net_initial_msg_send_size = QDEVICE_NET_DEFAULT_INITIAL_MSG_SEND_SIZE;
 	settings->net_min_msg_send_size = QDEVICE_NET_DEFAULT_MIN_MSG_SEND_SIZE;
 	settings->net_max_msg_receive_size = QDEVICE_NET_DEFAULT_MAX_MSG_RECEIVE_SIZE;
 	settings->net_max_send_buffers = QDEVICE_NET_DEFAULT_MAX_SEND_BUFFERS;
 	if ((settings->net_nss_qnetd_cn = strdup(QDEVICE_NET_DEFAULT_NSS_QNETD_CN)) == NULL) {
 		return (-1);
 	}
 	if ((settings->net_nss_client_cert_nickname =
 	    strdup(QDEVICE_NET_DEFAULT_NSS_CLIENT_CERT_NICKNAME)) == NULL) {
 		return (-1);
 	}
 	settings->net_heartbeat_interval_min = QDEVICE_NET_DEFAULT_HEARTBEAT_INTERVAL_MIN;
 	settings->net_heartbeat_interval_max = QDEVICE_NET_DEFAULT_HEARTBEAT_INTERVAL_MAX;
 	settings->net_min_connect_timeout = QDEVICE_NET_DEFAULT_MIN_CONNECT_TIMEOUT;
 	settings->net_max_connect_timeout = QDEVICE_NET_DEFAULT_MAX_CONNECT_TIMEOUT;
 	settings->net_delay_before_reconnect = QDEVICE_NET_DEFAULT_DELAY_BEFORE_RECONNECT;
 	settings->net_test_algorithm_enabled = QDEVICE_NET_DEFAULT_TEST_ALGORITHM_ENABLED;
 
+	settings->master_wins = QDEVICE_ADVANCED_SETTINGS_MASTER_WINS_MODEL;
+
 	return (0);
 }
 
 void
 qdevice_advanced_settings_destroy(struct qdevice_advanced_settings *settings)
 {
 
 	free(settings->local_socket_file);
 	free(settings->lock_file);
 	free(settings->votequorum_device_name);
 	free(settings->net_nss_db_dir);
 	free(settings->net_nss_qnetd_cn);
 	free(settings->net_nss_client_cert_nickname);
 }
 
 /*
  * 0 - No error
  * -1 - Unknown option
  * -2 - Incorrect value
  */
 int
 qdevice_advanced_settings_set(struct qdevice_advanced_settings *settings,
     const char *option, const char *value)
 {
 	long long int tmpll;
 	char *ep;
 
 	if (strcasecmp(option, "lock_file") == 0) {
 		free(settings->lock_file);
 
 		if ((settings->lock_file = strdup(value)) == NULL) {
 			return (-1);
 		}
 	} else if (strcasecmp(option, "local_socket_file") == 0) {
 		free(settings->local_socket_file);
 
 		if ((settings->local_socket_file = strdup(value)) == NULL) {
 			return (-1);
 		}
 	} else if (strcasecmp(option, "local_socket_backlog") == 0) {
 		tmpll = strtoll(value, &ep, 10);
 		if (tmpll < QDEVICE_MIN_LOCAL_SOCKET_BACKLOG || errno != 0 || *ep != '\0') {
 			return (-2);
 		}
 
 		settings->local_socket_backlog = (int)tmpll;
 	} else if (strcasecmp(option, "max_cs_try_again") == 0) {
 		tmpll = strtoll(value, &ep, 10);
 		if (tmpll < QDEVICE_MIN_MAX_CS_TRY_AGAIN || errno != 0 || *ep != '\0') {
 			return (-2);
 		}
 
 		settings->max_cs_try_again = (int)tmpll;
 	} else if (strcasecmp(option, "votequorum_device_name") == 0) {
 		free(settings->votequorum_device_name);
 
 		if ((settings->votequorum_device_name = strdup(value)) == NULL) {
 			return (-1);
 		}
 	} else if (strcasecmp(option, "ipc_max_clients") == 0) {
 		tmpll = strtoll(value, &ep, 10);
 		if (tmpll < QDEVICE_MIN_IPC_MAX_CLIENTS || errno != 0 || *ep != '\0') {
 			return (-2);
 		}
 
 		settings->ipc_max_clients = (size_t)tmpll;
 	} else if (strcasecmp(option, "ipc_max_receive_size") == 0) {
 		tmpll = strtoll(value, &ep, 10);
 		if (tmpll < QDEVICE_MIN_IPC_RECEIVE_SEND_SIZE || errno != 0 || *ep != '\0') {
 			return (-2);
 		}
 
 		settings->ipc_max_receive_size = (size_t)tmpll;
 	} else if (strcasecmp(option, "ipc_max_send_size") == 0) {
 		tmpll = strtoll(value, &ep, 10);
 		if (tmpll < QDEVICE_MIN_IPC_RECEIVE_SEND_SIZE || errno != 0 || *ep != '\0') {
 			return (-2);
 		}
 
 		settings->ipc_max_send_size = (size_t)tmpll;
 	} else if (strcasecmp(option, "net_nss_db_dir") == 0) {
 		free(settings->net_nss_db_dir);
 
 		if ((settings->net_nss_db_dir = strdup(value)) == NULL) {
 			return (-1);
 		}
 	} else if (strcasecmp(option, "net_initial_msg_receive_size") == 0) {
 		tmpll = strtoll(value, &ep, 10);
 		if (tmpll < QDEVICE_NET_MIN_MSG_RECEIVE_SEND_SIZE || errno != 0 || *ep != '\0') {
 			return (-2);
 		}
 
 		settings->net_initial_msg_receive_size = (size_t)tmpll;
 	} else if (strcasecmp(option, "net_initial_msg_send_size") == 0) {
 		tmpll = strtoll(value, &ep, 10);
 		if (tmpll < QDEVICE_NET_MIN_MSG_RECEIVE_SEND_SIZE || errno != 0 || *ep != '\0') {
 			return (-2);
 		}
 
 		settings->net_initial_msg_send_size = (size_t)tmpll;
 	} else if (strcasecmp(option, "net_min_msg_send_size") == 0) {
 		tmpll = strtoll(value, &ep, 10);
 		if (tmpll < QDEVICE_NET_MIN_MSG_RECEIVE_SEND_SIZE || errno != 0 || *ep != '\0') {
 			return (-2);
 		}
 
 		settings->net_min_msg_send_size = (size_t)tmpll;
 	} else if (strcasecmp(option, "net_max_msg_receive_size") == 0) {
 		tmpll = strtoll(value, &ep, 10);
 		if (tmpll < QDEVICE_NET_MIN_MSG_RECEIVE_SEND_SIZE || errno != 0 || *ep != '\0') {
 			return (-2);
 		}
 
 		settings->net_max_msg_receive_size = (size_t)tmpll;
 	} else if (strcasecmp(option, "net_max_send_buffers") == 0) {
 		tmpll = strtoll(value, &ep, 10);
 		if (tmpll < QDEVICE_NET_MIN_MAX_SEND_BUFFERS || errno != 0 || *ep != '\0') {
 			return (-2);
 		}
 
 		settings->net_max_send_buffers = (size_t)tmpll;
 	} else if (strcasecmp(option, "net_nss_qnetd_cn") == 0) {
 		free(settings->net_nss_qnetd_cn);
 
 		if ((settings->net_nss_qnetd_cn = strdup(value)) == NULL) {
 			return (-1);
 		}
 	} else if (strcasecmp(option, "net_nss_client_cert_nickname") == 0) {
 		free(settings->net_nss_client_cert_nickname);
 
 		if ((settings->net_nss_client_cert_nickname = strdup(value)) == NULL) {
 			return (-1);
 		}
 	} else if (strcasecmp(option, "net_heartbeat_interval_min") == 0) {
 		tmpll = strtoll(value, &ep, 10);
 		if (tmpll < QDEVICE_NET_MIN_HEARTBEAT_INTERVAL || errno != 0 || *ep != '\0') {
 			return (-2);
 		}
 
 		settings->net_heartbeat_interval_min = (uint32_t)tmpll;
 	} else if (strcasecmp(option, "net_heartbeat_interval_max") == 0) {
 		tmpll = strtoll(value, &ep, 10);
 		if (tmpll < QDEVICE_NET_MIN_HEARTBEAT_INTERVAL || errno != 0 || *ep != '\0') {
 			return (-2);
 		}
 
 		settings->net_heartbeat_interval_max = (uint32_t)tmpll;
 	} else if (strcasecmp(option, "net_min_connect_timeout") == 0) {
 		tmpll = strtoll(value, &ep, 10);
 		if (tmpll < QDEVICE_NET_MIN_CONNECT_TIMEOUT || errno != 0 || *ep != '\0') {
 			return (-2);
 		}
 
 		settings->net_min_connect_timeout = (uint32_t)tmpll;
 	} else if (strcasecmp(option, "net_max_connect_timeout") == 0) {
 		tmpll = strtoll(value, &ep, 10);
 		if (tmpll < QDEVICE_NET_MIN_CONNECT_TIMEOUT || errno != 0 || *ep != '\0') {
 			return (-2);
 		}
 
 		settings->net_max_connect_timeout = (uint32_t)tmpll;
 	} else if (strcasecmp(option, "net_delay_before_reconnect") == 0) {
 		tmpll = strtoll(value, &ep, 10);
 		if (tmpll < QDEVICE_NET_MIN_DELAY_BEFORE_RECONNECT || errno != 0 || *ep != '\0') {
 			return (-2);
 		}
 
 		settings->net_delay_before_reconnect = (int)tmpll;
 	} else if (strcasecmp(option, "net_test_algorithm_enabled") == 0) {
 		if ((tmpll = utils_parse_bool_str(value)) == -1) {
 			return (-2);
 		}
 
 		settings->net_test_algorithm_enabled = (uint8_t)tmpll;
+	} else if (strcasecmp(option, "master_wins") == 0) {
+		tmpll = utils_parse_bool_str(value);
+
+		if (tmpll == 0) {
+			settings->master_wins = QDEVICE_ADVANCED_SETTINGS_MASTER_WINS_FORCE_OFF;
+		} else if (tmpll == 1) {
+			settings->master_wins = QDEVICE_ADVANCED_SETTINGS_MASTER_WINS_FORCE_ON;
+		} else if (strcasecmp(value, "model") == 0) {
+			settings->master_wins = QDEVICE_ADVANCED_SETTINGS_MASTER_WINS_MODEL;
+		} else {
+			return (-2);
+		}
 	} else {
 		return (-1);
 	}
 
 	return (0);
 }
diff --git a/qdevices/qdevice-advanced-settings.h b/qdevices/qdevice-advanced-settings.h
index f9f5d2ce..bcdbb7bb 100644
--- a/qdevices/qdevice-advanced-settings.h
+++ b/qdevices/qdevice-advanced-settings.h
@@ -1,82 +1,89 @@
 /*
  * Copyright (c) 2015-2016 Red Hat, Inc.
  *
  * All rights reserved.
  *
  * Author: Jan Friesse (jfriesse@redhat.com)
  *
  * This software licensed under BSD license, the text of which follows:
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
  *
  * - Redistributions of source code must retain the above copyright notice,
  *   this list of conditions and the following disclaimer.
  * - Redistributions in binary form must reproduce the above copyright notice,
  *   this list of conditions and the following disclaimer in the documentation
  *   and/or other materials provided with the distribution.
  * - Neither the name of the Red Hat, Inc. nor the names of its
  *   contributors may be used to endorse or promote products derived from this
  *   software without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #ifndef _QDEVICE_ADVANCED_SETTINGS_H_
 #define _QDEVICE_ADVANCED_SETTINGS_H_
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+enum qdevice_advanced_settings_master_wins {
+	QDEVICE_ADVANCED_SETTINGS_MASTER_WINS_MODEL,
+	QDEVICE_ADVANCED_SETTINGS_MASTER_WINS_FORCE_ON,
+	QDEVICE_ADVANCED_SETTINGS_MASTER_WINS_FORCE_OFF,
+};
+
 struct qdevice_advanced_settings {
 	char *lock_file;
 	char *local_socket_file;
 	int local_socket_backlog;
 	int max_cs_try_again;
 	char *votequorum_device_name;
 	size_t ipc_max_clients;
 	size_t ipc_max_send_size;
 	size_t ipc_max_receive_size;
+	enum qdevice_advanced_settings_master_wins master_wins;
 
 	/*
 	 * Related to model NET
 	 */
 	char *net_nss_db_dir;
 	size_t net_initial_msg_receive_size;
 	size_t net_initial_msg_send_size;
 	size_t net_min_msg_send_size;
 	size_t net_max_msg_receive_size;
 	size_t net_max_send_buffers;
 	char *net_nss_qnetd_cn;
 	char *net_nss_client_cert_nickname;
 	uint32_t net_heartbeat_interval_min;
 	uint32_t net_heartbeat_interval_max;
 	uint32_t net_min_connect_timeout;
 	uint32_t net_max_connect_timeout;
 	int net_delay_before_reconnect;
 	uint8_t net_test_algorithm_enabled;
 };
 
 extern int		qdevice_advanced_settings_init(struct qdevice_advanced_settings *settings);
 
 extern int		qdevice_advanced_settings_set(struct qdevice_advanced_settings *settings,
     const char *option, const char *value);
 
 extern void		qdevice_advanced_settings_destroy(struct qdevice_advanced_settings *settings);
 
 #ifdef __cplusplus
 }
 #endif
 
 #endif /* _QDEVICE_ADVANCED_SETTINGS_H_ */
diff --git a/qdevices/qdevice-votequorum.c b/qdevices/qdevice-votequorum.c
index dd4350b6..2ea550c2 100644
--- a/qdevices/qdevice-votequorum.c
+++ b/qdevices/qdevice-votequorum.c
@@ -1,301 +1,337 @@
 /*
  * Copyright (c) 2015-2016 Red Hat, Inc.
  *
  * All rights reserved.
  *
  * Author: Jan Friesse (jfriesse@redhat.com)
  *
  * This software licensed under BSD license, the text of which follows:
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
  *
  * - Redistributions of source code must retain the above copyright notice,
  *   this list of conditions and the following disclaimer.
  * - Redistributions in binary form must reproduce the above copyright notice,
  *   this list of conditions and the following disclaimer in the documentation
  *   and/or other materials provided with the distribution.
  * - Neither the name of the Red Hat, Inc. nor the names of its
  *   contributors may be used to endorse or promote products derived from this
  *   software without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #include <poll.h>
 
 #include "qdevice-config.h"
 #include "qdevice-log.h"
 #include "qdevice-votequorum.h"
 #include "qdevice-model.h"
 #include "utils.h"
 
 static void
 qdevice_votequorum_quorum_notify_callback(votequorum_handle_t votequorum_handle,
     uint64_t context, uint32_t quorate,
     uint32_t node_list_entries, votequorum_node_t node_list[])
 {
 	struct qdevice_instance *instance;
 	uint32_t u32;
 
 	if (votequorum_context_get(votequorum_handle, (void **)&instance) != CS_OK) {
 		qdevice_log(LOG_CRIT, "Fatal error. Can't get votequorum context");
 		exit(1);
 	}
 
 	instance->sync_in_progress = 0;
 
 	qdevice_log(LOG_DEBUG, "Votequorum quorum notify callback:");
 	qdevice_log(LOG_DEBUG, "  Quorate = %u", quorate);
 
 	qdevice_log(LOG_DEBUG, "  Node list (size = %"PRIu32"):", node_list_entries);
 	for (u32 = 0; u32 < node_list_entries; u32++) {
 		qdevice_log(LOG_DEBUG, "    %"PRIu32" nodeid = "UTILS_PRI_NODE_ID", state = %"PRIu32,
 		    u32, node_list[u32].nodeid, node_list[u32].state);
 	}
 
 	if (qdevice_model_votequorum_quorum_notify(instance, quorate, node_list_entries,
 	    node_list) != 0) {
 		qdevice_log(LOG_DEBUG, "qdevice_model_votequorum_quorum_notify returned error -> exit");
 		exit(2);
 	}
 
 	instance->vq_quorum_quorate = quorate;
 	instance->vq_quorum_node_list_entries = node_list_entries;
 
 	free(instance->vq_quorum_node_list);
 	instance->vq_quorum_node_list = malloc(sizeof(*node_list) * node_list_entries);
 	if (instance->vq_quorum_node_list == NULL) {
 		qdevice_log(LOG_CRIT, "Can't alloc votequorum node list memory");
 		exit(1);
 	}
 	memcpy(instance->vq_quorum_node_list, node_list, sizeof(*node_list) * node_list_entries);
 }
 
 static void
 qdevice_votequorum_node_list_notify_callback(votequorum_handle_t votequorum_handle,
     uint64_t context, votequorum_ring_id_t votequorum_ring_id,
     uint32_t node_list_entries, uint32_t node_list[])
 {
 	struct qdevice_instance *instance;
 	uint32_t u32;
 
 	if (votequorum_context_get(votequorum_handle, (void **)&instance) != CS_OK) {
 		qdevice_log(LOG_CRIT, "Fatal error. Can't get votequorum context");
 		exit(1);
 	}
 
 	instance->sync_in_progress = 1;
 
 	qdevice_log(LOG_DEBUG, "Votequorum nodelist notify callback:");
 	qdevice_log(LOG_DEBUG, "  Ring_id = ("UTILS_PRI_RING_ID")",
 	    votequorum_ring_id.nodeid, votequorum_ring_id.seq);
 
 	qdevice_log(LOG_DEBUG, "  Node list (size = %"PRIu32"):", node_list_entries);
 	for (u32 = 0; u32 < node_list_entries; u32++) {
 		qdevice_log(LOG_DEBUG, "    %"PRIu32" nodeid = "UTILS_PRI_NODE_ID,
 		    u32, node_list[u32]);
 	}
 
 	if (qdevice_model_votequorum_node_list_notify(instance, votequorum_ring_id, node_list_entries,
 	    node_list) != 0) {
 		qdevice_log(LOG_DEBUG, "qdevice_votequorum_node_list_notify_callback returned error -> exit");
 		exit(2);
 	}
 
 	instance->vq_node_list_ring_id_set = 1;
 	memcpy(&instance->vq_node_list_ring_id, &votequorum_ring_id, sizeof(votequorum_ring_id));
 	instance->vq_node_list_entries = node_list_entries;
 	free(instance->vq_node_list);
 	instance->vq_node_list = malloc(sizeof(*node_list) * node_list_entries);
 	if (instance->vq_node_list == NULL) {
 		qdevice_log(LOG_CRIT, "Can't alloc votequorum node list memory");
 		exit(1);
 	}
 	memcpy(instance->vq_node_list, node_list, sizeof(*node_list) * node_list_entries);
 }
 
 static void
 qdevice_votequorum_expected_votes_notify_callback(votequorum_handle_t votequorum_handle,
     uint64_t context, uint32_t expected_votes)
 {
 	struct qdevice_instance *instance;
 
 	if (votequorum_context_get(votequorum_handle, (void **)&instance) != CS_OK) {
 		qdevice_log(LOG_CRIT, "Fatal error. Can't get votequorum context");
 		exit(1);
 	}
 
 	qdevice_log(LOG_DEBUG, "Votequorum expected_votes notify callback:");
 	qdevice_log(LOG_DEBUG, "  Expected_votes: "UTILS_PRI_EXPECTED_VOTES, expected_votes);
 
 	if (qdevice_model_votequorum_expected_votes_notify(instance, expected_votes) != 0) {
 		qdevice_log(LOG_DEBUG, "qdevice_votequorum_expected_votes_notify_callback returned error -> exit");
 		exit(2);
 	}
 
 	instance->vq_expected_votes = expected_votes;
 }
 
 void
 qdevice_votequorum_init(struct qdevice_instance *instance)
 {
 	votequorum_callbacks_t votequorum_callbacks;
 	votequorum_handle_t votequorum_handle;
 	cs_error_t res;
 	int no_retries;
 	struct votequorum_info vq_info;
 
 	memset(&votequorum_callbacks, 0, sizeof(votequorum_callbacks));
 
 	votequorum_callbacks.votequorum_quorum_notify_fn =
 	    qdevice_votequorum_quorum_notify_callback;
 
 	votequorum_callbacks.votequorum_nodelist_notify_fn =
 	    qdevice_votequorum_node_list_notify_callback;
 
 	votequorum_callbacks.votequorum_expectedvotes_notify_fn =
 	    qdevice_votequorum_expected_votes_notify_callback;
 
 	no_retries = 0;
 
 	while ((res = votequorum_initialize(&votequorum_handle,
 	    &votequorum_callbacks)) == CS_ERR_TRY_AGAIN &&
 	    no_retries++ < instance->advanced_settings->max_cs_try_again) {
 		(void)poll(NULL, 0, 1000);
 	}
 
 	if (res != CS_OK) {
 		qdevice_log(LOG_CRIT, "Failed to initialize the votequorum API. Error %s", cs_strerror(res));
 		exit(1);
 	}
 
 	if ((res = votequorum_qdevice_register(votequorum_handle,
 	    instance->advanced_settings->votequorum_device_name)) != CS_OK) {
 		qdevice_log(LOG_CRIT, "Can't register votequorum device. Error %s", cs_strerror(res));
 		exit(1);
 	}
 
 	if ((res = votequorum_context_set(votequorum_handle, (void *)instance)) != CS_OK) {
 		qdevice_log(LOG_CRIT, "Can't set votequorum context. Error %s", cs_strerror(res));
 		exit(1);
 	}
 
 	if ((res = votequorum_getinfo(votequorum_handle, VOTEQUORUM_QDEVICE_NODEID,
 	    &vq_info)) != CS_OK) {
 		qdevice_log(LOG_CRIT, "Can't get votequorum information. Error %s", cs_strerror(res));
 		exit(1);
 	}
 	instance->vq_expected_votes = vq_info.node_expected_votes;
 
 	instance->votequorum_handle = votequorum_handle;
 
 	votequorum_fd_get(votequorum_handle, &instance->votequorum_poll_fd);
 
 	if ((res = votequorum_trackstart(instance->votequorum_handle, 0,
 	    CS_TRACK_CHANGES)) != CS_OK) {
 		qdevice_log(LOG_CRIT, "Can't start tracking votequorum changes. Error %s",
 		    cs_strerror(res));
 		exit(1);
 	}
 }
 
 void
 qdevice_votequorum_destroy(struct qdevice_instance *instance)
 {
 	cs_error_t res;
 
 	free(instance->vq_quorum_node_list); instance->vq_quorum_node_list = NULL;
 	free(instance->vq_node_list); instance->vq_node_list = NULL;
 
 	res = votequorum_trackstop(instance->votequorum_handle);
 	if (res != CS_OK) {
 		qdevice_log(LOG_WARNING, "Can't start tracking votequorum changes. Error %s",
 		    cs_strerror(res));
 	}
 
 	res = votequorum_qdevice_unregister(instance->votequorum_handle,
 		instance->advanced_settings->votequorum_device_name);
 
 	if (res != CS_OK) {
 		qdevice_log(LOG_WARNING, "Unable to unregister votequorum device. Error %s", cs_strerror(res));
 	}
 
 	res = votequorum_finalize(instance->votequorum_handle);
 	if (res != CS_OK) {
 		qdevice_log(LOG_WARNING, "Unable to finalize votequorum. Error %s", cs_strerror(res));
 	}
 }
 
 int
 qdevice_votequorum_wait_for_ring_id(struct qdevice_instance *instance)
 {
 	int no_retries;
 
 	no_retries = 0;
 
 	while (qdevice_votequorum_dispatch(instance) != -1 &&
 	    no_retries++ < instance->advanced_settings->max_cs_try_again &&
 	    !instance->vq_node_list_ring_id_set) {
 		(void)poll(NULL, 0, 1000);
 	}
 
 	if (!instance->vq_node_list_ring_id_set) {
 		qdevice_log(LOG_CRIT, "Can't get initial votequorum membership information.");
 		return (-1);
 	}
 
 	return (0);
 }
 
 int
 qdevice_votequorum_dispatch(struct qdevice_instance *instance)
 {
 	cs_error_t res;
 
 	res = votequorum_dispatch(instance->votequorum_handle, CS_DISPATCH_ALL);
 
 	if (res != CS_OK && res != CS_ERR_TRY_AGAIN) {
 		qdevice_log(LOG_ERR, "Can't dispatch votequorum messages");
 
 		return (-1);
 	}
 
 	return (0);
 }
 
 int
 qdevice_votequorum_poll(struct qdevice_instance *instance, int cast_vote)
 {
 	cs_error_t res;
 
 	instance->vq_last_poll = time(NULL);
 	instance->vq_last_poll_cast_vote = cast_vote;
 
 	res = votequorum_qdevice_poll(instance->votequorum_handle,
 	    instance->advanced_settings->votequorum_device_name, cast_vote,
 	    instance->vq_node_list_ring_id);
 
 	if (res != CS_OK && res != CS_ERR_TRY_AGAIN) {
 		if (res == CS_ERR_MESSAGE_ERROR) {
 			qdevice_log(LOG_INFO, "qdevice_votequorum_poll called with old ring id");
 		} else {
 			qdevice_log(LOG_CRIT, "Can't call votequorum_qdevice_poll. Error %s",
 			    cs_strerror(res));
 
 			return (-1);
 		}
 	}
 
 	return (0);
 }
+
+int
+qdevice_votequorum_master_wins(struct qdevice_instance *instance, int allow)
+{
+	cs_error_t res;
+	int final_allow;
+
+	final_allow = allow;
+
+	if (instance->advanced_settings->master_wins ==
+	    QDEVICE_ADVANCED_SETTINGS_MASTER_WINS_FORCE_OFF && allow) {
+		qdevice_log(LOG_WARNING, "Allow of master wins is requested, but user forcibly "
+		    "disallowed it. Keeping master wins disallowed.");
+
+		final_allow = 0;
+	}
+
+	if (instance->advanced_settings->master_wins ==
+	    QDEVICE_ADVANCED_SETTINGS_MASTER_WINS_FORCE_ON && !allow) {
+		qdevice_log(LOG_WARNING, "Disallow of master wins is requested, but user forcibly "
+		    "allowed it. Keeping master wins allowed.");
+
+		final_allow = 1;
+	}
+
+	res = votequorum_qdevice_master_wins(instance->votequorum_handle,
+	    instance->advanced_settings->votequorum_device_name, final_allow);
+
+	if (res != CS_OK) {
+		qdevice_log(LOG_CRIT, "Can't set master wins. Error %s", cs_strerror(res));
+
+		return (-1);
+	}
+
+	return (0);
+}
diff --git a/qdevices/qdevice-votequorum.h b/qdevices/qdevice-votequorum.h
index c444315b..5230d22c 100644
--- a/qdevices/qdevice-votequorum.h
+++ b/qdevices/qdevice-votequorum.h
@@ -1,62 +1,65 @@
 /*
  * Copyright (c) 2015-2016 Red Hat, Inc.
  *
  * All rights reserved.
  *
  * Author: Jan Friesse (jfriesse@redhat.com)
  *
  * This software licensed under BSD license, the text of which follows:
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
  *
  * - Redistributions of source code must retain the above copyright notice,
  *   this list of conditions and the following disclaimer.
  * - Redistributions in binary form must reproduce the above copyright notice,
  *   this list of conditions and the following disclaimer in the documentation
  *   and/or other materials provided with the distribution.
  * - Neither the name of the Red Hat, Inc. nor the names of its
  *   contributors may be used to endorse or promote products derived from this
  *   software without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #ifndef _QDEVICE_VOTEQUORUM_H_
 #define _QDEVICE_VOTEQUORUM_H_
 
 #include <votequorum.h>
 
 #include "qdevice-instance.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 extern void			qdevice_votequorum_init(struct qdevice_instance *instance);
 
 extern void			qdevice_votequorum_destroy(struct qdevice_instance *instance);
 
 extern int			qdevice_votequorum_dispatch(struct qdevice_instance *instance);
 
 extern int			qdevice_votequorum_poll(struct qdevice_instance *instance,
     int cast_vote);
 
 extern int			qdevice_votequorum_wait_for_ring_id(
     struct qdevice_instance *instance);
 
+extern int			qdevice_votequorum_master_wins(struct qdevice_instance *instance,
+    int allow);
+
 #ifdef __cplusplus
 }
 #endif
 
 #endif /* _QDEVICE_VOTEQUORUM_H_ */