[Stgt-devel] [PATCH 2/4] iscsi: allow multiple initiators in tgt-setup-lun
Erez Zilber
erezz
Mon Jan 7 16:05:07 CET 2008
Currently, tgt-setup-lun only allows the assignment of a
single initiator per target. This fix allows the
assignment of multiple initiators per target (or all
initiators).
Signed-off-by: Erez Zilber <erezz at voltaire.com>
---
usr/scripts/tgt-setup-lun | 64 +++++++++++++++++++++++++++++++++-----------
1 files changed, 48 insertions(+), 16 deletions(-)
diff --git a/usr/scripts/tgt-setup-lun b/usr/scripts/tgt-setup-lun
index 0c8698c..d63a793 100644
--- a/usr/scripts/tgt-setup-lun
+++ b/usr/scripts/tgt-setup-lun
@@ -19,11 +19,28 @@
#!/bin/bash
+usage()
+{
+ name=$(basename $0)
+ echo "usage: $name -d dev -n target_name [initiator_IP1 initiator_IP2 ...] ";
+ echo "example: $name /dev/sdb1 noni 192.168.10.63";
+}
+
verify_params()
{
+ if ! [ "$dev" ]; then
+ echo "Error: a device is mandatory";
+ exit 1;
+ fi
+
# Make sure that the device exists
if ! [ -b $dev -o -f $dev ]; then
- echo "$dev is not a device";
+ echo "Error: $dev is not a device";
+ exit 1;
+ fi
+
+ if ! [ "$tgt_name" ]; then
+ echo "Error: target name is mandatory";
exit 1;
fi
}
@@ -86,16 +103,22 @@ find_vacant_lun()
return $next_vacant_lun
}
-if [ $# -ne 3 ]; then
- name=$(basename $0)
- echo "usage: $name <dev> <initiator name> <initiator IP>";
- echo "example: $name /dev/sdb1 noni 192.168.10.63";
- exit 1;
-fi
+while getopts "d:n:" opt
+do
+ case ${opt} in
+ d)
+ dev=$OPTARG;;
+ n)
+ tgt_name=$OPTARG;;
+ *)
+ usage
+ exit 1
+ esac
+done
+
+shift $(($OPTIND - 1))
-dev=$1
-initiator=$2
-initiator_ip=$3
+initiators=$*
verify_params
@@ -106,22 +129,31 @@ if [ $tgtd_count -ne 3 ]; then
tgtd
fi
-tgt_name="iqn.2001-04.com.$(hostname -s)-$initiator"
+tgt_name="iqn.2001-04.com.$(hostname -s)-$tgt_name"
find_vacant_tgt_id
tid=$?
# Create the new target
-echo "Creating the new target"
+echo "Creating the new target ($tgt_name)"
tgtadm --lld iscsi --op new --mode target --tid $tid -T $tgt_name
find_vacant_lun $tid
lun=$?
# Add a logical unit to the target
-echo "Adding a logical unit to the target"
+echo "Adding a logical unit ($dev) to the target"
tgtadm --lld iscsi --op new --mode logicalunit --tid $tid --lun $lun -b $dev
-# Accept only a specific initiator
-echo "Accepting connections only from $initiator_ip"
-tgtadm --lld iscsi --op bind --mode target --tid $tid -I $initiator_ip
+# Define which initiators can use this target
+if test "$initiators" ; then
+ # Allow access only for specific initiators
+ echo "Accepting connections only from $initiators"
+ for initiator in $initiators; do
+ tgtadm --lld iscsi --op bind --mode target --tid $tid -I $initiator
+ done
+else
+ # Allow access for everyone
+ echo "Accepting connections from every initiator"
+ tgtadm --lld iscsi --op bind --mode target --tid $tid -I ALL
+fi
--
1.5.3.7
More information about the stgt
mailing list