]> git.proxmox.com Git - pve-storage.git/commitdiff
do not automatically die on smartctl exit code > 0
authorDominik Csapak <d.csapak@proxmox.com>
Thu, 8 Sep 2016 12:27:12 +0000 (14:27 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 8 Sep 2016 14:52:33 +0000 (16:52 +0200)
since smartctl uses the return value to encode
disk health status (such as failure in the past)
we cannot die there, but have to parse the returncode

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

index dc6ff4ae00fc085ad127f58a729b4352eee23d62..bee5d99d2a973e68dd166466b87b8da49f33bfb5 100644 (file)
@@ -76,8 +76,9 @@ sub get_smart_data {
     my $smartdata = {};
     my $datastarted = 0;
 
+    my $returncode = 0;
     eval {
-       run_command([$SMARTCTL, '-a', '-f', 'brief', $disk], outfunc => sub{
+       $returncode = run_command([$SMARTCTL, '-a', '-f', 'brief', $disk], noerr => 1, outfunc => sub{
            my ($line) = @_;
 
            if ($datastarted && $line =~ m/^[ \d]{2}\d/) {
@@ -101,7 +102,14 @@ sub get_smart_data {
            }
        });
     };
-    die "Error getting S.M.A.R.T. data: $@\n" if $@;
+    my $err = $@;
+
+    # bit 0 and 1 mark an severe smartctl error
+    # all others are for disk status, so ignore them
+    # see smartctl(8)
+    if ((defined($returncode) && ($returncode & 0b00000011)) || $err) {
+       die "Error getting S.M.A.R.T. data: Exit code: $returncode\n";
+    }
     $smartdata->{health} = 'UNKOWN' if !defined $smartdata->{health};
     return $smartdata;
 }
@@ -114,7 +122,7 @@ sub get_smart_health {
     my $message = "UNKOWN";
 
     eval {
-       run_command([$SMARTCTL, '-H', $disk], outfunc => sub {
+       run_command([$SMARTCTL, '-H', $disk], noerr => 1, outfunc => sub {
            my ($line) = @_;
 
            if ($line =~ m/test result: (.*)$/) {