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