[Stgt-devel] [PATCH] tgt-admin: support persistent device binding
Doron Shoham
dorons
Mon Jul 28 11:26:49 CEST 2008
sync this patch with the current git.
The man page already have an example for using
direct-device.
I'll send a patch with an example of using
serial number instead of /dev/sdX after this
patch will be applied.
Tomo - can u please explain me how to use
git-am for checking my patches?
I use checkpatch.pl script to check my patches.
Thanks,
Doron
Signed-off-by: Doron Shoham <dorons at voltaire.com>
---
doc/manpages/tgt-admin.8 | 3 ++
scripts/tgt-admin | 64 ++++++++++++++++++++++++++++++++++-----------
2 files changed, 51 insertions(+), 16 deletions(-)
diff --git a/doc/manpages/tgt-admin.8 b/doc/manpages/tgt-admin.8
index 97d6484..5598932 100644
--- a/doc/manpages/tgt-admin.8
+++ b/doc/manpages/tgt-admin.8
@@ -85,6 +85,9 @@ example for a configuration file:
<target iqn.2007-02.com.example:san.xen1>
backing-store /dev/san/xen1-disk1 # LUN1
direct-store /dev/san/xen1-disk2 # LUN2
+ # for persistent binding use scsi serial number
+ backing-store 00c0ffd508d70048ed1dbc4704000000 #LUN3
+ direct-store 00c0ffd508d70048ed1dbc4704000001 # LUN4
initiator-address 192.168.1.2 # Allowed IP
initiator-address 192.168.5.6 # Allowed IP
diff --git a/scripts/tgt-admin b/scripts/tgt-admin
index 598bfb1..6c285c9 100755
--- a/scripts/tgt-admin
+++ b/scripts/tgt-admin
@@ -73,6 +73,22 @@ if ($show == 1) {
exit;
}
+# Create a hash of all the scsi id and their mapped devices
+my %sn_hash=();
+sub map_devices {
+ my @sd_list=();
+ my $sg_list=`sg_map -i -x`;
+ while ($sg_list=~/(\/dev\/sd\w)/sgi) {
+ push(@sd_list,$1);
+ }
+ foreach my $sd (@sd_list) {
+ my $inq=`sg_inq $sd`;
+ if ($inq=~/Unit serial number:\s*(\w+)/) {
+ $sn_hash{$1}=$sd;
+ }
+ }
+}
+
# Check if alternative configuration file was given
if ($alternate_conf ne 0) {
# Check if alternative configuration file exist
@@ -136,14 +152,19 @@ sub add_targets {
# Process options from the config file
sub process_options {
+ &map_devices;
if ( $option eq "backing-store" ) {
- # if we have one command, force it to be an array anyway
+ # if we have one command, force it to be an array anyway
unless (ref($value) eq 'ARRAY') {
$value = [ $value ];
}
my @value_arr = @$value;
my $i = 1;
foreach my $backing_store (@value_arr) {
+ # Check if a serial number was given
+ if ($backing_store!~/\/dev\//) {
+ $backing_store=$sn_hash{$backing_store};
+ }
# Check if device exists
if ( -e $backing_store) {
execute("tgtadm --lld iscsi --op new --mode logicalunit --tid $next_tid --lun $i -b $backing_store");
@@ -169,22 +190,33 @@ sub process_options {
my @value_arr = @$value;
my $i = 1;
foreach my $direct_store (@value_arr) {
- $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+)/)
- {
- $vendor_id="$1";
- $prod_id="$2";
- $prod_rev="$3";
- $scsi_serial="$4";
+ # Check if a serial number was given
+ if ($direct_store!~/\/dev\//) {
+ $direct_store=$sn_hash{$direct_store};
+ }
+ # Check if device exists
+ if ( -e $direct_store) {
+ $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+)/)
+ {
+ $vendor_id="$1";
+ $prod_id="$2";
+ $prod_rev="$3";
+ $scsi_serial="$4";
+ }
+ $vendor_id =~ s/\s+$//;
+ $prod_id =~ s/\s+$//;
+ $prod_rev =~ s/\s+$//;
+ $scsi_serial =~ s/\s+$//;
+
+ execute("tgtadm --lld iscsi --op new --mode logicalunit --tid $next_tid --lun 1 -b $direct_store");
+ execute("tgtadm --lld iscsi --op update --mode logicalunit --tid $next_tid --lun 1 --params vendor_id=\"$vendor_id\",product_id=\"$prod_id\",product_rev=\"$prod_rev\",scsi_sn=\"$scsi_serial\"");
+ $i += 1;
+ }
+ else {
+ print("skipping device $direct_store\n");
+ print("$direct_store does not exist - please check the configuration file\n");
}
- $vendor_id =~ s/\s+$//;
- $prod_id =~ s/\s+$//;
- $prod_rev =~ s/\s+$//;
- $scsi_serial =~ s/\s+$//;
-
- execute("tgtadm --lld iscsi --op new --mode logicalunit --tid $next_tid --lun 1 -b $direct_store");
- execute("tgtadm --lld iscsi --op update --mode logicalunit --tid $next_tid --lun 1 --params vendor_id=\"$vendor_id\",product_id=\"$prod_id\",product_rev=\"$prod_rev\",scsi_sn=\"$scsi_serial\"");
- $i += 1;
}
}
--
1.5.3.8
More information about the stgt
mailing list