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

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