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:
Wolfgang Bumiller
2024-04-04 12:55:40 +02:00
committed by Thomas Lamprecht
parent d09ed4bf76
commit 27591290c7

View File

@ -950,14 +950,21 @@ sub file_size_info {
}
my $json = '';
my $err_output = '';
eval {
run_command(['/usr/bin/qemu-img', 'info', '--output=json', $filename],
timeout => $timeout,
outfunc => sub { $json .= shift },
errfunc => sub { warn "$_[0]\n" }
errfunc => sub { $err_output .= shift . "\n"},
);
};
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) };
if (my $err = $@) {