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

Tomasz Chmielewski mangoo at wpkg.org
Mon Sep 1 15:27:16 CEST 2008


Doron Shoham schrieb:
> 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 /"`;

Instead of executing an external mount command we could do everything in 
perl - read /proc/mounts and parse it.


> +		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");

"is mounted on /" won't be very accurate if the device is mounted on 
/mnt/blah.


>  			}
>  		}
>  	}
> @@ -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;

/dev/hd* can be also local (used by legacy IDE). /dev/xvd* can be also 
local (used by Xen). mtd devices can be also local (although I doubt 
anyone would use them as targets).


> +		}
> +
>  		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");
>  			}
>  		}
>  	}



-- 
Tomasz Chmielewski
http://wpkg.org
--
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