followup: add JSON use and cleanup
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
@ -11,6 +11,8 @@ use PVE::Tools qw(run_command);
|
|||||||
use PVE::JSONSchema qw(get_standard_option);
|
use PVE::JSONSchema qw(get_standard_option);
|
||||||
use PVE::Cluster qw(cfs_register_file);
|
use PVE::Cluster qw(cfs_register_file);
|
||||||
|
|
||||||
|
use JSON;
|
||||||
|
|
||||||
use base qw(PVE::SectionConfig);
|
use base qw(PVE::SectionConfig);
|
||||||
|
|
||||||
our @COMMON_TAR_FLAGS = qw(
|
our @COMMON_TAR_FLAGS = qw(
|
||||||
@ -712,26 +714,20 @@ sub file_size_info {
|
|||||||
return wantarray ? (0, 'subvol', 0, undef) : 1;
|
return wantarray ? (0, 'subvol', 0, undef) : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $cmd = ['/usr/bin/qemu-img', 'info', '--output=json', $filename];
|
|
||||||
my $json = '';
|
my $json = '';
|
||||||
|
|
||||||
eval {
|
eval {
|
||||||
run_command($cmd, timeout => $timeout, outfunc => sub { $json .= shift },
|
run_command(['/usr/bin/qemu-img', 'info', '--output=json', $filename],
|
||||||
errfunc => sub {
|
timeout => $timeout,
|
||||||
my $line = shift;
|
outfunc => sub { $json .= shift },
|
||||||
warn $line;
|
errfunc => sub { warn "$_[0]\n" }
|
||||||
});
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
warn $@ if $@;
|
warn $@ if $@;
|
||||||
|
|
||||||
my $decoded = decode_json($json);
|
my $info = eval { decode_json($json) };
|
||||||
|
warn "could not parse qemu-img info command output for '$filename'\n" if $@;
|
||||||
|
|
||||||
my $format = $decoded->{format};
|
my ($size, $format, $used, $parent) = $info->@{qw(virtual-size format actual-size backing-filename)};
|
||||||
my $parent = $decoded->{'backing-filename'};
|
|
||||||
my $size = $decoded->{'virtual-size'};
|
|
||||||
my $used = $decoded->{'actual-size'};
|
|
||||||
|
|
||||||
return wantarray ? ($size, $format, $used, $parent) : $size;
|
return wantarray ? ($size, $format, $used, $parent) : $size;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user