powerpc-utils/SOURCES/0001-ofpathname-Use-NVMe-co...

79 lines
2.4 KiB
Diff

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