File s390-tools-sles11sp2-lsluns-fix-checks-for-sg.patch of Package s390-tools

Subject: [PATCH] [BZ 81636] lsluns: Fix checks for scsi generic (sg) functionality.
From: Seshagiri N Ippili <seshagiri.ippili@in.ibm.com>

Description: lsluns: Fix checks for scsi generic (sg) functionality.
Symptom:     lsluns fails, to list available luns and to show attached luns
             with option "-a".
Problem:     lsluns checks for sg functionality before scanning available
             luns or showing attached luns.
Solution:    Remove early sg availability check.
             Allow lsluns to execute first, to add LUN0 & WLUN with unit_add
             to report available luns. unit_add triggers sg to load via scsi
             mid layer. Check for sg functionality after LUN scan attempt.
             Check for the availability of sg functionality to show attached
             luns only if there is at least one scsi device.
Problem-ID:  81636
---
 zconf/lsluns |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

--- a/zconf/lsluns
+++ b/zconf/lsluns
@@ -15,6 +15,7 @@ use warnings;
 use English;
 use Getopt::Long;
 use File::Basename;
+use File::Glob;
 
 my %res_hash = ();
 my @adapter = ();
@@ -23,13 +24,13 @@ my $active = "";
 
 my $wlun = "0xc101000000000000";
 my $lun0 = "0x0000000000000000";
+my $sg_dir = "/sys/class/scsi_generic";
 
 
 sub list_luns
 {
     my %lun_hash = get_lun_hash();
     my $drv_dir = "/sys/bus/ccw/drivers/zfcp";
-    my $sg_dir = "/sys/class/scsi_generic";
     my $man_att;
 
     foreach my $a (sort keys %res_hash) {
@@ -89,6 +90,9 @@ sub list_luns
 		last if ($retries > 3);
 	    }
         }
+        if (! -d $sg_dir) {
+        	print "$PROGRAM_NAME: Error: Please load/configure SCSI Generic (sg) to use $PROGRAM_NAME.\n";
+        }
     }
 }
 
@@ -98,7 +102,7 @@ sub get_lun_hash
 {
     my %lun_hash;
 
-    foreach my $device (</sys/class/scsi_generic/sg*>) {
+    foreach my $device (</$sg_dir/sg*>) {
         my $l = `cat $device/device/fcp_lun`;
         my $p = `cat $device/device/wwpn`;
         my $a = `cat $device/device/hba_id`;
@@ -207,6 +211,9 @@ sub show_attached_lun_info
                    "CD/DVD", "Scanner", "OMD", "Changer","Comm","n/a",
                    "n/a","RAID", "Encl");
 
+        if (glob("/sys/class/scsi_device/*") && (! -d $sg_dir)) {
+        	print "$PROGRAM_NAME: Error: Please load/configure SCSI Generic (sg) to use $PROGRAM_NAME.\n";
+        }
         foreach my $a (sort keys %lun_hash) {
                 next if ("@adapter" !~ /$a/);
                 print "adapter = $a\n";
@@ -271,8 +278,6 @@ push @port, map { @{$res_hash{$_}} } key
 die "$PROGRAM_NAME: Unable to execute due to missing sg3_utils package. ".
     "Processing stopped.\n" if system("sg_luns -V > /dev/null 2>&1");
 
-die "$PROGRAM_NAME: Error: SCSI generic (sg) functionality is required. ".
-    "Please load/configure sg to use $PROGRAM_NAME.\n" if (! -d "/sys/class/scsi_generic");
 
 if ($active) {
         show_attached_lun_info();
openSUSE Build Service is sponsored by