]> git.proxmox.com Git - pve-storage.git/commitdiff
Introduce zfs_get_properties helper
authorFabian Ebner <f.ebner@proxmox.com>
Thu, 14 Nov 2019 10:33:48 +0000 (11:33 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 14 Nov 2019 11:38:25 +0000 (12:38 +0100)
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
PVE/Storage/ZFSPoolPlugin.pm

index 16fb0d62fedd0b457a60887a2c8f49c4edd7fe8c..b8adf1c5adad7129fe963d67d2179a41be2cb748 100644 (file)
@@ -287,16 +287,22 @@ sub list_images {
     return $res;
 }
 
+sub zfs_get_properties {
+    my ($class, $scfg, $properties, $dataset, $timeout) = @_;
+
+    my $result = $class->zfs_request($scfg, $timeout, 'get', '-o', 'value',
+                                    '-Hp', $properties, $dataset);
+    my @values = split /\n/, $result;
+    return wantarray ? @values : $values[0];
+}
+
 sub zfs_get_pool_stats {
     my ($class, $scfg) = @_;
 
     my $available = 0;
     my $used = 0;
 
-    my $text = $class->zfs_request($scfg, undef, 'get', '-o', 'value', '-Hp',
-               'available,used', $scfg->{pool});
-
-    my @lines = split /\n/, $text;
+    my @lines = $class->zfs_get_properties($scfg, 'available,used', $scfg->{pool});
 
     if($lines[0] =~ /^(\d+)$/) {
        $available = $1;
@@ -448,8 +454,8 @@ sub volume_size_info {
         $class->parse_volname($volname);
 
     my $attr = $format eq 'subvol' ? 'refquota' : 'volsize';
-    my $text = $class->zfs_request($scfg, undef, 'get', '-Hp', $attr, "$scfg->{pool}/$vname");
-    if ($text =~ /\s$attr\s(\d+)\s/) {
+    my $value = $class->zfs_get_properties($scfg, $attr, "$scfg->{pool}/$vname");
+    if ($value =~ /^(\d+)$/) {
        return $1;
     }