You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

240 lines
6.7 KiB

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