[stgt] [PATCH 2/2] tgt-admin: check if device is mounted on /

Doron Shoham dorons at Voltaire.COM
Mon Sep 1 15:16:11 CEST 2008


check if device is mounted on / before allocating it


Signed-off-by: Doron Shoham <dorons at voltaire.com>
---
 scripts/tgt-admin |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/scripts/tgt-admin b/scripts/tgt-admin
index 22c4725..9a3d304 100755
--- a/scripts/tgt-admin
+++ b/scripts/tgt-admin
@@ -270,16 +270,20 @@ sub process_options {
 		}
 		my @value_arr = @$value;
 		my $i = 1;
+		my $local_device = `mount |grep -w "on /"`;
+		if ($local_device =~ /(\/dev\/sd\w*)/) {
+			$local_device = $1;
+		}
 
 		foreach my $backing_store (@value_arr) {
-			# Check if device exists
-			if ( -e $backing_store) {
+			# Check if device exists and it is not mounted on /
+			if ( ( -e $backing_store) && ( $backing_store != $local_device) ) {
 				execute("tgtadm --lld $driver --op new --mode logicalunit --tid $next_tid --lun $i -b $backing_store");
 				$i += 1;
 			}
 			else {
 				print("skipping device $backing_store\n");
-				print("$backing_store does not exist - please check the configuration file\n");
+				print("$backing_store does not exist or is mounted on / - please check the configuration file\n");
 			}
 		}
 	}
@@ -296,9 +300,14 @@ sub process_options {
 		}
 		my @value_arr = @$value;
 		my $i = 1;
+		my $local_device = `mount |grep -w "on /"`;
+		if ($local_device =~ /(\/dev\/sd\w*)/) {
+			$local_device = $1;
+		}
+
 		foreach my $direct_store (@value_arr) {
-			# Check if device exists
-			if ( -e $direct_store) {
+			# Check if device exists and it is not mounted on /
+			if ( ( -e $direct_store) && ( $direct_store != $local_device) ) {
 				$inq=`sg_inq $direct_store`;
 				if ($inq=~/Vendor identification:\s*(\w+)\s*\n*Product identification:\s*([\w\s\/\-]+)\n\s*\n*Product revision level:\s*(\w*)\s*\n*Unit serial number:\s*(\w+)/)
 				{
@@ -318,7 +327,7 @@ sub process_options {
 			}
 			else {
 				print("skipping device $direct_store\n");
-				print("$direct_store does not exist - please check the configuration file\n");
+				print("$direct_store does not exist or is mounted on / - please check the configuration file\n");
 			}
 		}
 	}
-- 
1.5.3.8


--
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