[stgt] [PATCH 4/4] tgt-admin: Base blocksize & params on backing store if direct-store

Andy Grover agrover at redhat.com
Fri Jan 6 01:53:56 CET 2012


Use sg_inq and sg_readcap to read properties of backing device for
direct-store LUNs. Pass these values to tgtadm so the exported LUN can
match its backstore.
---
 scripts/tgt-admin |   36 +++++++++++++++++++++++++++++++++++-
 1 files changed, 35 insertions(+), 1 deletions(-)

diff --git a/scripts/tgt-admin b/scripts/tgt-admin
index 6a14446..6889280 100755
--- a/scripts/tgt-admin
+++ b/scripts/tgt-admin
@@ -544,6 +544,7 @@ sub add_backing_direct {
 			}
 			# Used only if lun is a direct-store
 			my $sg_inq;
+			my $sg_readcap;
 			my %direct_params;
 			if ($direct_store == 1) {
 				$sg_inq=`sg_inq $backing_store`;
@@ -568,6 +569,38 @@ sub add_backing_direct {
 						$direct_params{scsi_sn} = $4;
 					}
 				}
+
+				$sg_inq=`sg_inq -p 0xb0 $backing_store`;
+				if ($sg_inq=~m {
+					Optimal\ transfer\ length\ granularity:\s+?(\d+).*?\n
+					\s+Maximum\ transfer\ length:\s+?(\d+).*?\n
+					\s+Optimal\ transfer\ length:\s+?(\d+).*?\n
+					}xs ) {
+					if (not length $$target_options_ref{optimal_xfer_gran}) {
+						$direct_params{optimal_xfer_gran} = $1;
+					}
+					# $2 unused
+					if (not length $$target_options_ref{optimal_xfer_len}) {
+						$direct_params{optimal_xfer_len} = $3;
+					}
+				}
+
+				$sg_readcap=`sg_readcap -16 $backing_store`;
+				if ($sg_readcap=~ m {
+					Logical\ block\ length=(\d+).*?\n
+					\s+Logical\ blocks\ per\ physical\ block\ exponent=(\d+).*?\n
+					\s+Lowest\ aligned\ logical\ block\ address=(\d+).*?\n
+					}xs) {
+					if (not length $block_size) {
+						$block_size = $1;
+					}
+					if (not length $$target_options_ref{lbppbe}) {
+						$direct_params{lbppbe} = $2;
+					}
+					if (not length $$target_options_ref{la_lba}) {
+						$direct_params{la_lba} = $3;
+					}
+				}
 			}
 
 			# Add these parameters if they were not overwritten in the config file
@@ -581,7 +614,8 @@ sub add_backing_direct {
 				}
 			}
 			# These options can be fetched by sg_inq for direct-store
-			my @opts = ("vendor_id", "product_id", "product_rev", "scsi_sn");
+			my @opts = ("vendor_id", "product_id", "product_rev", "scsi_sn",
+				    "lbppbe", "la_lba", "optimal_xfer_gran", "optimal_xfer_len");
 			foreach my $single_opt (@opts) {
 				check_if_hash_array($$target_options_ref{$single_opt},$single_opt);
 				my $this_opt;
-- 
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