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

Fabian Grünbichler f.gruenbichler at proxmox.com
Mon Oct 3 13:53:33 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.

drop the implicit skipping of smart checks if $disk is set,
since we have an explicit parameter for this now.
---
changes to v1:
- drop !defined($disk) checks

 PVE/Diskmanage.pm | 48 +++++++++++++++++++++++++-----------------------
 1 file changed, 25 insertions(+), 23 deletions(-)

diff --git a/PVE/Diskmanage.pm b/PVE/Diskmanage.pm
index bcd3883..5530233 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,30 @@ 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') {
+		    # 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);
+		    }
+		} else {
+		    # else we just get the health
+		    $health = get_smart_health($devpath);
 		}
-	    } 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