From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 89AAA741DB for ; Tue, 1 Jun 2021 08:43:40 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 7C1B825655 for ; Tue, 1 Jun 2021 08:43:10 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id B6F9325642 for ; Tue, 1 Jun 2021 08:43:09 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 6BF394338C for ; Tue, 1 Jun 2021 08:43:09 +0200 (CEST) From: Fabian Ebner To: pve-devel@lists.proxmox.com Date: Tue, 1 Jun 2021 08:43:05 +0200 Message-Id: <20210601064306.13507-1-f.ebner@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.010 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [lxc.pm] Subject: [pve-devel] [PATCH v2 container] vm status: force int where appropriate X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Jun 2021 06:43:40 -0000 In the case of a running container with cgroupv2, swap would be a string, causing a size.toFixed is not a function error for the format_size call in the containers's "Summary" page in the UI. The vmids from config_list() are already integers as the return schema expects, while the opt_vmid passed from the status/current API call needs to be converted. Signed-off-by: Fabian Ebner --- Changes from v1: * also make vmid an integer. src/PVE/LXC.pm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm index bb1cbdb..2b997ba 100644 --- a/src/PVE/LXC.pm +++ b/src/PVE/LXC.pm @@ -171,7 +171,7 @@ our $vmstatus_return_properties = { sub vmstatus { my ($opt_vmid) = @_; - my $list = $opt_vmid ? { $opt_vmid => { type => 'lxc', vmid => $opt_vmid }} : config_list(); + my $list = $opt_vmid ? { $opt_vmid => { type => 'lxc', vmid => int($opt_vmid) }} : config_list(); my $active_hash = list_active_containers(); @@ -187,7 +187,7 @@ sub vmstatus { foreach my $vmid (keys %$list) { my $d = $list->{$vmid}; - eval { $d->{pid} = find_lxc_pid($vmid) if defined($active_hash->{$vmid}); }; + eval { $d->{pid} = int(find_lxc_pid($vmid)) if defined($active_hash->{$vmid}); }; warn $@ if $@; # ignore errors (consider them stopped) $d->{status} = $active_hash->{$vmid} ? 'running' : 'stopped'; @@ -207,8 +207,8 @@ sub vmstatus { if ($d->{pid}) { my $res = get_container_disk_usage($vmid, $d->{pid}); - $d->{disk} = $res->{used}; - $d->{maxdisk} = $res->{total}; + $d->{disk} = int($res->{used}); + $d->{maxdisk} = int($res->{total}); } else { $d->{disk} = 0; # use 4GB by default ?? @@ -252,16 +252,16 @@ sub vmstatus { my $cgroups = PVE::LXC::CGroup->new($vmid); if (defined(my $mem = $cgroups->get_memory_stat())) { - $d->{mem} = $mem->{mem}; - $d->{swap} = $mem->{swap}; + $d->{mem} = int($mem->{mem}); + $d->{swap} = int($mem->{swap}); } else { $d->{mem} = 0; $d->{swap} = 0; } if (defined(my $blkio = $cgroups->get_io_stats())) { - $d->{diskread} = $blkio->{diskread}; - $d->{diskwrite} = $blkio->{diskwrite}; + $d->{diskread} = int($blkio->{diskread}); + $d->{diskwrite} = int($blkio->{diskwrite}); } else { $d->{diskread} = 0; $d->{diskwrite} = 0; -- 2.30.2