Blob Blame History Raw
From fef35da9603a70a60d29420b9cff0db4fc2f0f82 Mon Sep 17 00:00:00 2001
Message-Id: <fef35da9603a70a60d29420b9cff0db4fc2f0f82@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:06:02 +0200
Subject: [PATCH] lxc: Use virCgroupGetMemoryStat
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit e634c7cd0d3265506198e1f58f1af1fd774f06b1)

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <28c2e0f232ee1c3bce10654df15aa212d5f09996.1561993099.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 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.22.0