[pve-devel] applied: [PATCH storage] base plugin: do not decode the empty string

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Sep 6 19:09:44 CEST 2024


Am 02/09/2024 um 14:47 schrieb Maximiliano Sandoval:
> If the json was empty, for example if the qemu-img command times out, a
> message
> 
>     warn "could not parse qemu-img info command output for '$filename' - $err\n";
> 
> would have been printed.
> 
> This message could lead one to think the issue lies in the contents of
> the json, even if the previous warning said that there was a timeout.
> 
> Signed-off-by: Maximiliano Sandoval <m.sandoval at proxmox.com>
> ---
>  src/PVE/Storage/Plugin.pm | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm
> index 6444390f..8cc693c7 100644
> --- a/src/PVE/Storage/Plugin.pm
> +++ b/src/PVE/Storage/Plugin.pm
> @@ -974,6 +974,10 @@ sub file_size_info {
>  	# otherwise we warn about it and try to parse the json
>  	warn $err_output;
>      }
> +    if (!$json) {
> +	# skip decoding if there was no output, e.g. if there was a timeout.
> +	return wantarray ? (undef, undef, undef, undef, $st->ctime) : undef;
> +    }
>  

FWIW, one could have avoided a tiny bit of duplication (trading against being
explicit) by changing the call to warn in the error path to something like:

warn "..." if !!$json;

but OTOH trying to parse json when one knows that it cannot work makes no sense
either, so your variant is probably better...

applied, thanks!




More information about the pve-devel mailing list