]> git.proxmox.com Git - pve-storage.git/commitdiff
ZFS: use -p flag and remove zfs_parse_size
authorAaron Lauterer <a.lauterer@proxmox.com>
Tue, 7 Apr 2020 12:25:36 +0000 (14:25 +0200)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Thu, 9 Apr 2020 08:20:06 +0000 (10:20 +0200)
ZFS supports the -p flag in the list command since a few years now.
Let us use the real byte values and avoid the error prone calculation
from human readable numbers that can lead to incorrect numbers if the
reported human readable value is a rounded number.

Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
PVE/Storage.pm
PVE/Storage/ZFSPoolPlugin.pm

index 4863d8405885f6bcb1973502be4b34b872b0642d..c3813944feaefcb86f37526257c0417b16d27501 100755 (executable)
@@ -1210,7 +1210,7 @@ sub scan_cifs {
 
 sub scan_zfs {
 
-    my $cmd = ['zfs',  'list', '-t', 'filesystem', '-H', '-o', 'name,avail,used'];
+    my $cmd = ['zfs',  'list', '-t', 'filesystem', '-Hp', '-o', 'name,avail,used'];
 
     my $res = [];
     run_command($cmd, outfunc => sub {
@@ -1218,8 +1218,8 @@ sub scan_zfs {
 
        if ($line =~m/^(\S+)\s+(\S+)\s+(\S+)$/) {
            my ($pool, $size_str, $used_str) = ($1, $2, $3);
-           my $size = PVE::Storage::ZFSPoolPlugin::zfs_parse_size($size_str);
-           my $used = PVE::Storage::ZFSPoolPlugin::zfs_parse_size($used_str);
+           my $size = $size_str + 0;
+           my $used = $used_str + 0;
            # ignore subvolumes generated by our ZFSPoolPlugin
            return if $pool =~ m!/subvol-\d+-[^/]+$!;
            return if $pool =~ m!/basevol-\d+-[^/]+$!;
index 7da9e7829f9b7541270a9ecf860fc8dac03863dd..3808ab7e9ec0e3896c1068ed2b26b007393a228d 100644 (file)
@@ -54,42 +54,6 @@ sub options {
 
 # static zfs helper methods
 
-sub zfs_parse_size {
-    my ($text) = @_;
-
-    return 0 if !$text;
-
-    if ($text =~ m/^(\d+(\.\d+)?)([TGMK])?$/) {
-
-       my ($size, $reminder, $unit) = ($1, $2, $3);
-
-       if ($unit) {
-           if ($unit eq 'K') {
-               $size *= 1024;
-           } elsif ($unit eq 'M') {
-               $size *= 1024*1024;
-           } elsif ($unit eq 'G') {
-               $size *= 1024*1024*1024;
-           } elsif ($unit eq 'T') {
-               $size *= 1024*1024*1024*1024;
-           } else {
-               die "got unknown zfs size unit '$unit'\n";
-           }
-       }
-
-       if ($reminder) {
-           $size = ceil($size);
-       }
-
-       return $size + 0;
-
-    }
-
-    warn "unable to parse zfs size '$text'\n";
-
-    return 0;
-}
-
 sub zfs_parse_zvol_list {
     my ($text) = @_;
 
@@ -117,11 +81,11 @@ sub zfs_parse_zvol_list {
            if ($refquota eq 'none') {
                $zvol->{size} = 0;
            } else {
-               $zvol->{size} = zfs_parse_size($refquota);
+               $zvol->{size} = $refquota + 0;
            }
            $zvol->{format} = 'subvol';
        } else {
-           $zvol->{size} = zfs_parse_size($size);
+           $zvol->{size} = $size + 0;
            $zvol->{format} = 'raw';
        }
        if ($origin !~ /^-$/) {