[Stgt-devel] [PATCH 3/4] iscsi: test tgtadm ret values in tgt-setup-lun
Erez Zilber
erezz
Mon Jan 7 16:06:26 CET 2008
If tgtadm fails, we need to rollback (i.e. delete the
target).
Signed-off-by: Erez Zilber <erezz at voltaire.com>
---
usr/scripts/tgt-setup-lun | 37 +++++++++++++++++++++++++++++++++++++
1 files changed, 37 insertions(+), 0 deletions(-)
mode change 100644 => 100755 usr/scripts/tgt-setup-lun
diff --git a/usr/scripts/tgt-setup-lun b/usr/scripts/tgt-setup-lun
old mode 100644
new mode 100755
index d63a793..df5418a
--- a/usr/scripts/tgt-setup-lun
+++ b/usr/scripts/tgt-setup-lun
@@ -103,6 +103,19 @@ find_vacant_lun()
return $next_vacant_lun
}
+err_exit()
+{
+ echo "Deleting the new target"
+ tgtadm --lld iscsi --op delete --mode target --tid $tid
+ res=$?
+
+ if [ $res -ne 0 ]; then
+ echo "Error: could not delete a target"
+ fi
+
+ exit 1
+}
+
while getopts "d:n:" opt
do
case ${opt} in
@@ -137,6 +150,12 @@ tid=$?
# Create the new target
echo "Creating the new target ($tgt_name)"
tgtadm --lld iscsi --op new --mode target --tid $tid -T $tgt_name
+res=$?
+
+if [ $res -ne 0 ]; then
+ echo "Error: could not create a target"
+ exit 1
+fi
find_vacant_lun $tid
lun=$?
@@ -144,6 +163,12 @@ lun=$?
# Add 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
+res=$?
+
+if [ $res -ne 0 ]; then
+ echo "Error: could not add a logical unit to the target"
+ err_exit
+fi
# Define which initiators can use this target
if test "$initiators" ; then
@@ -151,9 +176,21 @@ if test "$initiators" ; then
echo "Accepting connections only from $initiators"
for initiator in $initiators; do
tgtadm --lld iscsi --op bind --mode target --tid $tid -I $initiator
+ res=$?
+
+ if [ $res -ne 0 ]; then
+ echo "Error: could not assign an initiator to the target"
+ err_exit
+ fi
done
else
# Allow access for everyone
echo "Accepting connections from every initiator"
tgtadm --lld iscsi --op bind --mode target --tid $tid -I ALL
+ res=$?
+
+ if [ $res -ne 0 ]; then
+ echo "Error: could not assign initiators to the target"
+ err_exit
+ fi
fi
--
1.5.3.7
More information about the stgt
mailing list