Signed-off-by: Pavel Hrdina <phrdina@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 22db0a4bf1..1229959300 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -1639,14 +1639,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 5ccda8e044..672fb082c1 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -215,6 +215,10 @@ typedef int
unsigned long long *inactiveFile,
unsigned long long *unevictable);
+typedef int
+(*virCgroupGetMemoryUsageCB)(virCgroupPtr group,
+ unsigned long *kb);
+
struct _virCgroupBackend {
virCgroupBackendType type;
@@ -256,6 +260,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 cfe29649fb..7abb137b81 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -1473,6 +1473,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,
@@ -1512,6 +1527,7 @@ virCgroupBackend virCgroupV1Backend = {
.setMemory = virCgroupV1SetMemory,
.getMemoryStat = virCgroupV1GetMemoryStat,
+ .getMemoryUsage = virCgroupV1GetMemoryUsage,
};
--
2.17.1
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list