Fix #2020: use /sys to map nvmeXnY to nvmeX

`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>
This commit is contained in:
Wolfgang Bumiller
2018-12-10 14:17:06 +01:00
committed by Thomas Lamprecht
parent d35a0b4b62
commit c3442aa554
3 changed files with 11 additions and 2 deletions

View 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;
}

View File

@ -0,0 +1 @@
../nvme0