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