render / rpms / libvirt

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