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

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