libvirt/SOURCES/libvirt-vircgroup-extract-virCgroupV1GetMemoryUsage.patch
2021-10-08 13:11:16 +00:00

106 lines
3.4 KiB
Diff

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