use stderr from qemu-img invocation as error
Instead of just using it as a warning and then trying to parse an empty string as json. For example, trying to parse unsupported vmdks, previously we'd see something like this: qemu-img: Could not open '/run/pve/import/esxi/foo/mnt/ha-datacenter/vsanDatastore/asdf/asdf-000001.vmdk': Unsupported image type 'vsanSparse' could not parse qemu-img info command output for '/run/pve/import/esxi/foo/mnt/ha-datacenter/vsanDatastore/asdf/asdf-000001.vmdk' - malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "(end of string)") at src/PVE/Storage/Plugin.pm line 962, <DATA> line 960. Now it simply shows: qemu-img: Could not open '/run/pve/import/esxi/foo/mnt/ha-datacenter/vsanDatastore/asdf/asdf-000001.vmdk': Unsupported image type 'vsanSparse' Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
committed by
Thomas Lamprecht
parent
d09ed4bf76
commit
27591290c7
@ -950,14 +950,21 @@ sub file_size_info {
|
|||||||
}
|
}
|
||||||
|
|
||||||
my $json = '';
|
my $json = '';
|
||||||
|
my $err_output = '';
|
||||||
eval {
|
eval {
|
||||||
run_command(['/usr/bin/qemu-img', 'info', '--output=json', $filename],
|
run_command(['/usr/bin/qemu-img', 'info', '--output=json', $filename],
|
||||||
timeout => $timeout,
|
timeout => $timeout,
|
||||||
outfunc => sub { $json .= shift },
|
outfunc => sub { $json .= shift },
|
||||||
errfunc => sub { warn "$_[0]\n" }
|
errfunc => sub { $err_output .= shift . "\n"},
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
warn $@ if $@;
|
warn $@ if $@;
|
||||||
|
if ($err_output) {
|
||||||
|
# if qemu did not output anything to stdout we die with stderr as an error
|
||||||
|
die $err_output if !$json;
|
||||||
|
# otherwise we warn about it and try to parse the json
|
||||||
|
warn $err_output;
|
||||||
|
}
|
||||||
|
|
||||||
my $info = eval { decode_json($json) };
|
my $info = eval { decode_json($json) };
|
||||||
if (my $err = $@) {
|
if (my $err = $@) {
|
||||||
|
|||||||
Reference in New Issue
Block a user