]> git.proxmox.com Git - pve-storage.git/commitdiff
file_size_info: move parser to own variable
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 9 Sep 2019 13:36:14 +0000 (15:36 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 9 Sep 2019 13:36:14 +0000 (15:36 +0200)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/Storage/Plugin.pm

index 6b79e7afa95d763d0eb9a7f82340ee54a2891563..bcd948da3291deeb654d361b10a39a6811e681d7 100644 (file)
@@ -712,36 +712,36 @@ sub file_size_info {
        return wantarray ? (0, 'subvol', 0, undef) : 1;
     }
 
-    my $cmd = ['/usr/bin/qemu-img', 'info', $filename];
-
     my $format;
     my $parent;
     my $size = 0;
     my $used = 0;
 
-    eval {
-       run_command($cmd, timeout => $timeout, outfunc => sub {
-           my $line = shift;
-           if ($line =~ m/^file format:\s+(\S+)\s*$/) {
-               $format = $1;
-           } elsif ($line =~ m/^backing file:\s(\S+)\s/) {
-               $parent = $1;
-           } elsif ($line =~ m/^virtual size:\s\S+\s+\((\d+)\s+bytes\)$/) {
-               $size = int($1);
-           } elsif ($line =~ m/^disk size:\s+(\d+(.\d+)?)([KMGT])\s*$/) {
-               $used = $1;
-               my $u = $3;
-
-               $used *= 1024 if $u eq 'K';
-               $used *= (1024*1024) if $u eq 'M';
-               $used *= (1024*1024*1024) if $u eq 'G';
-               $used *= (1024*1024*1024*1024) if $u eq 'T';
-
-               $used = int($used);
-           }
-       });
+    my $parse_qemu_img_info = sub {
+       my $line = shift;
+       if ($line =~ m/^file format:\s+(\S+)\s*$/) {
+           $format = $1;
+       } elsif ($line =~ m/^backing file:\s(\S+)\s/) {
+           $parent = $1;
+       } elsif ($line =~ m/^virtual size:\s\S+\s+\((\d+)\s+bytes\)$/) {
+           $size = int($1);
+       } elsif ($line =~ m/^disk size:\s+(\d+(.\d+)?)([KMGT])\s*$/) {
+           $used = $1;
+           my $u = $3;
+
+           $used *= 1024 if $u eq 'K';
+           $used *= (1024*1024) if $u eq 'M';
+           $used *= (1024*1024*1024) if $u eq 'G';
+           $used *= (1024*1024*1024*1024) if $u eq 'T';
+
+           $used = int($used);
+       }
     };
 
+    my $cmd = ['/usr/bin/qemu-img', 'info', $filename];
+    eval {
+       run_command($cmd, timeout => $timeout, outfunc => $parse_qemu_img_info );
+    };
     warn $@ if $@;
 
     return wantarray ? ($size, $format, $used, $parent) : $size;