File 0161-95zfcp_rules-simplified-rd.zfcp-commandline-for-NPIV.patch of Package dracut.4068

From 61d345654fbdd895a406a5a7517f01a7c984a7ed Mon Sep 17 00:00:00 2001
From: Hannes Reinecke <hare@suse.de>
Date: Thu, 10 Mar 2016 15:45:43 +0100
Subject: [PATCH] 95zfcp_rules: simplified rd.zfcp commandline for NPIV

When NPIV is enabled and the allow_lun_scan parameter is set to 'Y'
the HBA will initiate a LUN scan automatically, so there is no need
to specify the WWPN and LUN number manually.

References: bsc#964456

Signed-off-by: Hannes Reinecke <hare@suse.com>
---
 dracut.cmdline.7.asc                   |  9 ++++++++-
 modules.d/95zfcp_rules/module-setup.sh | 23 +++++++++++++++++++----
 modules.d/95zfcp_rules/parse-zfcp.sh   |  1 +
 3 files changed, 28 insertions(+), 5 deletions(-)

Index: dracut-044/dracut.cmdline.7.asc
===================================================================
--- dracut-044.orig/dracut.cmdline.7.asc	2016-04-12 15:48:42.072804543 +0200
+++ dracut-044/dracut.cmdline.7.asc	2016-04-12 15:48:46.869076048 +0200
@@ -771,12 +771,19 @@ DASD
 ZFCP
 ~~~~
 **rd.zfcp=**__<zfcp adaptor device bus ID>__,__<WWPN>__,__<FCPLUN>__::
-    rd.zfcp can be specified multiple times on the kernel command line.
+    rd.zfcp can be specified multiple times on the kernel command
+    line.
+
+**rd.zfcp=**__<zfcp adaptor device bus ID>__::
+    If NPIV is enabled and the 'allow_lun_scan' parameter to the zfcp
+    module is set to 'Y' then the zfcp adaptor will be initiating a
+    scan internally and the <WWPN> and <FCPLUN> parameters can be omitted.
 +
 [listing]
 .Example
 --
 rd.zfcp=0.0.4000,0x5005076300C213e9,0x5022000000000000
+rd.zfcp=0.0.4000
 --
 
 **rd.zfcp.conf=0**::
Index: dracut-044/modules.d/95zfcp_rules/module-setup.sh
===================================================================
--- dracut-044.orig/modules.d/95zfcp_rules/module-setup.sh	2016-04-12 15:48:42.072804543 +0200
+++ dracut-044/modules.d/95zfcp_rules/module-setup.sh	2016-04-12 15:48:46.869076048 +0200
@@ -5,15 +5,30 @@ cmdline() {
     is_zfcp() {
         local _dev=$1
         local _devpath=$(cd -P /sys/dev/block/$_dev ; echo $PWD)
-        local _sdev _lun _wwpn _ccw
+        local _sdev _scsiid _hostno _lun _wwpn _ccw _port_type
+        local _allow_lun_scan _is_npiv
 
+        _allow_lun_scan=$(cat /sys/module/zfcp/parameters/allow_lun_scan)
         [ "${_devpath#*/sd}" == "$_devpath" ] && return 1
         _sdev="${_devpath%%/block/*}"
         [ -e ${_sdev}/fcp_lun ] || return 1
-        _lun=$(cat ${_sdev}/fcp_lun)
-        _wwpn=$(cat ${_sdev}/wwpn)
+        _scsiid="${_sdev##*/}"
+        _hostno="${_scsiid%%:*}"
+        [ -d /sys/class/fc_host/host${_hostno} ] || return 1
+        _port_type=$(cat /sys/class/fc_host/host${_hostno}/port_type)
+        case "$_port_type" in
+            NPIV*)
+                _is_npiv=1
+                ;;
+        esac
         _ccw=$(cat ${_sdev}/hba_id)
-        echo "rd.zfcp=${_ccw},${_wwpn},${_lun}"
+        if [ "$_is_npiv" ] && [ "$_allow_lun_scan" = "Y" ] ; then
+            echo "rd.zfcp=${_ccw}"
+        else
+            _lun=$(cat ${_sdev}/fcp_lun)
+            _wwpn=$(cat ${_sdev}/wwpn)
+            echo "rd.zfcp=${_ccw},${_wwpn},${_lun}"
+        fi
         return 0
     }
     [[ $hostonly ]] || [[ $mount_needs ]] && {
Index: dracut-044/modules.d/95zfcp_rules/parse-zfcp.sh
===================================================================
--- dracut-044.orig/modules.d/95zfcp_rules/parse-zfcp.sh	2016-04-12 15:48:42.072804543 +0200
+++ dracut-044/modules.d/95zfcp_rules/parse-zfcp.sh	2016-04-12 15:48:46.869076048 +0200
@@ -31,6 +31,7 @@ ACTION=="add", SUBSYSTEM=="drivers", KER
 ACTION=="add", ENV{COLLECT_$ccw}=="0", ATTR{[ccw/$ccw]online}="1"
 EOF
     fi
+    [ -z "$wwpn" -o -z "$lun" ] && return
     m=$(sed -n "/.*${wwpn}.*${lun}.*/p" $_rule)
     if [ -z "$m" ] ; then
         cat >> $_rule <<EOF
openSUSE Build Service is sponsored by