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

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