Blame SOURCES/0128-RHBZ-1222123-mpathconf-allow.patch

ecd2a9
---
ecd2a9
 multipath/mpathconf |  135 +++++++++++++++++++++++++++++++++++++++++++++++-----
ecd2a9
 1 file changed, 124 insertions(+), 11 deletions(-)
ecd2a9
ecd2a9
Index: multipath-tools-130222/multipath/mpathconf
ecd2a9
===================================================================
ecd2a9
--- multipath-tools-130222.orig/multipath/mpathconf
ecd2a9
+++ multipath-tools-130222/multipath/mpathconf
ecd2a9
@@ -1,4 +1,4 @@
ecd2a9
-#!/bin/sh
ecd2a9
+#!/bin/bash
ecd2a9
 #
ecd2a9
 # Copyright (C) 2010 Red Hat, Inc. All rights reserved.
ecd2a9
 #
ecd2a9
@@ -17,12 +17,14 @@
ecd2a9
 # This program was largely ripped off from lvmconf
ecd2a9
 #
ecd2a9
 
ecd2a9
-unset ENABLE FIND FRIENDLY MODULE MULTIPATHD HAVE_DISABLE HAVE_FIND HAVE_BLACKLIST HAVE_DEFAULTS HAVE_FRIENDLY HAVE_MULTIPATHD HAVE_MODULE SHOW_STATUS CHANGED_CONFIG
ecd2a9
+unset ENABLE FIND FRIENDLY MODULE MULTIPATHD HAVE_DISABLE HAVE_WWID_DISABLE HAVE_FIND HAVE_BLACKLIST HAVE_EXCEPTIONS HAVE_DEFAULTS HAVE_FRIENDLY HAVE_MULTIPATHD HAVE_MODULE HAVE_OUTFILE SHOW_STATUS CHANGED_CONFIG WWID_LIST
ecd2a9
 
ecd2a9
 DEFAULT_CONFIGFILE="/usr/share/doc/device-mapper-multipath-0.4.9/multipath.conf"
ecd2a9
 CONFIGFILE="/etc/multipath.conf"
ecd2a9
+OUTPUTFILE="/etc/multipath.conf"
ecd2a9
 MULTIPATHDIR="/etc/multipath"
ecd2a9
 TMPFILE=/etc/multipath/.multipath.conf.tmp
ecd2a9
+WWIDS=0
ecd2a9
 
ecd2a9
 function usage
ecd2a9
 {
ecd2a9
@@ -31,13 +33,60 @@ function usage
ecd2a9
 	echo "Commands:"
ecd2a9
 	echo "Enable: --enable "
ecd2a9
 	echo "Disable: --disable"
ecd2a9
+	echo "Only allow certain wwids (instead of enable): --allow <WWID>"
ecd2a9
 	echo "Set user_friendly_names (Default y): --user_friendly_names <y|n>"
ecd2a9
 	echo "Set find_multipaths (Default y): --find_multipaths <y|n>"
ecd2a9
 	echo "Load the dm-multipath modules on enable (Default y): --with_module <y|n>"
ecd2a9
 	echo "start/stop/reload multipathd (Default n): --with_multipathd <y|n>"
ecd2a9
+	echo "select output file (Default /etc/multipath.conf): --outfile <FILE>"
ecd2a9
 	echo ""
ecd2a9
 }
ecd2a9
 
ecd2a9
+function get_dm_deps
ecd2a9
+{
ecd2a9
+	shift 3
ecd2a9
+	while [ -n "$1" -a -n "$2" ]; do
ecd2a9
+		MAJOR=$(echo $1 | tr -d '(,')
ecd2a9
+		MINOR=$(echo $2 | tr -d ')')
ecd2a9
+		UUID=`dmsetup info -c --noheadings -o uuid -j $MAJOR -m $MINOR  2> /dev/null`
ecd2a9
+		if [ -n "$UUID" ] ; then
ecd2a9
+			set_dm_wwid $UUID
ecd2a9
+		fi
ecd2a9
+		shift 2
ecd2a9
+	done
ecd2a9
+}
ecd2a9
+
ecd2a9
+function set_dm_wwid
ecd2a9
+{
ecd2a9
+	if [[ "$1" =~ ^part[[:digit:]]+-mpath- ]] ; then
ecd2a9
+		WWID_LIST[$WWIDS]="${1##part*-mpath-}"
ecd2a9
+		((WWIDS++))
ecd2a9
+	elif [[ "$1" =~ ^mpath- ]] ; then
ecd2a9
+		WWID_LIST[$WWIDS]="${1##mpath-}"
ecd2a9
+		((WWIDS++))
ecd2a9
+	else
ecd2a9
+		get_dm_deps `dmsetup deps -u $1`
ecd2a9
+	fi
ecd2a9
+}
ecd2a9
+
ecd2a9
+function set_wwid
ecd2a9
+{
ecd2a9
+	UUID=""
ecd2a9
+	if [[ "$1" =~ ^[[:digit:]]+:[[:digit:]]+$ ]] ; then
ecd2a9
+		MAJOR=${1%%:*}
ecd2a9
+		MINOR=${1##*:}
ecd2a9
+		UUID=`dmsetup info -c --noheadings -o uuid -j $MAJOR -m $MINOR  2> /dev/null`
ecd2a9
+	else
ecd2a9
+		UUID=`dmsetup info -c --noheadings -o uuid $1 2> /dev/null`
ecd2a9
+	fi
ecd2a9
+	if [ -n "$UUID" ] ; then
ecd2a9
+		set_dm_wwid $UUID
ecd2a9
+	else
ecd2a9
+		WWID_LIST[$WWIDS]="$1"
ecd2a9
+		((WWIDS++))
ecd2a9
+	fi
ecd2a9
+}
ecd2a9
+
ecd2a9
 function parse_args
ecd2a9
 {
ecd2a9
 	while [ -n "$1" ]; do
ecd2a9
@@ -50,6 +99,16 @@ function parse_args
ecd2a9
 				ENABLE=0
ecd2a9
 				shift
ecd2a9
 				;;
ecd2a9
+			--allow)
ecd2a9
+				ENABLE=2
ecd2a9
+				if [ -n "$2" ]; then
ecd2a9
+					set_wwid $2
ecd2a9
+					shift 2
ecd2a9
+				else
ecd2a9
+					usage
ecd2a9
+					exit 1
ecd2a9
+				fi
ecd2a9
+				;;
ecd2a9
 			--user_friendly_names)
ecd2a9
 				if [ -n "$2" ]; then
ecd2a9
 					FRIENDLY=$2
ecd2a9
@@ -86,6 +145,16 @@ function parse_args
ecd2a9
 					exit 1
ecd2a9
 				fi
ecd2a9
 				;;
ecd2a9
+			--outfile)
ecd2a9
+				if [ -n "$2" ]; then
ecd2a9
+					OUTPUTFILE=$2
ecd2a9
+					HAVE_OUTFILE=1
ecd2a9
+					shift 2
ecd2a9
+				else
ecd2a9
+					usage
ecd2a9
+					exit 1
ecd2a9
+				fi
ecd2a9
+				;;
ecd2a9
 			*)
ecd2a9
 				usage
ecd2a9
 				exit
ecd2a9
@@ -120,6 +189,22 @@ function validate_args
ecd2a9
 		echo "--with_multipathd must be either 'y' or 'n'"
ecd2a9
 		exit 1
ecd2a9
 	fi
ecd2a9
+	if [ "$ENABLE" = 2 -a -z "$HAVE_OUTFILE" ]; then
ecd2a9
+		echo "Because --allow makes changes that cannot be automatically reversed,"
ecd2a9
+		echo "you must set --outfile when you set --allow"
ecd2a9
+		exit 1
ecd2a9
+	fi
ecd2a9
+}
ecd2a9
+
ecd2a9
+function add_blacklist_exceptions
ecd2a9
+{
ecd2a9
+	echo "blacklist_exceptions {" >> $TMPFILE
ecd2a9
+	INDEX=0
ecd2a9
+	while [ "$INDEX" -lt "$WWIDS" ] ; do
ecd2a9
+		echo "	wwid \"${WWID_LIST[$INDEX]}\"" >> $TMPFILE
ecd2a9
+		((INDEX++))
ecd2a9
+	done
ecd2a9
+	echo "}" >> $TMPFILE
ecd2a9
 }
ecd2a9
 
ecd2a9
 umask 0077
ecd2a9
@@ -146,6 +231,10 @@ if grep -q "^blacklist[[:space:]]*{" $TM
ecd2a9
 	HAVE_BLACKLIST=1
ecd2a9
 fi
ecd2a9
 
ecd2a9
+if grep -q "^blacklist_exceptions[[:space:]]*{" $TMPFILE ; then
ecd2a9
+	HAVE_EXCEPTIONS=1
ecd2a9
+fi
ecd2a9
+
ecd2a9
 if grep -q "^defaults[[:space:]]*{" $TMPFILE ; then
ecd2a9
 	HAVE_DEFAULTS=1
ecd2a9
 fi
ecd2a9
@@ -169,11 +258,19 @@ fi
ecd2a9
 if [ "$HAVE_BLACKLIST" = "1" ]; then
ecd2a9
 	if sed -n '/^blacklist[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*devnode \"\.\?\*\"" ; then
ecd2a9
 		HAVE_DISABLE=1
ecd2a9
-	elif sed -n '/^blacklist[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*#[#[:space:]]*devnode \"\.\?\*\"" ; then
ecd2a9
+	elif sed -n '/^blacklist[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*#[[:space:]]*devnode \"\.\?\*\"" ; then
ecd2a9
 		HAVE_DISABLE=0
ecd2a9
 	fi
ecd2a9
 fi
ecd2a9
 
ecd2a9
+if [ "$HAVE_BLACKLIST" = "1" ]; then
ecd2a9
+	if sed -n '/^blacklist[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*wwid \"\.\?\*\"" ; then
ecd2a9
+		HAVE_WWID_DISABLE=1
ecd2a9
+	elif sed -n '/^blacklist[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*#[[:space:]]*wwid \"\.\?\*\"" ; then
ecd2a9
+		HAVE_WWID_DISABLE=0
ecd2a9
+	fi
ecd2a9
+fi
ecd2a9
+
ecd2a9
 if [ "$HAVE_DEFAULTS" = "1" ]; then
ecd2a9
 	if sed -n '/^defaults[[:space:]]*{/,/^}/ p' $TMPFILE | grep -q "^[[:space:]]*find_multipaths[[:space:]]*\(yes\|1\)" ; then
ecd2a9
 		HAVE_FIND=1
ecd2a9
@@ -241,17 +338,33 @@ defaults {
ecd2a9
 _EOF_
ecd2a9
 fi
ecd2a9
 
ecd2a9
-if [ "$ENABLE" = 1 ]; then
ecd2a9
+if [ "$ENABLE" = 2 ]; then
ecd2a9
+	if [ "$HAVE_DISABLE" = 1 ]; then
ecd2a9
+		sed -i '/^blacklist[[:space:]]*{/,/^}/ s/^[[:space:]]*devnode \"\.\?\*\"/#	devnode ".*"/' $TMPFILE
ecd2a9
+	fi
ecd2a9
+	if [ -z "$HAVE_WWID_DISABLE" ]; then
ecd2a9
+		sed -i '/^blacklist[[:space:]]*{/ a\
ecd2a9
+	wwid ".*"
ecd2a9
+' $TMPFILE
ecd2a9
+	elif [ "$HAVE_WWID_DISABLE" = 0 ]; then
ecd2a9
+		sed -i '/^blacklist[[:space:]]*{/,/^}/ s/^[[:space:]]*#[[:space:]]*wwid \"\.\?\*\"/	wwid ".*"/' $TMPFILE
ecd2a9
+	fi
ecd2a9
+	if [ "$HAVE_EXCEPTIONS" = 1 ]; then
ecd2a9
+		sed -i '/^blacklist_exceptions[[:space:]]*{/,/^}/d' $TMPFILE
ecd2a9
+	fi
ecd2a9
+	echo $HAVE_WWID_DISABLE
ecd2a9
+	add_blacklist_exceptions
ecd2a9
+elif [ "$ENABLE" = 1 ]; then
ecd2a9
 	if [ "$HAVE_DISABLE" = 1 ]; then
ecd2a9
 		sed -i '/^blacklist[[:space:]]*{/,/^}/ s/^[[:space:]]*devnode \"\.\?\*\"/#	devnode ".*"/' $TMPFILE
ecd2a9
 	fi
ecd2a9
 elif [ "$ENABLE" = 0 ]; then
ecd2a9
 	if [ -z "$HAVE_DISABLE" ]; then
ecd2a9
 		sed -i '/^blacklist[[:space:]]*{/ a\
ecd2a9
-	devnode "*"
ecd2a9
+	devnode ".*"
ecd2a9
 ' $TMPFILE
ecd2a9
 	elif [ "$HAVE_DISABLE" = 0 ]; then
ecd2a9
-		sed -i '/^blacklist[[:space:]]*{/,/^}/ s/^[[:space:]]*#[#[:space:]]*devnode \"\.\?\*\"/	devnode ".*"/' $TMPFILE
ecd2a9
+		sed -i '/^blacklist[[:space:]]*{/,/^}/ s/^[[:space:]]*#[[:space:]]*devnode \"\.\?\*\"/	devnode ".*"/' $TMPFILE
ecd2a9
 	fi
ecd2a9
 fi
ecd2a9
 
ecd2a9
@@ -289,17 +402,17 @@ elif [ "$FRIENDLY" = "y" ]; then
ecd2a9
 	fi
ecd2a9
 fi
ecd2a9
 
ecd2a9
-if [ -f "$CONFIGFILE" ]; then
ecd2a9
-	cp $CONFIGFILE $CONFIGFILE.old
ecd2a9
+if [ -f "$OUTPUTFILE" ]; then
ecd2a9
+	cp $OUTPUTFILE $OUTPUTFILE.old
ecd2a9
 	if [ $? != 0 ]; then
ecd2a9
-		echo "failed to backup old config file, $CONFIGFILE not updated"
ecd2a9
+		echo "failed to backup old config file, $OUTPUTFILE not updated"
ecd2a9
 		exit 1
ecd2a9
 	fi
ecd2a9
 fi
ecd2a9
 
ecd2a9
-cp $TMPFILE $CONFIGFILE
ecd2a9
+cp $TMPFILE $OUTPUTFILE
ecd2a9
 if [ $? != 0 ]; then
ecd2a9
-	echo "failed to copy new config file into place, check $CONFIGFILE is still OK"
ecd2a9
+	echo "failed to copy new config file into place, check $OUTPUTFILE is still OK"
ecd2a9
 	exit 1
ecd2a9
 fi
ecd2a9