Blame SOURCES/0015-RH-add-mpathconf.patch

b7ef27
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
b7ef27
From: Benjamin Marzinski <bmarzins@redhat.com>
b7ef27
Date: Thu, 16 Oct 2014 15:49:01 -0500
b7ef27
Subject: [PATCH] RH: add mpathconf
b7ef27
b7ef27
mpathconf is a program (largely based on lvmcomf) to help users
b7ef27
configure /etc/multipath.conf and enable or disable multipathing.  It
b7ef27
has a couple of built-in options that can be set directly from the
b7ef27
command line.  But, mostly it is used to get a multipath.conf file
b7ef27
with the OS defaults, and to enable and disable multipathing via
b7ef27
a single command.
b7ef27
b7ef27
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
b7ef27
---
b7ef27
 libmultipath/config.c |   2 +
b7ef27
 multipath/Makefile    |   5 +
b6d9ac
 multipath/mpathconf   | 555 ++++++++++++++++++++++++++++++++++++++++++
b6d9ac
 multipath/mpathconf.8 | 135 ++++++++++
b6d9ac
 4 files changed, 697 insertions(+)
b7ef27
 create mode 100644 multipath/mpathconf
b7ef27
 create mode 100644 multipath/mpathconf.8
b7ef27
b7ef27
diff --git a/libmultipath/config.c b/libmultipath/config.c
49190a
index b36778b0..26f8e050 100644
b7ef27
--- a/libmultipath/config.c
b7ef27
+++ b/libmultipath/config.c
49190a
@@ -781,6 +781,8 @@ load_config (char * file)
b7ef27
 		factorize_hwtable(conf->hwtable, builtin_hwtable_size, file);
b7ef27
 	} else {
b7ef27
 		condlog(0, "/etc/multipath.conf does not exist, blacklisting all devices.");
b7ef27
+		condlog(0, "You can run \"/sbin/mpathconf --enable\" to create");
b7ef27
+		condlog(0, "/etc/multipath.conf. See man mpathconf(8) for more details");
b7ef27
 		if (conf->blist_devnode == NULL) {
b7ef27
 			conf->blist_devnode = vector_alloc();
b7ef27
 			if (!conf->blist_devnode) {
b7ef27
diff --git a/multipath/Makefile b/multipath/Makefile
b6d9ac
index b9bbb3cf..e720c7f6 100644
b7ef27
--- a/multipath/Makefile
b7ef27
+++ b/multipath/Makefile
b7ef27
@@ -18,10 +18,12 @@ $(EXEC): $(OBJS) $(multipathdir)/libmultipath.so $(mpathcmddir)/libmpathcmd.so
b7ef27
 	$(CC) $(CFLAGS) $(OBJS) -o $(EXEC) $(LDFLAGS) $(LIBDEPS)
b7ef27
 	$(GZIP) $(EXEC).8 > $(EXEC).8.gz
b7ef27
 	$(GZIP) $(EXEC).conf.5 > $(EXEC).conf.5.gz
b7ef27
+	$(GZIP) mpathconf.8 > mpathconf.8.gz
b7ef27
 
b7ef27
 install:
b7ef27
 	$(INSTALL_PROGRAM) -d $(DESTDIR)$(bindir)
b7ef27
 	$(INSTALL_PROGRAM) -m 755 $(EXEC) $(DESTDIR)$(bindir)/
b7ef27
+	$(INSTALL_PROGRAM) -m 755 mpathconf $(DESTDIR)$(bindir)/
b7ef27
 	$(INSTALL_PROGRAM) -d $(DESTDIR)$(udevrulesdir)
b7ef27
 	$(INSTALL_PROGRAM) -m 644 11-dm-mpath.rules $(DESTDIR)$(udevrulesdir)
b7ef27
 	$(INSTALL_PROGRAM) -m 644 $(EXEC).rules $(DESTDIR)$(libudevdir)/rules.d/62-multipath.rules
b7ef27
@@ -29,13 +31,16 @@ install:
b7ef27
 	$(INSTALL_PROGRAM) -m 644 $(EXEC).8.gz $(DESTDIR)$(man8dir)
b7ef27
 	$(INSTALL_PROGRAM) -d $(DESTDIR)$(man5dir)
b7ef27
 	$(INSTALL_PROGRAM) -m 644 $(EXEC).conf.5.gz $(DESTDIR)$(man5dir)
b7ef27
+	$(INSTALL_PROGRAM) -m 644 mpathconf.8.gz $(DESTDIR)$(man8dir)
b7ef27
 
b7ef27
 uninstall:
b7ef27
 	$(RM) $(DESTDIR)$(bindir)/$(EXEC)
b7ef27
 	$(RM) $(DESTDIR)$(udevrulesdir)/11-dm-mpath.rules
b7ef27
 	$(RM) $(DESTDIR)$(libudevdir)/rules.d/62-multipath.rules
b7ef27
+	$(RM) $(DESTDIR)$(bindir)/mpathconf
b7ef27
 	$(RM) $(DESTDIR)$(man8dir)/$(EXEC).8.gz
b7ef27
 	$(RM) $(DESTDIR)$(man5dir)/$(EXEC).conf.5.gz
b7ef27
+	$(RM) $(DESTDIR)$(man8dir)/mpathconf.8.gz
b7ef27
 
b7ef27
 clean: dep_clean
b7ef27
 	$(RM) core *.o $(EXEC) *.gz
b7ef27
diff --git a/multipath/mpathconf b/multipath/mpathconf
b7ef27
new file mode 100644
b6d9ac
index 00000000..f34003c9
b7ef27
--- /dev/null
b7ef27
+++ b/multipath/mpathconf
b6d9ac
@@ -0,0 +1,555 @@
b7ef27
+#!/bin/bash
b7ef27
+#
b7ef27
+# Copyright (C) 2010 Red Hat, Inc. All rights reserved.
b7ef27
+#
b7ef27
+# This file is part of the device-mapper-multipath package.
b7ef27
+#
b7ef27
+# This copyrighted material is made available to anyone wishing to use,
b7ef27
+# modify, copy, or redistribute it subject to the terms and conditions
b7ef27
+# of the GNU General Public License v.2.
b7ef27
+#
b7ef27
+# You should have received a copy of the GNU General Public License
b7ef27
+# along with this program; if not, write to the Free Software Foundation,
b7ef27
+# Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
b7ef27
+
b7ef27
+#
b7ef27
+# Simple editting of /etc/multipath.conf
b7ef27
+# This program was largely ripped off from lvmconf
b7ef27
+#
b7ef27
+
b6d9ac
+unset ENABLE FIND FRIENDLY PROPERTY FOREIGN MODULE MULTIPATHD HAVE_DISABLE HAVE_WWID_DISABLE HAVE_FIND HAVE_BLACKLIST HAVE_EXCEPTIONS HAVE_DEFAULTS HAVE_FRIENDLY HAVE_PROPERTY HAVE_FOREIGN HAVE_MULTIPATHD HAVE_MODULE HAVE_OUTFILE SHOW_STATUS CHANGED_CONFIG WWID_LIST
b7ef27
+
b7ef27
+DEFAULT_CONFIG="# device-mapper-multipath configuration file
b7ef27
+
b7ef27
+# For a complete list of the default configuration values, run either:
b7ef27
+# # multipath -t
b7ef27
+# or
b7ef27
+# # multipathd show config
b7ef27
+
b7ef27
+# For a list of configuration options with descriptions, see the
b7ef27
+# multipath.conf man page.
b7ef27
+
b7ef27
+defaults {
b7ef27
+	user_friendly_names yes
b7ef27
+	find_multipaths yes
b6d9ac
+	enable_foreign \"^$\"
b7ef27
+}
b7ef27
+
b7ef27
+blacklist_exceptions {
b7ef27
+        property \"(SCSI_IDENT_|ID_WWN)\"
b7ef27
+}"
b7ef27
+
b7ef27
+CONFIGFILE="/etc/multipath.conf"
b7ef27
+OUTPUTFILE="/etc/multipath.conf"
b7ef27
+MULTIPATHDIR="/etc/multipath"
b7ef27
+TMPFILE="/etc/multipath/.multipath.conf.tmp"
b7ef27
+WWIDS=0
b7ef27
+
b7ef27
+function usage
b7ef27
+{
b7ef27
+	echo "usage: $0 <command>"
b7ef27
+	echo ""
b7ef27
+	echo "Commands:"
b7ef27
+	echo "Enable: --enable "
b7ef27
+	echo "Disable: --disable"
b7ef27
+	echo "Only allow certain wwids (instead of enable): --allow <WWID>"
b7ef27
+	echo "Set user_friendly_names (Default y): --user_friendly_names <y|n>"
b7ef27
+	echo "Set find_multipaths (Default y): --find_multipaths <y|n>"
b6d9ac
+	echo "Set default property blacklist (Default y): --property_blacklist <y|n>"
b6d9ac
+	echo "Set enable_foreign to show foreign devices (Default n): --enable_foreign <y|n>"
b7ef27
+	echo "Load the dm-multipath modules on enable (Default y): --with_module <y|n>"
b7ef27
+	echo "start/stop/reload multipathd (Default n): --with_multipathd <y|n>"
b7ef27
+	echo "select output file (Default /etc/multipath.conf): --outfile <FILE>"
b7ef27
+	echo ""
b7ef27
+}
b7ef27
+
b7ef27
+function add_wwid
b7ef27
+{
b7ef27
+	INDEX=0
b7ef27
+	while [ "$INDEX" -lt "$WWIDS" ] ; do
b7ef27
+		if [ "$1" = "${WWID_LIST[$INDEX]}" ] ; then
b7ef27
+			return
b7ef27
+		fi
b7ef27
+		((INDEX++))
b7ef27
+	done
b7ef27
+	WWID_LIST[$WWIDS]="$1"
b7ef27
+	((WWIDS++))
b7ef27
+}
b7ef27
+
b7ef27
+function get_dm_deps
b7ef27
+{
b7ef27
+	shift 3
b7ef27
+	while [ -n "$1" -a -n "$2" ]; do
b7ef27
+		MAJOR=$(echo $1 | tr -d '(,')
b7ef27
+		MINOR=$(echo $2 | tr -d ')')
b7ef27
+		UUID=`dmsetup info -c --noheadings -o uuid -j $MAJOR -m $MINOR  2> /dev/null`
b7ef27
+		if [ -n "$UUID" ] ; then
b7ef27
+			set_dm_wwid $UUID
b7ef27
+		fi
b7ef27
+		shift 2
b7ef27
+	done
b7ef27
+}
b7ef27
+
b7ef27
+function set_dm_wwid
b7ef27
+{
b7ef27
+	if [[ "$1" =~ ^part[[:digit:]]+-mpath- ]] ; then
b7ef27
+		add_wwid "${1##part*-mpath-}"
b7ef27
+	elif [[ "$1" =~ ^mpath- ]] ; then
b7ef27
+		add_wwid "${1##mpath-}"
b7ef27
+	else
b7ef27
+		get_dm_deps `dmsetup deps -u $1`
b7ef27
+	fi
b7ef27
+}
b7ef27
+
b7ef27
+function set_wwid
b7ef27
+{
b7ef27
+	UUID=""
b7ef27
+	if [[ "$1" =~ ^[[:digit:]]+:[[:digit:]]+$ ]] ; then
b7ef27
+		MAJOR=${1%%:*}
b7ef27
+		MINOR=${1##*:}
b7ef27
+		UUID=`dmsetup info -c --noheadings -o uuid -j $MAJOR -m $MINOR  2> /dev/null`
b7ef27
+	else
b7ef27
+		UUID=`dmsetup info -c --noheadings -o uuid $1 2> /dev/null`
b7ef27
+	fi
b7ef27
+	if [ -n "$UUID" ] ; then
b7ef27
+		set_dm_wwid $UUID
b7ef27
+	else
b7ef27
+		add_wwid "$1"
b7ef27
+	fi
b7ef27
+}
b7ef27
+
b7ef27
+function parse_args
b7ef27
+{
b7ef27
+	while [ -n "$1" ]; do
b7ef27
+		case $1 in
b7ef27
+			--enable)
b7ef27
+				ENABLE=1
b7ef27
+				shift
b7ef27
+				;;
b7ef27
+			--disable)
b7ef27
+				ENABLE=0
b7ef27
+				shift
b7ef27
+				;;
b7ef27
+			--allow)
b7ef27
+				ENABLE=2
b7ef27
+				if [ -n "$2" ]; then
b7ef27
+					set_wwid $2
b7ef27
+					shift 2
b7ef27
+				else
b7ef27
+					usage
b7ef27
+					exit 1
b7ef27
+				fi
b7ef27
+				;;
b7ef27
+			--user_friendly_names)
b7ef27
+				if [ -n "$2" ]; then
b7ef27
+					FRIENDLY=$2
b7ef27
+					shift 2
b7ef27
+				else
b7ef27
+					usage
b7ef27
+					exit 1
b7ef27
+				fi
b7ef27
+				;;
b7ef27
+			--find_multipaths)
b7ef27
+				if [ -n "$2" ]; then
b7ef27
+					FIND=$2
b7ef27
+					shift 2
b7ef27
+				else
b7ef27
+					usage
b7ef27
+					exit 1
b7ef27
+				fi
b7ef27
+				;;
b6d9ac
+			--property_blacklist)
b6d9ac
+				if [ -n "$2" ]; then
b6d9ac
+					PROPERTY=$2
b6d9ac
+					shift 2
b6d9ac
+				else
b6d9ac
+					usage
b6d9ac
+					exit 1
b6d9ac
+				fi
b6d9ac
+				;;
b6d9ac
+			--enable_foreign)
b6d9ac
+				if [ -n "$2" ]; then
b6d9ac
+					FOREIGN=$2
b6d9ac
+					shift 2
b6d9ac
+				else
b6d9ac
+					usage
b6d9ac
+					exit 1
b6d9ac
+				fi
b6d9ac
+				;;
b7ef27
+			--with_module)
b7ef27
+				if [ -n "$2" ]; then
b7ef27
+					MODULE=$2
b7ef27
+					shift 2
b7ef27
+				else
b7ef27
+					usage
b7ef27
+					exit 1
b7ef27
+				fi
b7ef27
+				;;
b7ef27
+			--with_multipathd)
b7ef27
+				if [ -n "$2" ]; then
b7ef27
+					MULTIPATHD=$2
b7ef27
+					shift 2
b7ef27
+				else
b7ef27
+					usage
b7ef27
+					exit 1
b7ef27
+				fi
b7ef27
+				;;
b7ef27
+			--outfile)
b7ef27
+				if [ -n "$2" ]; then
b7ef27
+					OUTPUTFILE=$2
b7ef27
+					HAVE_OUTFILE=1
b7ef27
+					shift 2
b7ef27
+				else
b7ef27
+					usage
b7ef27
+					exit 1
b7ef27
+				fi
b7ef27
+				;;
b7ef27
+			*)
b7ef27
+				usage
b7ef27
+				exit
b7ef27
+		esac
b7ef27
+	done
b7ef27
+}
b7ef27
+
b7ef27
+function validate_args
b7ef27
+{
b6d9ac
+	if [ "$ENABLE" = "0" ] && [ -n "$FRIENDLY" -o -n "$FIND" -o -n "$PROPERTY" -o -n "$MODULE" ]; then
b7ef27
+		echo "ignoring extra parameters on disable"
b7ef27
+		FRIENDLY=""
b7ef27
+		FIND=""
b6d9ac
+		PROPERTY=""
b7ef27
+		MODULE=""
b7ef27
+	fi
b7ef27
+	if [ -n "$FRIENDLY" ] && [ "$FRIENDLY" != "y" -a "$FRIENDLY" != "n" ]; then
b7ef27
+		echo "--user_friendly_names must be either 'y' or 'n'"
b7ef27
+		exit 1
b7ef27
+	fi
b7ef27
+	if [ -n "$FIND" ] && [ "$FIND" != "y" -a "$FIND" != "n" ]; then
b7ef27
+		echo "--find_multipaths must be either 'y' or 'n'"
b7ef27
+		exit 1
b7ef27
+	fi
b6d9ac
+	if [ -n "$PROPERTY" ] && [ "$PROPERTY" != "y" -a "$PROPERTY" != "n" ]; then
b6d9ac
+		echo "--property_blacklist must be either 'y' or 'n'"
b6d9ac
+		exit 1
b6d9ac
+	fi
b6d9ac
+	if [ -n "$FOREIGN" ] && [ "$FOREIGN" != "y" -a "$FOREIGN" != "n" ]; then
b6d9ac
+		echo "--enable_foreign must be either 'y' or 'n'"
b6d9ac
+		exit 1
b6d9ac
+	fi
b6d9ac
+	if [ -z "$ENABLE" -a -z "$FIND" -a -z "$FRIENDLY" -a -z "$PROPERTY" ]; then
b7ef27
+		SHOW_STATUS=1
b7ef27
+	fi
b7ef27
+	if [ -n "$MODULE" ] && [ "$MODULE" != "y" -a "$MODULE" != "n" ]; then
b7ef27
+		echo "--with_module must be either 'y' or 'n'"
b7ef27
+		exit 1
b7ef27
+	fi
b7ef27
+	if [ -n "$MULTIPATHD" ] && [ "$MULTIPATHD" != "y" -a "$MULTIPATHD" != "n" ]; then
b7ef27
+		echo "--with_multipathd must be either 'y' or 'n'"
b7ef27
+		exit 1
b7ef27
+	fi
b7ef27
+	if [ "$ENABLE" = 2 -a -z "$HAVE_OUTFILE" ]; then
b7ef27
+		echo "Because --allow makes changes that cannot be automatically reversed,"
b7ef27
+		echo "you must set --outfile when you set --allow"
b7ef27
+		exit 1
b7ef27
+	fi
b7ef27
+}
b7ef27
+
b7ef27
+function add_blacklist_exceptions
b7ef27
+{
b7ef27
+	INDEX=0
b7ef27
+	while [ "$INDEX" -lt "$WWIDS" ] ; do
b7ef27
+		sed -i '/^blacklist_exceptions[[:space:]]*{/ a\
b7ef27
+	wwid '"\"${WWID_LIST[$INDEX]}\""'
b7ef27
+' $TMPFILE
b7ef27
+		((INDEX++))
b7ef27
+	done
b7ef27
+}
b7ef27
+
b7ef27
+umask 0077
b7ef27
+
b7ef27
+parse_args "$@"
b7ef27
+
b7ef27
+validate_args
b7ef27
+
b7ef27
+if [ ! -d "$MULTIPATHDIR" ]; then
b7ef27
+	echo "/etc/multipath/ does not exist. failing"
b7ef27
+	exit 1
b7ef27
+fi
b7ef27
+
b7ef27
+rm $TMPFILE 2> /dev/null
b7ef27
+echo "$DEFAULT_CONFIG" > $TMPFILE
b7ef27
+if [ -f "$CONFIGFILE" ]; then
b7ef27
+	cp $CONFIGFILE $TMPFILE
b7ef27
+fi
b7ef27
+
b7ef27
+if grep -q "^blacklist[[:space:]]*{" $TMPFILE ; then
b7ef27
+	HAVE_BLACKLIST=1
b7ef27
+fi
b7ef27
+
b7ef27
+if grep -q "^blacklist_exceptions[[:space:]]*{" $TMPFILE ; then
b7ef27
+	HAVE_EXCEPTIONS=1
b7ef27
+fi
b7ef27
+
b7ef27
+if grep -q "^defaults[[:space:]]*{" $TMPFILE ; then
b7ef27
+	HAVE_DEFAULTS=1
b7ef27
+fi
b7ef27
+
b7ef27
+if [ -z "$MODULE" -o "$MODULE" = "y" ]; then
b7ef27
+	if lsmod | grep -q "dm_multipath" ; then
b7ef27
+		HAVE_MODULE=1
b7ef27
+	else
b7ef27
+		HAVE_MODULE=0
b7ef27
+	fi
b7ef27
+fi
b7ef27
+
b7ef27
+if [ "$MULTIPATHD" = "y" ]; then
b7ef27
+	if /bin/systemctl status multipathd.service > /dev/null 2>&1 ; then
b7ef27
+		HAVE_MULTIPATHD=1
b7ef27
+	else
b7ef27
+		HAVE_MULTIPATHD=0
b7ef27
+	fi
b7ef27
+fi
b7ef27
+
b7ef27
+if [ "$HAVE_BLACKLIST" = "1" ]; then
b7ef27
+	if sed -n '/^blacklist[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*devnode \"\.\?\*\"" ; then
b7ef27
+		HAVE_DISABLE=1
b7ef27
+	elif sed -n '/^blacklist[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*#[[:space:]]*devnode \"\.\?\*\"" ; then
b7ef27
+		HAVE_DISABLE=0
b7ef27
+	fi
b7ef27
+fi
b7ef27
+
b7ef27
+if [ "$HAVE_BLACKLIST" = "1" ]; then
b7ef27
+	if sed -n '/^blacklist[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*wwid \"\.\?\*\"" ; then
b7ef27
+		HAVE_WWID_DISABLE=1
b7ef27
+	elif sed -n '/^blacklist[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*#[[:space:]]*wwid \"\.\?\*\"" ; then
b7ef27
+		HAVE_WWID_DISABLE=0
b7ef27
+	fi
b7ef27
+fi
b7ef27
+
b7ef27
+if [ "$HAVE_DEFAULTS" = "1" ]; then
b7ef27
+	if sed -n '/^defaults[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*find_multipaths[[:space:]]*\(yes\|1\)" ; then
b7ef27
+		HAVE_FIND=1
b7ef27
+	elif sed -n '/^defaults[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*find_multipaths[[:space:]]*\(no\|0\)" ; then
b7ef27
+		HAVE_FIND=0
b7ef27
+	fi
b7ef27
+	if sed -n '/^defaults[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*user_friendly_names[[:space:]]*\(yes\|1\)" ; then
b7ef27
+		HAVE_FRIENDLY=1
b7ef27
+	elif sed -n '/^defaults[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*user_friendly_names[[:space:]]*\(no\|0\)" ; then
b7ef27
+		HAVE_FRIENDLY=0
b7ef27
+	fi
b6d9ac
+	if sed -n '/^defaults[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*#[[:space:]]*enable_foreign" ; then
b6d9ac
+		HAVE_FOREIGN=0
b6d9ac
+	elif sed -n '/^defaults[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*enable_foreign[[:space:]]*\"\^\$\"" ; then
b6d9ac
+		HAVE_FOREIGN=1
b6d9ac
+	elif sed -n '/^defaults[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*enable_foreign" ; then
b6d9ac
+		HAVE_FOREIGN=2
b6d9ac
+	fi
b6d9ac
+fi
b6d9ac
+
b6d9ac
+if [ "$HAVE_EXCEPTIONS" = "1" ]; then
b6d9ac
+	if sed -n '/^blacklist_exceptions[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*property[[:space:]]*\"(SCSI_IDENT_|ID_WWN)\"" ; then
b6d9ac
+                HAVE_PROPERTY=1
b6d9ac
+        elif sed -n '/^blacklist_exceptions[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*#[[:space:]]*property[[:space:]]*\"(SCSI_IDENT_|ID_WWN)\"" ; then
b6d9ac
+                HAVE_PROPERTY=0
b6d9ac
+        fi
b7ef27
+fi
b7ef27
+
b7ef27
+if [ -n "$SHOW_STATUS" ]; then
b7ef27
+	if [ -z "$HAVE_DISABLE" -o "$HAVE_DISABLE" = 0 ]; then
b7ef27
+		echo "multipath is enabled"
b7ef27
+	else
b7ef27
+		echo "multipath is disabled"
b7ef27
+	fi
b7ef27
+	if [ -z "$HAVE_FIND"  -o "$HAVE_FIND" = 0 ]; then
b7ef27
+		echo "find_multipaths is disabled"
b7ef27
+	else
b7ef27
+		echo "find_multipaths is enabled"
b7ef27
+	fi
b7ef27
+	if [ -z "$HAVE_FRIENDLY" -o "$HAVE_FRIENDLY" = 0 ]; then
b7ef27
+		echo "user_friendly_names is disabled"
b7ef27
+	else
b7ef27
+		echo "user_friendly_names is enabled"
b7ef27
+	fi
b6d9ac
+	if [ -z "$HAVE_PROPERTY" -o "$HAVE_PROPERTY" = 0 ]; then
b6d9ac
+		echo "default property blacklist is disabled"
b6d9ac
+	else
b6d9ac
+		echo "default property blacklist is enabled"
b6d9ac
+	fi
b6d9ac
+	if [ -z "$HAVE_FOREIGN" -o "$HAVE_FOREIGN" = 0 ]; then
b6d9ac
+		echo "enable_foreign is not set (all foreign multipath devices will be shown)"
b6d9ac
+	elif [ "$HAVE_FOREIGN" = 1 ]; then
b6d9ac
+		echo "enable_foreign is set (no foreign multipath devices will be shown)"
b6d9ac
+	else
b6d9ac
+		echo "enable_foreign is set (foreign multipath devices may not be shown)"
b6d9ac
+	fi
b7ef27
+	if [ -n "$HAVE_MODULE" ]; then
b7ef27
+		if [ "$HAVE_MODULE" = 1 ]; then
b7ef27
+			echo "dm_multipath module is loaded"
b7ef27
+		else
b7ef27
+			echo "dm_multipath module is not loaded"
b7ef27
+		fi
b7ef27
+	fi
b7ef27
+	if [ -z "$HAVE_MULTIPATHD" ]; then
b7ef27
+		if /bin/systemctl status multipathd.service > /dev/null 2>&1 ; then
b7ef27
+			HAVE_MULTIPATHD=1
b7ef27
+		else
b7ef27
+			HAVE_MULTIPATHD=0
b7ef27
+		fi
b7ef27
+	fi
b7ef27
+	if [ "$HAVE_MULTIPATHD" = 1 ]; then
b7ef27
+		echo "multipathd is running"
b7ef27
+	else
b7ef27
+		echo "multipathd is not running"
b7ef27
+	fi
b7ef27
+	exit 0
b7ef27
+fi
b7ef27
+
b7ef27
+if [ -z "$HAVE_BLACKLIST" ]; then
b7ef27
+	cat >> $TMPFILE <<- _EOF_
b7ef27
+
b7ef27
+blacklist {
b7ef27
+}
b7ef27
+_EOF_
b7ef27
+fi
b7ef27
+
b7ef27
+if [ -z "$HAVE_DEFAULTS" ]; then
b7ef27
+	cat >> $TMPFILE <<- _EOF_
b7ef27
+
b7ef27
+defaults {
b7ef27
+}
b7ef27
+_EOF_
b7ef27
+fi
b7ef27
+
b7ef27
+if [ "$ENABLE" = 2 ]; then
b7ef27
+	if [ "$HAVE_DISABLE" = 1 ]; then
b7ef27
+		sed -i '/^blacklist[[:space:]]*{/,/^}/ s/^[[:space:]]*devnode \"\.\?\*\"/#	devnode ".*"/' $TMPFILE
b7ef27
+	fi
b7ef27
+	if [ -z "$HAVE_WWID_DISABLE" ]; then
b7ef27
+		sed -i '/^blacklist[[:space:]]*{/ a\
b7ef27
+	wwid ".*"
b7ef27
+' $TMPFILE
b7ef27
+	elif [ "$HAVE_WWID_DISABLE" = 0 ]; then
b7ef27
+		sed -i '/^blacklist[[:space:]]*{/,/^}/ s/^[[:space:]]*#[[:space:]]*wwid \"\.\?\*\"/	wwid ".*"/' $TMPFILE
b7ef27
+	fi
b7ef27
+	if [ "$HAVE_EXCEPTIONS" = 1 ]; then
b7ef27
+		sed -i '/^blacklist_exceptions[[:space:]]*{/,/^}/ {/^[[:space:]]*wwid/ d}' $TMPFILE
b7ef27
+	else
b7ef27
+		cat >> $TMPFILE <<- _EOF_
b7ef27
+
b7ef27
+blacklist_exceptions {
b7ef27
+}
b7ef27
+_EOF_
b7ef27
+	fi
b7ef27
+	add_blacklist_exceptions
b7ef27
+elif [ "$ENABLE" = 1 ]; then
b7ef27
+	if [ "$HAVE_DISABLE" = 1 ]; then
b7ef27
+		sed -i '/^blacklist[[:space:]]*{/,/^}/ s/^[[:space:]]*devnode \"\.\?\*\"/#	devnode ".*"/' $TMPFILE
b7ef27
+	fi
b7ef27
+elif [ "$ENABLE" = 0 ]; then
b7ef27
+	if [ -z "$HAVE_DISABLE" ]; then
b7ef27
+		sed -i '/^blacklist[[:space:]]*{/ a\
b7ef27
+	devnode ".*"
b7ef27
+' $TMPFILE
b7ef27
+	elif [ "$HAVE_DISABLE" = 0 ]; then
b7ef27
+		sed -i '/^blacklist[[:space:]]*{/,/^}/ s/^[[:space:]]*#[[:space:]]*devnode \"\.\?\*\"/	devnode ".*"/' $TMPFILE
b7ef27
+	fi
b7ef27
+fi
b7ef27
+
b7ef27
+if [ "$FIND" = "n" ]; then
b7ef27
+	if [ "$HAVE_FIND" = 1 ]; then
b7ef27
+		sed -i '/^defaults[[:space:]]*{/,/^}/ s/^[[:space:]]*find_multipaths[[:space:]]*\(yes\|1\)/	find_multipaths no/' $TMPFILE
b7ef27
+		CHANGED_CONFIG=1
b7ef27
+	fi
b7ef27
+elif [ "$FIND" = "y" ]; then
b7ef27
+	if [ -z "$HAVE_FIND" ]; then
b7ef27
+		sed -i '/^defaults[[:space:]]*{/ a\
b7ef27
+	find_multipaths yes
b7ef27
+' $TMPFILE
b7ef27
+		CHANGED_CONFIG=1
b7ef27
+	elif [ "$HAVE_FIND" = 0 ]; then
b7ef27
+		sed -i '/^defaults[[:space:]]*{/,/^}/ s/^[[:space:]]*find_multipaths[[:space:]]*\(no\|0\)/	find_multipaths yes/' $TMPFILE
b7ef27
+		CHANGED_CONFIG=1
b7ef27
+	fi
b7ef27
+fi
b7ef27
+
b7ef27
+if [ "$FRIENDLY" = "n" ]; then
b7ef27
+	if [ "$HAVE_FRIENDLY" = 1 ]; then
b7ef27
+		sed -i '/^defaults[[:space:]]*{/,/^}/ s/^[[:space:]]*user_friendly_names[[:space:]]*\(yes\|1\)/	user_friendly_names no/' $TMPFILE
b7ef27
+		CHANGED_CONFIG=1
b7ef27
+	fi
b7ef27
+elif [ "$FRIENDLY" = "y" ]; then
b7ef27
+	if [ -z "$HAVE_FRIENDLY" ]; then
b7ef27
+		sed -i '/^defaults[[:space:]]*{/ a\
b7ef27
+	user_friendly_names yes
b7ef27
+' $TMPFILE
b7ef27
+		CHANGED_CONFIG=1
b7ef27
+	elif [ "$HAVE_FRIENDLY" = 0 ]; then
b7ef27
+		sed -i '/^defaults[[:space:]]*{/,/^}/ s/^[[:space:]]*user_friendly_names[[:space:]]*\(no\|0\)/	user_friendly_names yes/' $TMPFILE
b7ef27
+		CHANGED_CONFIG=1
b7ef27
+	fi
b7ef27
+fi
b7ef27
+
b6d9ac
+if [ "$PROPERTY" = "n" ]; then
b6d9ac
+	if [ "$HAVE_PROPERTY" = 1 ]; then
b6d9ac
+		sed -i '/^blacklist_exceptions[[:space:]]*{/,/^}/ s/^[[:space:]]*property[[:space:]]*\"(SCSI_IDENT_|ID_WWN)\"/#	property \"(SCSI_IDENT_|ID_WWN)\"/' $TMPFILE
b6d9ac
+		CHANGED_CONFIG=1
b6d9ac
+	fi
b6d9ac
+elif [ "$PROPERTY" = "y" ]; then
b6d9ac
+	if [ -z "$HAVE_PROPERTY" ]; then
b6d9ac
+		sed -i '/^blacklist_exceptions[[:space:]]*{/ a\
b6d9ac
+	property "(SCSI_IDENT_|ID_WWN)"
b6d9ac
+' $TMPFILE
b6d9ac
+		CHANGED_CONFIG=1
b6d9ac
+	elif [ "$HAVE_PROPERTY" = 0 ]; then
b6d9ac
+		sed -i '/^blacklist_exceptions[[:space:]]*{/,/^}/ s/^[[:space:]]*#[[:space:]]*property[[:space:]]*\"(SCSI_IDENT_|ID_WWN)\"/	property \"(SCSI_IDENT_|ID_WWN)\"/' $TMPFILE
b6d9ac
+		CHANGED_CONFIG=1
b6d9ac
+	fi
b6d9ac
+fi
b6d9ac
+
b6d9ac
+if [ "$FOREIGN" = "y" ]; then
b6d9ac
+	if [ "$HAVE_FOREIGN" = 1 -o "$HAVE_FOREIGN" = 2 ]; then
b6d9ac
+		sed -i '/^defaults[[:space:]]*{/,/^}/ s/^[[:space:]]*enable_foreign/#	enable_foreign/' $TMPFILE
b6d9ac
+		CHANGED_CONFIG=1
b6d9ac
+	fi
b6d9ac
+elif [ "$FOREIGN" = "n" ]; then
b6d9ac
+	if [ -z "$HAVE_FOREIGN" ]; then
b6d9ac
+		sed -i '/^defaults[[:space:]]*{/ a\
b6d9ac
+	enable_foreign "^$"
b6d9ac
+' $TMPFILE
b6d9ac
+		CHANGED_CONFIG=1
b6d9ac
+	elif [ "$HAVE_FOREIGN" = 0 -o "$HAVE_FOREIGN" = 2 ]; then
b6d9ac
+		sed -i '/^defaults[[:space:]]*{/,/^}/ s/^[[:space:]]*#\?[[:space:]]*enable_foreign.*$/	enable_foreign "^$"/' $TMPFILE
b6d9ac
+		CHANGED_CONFIG=1
b6d9ac
+	fi
b6d9ac
+fi
b6d9ac
+
b7ef27
+if [ -f "$OUTPUTFILE" ]; then
b7ef27
+	cp $OUTPUTFILE $OUTPUTFILE.old
b7ef27
+	if [ $? != 0 ]; then
b7ef27
+		echo "failed to backup old config file, $OUTPUTFILE not updated"
b7ef27
+		exit 1
b7ef27
+	fi
b7ef27
+fi
b7ef27
+
b7ef27
+cp $TMPFILE $OUTPUTFILE
b7ef27
+if [ $? != 0 ]; then
b7ef27
+	echo "failed to copy new config file into place, check $OUTPUTFILE is still OK"
b7ef27
+	exit 1
b7ef27
+fi
b7ef27
+
b7ef27
+rm -f $TMPFILE
b7ef27
+
b7ef27
+if [ "$ENABLE" = 1 ]; then
b7ef27
+	if [ "$HAVE_MODULE" = 0 ]; then
b7ef27
+		modprobe dm_multipath
b7ef27
+	fi
b7ef27
+	if [ "$HAVE_MULTIPATHD" = 0 ]; then
b7ef27
+		systemctl start multipathd.service
b7ef27
+	fi
b7ef27
+elif [ "$ENABLE" = 0 ]; then
b7ef27
+	if [ "$HAVE_MULTIPATHD" = 1 ]; then
b7ef27
+		systemctl stop multipathd.service
b7ef27
+	fi
b7ef27
+elif [ -n "$CHANGED_CONFIG" -a "$HAVE_MULTIPATHD" = 1 ]; then
b7ef27
+	systemctl reload multipathd.service
b7ef27
+fi
b7ef27
diff --git a/multipath/mpathconf.8 b/multipath/mpathconf.8
b7ef27
new file mode 100644
49190a
index 00000000..b82961d6
b7ef27
--- /dev/null
b7ef27
+++ b/multipath/mpathconf.8
b6d9ac
@@ -0,0 +1,135 @@
b7ef27
+.TH MPATHCONF 8 "June 2010" "" "Linux Administrator's Manual"
b7ef27
+.SH NAME
b7ef27
+mpathconf - A tool for configuring device-mapper-multipath
b7ef27
+.SH SYNOPSIS
b7ef27
+.B mpathconf
b7ef27
+.RB [\| commands \|]
b7ef27
+.RB [\| options \|]
b7ef27
+.SH DESCRIPTION
b7ef27
+.B mpathconf
b7ef27
+is a utility that creates or modifies
b7ef27
+.B /etc/multipath.conf.
b7ef27
+It can enable or disable multipathing and configure some common options.
b7ef27
+.B mpathconf
b7ef27
+can also load the
b7ef27
+.B dm_multipath
b7ef27
+module, start and stop the
b7ef27
+.B multipathd
b7ef27
+daemon, and configure the
b7ef27
+.B multipathd
b7ef27
+service to start automatically or not. If
b7ef27
+.B mpathconf
b7ef27
+is called with no commands, it will display the current configuration, but
b7ef27
+will not create of modify
b7ef27
+.B /etc/multipath.conf
b7ef27
+
b7ef27
+The default options for mpathconf are
b7ef27
+.B --with_module
b7ef27
+The
b7ef27
+.B --with_multipathd
b7ef27
+option is not set by default.  Enabling multipathing will load the
b7ef27
+.B dm_multipath
b7ef27
+module but it will not immediately start it. This is so
b7ef27
+that users can manually edit their config file if necessary, before starting
b7ef27
+.B multipathd.
b7ef27
+
b7ef27
+If
b7ef27
+.B /etc/multipath.conf
b7ef27
+already exists, mpathconf will edit it. If it does not exist, mpathconf will
b7ef27
+create a default file with
b7ef27
+.B user_friendly_names
b7ef27
+and
b7ef27
+.B find_multipaths
b7ef27
+set. To disable these, use the
b7ef27
+.B --user_friendly_names n
b7ef27
+and
b7ef27
+.B --find_multipaths n
b7ef27
+options
b7ef27
+.SH COMMANDS
b7ef27
+.TP
b7ef27
+.B --enable
b7ef27
+Removes any line that blacklists all device nodes from the
b7ef27
+.B /etc/multipath.conf
b7ef27
+blacklist section. Also, creates
b7ef27
+.B /etc/multipath.conf
b7ef27
+if it doesn't exist.
b7ef27
+.TP
b7ef27
+.B --disable
b7ef27
+Adds a line that blacklists all device nodes to the
b7ef27
+.B /etc/multipath.conf
b7ef27
+blacklist section. If no blacklist section exists, it will create one.
b7ef27
+.TP
b7ef27
+.B --allow \fB<device>\fP
b7ef27
+Modifies the \fB/etc/multipath/conf\fP blacklist to blacklist all
b7ef27
+wwids and the blacklist_exceptions to whitelist \fB<device>\fP. \fB<device>\fP
b7ef27
+can be in the form of MAJOR:MINOR, a wwid, or the name of a device-mapper
b7ef27
+device, either a multipath device, or any device on stacked on top of one or
b7ef27
+more multipath devices. This command can be used multiple times to allow
b7ef27
+multiple devices.  \fBNOTE:\fP This action will create a configuration file that
b7ef27
+mpathconf will not be able to revert back to its previous state. Because
b7ef27
+of this, \fB--outfile\fP is required when using \fB--allow\fP.
b7ef27
+.TP
49190a
+.B --user_friendly_names \fP { \fBy\fP | \fBn\fP }
b7ef27
+If set to \fBy\fP, this adds the line
b7ef27
+.B user_friendly_names yes
b7ef27
+to the
b7ef27
+.B /etc/multipath.conf
b7ef27
+defaults section. If set to \fBn\fP, this removes the line, if present. This
b7ef27
+command can be used along with any other command.
b7ef27
+.TP
b7ef27
+.B --find_multipaths\fP { \fBy\fP | \fBn\fP }
b7ef27
+If set to \fBy\fP, this adds the line
b7ef27
+.B find_multipaths yes
b7ef27
+to the
b7ef27
+.B /etc/multipath.conf
b7ef27
+defaults section. If set to \fBn\fP, this removes the line, if present. This
b6d9ac
+command can be used along with any other command.
b6d9ac
+.TP
b6d9ac
+.B --property_blacklist \fP { \fBy\fP | \fBn\fP }
b6d9ac
+If set to \fBy\fP, this adds the line
b6d9ac
+.B property "(SCSI_IDENT_|ID_WWN)"
b6d9ac
+to the
b6d9ac
+.B /etc/multipath.conf
b6d9ac
+blacklist_exceptions section. If set to \fBn\fP, this removes the line, if
b6d9ac
+present. This command can be used along with any other command.
b6d9ac
+.TP
b6d9ac
+.B --enable_foreign\fP { \fBy\fP | \fBn\fP }
b6d9ac
+If set to \fBn\fP, this adds the line
b6d9ac
+.B enable_foreign "^$"
b6d9ac
+to the
b6d9ac
+.B /etc/multipath.conf
b6d9ac
+defaults section. if set to \fBy\fP, this removes the line, if present. This
b6d9ac
+command can be used along with any other command.
b7ef27
+.TP
b7ef27
+.B --outfile \fB<filename>\fP
b7ef27
+Write the resulting multipath configuration to \fB<filename>\fP instead of
b7ef27
+\fB/etc/multipath.conf\fP.
b7ef27
+.SH OPTIONS
b7ef27
+.TP
b7ef27
+.B --with_module\fP { \fBy\fP | \fBn\fP }
b7ef27
+If set to \fBy\fP, this runs
b7ef27
+.B modprobe dm_multipath
b7ef27
+to install the multipath modules. This option only works with the
b7ef27
+.B --enable
b7ef27
+command. This option is set to \fBy\fP by default.
b7ef27
+.TP
b7ef27
+.B --with_multipathd { \fBy\fP | \fBn\fP }
b7ef27
+If set to \fBy\fP, this runs
b7ef27
+.B service multipathd start
b7ef27
+to start the multipathd daemon on \fB--enable\fP,
b7ef27
+.B service multipathd stop
b7ef27
+to stop the multipathd daemon on \fB--disable\fP, and
b7ef27
+.B service multipathd reload
b7ef27
+to reconfigure multipathd on \fB--user_frindly_names\fP and
b7ef27
+\fB--find_multipaths\fP.
b7ef27
+This option is set to \fBn\fP by default.
b7ef27
+.SH FILES
b7ef27
+.BR /etc/multipath.conf
b7ef27
+.SH "SEE ALSO"
b7ef27
+.BR multipath.conf (5),
b7ef27
+.BR modprobe (8),
b7ef27
+.BR multipath (8),
b7ef27
+.BR multipathd (8),
b7ef27
+.BR service (8),
b7ef27
+.SH AUTHOR
b7ef27
+Benjamin Marzinski <bmarzins@redhat.com>
b7ef27
-- 
b7ef27
2.17.2
b7ef27