提交 e634c7cd 编写于 作者: P Pavel Hrdina

lxc: Use virCgroupGetMemoryStat

Signed-off-by: NPavel Hrdina <phrdina@redhat.com>
上级 901d2b9c
......@@ -220,64 +220,13 @@ static int virLXCCgroupGetMemTotal(virCgroupPtr cgroup,
static int virLXCCgroupGetMemStat(virCgroupPtr cgroup,
virLXCMeminfoPtr meminfo)
{
int ret = 0;
FILE *statfd = NULL;
char *statFile = NULL;
char *line = NULL;
size_t n;
ret = virCgroupPathOfController(cgroup, VIR_CGROUP_CONTROLLER_MEMORY,
"memory.stat", &statFile);
if (ret != 0) {
virReportSystemError(-ret, "%s",
_("cannot get the path of MEMORY cgroup controller"));
return ret;
}
statfd = fopen(statFile, "r");
if (statfd == NULL) {
ret = -errno;
goto cleanup;
}
while (getline(&line, &n, statfd) > 0) {
char *value = strchr(line, ' ');
char *nl = value ? strchr(line, '\n') : NULL;
unsigned long long stat_value;
if (!value)
continue;
if (nl)
*nl = '\0';
*value = '\0';
if (virStrToLong_ull(value + 1, NULL, 10, &stat_value) < 0) {
ret = -EINVAL;
goto cleanup;
}
if (STREQ(line, "cache"))
meminfo->cached = stat_value >> 10;
else if (STREQ(line, "inactive_anon"))
meminfo->inactive_anon = stat_value >> 10;
else if (STREQ(line, "active_anon"))
meminfo->active_anon = stat_value >> 10;
else if (STREQ(line, "inactive_file"))
meminfo->inactive_file = stat_value >> 10;
else if (STREQ(line, "active_file"))
meminfo->active_file = stat_value >> 10;
else if (STREQ(line, "unevictable"))
meminfo->unevictable = stat_value >> 10;
}
ret = 0;
cleanup:
VIR_FREE(line);
VIR_FREE(statFile);
VIR_FORCE_FCLOSE(statfd);
return ret;
return virCgroupGetMemoryStat(cgroup,
&meminfo->cached,
&meminfo->inactive_anon,
&meminfo->active_anon,
&meminfo->inactive_file,
&meminfo->active_file,
&meminfo->unevictable);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册