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:
committed by
Thomas Lamprecht
parent
d35a0b4b62
commit
c3442aa554
@ -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;
|
||||
}
|
||||
|
||||
|
||||
1
test/disk_tests/nvme_smart/nvme0n1/device
Symbolic link
1
test/disk_tests/nvme_smart/nvme0n1/device
Symbolic link
@ -0,0 +1 @@
|
||||
../nvme0
|
||||
Reference in New Issue
Block a user