mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
util: Fix virCgroupGetMemoryStat
Commit901d2b9c
introduced virCgroupGetMemoryStat and replaced the LXC virLXCCgroupGetMemStat logic in commite634c7cd0
. 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>
This commit is contained in:
parent
b04b82f8cb
commit
b8176d6eaa
@ -1476,7 +1476,7 @@ virCgroupV1GetMemoryStat(virCgroupPtr group,
|
||||
|
||||
line = stat;
|
||||
|
||||
while (line) {
|
||||
while (*line) {
|
||||
char *newLine = strchr(line, '\n');
|
||||
char *valueStr = strchr(line, ' ');
|
||||
unsigned long long value;
|
||||
@ -1506,6 +1506,11 @@ virCgroupV1GetMemoryStat(virCgroupPtr group,
|
||||
inactiveFileVal = value >> 10;
|
||||
else if (STREQ(line, "unevictable"))
|
||||
unevictableVal = value >> 10;
|
||||
|
||||
if (newLine)
|
||||
line = newLine + 1;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
*cache = cacheVal;
|
||||
|
@ -1068,7 +1068,7 @@ virCgroupV2GetMemoryStat(virCgroupPtr group,
|
||||
|
||||
line = stat;
|
||||
|
||||
while (line) {
|
||||
while (*line) {
|
||||
char *newLine = strchr(line, '\n');
|
||||
char *valueStr = strchr(line, ' ');
|
||||
unsigned long long value;
|
||||
@ -1102,6 +1102,11 @@ virCgroupV2GetMemoryStat(virCgroupPtr group,
|
||||
inactiveFileVal = value >> 10;
|
||||
else if (STREQ(line, "unevictable"))
|
||||
unevictableVal = value >> 10;
|
||||
|
||||
if (newLine)
|
||||
line = newLine + 1;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
*cache = cacheVal;
|
||||
|
Loading…
Reference in New Issue
Block a user