Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx> --- src/lxc/lxc_cgroup.c | 65 +++++--------------------------------------- 1 file changed, 7 insertions(+), 58 deletions(-) diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 8e937ec389..d93a19d684 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -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); } -- 2.17.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list