c480ed
From fadcb498572cd664d45d31039f2bd34e22cc02b3 Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <fadcb498572cd664d45d31039f2bd34e22cc02b3@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:06:51 +0200
c480ed
Subject: [PATCH] vircgroup: extract virCgroupV1GetMemoryUsage
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
(cherry picked from commit e92f8bad6681439d50251e7ac13e5f9f1bef62d5)
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: <aa1a9f774f8757730539caad64376dc6f4be9e70.1561993100.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/util/vircgroup.c        |  9 +--------
c480ed
 src/util/vircgroupbackend.h |  5 +++++
c480ed
 src/util/vircgroupv1.c      | 16 ++++++++++++++++
c480ed
 3 files changed, 22 insertions(+), 8 deletions(-)
c480ed
c480ed
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
c480ed
index 786034d555..ed7252243c 100644
c480ed
--- a/src/util/vircgroup.c
c480ed
+++ b/src/util/vircgroup.c
c480ed
@@ -1637,14 +1637,7 @@ virCgroupGetMemoryStat(virCgroupPtr group,
c480ed
 int
c480ed
 virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb)
c480ed
 {
c480ed
-    long long unsigned int usage_in_bytes;
c480ed
-    int ret;
c480ed
-    ret = virCgroupGetValueU64(group,
c480ed
-                               VIR_CGROUP_CONTROLLER_MEMORY,
c480ed
-                               "memory.usage_in_bytes", &usage_in_bytes);
c480ed
-    if (ret == 0)
c480ed
-        *kb = (unsigned long) usage_in_bytes >> 10;
c480ed
-    return ret;
c480ed
+    VIR_CGROUP_BACKEND_CALL(group, getMemoryUsage, -1, kb);
c480ed
 }
c480ed
 
c480ed
 
c480ed
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
c480ed
index 99754a6310..8bdfc5c835 100644
c480ed
--- a/src/util/vircgroupbackend.h
c480ed
+++ b/src/util/vircgroupbackend.h
c480ed
@@ -223,6 +223,10 @@ typedef int
c480ed
                             unsigned long long *inactiveFile,
c480ed
                             unsigned long long *unevictable);
c480ed
 
c480ed
+typedef int
c480ed
+(*virCgroupGetMemoryUsageCB)(virCgroupPtr group,
c480ed
+                             unsigned long *kb);
c480ed
+
c480ed
 struct _virCgroupBackend {
c480ed
     virCgroupBackendType type;
c480ed
 
c480ed
@@ -264,6 +268,7 @@ struct _virCgroupBackend {
c480ed
 
c480ed
     virCgroupSetMemoryCB setMemory;
c480ed
     virCgroupGetMemoryStatCB getMemoryStat;
c480ed
+    virCgroupGetMemoryUsageCB getMemoryUsage;
c480ed
 };
c480ed
 typedef struct _virCgroupBackend virCgroupBackend;
c480ed
 typedef virCgroupBackend *virCgroupBackendPtr;
c480ed
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
c480ed
index fcb2607e26..4f1d79a758 100644
c480ed
--- a/src/util/vircgroupv1.c
c480ed
+++ b/src/util/vircgroupv1.c
c480ed
@@ -1479,6 +1479,21 @@ virCgroupV1GetMemoryStat(virCgroupPtr group,
c480ed
 }
c480ed
 
c480ed
 
c480ed
+static int
c480ed
+virCgroupV1GetMemoryUsage(virCgroupPtr group,
c480ed
+                          unsigned long *kb)
c480ed
+{
c480ed
+    long long unsigned int usage_in_bytes;
c480ed
+    int ret;
c480ed
+    ret = virCgroupGetValueU64(group,
c480ed
+                               VIR_CGROUP_CONTROLLER_MEMORY,
c480ed
+                               "memory.usage_in_bytes", &usage_in_bytes);
c480ed
+    if (ret == 0)
c480ed
+        *kb = (unsigned long) usage_in_bytes >> 10;
c480ed
+    return ret;
c480ed
+}
c480ed
+
c480ed
+
c480ed
 virCgroupBackend virCgroupV1Backend = {
c480ed
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
c480ed
 
c480ed
@@ -1518,6 +1533,7 @@ virCgroupBackend virCgroupV1Backend = {
c480ed
 
c480ed
     .setMemory = virCgroupV1SetMemory,
c480ed
     .getMemoryStat = virCgroupV1GetMemoryStat,
c480ed
+    .getMemoryUsage = virCgroupV1GetMemoryUsage,
c480ed
 };
c480ed
 
c480ed
 
c480ed
-- 
c480ed
2.22.0
c480ed