File ofpathname-Fix-several-issues-in-nvmf-boot-install-s.patch of Package powerpc-utils

From 2fbd7c1ff428e534d80f60e03501d625ab594eca Mon Sep 17 00:00:00 2001
From: Wen Xiong <wenxiong@linux.ibm.com>
Date: Wed, 15 Jun 2022 13:05:51 -0500
Subject: [PATCH] ofpathname: Fix several issues in nvmf boot/install support

Patch-mainline: accepted, expected in 1.3.11
Git-commit: 2fbd7c1ff428e534d80f60e03501d625ab594eca

This patch fixes several issues in boot/install over nvme-over-fc
device support.

- change cntlid to ffff
- add devnisd from sysfs
- add subsysnqn

Signed-off-by: Wen Xiong <wenxiong@linux.ibm.com>
Signed-off-by: Tyrel Datwyler <tyreld@linux.ibm.com>
---
 scripts/ofpathname | 38 +++++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 13 deletions(-)

diff --git a/scripts/ofpathname b/scripts/ofpathname
index b1d6b09..33d7702 100755
--- a/scripts/ofpathname
+++ b/scripts/ofpathname
@@ -773,8 +773,7 @@ l2of_nvmf()
             t_wwpn="${t_wwpn#0x}"
             t_wwpn="${t_wwpn%,*}"
             nqn=`$CAT $PWD/subsysnqn`
-            cntlid_dec=`$CAT $PWD/cntlid`
-            cntlid=`echo "obase=16; $cntlid_dec" |bc`
+            cntlid=`echo ffff`
             if [[ -n $h_wwpn ]]; then
                 for f in `$FIND /sys/devices -name "port_name"`; do
                     sys_wwpn=`$CAT $f 2>/dev/null`
@@ -808,6 +807,9 @@ l2of_nvmf()
         if [[ ${#res} = 0 ]]; then
             OF_PATH=""
         else
+            goto_dir $res
+            devnsid=`$CAT $PWD/nsid | tr -d '\000'`
+            devnsid=`echo "obase=16; $devnsid" |bc`
             OF_PATH="$OF_PATH/namespace@$devnsid"
         fi
     fi
@@ -818,6 +820,8 @@ l2of_nvmf()
         if [[ ${#res} = 0 ]]; then
             OF_PATH=""
         else
+            goto_dir $res
+            devpart=`$CAT $PWD/partition | tr -d '\000'`
             OF_PATH="${OF_PATH}:${devpart}"
         fi
     fi
@@ -1826,8 +1830,7 @@ of2l_nvmf()
     ctrl_name=`echo $DEVNAME | cut -d "/" -f 5`
     OF_WWPN=${ctrl_name%,*}
     OF_WWPN=${OF_WWPN#*@}
-    of_cntlid=${ctrl_name%%:*}
-    of_cntlid=${of_cntlid#*,}
+    OF_NQN=`echo $ctrl_name | cut -d "=" -f 2`
     # set partition number only if ':' is present
     case "${nsid_part}" in
     *:*)
@@ -1835,6 +1838,7 @@ of2l_nvmf()
         ;;
     esac
     local dir
+    local found=0
 
     for dir in `$FIND /sys/devices/virtual/nvme-fabrics -name "nvme[0-9]*"`; do
         cd $dir
@@ -1844,10 +1848,9 @@ of2l_nvmf()
             t_wwpn="${t_wwpn%,*}"
             h_wwpn=`$CAT $PWD/address | cut  -f 5 -d "-"`
             h_wwpn="${h_wwpn#0x}"
-            cntlid_dec=`$CAT $PWD/cntlid 2>/dev/null`
-            cntlid=`echo "obase=16; $cntlid_dec" |bc`
+            nqn=`$CAT $PWD/subsysnqn`
             if [[ $t_wwpn = $OF_WWPN ]] && \
-                [[ $cntlid == $of_cntlid ]]; then
+                [[ $nqn == $OF_NQN ]]; then
                 for f in `$FIND /sys/devices -name "port_name"`; do
                     sys_wwpn=`$CAT $f 2>/dev/null`
                     sys_wwpn="${sys_wwpn#0x}"
@@ -1871,14 +1874,23 @@ of2l_nvmf()
             fi
         fi
     done
+
     if [[ -n $LOGICAL_DEVNAME ]] && \
        [[ -n $nsid ]]; then
-        res=`$FIND /sys/devices/virtual -name ${LOGICAL_DEVNAME}n${nsid}`
-        if [[ ${#res} = 0 ]]; then
-            LOGICAL_DEVNAME=''
-        else
-            LOGICAL_DEVNAME="${LOGICAL_DEVNAME}n${nsid}"
-        fi
+        for dir in `$FIND /sys/block -name "${LOGICAL_DEVNAME}n[0-9]*"`; do
+            cd $dir
+
+            local devnsid=`$CAT ./nsid 2>/dev/null`
+            devnsid=`echo "obase=16; $devnsid" |bc`
+            if [[ $devnsid = $nsid ]]; then
+                found=1
+                LOGICAL_DEVNAME="${dir##*/}"
+                break
+            fi
+        done
+    	 if [[ $found -eq 0 ]]; then
+            LOGICAL_DEVNAME=""
+         fi
     fi
 
     if [[ -n $LOGICAL_DEVNAME ]] && \
-- 
2.38.0

openSUSE Build Service is sponsored by