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

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