The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/3483

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Closes #3482

Signed-off-by: Stéphane Graber <[email protected]>
From dd8d99e68d22f2af58e06862e82c6e19e2f50653 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <[email protected]>
Date: Sun, 2 Jul 2017 18:14:10 -0400
Subject: [PATCH] Better handle errors in memory reporting
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #3482

Signed-off-by: Stéphane Graber <[email protected]>
---
 lxd/container_lxc.go | 39 ++++++++++++++++++---------------------
 1 file changed, 18 insertions(+), 21 deletions(-)

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 7484a3319..c94bd3b1e 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -4998,39 +4998,36 @@ func (c *containerLXC) memoryState() 
api.ContainerStateMemory {
 
        // Memory in bytes
        value, err := c.CGroupGet("memory.usage_in_bytes")
-       valueInt, err := strconv.ParseInt(value, 10, 64)
-       if err != nil {
-               valueInt = -1
+       valueInt, err1 := strconv.ParseInt(value, 10, 64)
+       if err == nil && err1 == nil {
+               memory.Usage = valueInt
        }
-       memory.Usage = valueInt
 
        // Memory peak in bytes
        value, err = c.CGroupGet("memory.max_usage_in_bytes")
-       valueInt, err = strconv.ParseInt(value, 10, 64)
-       if err != nil {
-               valueInt = -1
+       valueInt, err1 = strconv.ParseInt(value, 10, 64)
+       if err == nil && err1 == nil {
+               memory.UsagePeak = valueInt
        }
 
-       memory.UsagePeak = valueInt
-
        if cgSwapAccounting {
                // Swap in bytes
-               value, err := c.CGroupGet("memory.memsw.usage_in_bytes")
-               valueInt, err := strconv.ParseInt(value, 10, 64)
-               if err != nil {
-                       valueInt = -1
+               if memory.Usage > 0 {
+                       value, err := c.CGroupGet("memory.memsw.usage_in_bytes")
+                       valueInt, err1 := strconv.ParseInt(value, 10, 64)
+                       if err == nil && err1 == nil {
+                               memory.SwapUsage = valueInt - memory.Usage
+                       }
                }
 
-               memory.SwapUsage = valueInt - memory.Usage
-
                // Swap peak in bytes
-               value, err = c.CGroupGet("memory.memsw.max_usage_in_bytes")
-               valueInt, err = strconv.ParseInt(value, 10, 64)
-               if err != nil {
-                       valueInt = -1
+               if memory.UsagePeak > 0 {
+                       value, err = 
c.CGroupGet("memory.memsw.max_usage_in_bytes")
+                       valueInt, err1 = strconv.ParseInt(value, 10, 64)
+                       if err == nil && err1 == nil {
+                               memory.SwapUsagePeak = valueInt - 
memory.UsagePeak
+                       }
                }
-
-               memory.SwapUsagePeak = valueInt - memory.UsagePeak
        }
 
        return memory
_______________________________________________
lxc-devel mailing list
[email protected]
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to