]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Diskmanage.pm
fix #1123: modify NVME device path for SMART support
[pve-storage.git] / PVE / Diskmanage.pm
index 4cae46bec73a77585c668e828f2acccb4ce4a11c..36a5b5b7cbac26ea1255143dc902c2a755710a22 100644 (file)
@@ -74,9 +74,13 @@ sub get_smart_data {
 
     assert_blockdev($disk);
     my $smartdata = {};
-    my $datastarted = 0;
+    my $type;
 
     my $returncode = 0;
+
+    $disk =~ s/n\d+$//
+        if $disk =~ m!^/dev/nvme\d+n\d+$!;
+
     eval {
        $returncode = run_command([$SMARTCTL, '-H', '-A', '-f', 'brief', $disk], noerr => 1, outfunc => sub{
            my ($line) = @_;
@@ -84,7 +88,12 @@ sub get_smart_data {
 # ATA SMART attributes, e.g.:
 # ID# ATTRIBUTE_NAME          FLAGS    VALUE WORST THRESH FAIL RAW_VALUE
 #   1 Raw_Read_Error_Rate     POSR-K   100   100   000    -    0
-           if ($datastarted && $line =~ m/^([ \d]{2}\d)\s+(\S+)\s+(\S{6})\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(.*)$/) {
+#
+# SAS and NVME disks, e.g.:
+# Data Units Written:                 5,584,952 [2.85 TB]
+# Accumulated start-stop cycles:  34
+
+           if (defined($type) && $type eq 'ata' && $line =~ m/^([ \d]{2}\d)\s+(\S+)\s+(\S{6})\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(.*)$/) {
                my $entry = {};
                $entry->{name} = $2 if defined $2;
                $entry->{flags} = $3 if defined $3;
@@ -99,7 +108,13 @@ sub get_smart_data {
            } elsif ($line =~ m/(?:Health Status|self\-assessment test result): (.*)$/ ) {
                $smartdata->{health} = $1;
            } elsif ($line =~ m/Vendor Specific SMART Attributes with Thresholds:/) {
-               $datastarted = 1;
+               $type = 'ata';
+               delete $smartdata->{text};
+           } elsif ($line =~ m/=== START OF (READ )?SMART DATA SECTION ===/) {
+               $type = 'text';
+           } elsif (defined($type) && $type eq 'text') {
+               $smartdata->{text} = '' if !defined $smartdata->{text};
+               $smartdata->{text} .= "$line\n";
            }
        });
     };
@@ -111,6 +126,9 @@ sub get_smart_data {
     if ((defined($returncode) && ($returncode & 0b00000011)) || $err) {
        die "Error getting S.M.A.R.T. data: Exit code: $returncode\n";
     }
+
+    $smartdata->{type} = $type;
+
     return $smartdata;
 }
 
@@ -120,6 +138,8 @@ sub get_smart_health {
     return "NOT A DEVICE" if !assert_blockdev($disk, 1);
 
     my $message;
+    $disk =~ s/n\d+$//
+        if $disk =~ m!^/dev/nvme\d+n\d+$!;
 
     run_command([$SMARTCTL, '-H', $disk], noerr => 1, outfunc => sub {
        my ($line) = @_;