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:
|
|
|
|
# FABRIC-VPWWPN-VPWWNN-TGTWWPN-LUN#
|
|
|
|
# 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
|
|
|
|
VPORTWWPN=${NPIVARGS##*-}; NPIVARGS=${NPIVARGS%-*}
|
|
|
|
if test $VPORTWWPN = $NPIVARGS ; then exit 1; fi
|
|
|
|
FABRICNM=$NPIVARGS
|
|
|
|
|
|
|
|
# Ensure we compare everything using lower-case hex characters
|
|
|
|
TGTWWPN=`echo $TGTWWPN | tr A-Z a-z`
|
|
|
|
VPORTWWPN=`echo $VPORTWWPN | tr A-Z a-z`
|
|
|
|
VPORTWWNN=`echo $VPORTWWNN | tr A-Z a-z`
|
|
|
|
FABRICNM=`echo $FABRICNM | tr A-Z a-z`
|
|
|
|
|
|
|
|
find_vhost $VPORTWWPN
|
|
|
|
if test -z "$vhost" ; then
|
|
|
|
create_vport $FABRICNM $VPORTWWPN $VPORTWWNN
|
|
|
|
if [ $? -ne 0 ] ; then exit 2; fi
|
2007-06-19 00:21:15 +02:00
|
|
|
sleep 8
|
2008-02-02 01:58:27 +01:00
|
|
|
find_vhost $VPORTWWPN
|
|
|
|
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
|
2007-06-19 00:21:15 +02:00
|
|
|
xenstore-write $XENBUS_PATH/node /dev/$dev
|
|
|
|
write_dev /dev/$dev
|
|
|
|
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
|
|
|
|
#node=$2
|
|
|
|
dev=$node; dev=${dev#/dev/}
|
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)
|
|
|
|
find_vhost_from_dev $dev
|
|
|
|
if test -z "$vhost" ; then exit 5; fi
|
|
|
|
flush_nodes_on_vhost $vhost
|
|
|
|
delete_vhost $vhost
|
2007-06-19 00:21:15 +02:00
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
esac
|