diff --git a/PVE/Diskmanage.pm b/PVE/Diskmanage.pm index def0791..854f0a5 100644 --- a/PVE/Diskmanage.pm +++ b/PVE/Diskmanage.pm @@ -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/nvme0n1/device/model b/test/disk_tests/nvme_smart/nvme0/model similarity index 100% rename from test/disk_tests/nvme_smart/nvme0n1/device/model rename to test/disk_tests/nvme_smart/nvme0/model diff --git a/test/disk_tests/nvme_smart/nvme0n1/device b/test/disk_tests/nvme_smart/nvme0n1/device new file mode 120000 index 0000000..e890f3e --- /dev/null +++ b/test/disk_tests/nvme_smart/nvme0n1/device @@ -0,0 +1 @@ +../nvme0 \ No newline at end of file