Subject: [PATCH] [BZ 161888] lsluns: do not scan (all) if filters match nothing
From: Jens Remus <jremus@linux.vnet.ibm.com>

Description:  lsluns: Fix filter handling and documentation enhancements.
Symptom:      lsluns lists all LUNs discovered in the FC SAN despite user
              given filter(s) that do not match anything:
                # lsluns -c 0.0.5080
                    No valid combination found for adapter '0.0.5080'. Removing
                    from resource list.
                No valid parameters left, using all available resources in
                system.
                Scanning for LUNs on adapter 0.0.5090
                ...

              lsluns prints the message "No valid combination found for
              {adapter|port} '...'. Removing from resource list." for every
              adapter and port filter that does not contribute to the final
              filtered results.

              The formatting of the lsluns (8) man page is flawed.

              lsluns is used in unexpected or even unsupported ways.
Problem:      Scanning can be resource consumptive. So if a user already wants
              to filter, possibly to reduce resource consumption, he does not
              want to happen to scan everything and thus consume the worst case
              of resources.

              The message "No valid combination found for {adapter|port} '...'.
              Removing from resource list." is potentially confusing. It is
              unclear which combination is being referred to, especially if
              only one single adapter or port filter was specified. There is
              also no differentiation whether the denoted adapter or port
              exists for its own or not. It just does not exist in the final
              filtered results.

              The formatting of the lsluns (8) man page is flawed.

              The lsluns usage text and lsluns (8) man page lack the
              information on the intended use cases, requirements, and
              restrictions.
Solution:     Print a message and exit when all filters match nothing.

              Do not print confusing messages when a filter matches nothing.

              Fix man page formatting.

              Enhance usage text and man page. Clarify discovery use case,
              relation to NPIV and to zfcp auto LUN scan. Point out
              IBM Storwize configuration requirements. Document restriction to
              zfcp-only systems.
Reproduction: Use lsluns and specify adapter bus-ID and/or target port WWPN
              filter(s) that do not match anything. Either specify inexistent
              bus-IDs and/or WWPNs or invalid filter arguments.
Upstream-ID:  398f9ceac8c20705f573671bde4bc482967f5c13
Problem-ID:   161888

Upstream-Description:

              lsluns: do not scan (all) if filters match nothing

              Fix the following undesired behavior of lsluns to scan all resources if the
              user provided filters did not match anything:

                  No valid combination found for adapter '5080'. Removing from resource
                  list.
              No valid parameters left, using all available resources in system.
              Scanning for LUNs on adapter 0.0.5080
              ...

              Scanning can be resource consumptive. So if a user already wants to filter,
              possibly to reduce resource consumption, he does not want to happen to scan
              everything and thus consume the worst case of resources.

              Instead print a message to inform the user why nothing was scanned.

              Reported-by: Steffen Maier <maier@linux.vnet.ibm.com>
              Signed-off-by: Jens Remus <jremus@linux.vnet.ibm.com>
              Reviewed-by: Steffen Maier <maier@linux.vnet.ibm.com>
              Reviewed-by: Benjamin Block <bblock@linux.vnet.ibm.com>
              Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>


Signed-off-by: Jens Remus <jremus@linux.vnet.ibm.com>
---
 zconf/lsluns |   12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

--- a/zconf/lsluns
+++ b/zconf/lsluns
@@ -3,7 +3,7 @@
 ###############################################################################
 # Script to list all available LUNs.
 #
-# Copyright IBM Corp. 2008, 2015.
+# Copyright IBM Corp. 2008, 2017.
 #
 # Author(s): Martin Petermann <martin@linux.vnet.ibm.com>
 #            Swen Schillig    <swen@vnet.ibm.com>
@@ -203,7 +203,7 @@ EOD
 
 sub lsluns_version {
     print "$PROGRAM_NAME: version %S390_TOOLS_VERSION%\n";
-    print "Copyright IBM Corp. 2008\n";
+    print "Copyright IBM Corp. 2008, 2017\n";
 }
 
 sub lsluns_invalid_usage {
@@ -221,7 +221,6 @@ sub get_env_list
 
     @res = </sys/bus/ccw/drivers/zfcp/*.*.*/0x*>;
     return () if (!@res);
-reload:
     foreach my $entry (@res) {
         my $a = ${[split('/', $entry)]}[-2];
         my $p = ${[split('/', $entry)]}[-1];
@@ -245,12 +244,7 @@ reload:
     }
 
     if (!%res_hash) {
-        print "\nNo valid parameters left, ",
-        "using all available resources in system.\n\n";
-        @$a_ref_list = ();
-        @$p_ref_list = ();
-        @t_arr = ();
-        goto reload;
+        print "$PROGRAM_NAME: Adapter and/or port filter(s) did not match anything\n";
     }
     return %res_hash;
 }
