2007-06-19 00:21:15 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Usage: block-npiv [add npiv | remove dev]
|
|
|
|
|
|
|
|
dir=$(dirname "$0")
|
2009-09-27 00:20:08 +02:00
|
|
|
. "$dir/block-npiv-common.sh"
|
2007-06-19 00:21:15 +02:00
|
|
|
. "$dir/block-common.sh"
|
|
|
|
|
|
|
|
#set -x
|
|
|
|
#command=$1
|
|
|
|
|
|
|
|
case "$command" in
|
|
|
|
add)
|
2008-02-02 01:58:27 +01:00
|
|
|
# Params is one big arg, with fields separated by hyphens:
|
2011-08-05 22:04:48 +02:00
|
|
|
# single path:
|
|
|
|
# FABRIC-VPWWPN-VPWWNN-TGTWWPN-LUN#
|
|
|
|
# multipath:
|
2011-09-15 23:43:21 +02:00
|
|
|
# {FABRIC1.FABRIC2}-{VPWWPN1.VPWWPN2.VPWWPN3}-VPWWNN-TGTWWPN-LUN#
|
2008-02-02 01:58:27 +01:00
|
|
|
# arg 2 - Fabric Name
|
|
|
|
# arg 3 - VPORT's WWPN
|
|
|
|
# arg 4 - VPORT's WWNN
|
|
|
|
# arg 5 - Target's WWPN
|
|
|
|
# arg 6 - LUN # on Target
|
|
|
|
# no wwn contains a leading 0x - it is a 16 character hex value
|
|
|
|
# You may want to optionally pick a specific adapter ?
|
2007-06-19 00:21:15 +02:00
|
|
|
par=`xenstore-read $XENBUS_PATH/params` || true
|
|
|
|
#par=$2
|
2008-02-02 01:58:27 +01:00
|
|
|
NPIVARGS=$par;
|
|
|
|
LUN=${NPIVARGS##*-*-*-*-}; NPIVARGS=${NPIVARGS%-*}
|
|
|
|
if test $LUN = $NPIVARGS ; then exit 1; fi
|
|
|
|
TGTWWPN=${NPIVARGS##*-*-*-}; NPIVARGS=${NPIVARGS%-*}
|
|
|
|
if test $TGTWWPN = $NPIVARGS ; then exit 1; fi
|
|
|
|
VPORTWWNN=${NPIVARGS##*-*-}; NPIVARGS=${NPIVARGS%-*}
|
|
|
|
if test $VPORTWWNN = $NPIVARGS ; then exit 1; fi
|
2011-08-05 22:04:48 +02:00
|
|
|
VPORTWWPNS=${NPIVARGS##*-}; NPIVARGS=${NPIVARGS%-*}
|
|
|
|
if test $VPORTWWPNS = $NPIVARGS ; then exit 1; fi
|
|
|
|
FABRICNMS=$NPIVARGS
|
2008-02-02 01:58:27 +01:00
|
|
|
|
|
|
|
# Ensure we compare everything using lower-case hex characters
|
|
|
|
TGTWWPN=`echo $TGTWWPN | tr A-Z a-z`
|
2011-09-15 23:43:21 +02:00
|
|
|
VPORTWWPNS=`echo $VPORTWWPNS | tr A-Z a-z |sed 's/[{.}]/ /g'`
|
2011-08-05 22:04:48 +02:00
|
|
|
VPORTWWNN=`echo $VPORTWWNN | tr A-Z a-z`
|
2011-09-15 23:43:21 +02:00
|
|
|
FABRICNMS=`echo $FABRICNMS | tr A-Z a-z |sed 's/[{.}]/ /g'`
|
2008-02-02 01:58:27 +01:00
|
|
|
|
2010-05-14 00:42:02 +02:00
|
|
|
|
2011-08-05 22:04:48 +02:00
|
|
|
claim_lock "npiv"
|
|
|
|
paths=0
|
|
|
|
for FABRICNM in $FABRICNMS; do
|
|
|
|
for VPORTWWPN in $VPORTWWPNS; do
|
|
|
|
find_vhost $VPORTWWPN $FABRICNM
|
|
|
|
if test -z "$vhost" ; then
|
|
|
|
create_vport $FABRICNM $VPORTWWPN $VPORTWWNN
|
|
|
|
if [ $? -ne 0 ] ; then exit 2; fi
|
|
|
|
sleep 8
|
|
|
|
find_vhost $VPORTWWPN $FABRICNM
|
|
|
|
if test -z "$vhost" ; then exit 3; fi
|
|
|
|
fi
|
|
|
|
find_sdev $vhost $TGTWWPN $LUN
|
|
|
|
if test -z "$dev"; then
|
|
|
|
echo "- - -" > /sys/class/scsi_host/$vhost/scan
|
|
|
|
sleep 2
|
|
|
|
find_sdev $vhost $TGTWWPN $LUN
|
|
|
|
fi
|
|
|
|
if test -z "$dev"; then
|
|
|
|
exit 4
|
|
|
|
fi
|
|
|
|
paths=$(($paths+1))
|
|
|
|
done
|
|
|
|
done
|
2010-05-14 00:42:02 +02:00
|
|
|
release_lock "npiv"
|
|
|
|
|
2011-08-05 22:04:48 +02:00
|
|
|
if test $paths -gt 1; then
|
|
|
|
xenstore-write $XENBUS_PATH/multipath 1
|
|
|
|
/etc/init.d/multipathd start
|
|
|
|
if test $? -ne 0 ; then exit 4; fi
|
|
|
|
dm=`multipath -l /dev/$dev | grep dm | cut -f2 -d' '`
|
|
|
|
else
|
|
|
|
xenstore-write $XENBUS_PATH/multipath 0
|
|
|
|
dm=$dev
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test ! -z "$dm"; then
|
|
|
|
xenstore-write $XENBUS_PATH/node /dev/$dm
|
|
|
|
write_dev /dev/$dm
|
2007-06-19 00:21:15 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
2008-02-02 01:58:27 +01:00
|
|
|
|
|
|
|
exit 4
|
2007-06-19 00:21:15 +02:00
|
|
|
;;
|
2008-02-02 01:58:27 +01:00
|
|
|
|
2007-06-19 00:21:15 +02:00
|
|
|
remove)
|
|
|
|
node=`xenstore-read $XENBUS_PATH/node` || true
|
2011-08-05 22:04:48 +02:00
|
|
|
multipath=`xenstore-read $XENBUS_PATH/multipath` || true
|
2008-02-02 01:58:27 +01:00
|
|
|
# this is really screwy. the first delete of a lun will
|
|
|
|
# terminate the entire vport (all luns)
|
2011-08-05 22:04:48 +02:00
|
|
|
if test $multipath = 1; then
|
|
|
|
par=`xenstore-read $XENBUS_PATH/params` || true
|
|
|
|
NPIVARGS=$par;
|
|
|
|
FABRICNMS=${NPIVARGS%%-*}; NPIVARGS=${NPIVARGS#*-}
|
|
|
|
VPORTWWPNS=${NPIVARGS%%-*}
|
2011-09-15 23:43:21 +02:00
|
|
|
VPORTWWPNS=`echo $VPORTWWPNS | tr A-Z a-z |sed 's/[{.}]/ /g'`
|
|
|
|
FABRICNMS=`echo $FABRICNMS | tr A-Z a-z |sed 's/[{.}]/ /g'`
|
2011-08-05 22:04:48 +02:00
|
|
|
for FABRICNM in $FABRICNMS; do
|
|
|
|
for VPORTWWPN in $VPORTWWPNS; do
|
|
|
|
find_vhost $VPORTWWPN $FABRICNM
|
|
|
|
if test -z "$vhost" ; then exit 5; fi
|
|
|
|
flush_nodes_on_vhost $vhost
|
|
|
|
delete_vhost $vhost
|
|
|
|
done
|
|
|
|
done
|
|
|
|
else
|
|
|
|
dev=$node; dev=${dev#/dev/}
|
|
|
|
find_vhost_from_dev $dev
|
|
|
|
if test -z "$vhost" ; then exit 5; fi
|
|
|
|
flush_nodes_on_vhost $vhost
|
|
|
|
delete_vhost $vhost
|
|
|
|
fi
|
|
|
|
|
2007-06-19 00:21:15 +02:00
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
esac
|