]> git.proxmox.com Git - pve-storage.git/commitdiff
fix #1135: refactor wear level parsing
authorDominik Csapak <d.csapak@proxmox.com>
Wed, 5 Oct 2016 08:57:10 +0000 (10:57 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 6 Oct 2016 05:49:30 +0000 (07:49 +0200)
refactored the wear level parsing into its
own function, where we can now define a
vendor <-> attribute id
mapping

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
PVE/Diskmanage.pm

index 4ee89ae89860c03300c40044b5c0a7e32f5969d6..1befd9e89214955b81a805976de42881fe91922c 100644 (file)
@@ -284,6 +284,44 @@ sub get_sysdir_info {
     return $data;
 }
 
+sub get_wear_leveling_info {
+    my ($attributes, $model) = @_;
+
+    my $wearout;
+
+    my $vendormap = {
+       'kingston' => 231,
+       'samsung' => 177,
+       'intel' => 233,
+       'sandisk' => 233,
+       'default' => 233,
+    };
+
+    # find target attr id
+
+    my $attrid;
+
+    foreach my $vendor (keys $vendormap) {
+       if ($model =~ m/$vendor/i) {
+           $attrid = $vendormap->{$vendor};
+           # found the attribute
+           last;
+       }
+    }
+
+    if (!$attrid) {
+       $attrid = $vendormap->{default};
+    }
+
+    foreach my $attr (@$attributes) {
+       next if $attr->{id} != $attrid;
+       $wearout = $attr->{value};
+       last;
+    }
+
+    return $wearout;
+}
+
 sub get_disks {
     my ($disk, $nosmart) = @_;
     my $disklist = {};
@@ -366,7 +404,7 @@ sub get_disks {
        }
 
        my $health = 'UNKNOWN';
-       my $wearout;
+       my $wearout = 'N/A';
 
        if (!$nosmart) {
            eval {
@@ -375,17 +413,8 @@ sub get_disks {
 
                if ($type eq 'ssd') {
                    # if we have an ssd we try to get the wearout indicator
-                   $wearout = 'N/A';
-                   foreach my $attr (@{$smartdata->{attributes}}) {
-                       # ID 233 is media wearout indicator on intel and sandisk
-                       # ID 177 is media wearout indicator on samsung
-                       next if ($attr->{id} != 233 && $attr->{id} != 177);
-                       next if ($attr->{name} !~ m/wear/i);
-                       $wearout = $attr->{value};
-
-                       # prefer the 233 value
-                       last if ($attr->{id} == 233);
-                   }
+                   my $wearval = get_wear_leveling_info($smartdata->{attributes}, $sysdata->{model});
+                   $wearout = $wearval if $wearval;
                }
            };
        }