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