render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
c480ed
From fef35da9603a70a60d29420b9cff0db4fc2f0f82 Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <fef35da9603a70a60d29420b9cff0db4fc2f0f82@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:06:02 +0200
c480ed
Subject: [PATCH] lxc: Use virCgroupGetMemoryStat
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
(cherry picked from commit e634c7cd0d3265506198e1f58f1af1fd774f06b1)
c480ed
c480ed
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
c480ed
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
Message-Id: <28c2e0f232ee1c3bce10654df15aa212d5f09996.1561993099.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/lxc/lxc_cgroup.c | 65 +++++---------------------------------------
c480ed
 1 file changed, 7 insertions(+), 58 deletions(-)
c480ed
c480ed
diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c
c480ed
index 8e937ec389..d93a19d684 100644
c480ed
--- a/src/lxc/lxc_cgroup.c
c480ed
+++ b/src/lxc/lxc_cgroup.c
c480ed
@@ -220,64 +220,13 @@ static int virLXCCgroupGetMemTotal(virCgroupPtr cgroup,
c480ed
 static int virLXCCgroupGetMemStat(virCgroupPtr cgroup,
c480ed
                                   virLXCMeminfoPtr meminfo)
c480ed
 {
c480ed
-    int ret = 0;
c480ed
-    FILE *statfd = NULL;
c480ed
-    char *statFile = NULL;
c480ed
-    char *line = NULL;
c480ed
-    size_t n;
c480ed
-
c480ed
-    ret = virCgroupPathOfController(cgroup, VIR_CGROUP_CONTROLLER_MEMORY,
c480ed
-                                    "memory.stat", &statFile);
c480ed
-    if (ret != 0) {
c480ed
-        virReportSystemError(-ret, "%s",
c480ed
-                             _("cannot get the path of MEMORY cgroup controller"));
c480ed
-        return ret;
c480ed
-    }
c480ed
-
c480ed
-    statfd = fopen(statFile, "r");
c480ed
-    if (statfd == NULL) {
c480ed
-        ret = -errno;
c480ed
-        goto cleanup;
c480ed
-    }
c480ed
-
c480ed
-    while (getline(&line, &n, statfd) > 0) {
c480ed
-
c480ed
-        char *value = strchr(line, ' ');
c480ed
-        char *nl = value ? strchr(line, '\n') : NULL;
c480ed
-        unsigned long long stat_value;
c480ed
-
c480ed
-        if (!value)
c480ed
-            continue;
c480ed
-
c480ed
-        if (nl)
c480ed
-            *nl = '\0';
c480ed
-
c480ed
-        *value = '\0';
c480ed
-
c480ed
-        if (virStrToLong_ull(value + 1, NULL, 10, &stat_value) < 0) {
c480ed
-            ret = -EINVAL;
c480ed
-            goto cleanup;
c480ed
-        }
c480ed
-        if (STREQ(line, "cache"))
c480ed
-            meminfo->cached = stat_value >> 10;
c480ed
-        else if (STREQ(line, "inactive_anon"))
c480ed
-            meminfo->inactive_anon = stat_value >> 10;
c480ed
-        else if (STREQ(line, "active_anon"))
c480ed
-            meminfo->active_anon = stat_value >> 10;
c480ed
-        else if (STREQ(line, "inactive_file"))
c480ed
-            meminfo->inactive_file = stat_value >> 10;
c480ed
-        else if (STREQ(line, "active_file"))
c480ed
-            meminfo->active_file = stat_value >> 10;
c480ed
-        else if (STREQ(line, "unevictable"))
c480ed
-            meminfo->unevictable = stat_value >> 10;
c480ed
-    }
c480ed
-    ret = 0;
c480ed
-
c480ed
- cleanup:
c480ed
-    VIR_FREE(line);
c480ed
-    VIR_FREE(statFile);
c480ed
-    VIR_FORCE_FCLOSE(statfd);
c480ed
-    return ret;
c480ed
+    return virCgroupGetMemoryStat(cgroup,
c480ed
+                                  &meminfo->cached,
c480ed
+                                  &meminfo->inactive_anon,
c480ed
+                                  &meminfo->active_anon,
c480ed
+                                  &meminfo->inactive_file,
c480ed
+                                  &meminfo->active_file,
c480ed
+                                  &meminfo->unevictable);
c480ed
 }
c480ed
 
c480ed
 
c480ed
-- 
c480ed
2.22.0
c480ed