f30d899
From 21c860888425762468d339950518ab8b0940ecea Mon Sep 17 00:00:00 2001
f30d899
From: Tyrel Datwyler <tyreld@linux.ibm.com>
f30d899
Date: Mon, 5 Oct 2020 13:03:45 -0700
f30d899
Subject: [PATCH] ofpathname: Use NVMe controller physical nsid
f30d899
f30d899
Linux creates logical block devices of the the form nvmeXnYpZ such that X = the
f30d899
controller, Y = namepsace, and Z = partition. For example:
f30d899
f30d899
/dev/nvme0n1p1
f30d899
f30d899
The Linux namespace numbering scheme for namespaces always starts at 1 and
f30d899
increases monotonically regardless of the actual numbering scheme of the
f30d899
namespaces as seen by the  physical NVMe controller. Accordingly, the Open
f30d899
firmware path binding utilizes the namespace id as seen by the controller and
f30d899
not the necessarily the one given in the logical block device name.
f30d899
f30d899
As such we need to use the "nsid" attribute in the sysfs entry for the logical
f30d899
device to properly map back and forth from OP pathnames.
f30d899
f30d899
Signed-off-by: Tyrel Datwyler <tyreld@linux.ibm.com>
f30d899
---
f30d899
 scripts/ofpathname | 24 ++++++++++++++++--------
f30d899
 1 file changed, 16 insertions(+), 8 deletions(-)
f30d899
f30d899
diff --git a/scripts/ofpathname b/scripts/ofpathname
f30d899
index 2ceae25..41b8c5c 100755
f30d899
--- a/scripts/ofpathname
f30d899
+++ b/scripts/ofpathname
f30d899
@@ -659,6 +659,11 @@ l2of_nvme()
f30d899
         devspec=`$CAT $PWD/device/devspec | tr -d '\000'`
f30d899
         if [[ -n $devspec ]]; then
f30d899
             found=1
f30d899
+            if [[ -n $devnsid ]]; then
f30d899
+                # Linux logical nsid might not match nvme controller nsid
f30d899
+                goto_dir $dir "nsid"
f30d899
+                devnsid=`$CAT $PWD/nsid | tr -d '\000'`
f30d899
+            fi
f30d899
             break
f30d899
         fi
f30d899
     done
f30d899
@@ -1609,16 +1614,9 @@ of2l_nvme()
f30d899
     local dir
f30d899
     local link
f30d899
 
f30d899
-    for dir in `$FIND /sys/block -name "nvme*n$nsid"`; do
f30d899
+    for dir in `$FIND /sys/class/nvme -name "nvme[0-9]*"`; do
f30d899
         cd $dir
f30d899
 
f30d899
-        link=`get_link "device"` # points to nvme[0-9]+ (non-namespace)
f30d899
-        if [[ -n $link ]]; then
f30d899
-            cd $link
f30d899
-        else
f30d899
-            continue
f30d899
-        fi
f30d899
-
f30d899
         link=`get_link "device"` # points to pci address dir
f30d899
         if [[ -n $link ]]; then
f30d899
             cd $link
f30d899
@@ -1635,6 +1633,16 @@ of2l_nvme()
f30d899
         fi
f30d899
     done
f30d899
 
f30d899
+    for dir in `$FIND /sys/block -name "${LOGICAL_DEVNAME}n[0-9]*"`; do
f30d899
+	    cd $dir
f30d899
+
f30d899
+	    local devnsid=`$CAT ./nsid 2>/dev/null`
f30d899
+	    if [[ $devnsid = $nsid ]]; then
f30d899
+		    LOGICAL_DEVNAME="${dir##*/}"
f30d899
+		    break
f30d899
+	    fi
f30d899
+    done
f30d899
+
f30d899
     if [[ -n $LOGICAL_DEVNAME ]] \
f30d899
     && [[ -n $part ]]; then
f30d899
 
f30d899
-- 
f30d899
1.8.3.1
f30d899