[Stgt-devel] [PATCH 1/4] iscsi: renamed setup_lun to tgt-setup-lun

Erez Zilber erezz
Mon Jan 7 16:03:32 CET 2008


Renamed setup_lun to tgt-setup-lun. It enables
users to easily find that this script is for tgt.

Signed-off-by: Erez Zilber <erezz at voltaire.com>
---
 usr/scripts/setup_lun     |  127 ---------------------------------------------
 usr/scripts/tgt-setup-lun |  127 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 127 insertions(+), 127 deletions(-)
 delete mode 100644 usr/scripts/setup_lun
 create mode 100644 usr/scripts/tgt-setup-lun

diff --git a/usr/scripts/setup_lun b/usr/scripts/setup_lun
deleted file mode 100644
index 0c8698c..0000000
--- a/usr/scripts/setup_lun
+++ /dev/null
@@ -1,127 +0,0 @@
-# LUN assignment script
-#
-# Copyright (C) 2007 Erez Zilber <erezz at voltaire.com>
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation, version 2 of the
-# License.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-# 02110-1301 USA
-
-#!/bin/bash
-
-verify_params()
-{
-	# Make sure that the device exists
-	if ! [ -b $dev -o -f $dev ]; then
-		echo "$dev is not a device";
-		exit 1;
-	fi
-}
-
-find_vacant_tgt_id()
-{
-	id_list=$(tgtadm --lld iscsi --op show --mode target | grep Target | cut -d" " -f2 | sed s/://)
-
-	next_vacant_id=1
-
-	for id in $id_list; do
-		if (($id > $next_vacant_id)); then
-			break;
-		else
-			next_vacant_id=$((next_vacant_id+1))
-		fi
-	done
-
-	return $next_vacant_id
-}
-
-find_vacant_lun()
-{
-	tid=$1
-	tgt_found=0
-	next_vacant_lun=0
-	tmp_file=/tmp/target_list.txt
-
-	tgtadm --lld iscsi --op show --mode target > $tmp_file
-
-	while read line; do
-		# Check if we finished going over this target
-		if ((tgt_found == 1 && $(echo $line | grep -c "^Target") == 1)); then
-			break
-		fi
-
-		# Check if we found the requested target
-		if (($(echo $line | grep -c "Target $tid:") == 1)); then
-			tgt_found=1
-			continue
-		fi
-
-		if ((tgt_found == 1 && $(echo $line | grep -c "LUN:") == 1)); then
-			curr_lun=$(echo $line | cut -d" " -f2)
-			if (($curr_lun > $next_vacant_lun)); then
-				break
-			else
-				next_vacant_lun=$((next_vacant_lun+1))
-			fi
-		fi
-	done < $tmp_file
-
-	rm -f $tmp_file
-
-	if ((tgt_found == 0)); then
-		echo "Error: could not find a LUN for target $tid"
-		return -1
-	fi
-
-	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
-
-dev=$1
-initiator=$2
-initiator_ip=$3
-
-verify_params
-
-# Check if tgtd is running (we should have 2 daemons)
-tgtd_count=$(ps aux|grep -c tgtd)
-if [ $tgtd_count -ne 3 ]; then
-	echo "Starting tgtd"
-	tgtd
-fi
-
-tgt_name="iqn.2001-04.com.$(hostname -s)-$initiator"
-
-find_vacant_tgt_id
-tid=$?
-
-# Create the new target
-echo "Creating the new target"
-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"
-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
diff --git a/usr/scripts/tgt-setup-lun b/usr/scripts/tgt-setup-lun
new file mode 100644
index 0000000..0c8698c
--- /dev/null
+++ b/usr/scripts/tgt-setup-lun
@@ -0,0 +1,127 @@
+# LUN assignment script
+#
+# Copyright (C) 2007 Erez Zilber <erezz at voltaire.com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, version 2 of the
+# License.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA
+
+#!/bin/bash
+
+verify_params()
+{
+	# Make sure that the device exists
+	if ! [ -b $dev -o -f $dev ]; then
+		echo "$dev is not a device";
+		exit 1;
+	fi
+}
+
+find_vacant_tgt_id()
+{
+	id_list=$(tgtadm --lld iscsi --op show --mode target | grep Target | cut -d" " -f2 | sed s/://)
+
+	next_vacant_id=1
+
+	for id in $id_list; do
+		if (($id > $next_vacant_id)); then
+			break;
+		else
+			next_vacant_id=$((next_vacant_id+1))
+		fi
+	done
+
+	return $next_vacant_id
+}
+
+find_vacant_lun()
+{
+	tid=$1
+	tgt_found=0
+	next_vacant_lun=0
+	tmp_file=/tmp/target_list.txt
+
+	tgtadm --lld iscsi --op show --mode target > $tmp_file
+
+	while read line; do
+		# Check if we finished going over this target
+		if ((tgt_found == 1 && $(echo $line | grep -c "^Target") == 1)); then
+			break
+		fi
+
+		# Check if we found the requested target
+		if (($(echo $line | grep -c "Target $tid:") == 1)); then
+			tgt_found=1
+			continue
+		fi
+
+		if ((tgt_found == 1 && $(echo $line | grep -c "LUN:") == 1)); then
+			curr_lun=$(echo $line | cut -d" " -f2)
+			if (($curr_lun > $next_vacant_lun)); then
+				break
+			else
+				next_vacant_lun=$((next_vacant_lun+1))
+			fi
+		fi
+	done < $tmp_file
+
+	rm -f $tmp_file
+
+	if ((tgt_found == 0)); then
+		echo "Error: could not find a LUN for target $tid"
+		return -1
+	fi
+
+	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
+
+dev=$1
+initiator=$2
+initiator_ip=$3
+
+verify_params
+
+# Check if tgtd is running (we should have 2 daemons)
+tgtd_count=$(ps aux|grep -c tgtd)
+if [ $tgtd_count -ne 3 ]; then
+	echo "Starting tgtd"
+	tgtd
+fi
+
+tgt_name="iqn.2001-04.com.$(hostname -s)-$initiator"
+
+find_vacant_tgt_id
+tid=$?
+
+# Create the new target
+echo "Creating the new target"
+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"
+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
-- 
1.5.3.7





More information about the stgt mailing list