libvirt/SOURCES/libvirt-util-Fix-virCgroupG...

90 lines
3.0 KiB
Diff

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