]> git.proxmox.com Git - pve-storage.git/commitdiff
Fix #2020: use /sys to map nvmeXnY to nvmeX
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 10 Dec 2018 13:17:06 +0000 (14:17 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 10 Dec 2018 13:54:11 +0000 (14:54 +0100)
`nvmeX` devices nodes are apparently allocated independently
from their namespace block devices `nvmeXnY` and therefore
they are not strictly related by name. For instance:
  $ readlink /sys/block/nvme0n1/device
  ../../nvme1
  $ readlink /sys/block/nvme1n1/device
  ../../nvme0

Here /dev/nvme0n1 is the first namespace of /dev/nvme1 while
/dev/nvme1n1 is the first namespace of /dev/nvme0.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
PVE/Diskmanage.pm
test/disk_tests/nvme_smart/nvme0/model [new file with mode: 0644]
test/disk_tests/nvme_smart/nvme0n1/device [new symlink]
test/disk_tests/nvme_smart/nvme0n1/device/model [deleted file]

index def0791d720ba5d3430a0a8d31465e703b72fe64..854f0a5bfa43bb84153197c52abaae31c17c3597 100644 (file)
@@ -79,8 +79,11 @@ sub get_smart_data {
 
     my $returncode = 0;
 
-    $disk =~ s/n\d+$//
-        if $disk =~ m!^/dev/nvme\d+n\d+$!;
+    if ($disk =~ m!^/dev/(nvme\d+n\d+)$!) {
+       my $info = get_sysdir_info("/sys/block/$1");
+       $disk = "/dev/".($info->{device}
+           or die "failed to get nvme controller device for $disk\n");
+    }
 
     my $cmd = [$SMARTCTL, '-H'];
     push @$cmd, '-A', '-f', 'brief' if !$healthonly;
@@ -306,6 +309,11 @@ sub get_sysdir_info {
     $data->{vendor} = file_read_firstline("$sysdir/device/vendor") || 'unknown';
     $data->{model} = file_read_firstline("$sysdir/device/model") || 'unknown';
 
+    if (defined(my $device = readlink("$sysdir/device"))) {
+       # strip directory and untaint:
+       ($data->{device}) = $device =~ m!([^/]+)$!;
+    }
+
     return $data;
 }
 
diff --git a/test/disk_tests/nvme_smart/nvme0/model b/test/disk_tests/nvme_smart/nvme0/model
new file mode 100644 (file)
index 0000000..9bd6eba
--- /dev/null
@@ -0,0 +1 @@
+NVME MODEL 1
diff --git a/test/disk_tests/nvme_smart/nvme0n1/device b/test/disk_tests/nvme_smart/nvme0n1/device
new file mode 120000 (symlink)
index 0000000..e890f3e
--- /dev/null
@@ -0,0 +1 @@
+../nvme0
\ No newline at end of file
diff --git a/test/disk_tests/nvme_smart/nvme0n1/device/model b/test/disk_tests/nvme_smart/nvme0n1/device/model
deleted file mode 100644 (file)
index 9bd6eba..0000000
+++ /dev/null
@@ -1 +0,0 @@
-NVME MODEL 1