[pve-devel] [PATCH RFC storage 3/4] fix #1120: non-ATA disks with label-value smart data

Fabian Grünbichler f.gruenbichler at proxmox.com
Fri Sep 30 10:52:22 CEST 2016


simple parser as fallback for non-ATA disks. note that this
does not collect all the data output, but just those lines
which match the following schema:

some label: some value

and also the special case of:

"manufactured in" some value
---
Note: see cover letter for possible alternative

 PVE/Diskmanage.pm | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/PVE/Diskmanage.pm b/PVE/Diskmanage.pm
index 1c9ebd0..29e07d1 100644
--- a/PVE/Diskmanage.pm
+++ b/PVE/Diskmanage.pm
@@ -74,7 +74,7 @@ sub get_smart_data {
 
     assert_blockdev($disk);
     my $smartdata = {};
-    my $datastarted = 0;
+    my $type;
 
     my $returncode = 0;
     eval {
@@ -84,7 +84,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 +104,14 @@ 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->{attributes};
+	    } elsif ($line =~ m/=== START OF (READ )?SMART DATA SECTION ===/) {
+		$type = 'label-value';
+	    } elsif (defined($type) && $type eq 'label-value' && $line =~ m/^([-a-z\d\s_]+):\s+(.*)$/i) {
+		push @{$smartdata->{attributes}}, { 'label' => $1, 'value' => $2 };
+	    } elsif (defined($type) && $type eq 'label-value' && $line =~ m/^(manufactured in)\s+(.*)$/i) {
+		push @{$smartdata->{attributes}}, { 'label' => $1, 'value' => $2 };
 	    }
 	});
     };
@@ -111,6 +123,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;
 }
 
-- 
2.1.4





More information about the pve-devel mailing list