]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
lxc: Use virCgroupGetMemoryStat
authorPavel Hrdina <phrdina@redhat.com>
Fri, 20 Jul 2018 12:48:56 +0000 (14:48 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Mon, 13 Aug 2018 09:53:53 +0000 (11:53 +0200)
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
src/lxc/lxc_cgroup.c

index 8e937ec3898537e1bd67510ce3989e2be490f5ff..d93a19d684e605dfa5761ded2fa69ea95a58317d 100644 (file)
@@ -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);
 }