c313de
From 3e61b08bd5d925b262e3ca84d234670917604fda Mon Sep 17 00:00:00 2001
c313de
Message-Id: <3e61b08bd5d925b262e3ca84d234670917604fda@dist-git>
c313de
From: Pavel Hrdina <phrdina@redhat.com>
c313de
Date: Mon, 1 Jul 2019 17:06:53 +0200
c313de
Subject: [PATCH] vircgroup: extract virCgroupV1GetMemSwapUsage
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 87d9fc5b3bfbe217af1a5316af4392540f676657)
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: <c660f81cdf6e8771917e54c44d362ebb4d2fbdb4.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 6708eef0da..088e97cb3f 100644
c313de
--- a/src/util/vircgroup.c
c313de
+++ b/src/util/vircgroup.c
c313de
@@ -1697,14 +1697,7 @@ virCgroupGetMemSwapHardLimit(virCgroupPtr group, unsigned long long *kb)
c313de
 int
c313de
 virCgroupGetMemSwapUsage(virCgroupPtr group, unsigned long 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.memsw.usage_in_bytes", &usage_in_bytes);
c313de
-    if (ret == 0)
c313de
-        *kb = usage_in_bytes >> 10;
c313de
-    return ret;
c313de
+    VIR_CGROUP_BACKEND_CALL(group, getMemSwapUsage, -1, kb);
c313de
 }
c313de
 
c313de
 
c313de
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
c313de
index cdbca4b907..27e6b18ea2 100644
c313de
--- a/src/util/vircgroupbackend.h
c313de
+++ b/src/util/vircgroupbackend.h
c313de
@@ -251,6 +251,10 @@ typedef int
c313de
 (*virCgroupGetMemSwapHardLimitCB)(virCgroupPtr group,
c313de
                                   unsigned long long *kb);
c313de
 
c313de
+typedef int
c313de
+(*virCgroupGetMemSwapUsageCB)(virCgroupPtr group,
c313de
+                              unsigned long long *kb);
c313de
+
c313de
 struct _virCgroupBackend {
c313de
     virCgroupBackendType type;
c313de
 
c313de
@@ -299,6 +303,7 @@ struct _virCgroupBackend {
c313de
     virCgroupGetMemorySoftLimitCB getMemorySoftLimit;
c313de
     virCgroupSetMemSwapHardLimitCB setMemSwapHardLimit;
c313de
     virCgroupGetMemSwapHardLimitCB getMemSwapHardLimit;
c313de
+    virCgroupGetMemSwapUsageCB getMemSwapUsage;
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 779288fb97..55b1d3ebd0 100644
c313de
--- a/src/util/vircgroupv1.c
c313de
+++ b/src/util/vircgroupv1.c
c313de
@@ -1656,6 +1656,21 @@ virCgroupV1GetMemSwapHardLimit(virCgroupPtr group,
c313de
 }
c313de
 
c313de
 
c313de
+static int
c313de
+virCgroupV1GetMemSwapUsage(virCgroupPtr group,
c313de
+                           unsigned long 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.memsw.usage_in_bytes", &usage_in_bytes);
c313de
+    if (ret == 0)
c313de
+        *kb = usage_in_bytes >> 10;
c313de
+    return ret;
c313de
+}
c313de
+
c313de
+
c313de
 virCgroupBackend virCgroupV1Backend = {
c313de
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
c313de
 
c313de
@@ -1702,6 +1717,7 @@ virCgroupBackend virCgroupV1Backend = {
c313de
     .getMemorySoftLimit = virCgroupV1GetMemorySoftLimit,
c313de
     .setMemSwapHardLimit = virCgroupV1SetMemSwapHardLimit,
c313de
     .getMemSwapHardLimit = virCgroupV1GetMemSwapHardLimit,
c313de
+    .getMemSwapUsage = virCgroupV1GetMemSwapUsage,
c313de
 };
c313de
 
c313de
 
c313de
-- 
c313de
2.22.0
c313de