[pve-devel] [PATCH RFC storage 1/4] disks: allow get_disks without smart checks

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


the smart checks are only needed for the API call(s) that
list all disks and their status, but get_disks is also used
in disk usage checks and in the Ceph code, where the smart
status is completely irrelevant.
---
 PVE/Diskmanage.pm | 49 ++++++++++++++++++++++++++-----------------------
 1 file changed, 26 insertions(+), 23 deletions(-)

diff --git a/PVE/Diskmanage.pm b/PVE/Diskmanage.pm
index bcd3883..54ede16 100644
--- a/PVE/Diskmanage.pm
+++ b/PVE/Diskmanage.pm
@@ -61,7 +61,7 @@ sub disk_is_used {
     my $dev = $disk;
     $dev =~ s|^/dev/||;
 
-    my $disklist = get_disks($dev);
+    my $disklist = get_disks($dev, 1);
 
     die "'$disk' is not a valid local disk\n" if !defined($disklist->{$dev});
     return 1 if $disklist->{$dev}->{used};
@@ -283,7 +283,7 @@ sub get_sysdir_info {
 }
 
 sub get_disks {
-    my ($disk) = @_;
+    my ($disk, $nosmart) = @_;
     my $disklist = {};
 
     my $mounted = {};
@@ -365,28 +365,31 @@ sub get_disks {
 
 	my $health = 'UNKNOWN';
 	my $wearout;
-	eval {
-	    if ($type eq 'ssd' && !defined($disk)) {
-		# if we have an ssd we try to get the wearout indicator
-		$wearout = 'N/A';
-		my $smartdata = get_smart_data($devpath);
-		$health = $smartdata->{health};
-		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);
+
+	if (!$nosmart) {
+	    eval {
+		if ($type eq 'ssd' && !defined($disk)) {
+		    # if we have an ssd we try to get the wearout indicator
+		    $wearout = 'N/A';
+		    my $smartdata = get_smart_data($devpath);
+		    $health = $smartdata->{health};
+		    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);
+		    }
+		} elsif (!defined($disk)) {
+		    # we do not need smart data if we check a single disk
+		    # because this functionality is only for disk_is_used
+		    $health = get_smart_health($devpath) if !defined($disk);
 		}
-	    } elsif (!defined($disk)) {
-		# we do not need smart data if we check a single disk
-		# because this functionality is only for disk_is_used
-		$health = get_smart_health($devpath) if !defined($disk);
-	    }
-	};
+	    };
+	}
 
 	my $used;
 
-- 
2.1.4





More information about the pve-devel mailing list