all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH v2 container] vm status: force int where appropriate
@ 2021-06-01  6:43 Fabian Ebner
  2021-06-01  6:43 ` [pve-devel] [PATCH v2 qemu-server] " Fabian Ebner
  2021-06-17 12:49 ` [pve-devel] applied: [PATCH v2 container] " Thomas Lamprecht
  0 siblings, 2 replies; 4+ messages in thread
From: Fabian Ebner @ 2021-06-01  6:43 UTC (permalink / raw)
  To: pve-devel

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 <f.ebner@proxmox.com>
---

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





^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pve-devel] [PATCH v2 qemu-server] vm status: force int where appropriate
  2021-06-01  6:43 [pve-devel] [PATCH v2 container] vm status: force int where appropriate Fabian Ebner
@ 2021-06-01  6:43 ` Fabian Ebner
  2021-06-17 12:49   ` [pve-devel] applied: " Thomas Lamprecht
  2021-06-17 12:49 ` [pve-devel] applied: [PATCH v2 container] " Thomas Lamprecht
  1 sibling, 1 reply; 4+ messages in thread
From: Fabian Ebner @ 2021-06-01  6:43 UTC (permalink / raw)
  To: pve-devel

to avoid potential problems with stringified numbers in Javascript and
elsewehere.

The vmid was not always an integer as the return schema expects, namely
when there was an opt_vmid argument, because the 'ne' comparision coerced the
vmid to be a string then.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---

Changes from v1:
    * also make vmid an integer.

 PVE/QemuServer.pm | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 25ac052..830a6e4 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -2651,8 +2651,8 @@ sub vmstatus {
 
 	my $conf = PVE::QemuConfig->load_config($vmid);
 
-	my $d = { vmid => $vmid };
-	$d->{pid} = $list->{$vmid}->{pid};
+	my $d = { vmid => int($vmid) };
+	$d->{pid} = int($list->{$vmid}->{pid});
 
 	# fixme: better status?
 	$d->{status} = $list->{$vmid}->{pid} ? 'running' : 'stopped';
@@ -2711,8 +2711,8 @@ sub vmstatus {
 	$d->{netin} += $netdev->{$dev}->{transmit};
 
 	if ($full) {
-	    $d->{nics}->{$dev}->{netout} = $netdev->{$dev}->{receive};
-	    $d->{nics}->{$dev}->{netin} = $netdev->{$dev}->{transmit};
+	    $d->{nics}->{$dev}->{netout} = int($netdev->{$dev}->{receive});
+	    $d->{nics}->{$dev}->{netin} = int($netdev->{$dev}->{transmit});
 	}
 
     }
-- 
2.30.2





^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pve-devel] applied: [PATCH v2 container] vm status: force int where appropriate
  2021-06-01  6:43 [pve-devel] [PATCH v2 container] vm status: force int where appropriate Fabian Ebner
  2021-06-01  6:43 ` [pve-devel] [PATCH v2 qemu-server] " Fabian Ebner
@ 2021-06-17 12:49 ` Thomas Lamprecht
  1 sibling, 0 replies; 4+ messages in thread
From: Thomas Lamprecht @ 2021-06-17 12:49 UTC (permalink / raw)
  To: Proxmox VE development discussion, Fabian Ebner

On 01.06.21 08:43, Fabian Ebner wrote:
> 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 <f.ebner@proxmox.com>
> ---
> 
> Changes from v1:
>     * also make vmid an integer.
> 
>  src/PVE/LXC.pm | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
>

applied, thanks!




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pve-devel] applied: [PATCH v2 qemu-server] vm status: force int where appropriate
  2021-06-01  6:43 ` [pve-devel] [PATCH v2 qemu-server] " Fabian Ebner
@ 2021-06-17 12:49   ` Thomas Lamprecht
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Lamprecht @ 2021-06-17 12:49 UTC (permalink / raw)
  To: Proxmox VE development discussion, Fabian Ebner

On 01.06.21 08:43, Fabian Ebner wrote:
> to avoid potential problems with stringified numbers in Javascript and
> elsewehere.
> 
> The vmid was not always an integer as the return schema expects, namely
> when there was an opt_vmid argument, because the 'ne' comparision coerced the
> vmid to be a string then.
> 
> Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
> ---
> 
> Changes from v1:
>     * also make vmid an integer.
> 
>  PVE/QemuServer.pm | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
>

applied, thanks!




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-06-17 12:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-01  6:43 [pve-devel] [PATCH v2 container] vm status: force int where appropriate Fabian Ebner
2021-06-01  6:43 ` [pve-devel] [PATCH v2 qemu-server] " Fabian Ebner
2021-06-17 12:49   ` [pve-devel] applied: " Thomas Lamprecht
2021-06-17 12:49 ` [pve-devel] applied: [PATCH v2 container] " Thomas Lamprecht

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal