mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 14:15:28 +00:00
lxc: fuse: Unindent meminfo logic
Reverse the conditional at the start so we aren't stuffing all the logic in an 'if' block
This commit is contained in:
parent
daeace5c5d
commit
f65dcfcd14
@ -161,68 +161,68 @@ static int lxcProcReadMeminfo(char *hostpath, virDomainDefPtr def,
|
|||||||
res = -1;
|
res = -1;
|
||||||
while (copied < size && getline(&line, &n, fd) > 0) {
|
while (copied < size && getline(&line, &n, fd) > 0) {
|
||||||
char *ptr = strchr(line, ':');
|
char *ptr = strchr(line, ':');
|
||||||
if (ptr) {
|
if (!ptr)
|
||||||
*ptr = '\0';
|
continue;
|
||||||
|
*ptr = '\0';
|
||||||
|
|
||||||
if (STREQ(line, "MemTotal") &&
|
if (STREQ(line, "MemTotal") &&
|
||||||
(virMemoryLimitIsSet(def->mem.hard_limit) ||
|
(virMemoryLimitIsSet(def->mem.hard_limit) ||
|
||||||
virDomainDefGetMemoryActual(def))) {
|
virDomainDefGetMemoryActual(def))) {
|
||||||
virBufferAsprintf(new_meminfo, "MemTotal: %8llu kB\n",
|
virBufferAsprintf(new_meminfo, "MemTotal: %8llu kB\n",
|
||||||
meminfo.memtotal);
|
meminfo.memtotal);
|
||||||
} else if (STREQ(line, "MemFree") &&
|
} else if (STREQ(line, "MemFree") &&
|
||||||
(virMemoryLimitIsSet(def->mem.hard_limit) ||
|
(virMemoryLimitIsSet(def->mem.hard_limit) ||
|
||||||
virDomainDefGetMemoryActual(def))) {
|
virDomainDefGetMemoryActual(def))) {
|
||||||
virBufferAsprintf(new_meminfo, "MemFree: %8llu kB\n",
|
virBufferAsprintf(new_meminfo, "MemFree: %8llu kB\n",
|
||||||
(meminfo.memtotal - meminfo.memusage));
|
(meminfo.memtotal - meminfo.memusage));
|
||||||
} else if (STREQ(line, "Buffers")) {
|
} else if (STREQ(line, "Buffers")) {
|
||||||
virBufferAsprintf(new_meminfo, "Buffers: %8d kB\n", 0);
|
virBufferAsprintf(new_meminfo, "Buffers: %8d kB\n", 0);
|
||||||
} else if (STREQ(line, "Cached")) {
|
} else if (STREQ(line, "Cached")) {
|
||||||
virBufferAsprintf(new_meminfo, "Cached: %8llu kB\n",
|
virBufferAsprintf(new_meminfo, "Cached: %8llu kB\n",
|
||||||
meminfo.cached);
|
meminfo.cached);
|
||||||
} else if (STREQ(line, "Active")) {
|
} else if (STREQ(line, "Active")) {
|
||||||
virBufferAsprintf(new_meminfo, "Active: %8llu kB\n",
|
virBufferAsprintf(new_meminfo, "Active: %8llu kB\n",
|
||||||
(meminfo.active_anon + meminfo.active_file));
|
(meminfo.active_anon + meminfo.active_file));
|
||||||
} else if (STREQ(line, "Inactive")) {
|
} else if (STREQ(line, "Inactive")) {
|
||||||
virBufferAsprintf(new_meminfo, "Inactive: %8llu kB\n",
|
virBufferAsprintf(new_meminfo, "Inactive: %8llu kB\n",
|
||||||
(meminfo.inactive_anon + meminfo.inactive_file));
|
(meminfo.inactive_anon + meminfo.inactive_file));
|
||||||
} else if (STREQ(line, "Active(anon)")) {
|
} else if (STREQ(line, "Active(anon)")) {
|
||||||
virBufferAsprintf(new_meminfo, "Active(anon): %8llu kB\n",
|
virBufferAsprintf(new_meminfo, "Active(anon): %8llu kB\n",
|
||||||
meminfo.active_anon);
|
meminfo.active_anon);
|
||||||
} else if (STREQ(line, "Inactive(anon)")) {
|
} else if (STREQ(line, "Inactive(anon)")) {
|
||||||
virBufferAsprintf(new_meminfo, "Inactive(anon): %8llu kB\n",
|
virBufferAsprintf(new_meminfo, "Inactive(anon): %8llu kB\n",
|
||||||
meminfo.inactive_anon);
|
meminfo.inactive_anon);
|
||||||
} else if (STREQ(line, "Active(file)")) {
|
} else if (STREQ(line, "Active(file)")) {
|
||||||
virBufferAsprintf(new_meminfo, "Active(file): %8llu kB\n",
|
virBufferAsprintf(new_meminfo, "Active(file): %8llu kB\n",
|
||||||
meminfo.active_file);
|
meminfo.active_file);
|
||||||
} else if (STREQ(line, "Inactive(file)")) {
|
} else if (STREQ(line, "Inactive(file)")) {
|
||||||
virBufferAsprintf(new_meminfo, "Inactive(file): %8llu kB\n",
|
virBufferAsprintf(new_meminfo, "Inactive(file): %8llu kB\n",
|
||||||
meminfo.inactive_file);
|
meminfo.inactive_file);
|
||||||
} else if (STREQ(line, "Unevictable")) {
|
} else if (STREQ(line, "Unevictable")) {
|
||||||
virBufferAsprintf(new_meminfo, "Unevictable: %8llu kB\n",
|
virBufferAsprintf(new_meminfo, "Unevictable: %8llu kB\n",
|
||||||
meminfo.unevictable);
|
meminfo.unevictable);
|
||||||
} else if (STREQ(line, "SwapTotal") &&
|
} else if (STREQ(line, "SwapTotal") &&
|
||||||
virMemoryLimitIsSet(def->mem.swap_hard_limit)) {
|
virMemoryLimitIsSet(def->mem.swap_hard_limit)) {
|
||||||
virBufferAsprintf(new_meminfo, "SwapTotal: %8llu kB\n",
|
virBufferAsprintf(new_meminfo, "SwapTotal: %8llu kB\n",
|
||||||
(meminfo.swaptotal - meminfo.memtotal));
|
(meminfo.swaptotal - meminfo.memtotal));
|
||||||
} else if (STREQ(line, "SwapFree") &&
|
} else if (STREQ(line, "SwapFree") &&
|
||||||
virMemoryLimitIsSet(def->mem.swap_hard_limit)) {
|
virMemoryLimitIsSet(def->mem.swap_hard_limit)) {
|
||||||
virBufferAsprintf(new_meminfo, "SwapFree: %8llu kB\n",
|
virBufferAsprintf(new_meminfo, "SwapFree: %8llu kB\n",
|
||||||
(meminfo.swaptotal - meminfo.memtotal -
|
(meminfo.swaptotal - meminfo.memtotal -
|
||||||
meminfo.swapusage + meminfo.memusage));
|
meminfo.swapusage + meminfo.memusage));
|
||||||
} else {
|
} else {
|
||||||
*ptr = ':';
|
*ptr = ':';
|
||||||
virBufferAdd(new_meminfo, line, -1);
|
virBufferAdd(new_meminfo, line, -1);
|
||||||
}
|
|
||||||
|
|
||||||
if (virBufferCheckError(new_meminfo) < 0) {
|
|
||||||
res = -errno;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
copied += strlen(line);
|
|
||||||
if (copied > size)
|
|
||||||
copied = size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (virBufferCheckError(new_meminfo) < 0) {
|
||||||
|
res = -errno;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
copied += strlen(line);
|
||||||
|
if (copied > size)
|
||||||
|
copied = size;
|
||||||
}
|
}
|
||||||
res = copied;
|
res = copied;
|
||||||
memcpy(buf, virBufferCurrentContent(new_meminfo), copied);
|
memcpy(buf, virBufferCurrentContent(new_meminfo), copied);
|
||||||
|
Loading…
Reference in New Issue
Block a user