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