[stgt] [PATCH 2/3] tgt-setup-lun: only delete new target on err when one was created

Andy Grover agrover at redhat.com
Thu Mar 10 01:51:02 CET 2011


See https://bugzilla.redhat.com/show_bug.cgi?id=676337 .

This patch only deletes the new target if the target was created
by tgt-setup-lun.

Signed-off-by: Andy Grover <agrover at redhat.com>
---
 scripts/tgt-setup-lun |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/scripts/tgt-setup-lun b/scripts/tgt-setup-lun
index 2685095..9fef7f9 100755
--- a/scripts/tgt-setup-lun
+++ b/scripts/tgt-setup-lun
@@ -120,6 +120,10 @@ find_vacant_lun()
 
 err_exit()
 {
+	if ((new_tgt == 0)); then
+		exit 1
+	fi
+
 	echo "Deleting new target, tid=$tid"
 	tgtadm --lld $lld_name --op delete --mode target --tid $tid
 	res=$?
@@ -196,6 +200,7 @@ if [ $? -eq 1 ]; then
 	fi
 	tid=$(tgtadm --lld $lld_name --op show --mode target | grep $tgt_name | cut -d" " -f2)
 	tid=${tid%:}
+	new_tgt=0
 else
 	find_vacant_tgt_id
 	tid=$?
@@ -209,6 +214,7 @@ else
 		echo "Error: failed to create target (name=$tgt_name, tid=$tid)"
 		exit 1
 	fi
+	new_tgt=1
 fi
 
 find_vacant_lun $tid
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html



More information about the stgt mailing list