c480ed
From bab2adc524f6a9a10a89a1055d8a15ed85e1df5a Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <bab2adc524f6a9a10a89a1055d8a15ed85e1df5a@dist-git>
c480ed
From: Peter Chubb <Peter.Chubb@data61.csiro.au>
c480ed
Date: Mon, 1 Jul 2019 17:08:07 +0200
c480ed
Subject: [PATCH] util: Fix virCgroupGetMemoryStat
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
Commit 901d2b9c introduced virCgroupGetMemoryStat and replaced
c480ed
the LXC virLXCCgroupGetMemStat logic in commit e634c7cd0. However,
c480ed
in doing so the replacement wasn't exact as the LXC logic used
c480ed
getline() to process the cgroup controller data, while the new
c480ed
virCgroupGetMemoryStat used "memory.stat" manual buffer read/
c480ed
processing which neglected to forward through @line in order
c480ed
to read each line in the output.
c480ed
c480ed
To fix that, we should be sure to carry forward the @line value
c480ed
for each line read updating it beyond that current @newLine value
c480ed
once we've calculated the values that we want.
c480ed
c480ed
Signed-off-by: Peter Chubb <peter.chubb@data61.csiro.au>
c480ed
Reviewed-by: John Ferlan <jferlan@redhat.com>
c480ed
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
(cherry picked from commit b8176d6eaa943bc9825ecc99d86c0c301e688dd0)
c480ed
c480ed
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
c480ed
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
Message-Id: <e5fcbe6cbcfc0cc54ebbf01167080845f590268b.1561993100.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/util/vircgroupv1.c | 7 ++++++-
c480ed
 src/util/vircgroupv2.c | 7 ++++++-
c480ed
 2 files changed, 12 insertions(+), 2 deletions(-)
c480ed
c480ed
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
c480ed
index 97d108d3ac..3147084f21 100644
c480ed
--- a/src/util/vircgroupv1.c
c480ed
+++ b/src/util/vircgroupv1.c
c480ed
@@ -1477,7 +1477,7 @@ virCgroupV1GetMemoryStat(virCgroupPtr group,
c480ed
 
c480ed
     line = stat;
c480ed
 
c480ed
-    while (line) {
c480ed
+    while (*line) {
c480ed
         char *newLine = strchr(line, '\n');
c480ed
         char *valueStr = strchr(line, ' ');
c480ed
         unsigned long long value;
c480ed
@@ -1507,6 +1507,11 @@ virCgroupV1GetMemoryStat(virCgroupPtr group,
c480ed
             inactiveFileVal = value >> 10;
c480ed
         else if (STREQ(line, "unevictable"))
c480ed
             unevictableVal = value >> 10;
c480ed
+
c480ed
+        if (newLine)
c480ed
+            line = newLine + 1;
c480ed
+        else
c480ed
+            break;
c480ed
     }
c480ed
 
c480ed
     *cache = cacheVal;
c480ed
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
c480ed
index d6362e2b05..bff2f78d7e 100644
c480ed
--- a/src/util/vircgroupv2.c
c480ed
+++ b/src/util/vircgroupv2.c
c480ed
@@ -1069,7 +1069,7 @@ virCgroupV2GetMemoryStat(virCgroupPtr group,
c480ed
 
c480ed
     line = stat;
c480ed
 
c480ed
-    while (line) {
c480ed
+    while (*line) {
c480ed
         char *newLine = strchr(line, '\n');
c480ed
         char *valueStr = strchr(line, ' ');
c480ed
         unsigned long long value;
c480ed
@@ -1103,6 +1103,11 @@ virCgroupV2GetMemoryStat(virCgroupPtr group,
c480ed
             inactiveFileVal = value >> 10;
c480ed
         else if (STREQ(line, "unevictable"))
c480ed
             unevictableVal = value >> 10;
c480ed
+
c480ed
+        if (newLine)
c480ed
+            line = newLine + 1;
c480ed
+        else
c480ed
+            break;
c480ed
     }
c480ed
 
c480ed
     *cache = cacheVal;
c480ed
-- 
c480ed
2.22.0
c480ed