[pve-devel] applied: [PATCH manager] Fix #2476: Fix auto-ballooning QMP command
Thomas Lamprecht
t.lamprecht at proxmox.com
Thu Nov 21 14:25:03 CET 2019
On 11/21/19 1:22 PM, Stefan Reiter wrote:
> Commit 77123edbd0 (statd: refactor update_node_status) changed $target
> in pvestatd's auto_balloning sub into a variable:
>
> my $target = int($res->{$vmid});
>
> but then uses it in a string as a parameter to the $log function:
>
> $log->("BALLOON $vmid to $target (%d)\n", $target - $current);
>
> This surprisingly causes the variable to be incorrectly converted into a
> JSON string by perl's to_json (called in QMPClient after mon_cmd):
>
> {"value":"1234"}
>
> instead of
>
> {"value":1234}
>
> which causes QEMU to report the parameter as invalid:
>
> "Invalid parameter type for 'value', expected: integer"
>
> This behaviour is made even trickier, since $target internally is still
> considered more of an 'int' (although that's a weak claim in perl
> anyway), showing up without quotes in Dumper et. al. - but the perldoc
> for to_json scheds some light:
>
> simple scalars
> Simple Perl scalars (any scalar that is not a reference) are the
> most difficult objects to encode: this module will encode undefined
> scalars as JSON "null" values, scalars that have last been used in a
> string context before encoding as JSON strings, and anything else as
> number value
>
> So coerce to_json to treat $target as an integer by using it as one and
> everything is fine again.
>
> Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
> ---
>
> Also reported by multiple users in the forum, since auto-ballooning is
> completely broken currently:
>
> https://forum.proxmox.com/threads/host-instable-after-update-5-0-21-5.60404/
>
> PVE/Service/pvestatd.pm | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/PVE/Service/pvestatd.pm b/PVE/Service/pvestatd.pm
> index 92d94809..b789b819 100755
> --- a/PVE/Service/pvestatd.pm
> +++ b/PVE/Service/pvestatd.pm
> @@ -155,7 +155,7 @@ sub auto_balloning {
> next if $target == $current; # no need to change
>
> $log->("BALLOON $vmid to $target (%d)\n", $target - $current);
> - eval { PVE::QemuServer::Monitor::mon_cmd($vmid, "balloon", value => $target) };
> + eval { PVE::QemuServer::Monitor::mon_cmd($vmid, "balloon", value => int($target)) };
> warn $@ if $@;
> }
> }
>
nice catch and another reason to hate weakly typed languages ;)
applied, thanks!
More information about the pve-devel
mailing list