render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
c480ed
From 64df2fa746eab23c73578c53b6d8501cbec2d04c Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <64df2fa746eab23c73578c53b6d8501cbec2d04c@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:07:45 +0200
c480ed
Subject: [PATCH] vircgroup: introduce virCgroupV2GetMemSwapUsage
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
(cherry picked from commit 3f728c720b782e853de4c43999a37aeceb3f95b8)
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: <c7135a2e07a613fb4f285556bc703843bb2fd872.1561993100.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/util/vircgroupv2.c | 16 ++++++++++++++++
c480ed
 1 file changed, 16 insertions(+)
c480ed
c480ed
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
c480ed
index fed6792e16..8d184bd963 100644
c480ed
--- a/src/util/vircgroupv2.c
c480ed
+++ b/src/util/vircgroupv2.c
c480ed
@@ -1290,6 +1290,21 @@ virCgroupV2GetMemSwapHardLimit(virCgroupPtr group,
c480ed
 }
c480ed
 
c480ed
 
c480ed
+static int
c480ed
+virCgroupV2GetMemSwapUsage(virCgroupPtr group,
c480ed
+                           unsigned long long *kb)
c480ed
+{
c480ed
+    unsigned long long usage_in_bytes;
c480ed
+    int ret;
c480ed
+    ret = virCgroupGetValueU64(group,
c480ed
+                               VIR_CGROUP_CONTROLLER_MEMORY,
c480ed
+                               "memory.swap.current", &usage_in_bytes);
c480ed
+    if (ret == 0)
c480ed
+        *kb = (unsigned long) usage_in_bytes >> 10;
c480ed
+    return ret;
c480ed
+}
c480ed
+
c480ed
+
c480ed
 virCgroupBackend virCgroupV2Backend = {
c480ed
     .type = VIR_CGROUP_BACKEND_TYPE_V2,
c480ed
 
c480ed
@@ -1336,6 +1351,7 @@ virCgroupBackend virCgroupV2Backend = {
c480ed
     .getMemorySoftLimit = virCgroupV2GetMemorySoftLimit,
c480ed
     .setMemSwapHardLimit = virCgroupV2SetMemSwapHardLimit,
c480ed
     .getMemSwapHardLimit = virCgroupV2GetMemSwapHardLimit,
c480ed
+    .getMemSwapUsage = virCgroupV2GetMemSwapUsage,
c480ed
 };
c480ed
 
c480ed
 
c480ed
-- 
c480ed
2.22.0
c480ed