From 3e61b08bd5d925b262e3ca84d234670917604fda Mon Sep 17 00:00:00 2001 Message-Id: <3e61b08bd5d925b262e3ca84d234670917604fda@dist-git> From: Pavel Hrdina Date: Mon, 1 Jul 2019 17:06:53 +0200 Subject: [PATCH] vircgroup: extract virCgroupV1GetMemSwapUsage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Fabiano Fidêncio Reviewed-by: Ján Tomko Signed-off-by: Pavel Hrdina (cherry picked from commit 87d9fc5b3bfbe217af1a5316af4392540f676657) Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297 Signed-off-by: Pavel Hrdina Message-Id: Reviewed-by: Ján Tomko --- 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 6708eef0da..088e97cb3f 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1697,14 +1697,7 @@ virCgroupGetMemSwapHardLimit(virCgroupPtr group, unsigned long long *kb) int virCgroupGetMemSwapUsage(virCgroupPtr group, unsigned long long *kb) { - long long unsigned int usage_in_bytes; - int ret; - ret = virCgroupGetValueU64(group, - VIR_CGROUP_CONTROLLER_MEMORY, - "memory.memsw.usage_in_bytes", &usage_in_bytes); - if (ret == 0) - *kb = usage_in_bytes >> 10; - return ret; + VIR_CGROUP_BACKEND_CALL(group, getMemSwapUsage, -1, kb); } diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index cdbca4b907..27e6b18ea2 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -251,6 +251,10 @@ typedef int (*virCgroupGetMemSwapHardLimitCB)(virCgroupPtr group, unsigned long long *kb); +typedef int +(*virCgroupGetMemSwapUsageCB)(virCgroupPtr group, + unsigned long long *kb); + struct _virCgroupBackend { virCgroupBackendType type; @@ -299,6 +303,7 @@ struct _virCgroupBackend { virCgroupGetMemorySoftLimitCB getMemorySoftLimit; virCgroupSetMemSwapHardLimitCB setMemSwapHardLimit; virCgroupGetMemSwapHardLimitCB getMemSwapHardLimit; + virCgroupGetMemSwapUsageCB getMemSwapUsage; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 779288fb97..55b1d3ebd0 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1656,6 +1656,21 @@ virCgroupV1GetMemSwapHardLimit(virCgroupPtr group, } +static int +virCgroupV1GetMemSwapUsage(virCgroupPtr group, + unsigned long long *kb) +{ + long long unsigned int usage_in_bytes; + int ret; + ret = virCgroupGetValueU64(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.memsw.usage_in_bytes", &usage_in_bytes); + if (ret == 0) + *kb = usage_in_bytes >> 10; + return ret; +} + + virCgroupBackend virCgroupV1Backend = { .type = VIR_CGROUP_BACKEND_TYPE_V1, @@ -1702,6 +1717,7 @@ virCgroupBackend virCgroupV1Backend = { .getMemorySoftLimit = virCgroupV1GetMemorySoftLimit, .setMemSwapHardLimit = virCgroupV1SetMemSwapHardLimit, .getMemSwapHardLimit = virCgroupV1GetMemSwapHardLimit, + .getMemSwapUsage = virCgroupV1GetMemSwapUsage, }; -- 2.22.0