From 75e53d9323c069ece39b40a99675425967ac2d62 Mon Sep 17 00:00:00 2001 Message-Id: <75e53d9323c069ece39b40a99675425967ac2d62@dist-git> From: Pavel Hrdina Date: Mon, 1 Jul 2019 17:06:49 +0200 Subject: [PATCH] vircgroup: extract virCgroupV1SetMemory 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 53f43deb0dfa666cb8c614cabbf5add075ccc33f) 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 | 20 +------------------- src/util/vircgroupbackend.h | 6 ++++++ src/util/vircgroupv1.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 684bce4997..4053c65939 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1593,25 +1593,7 @@ virCgroupGetMemoryUnlimitedKB(void) int virCgroupSetMemory(virCgroupPtr group, unsigned long long kb) { - unsigned long long maxkb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; - - if (kb > maxkb) { - virReportError(VIR_ERR_INVALID_ARG, - _("Memory '%llu' must be less than %llu"), - kb, maxkb); - return -1; - } - - if (kb == maxkb) - return virCgroupSetValueI64(group, - VIR_CGROUP_CONTROLLER_MEMORY, - "memory.limit_in_bytes", - -1); - else - return virCgroupSetValueU64(group, - VIR_CGROUP_CONTROLLER_MEMORY, - "memory.limit_in_bytes", - kb << 10); + VIR_CGROUP_BACKEND_CALL(group, setMemory, -1, kb); } diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 67e795a2b7..e1f75c5c31 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -210,6 +210,10 @@ typedef int const char *path, unsigned long long *wbps); +typedef int +(*virCgroupSetMemoryCB)(virCgroupPtr group, + unsigned long long kb); + struct _virCgroupBackend { virCgroupBackendType type; @@ -248,6 +252,8 @@ struct _virCgroupBackend { virCgroupGetBlkioDeviceReadBpsCB getBlkioDeviceReadBps; virCgroupSetBlkioDeviceWriteBpsCB setBlkioDeviceWriteBps; virCgroupGetBlkioDeviceWriteBpsCB getBlkioDeviceWriteBps; + + virCgroupSetMemoryCB setMemory; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index c044414dfd..17a4d67972 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1378,6 +1378,32 @@ virCgroupV1GetBlkioDeviceWriteBps(virCgroupPtr group, } +static int +virCgroupV1SetMemory(virCgroupPtr group, + unsigned long long kb) +{ + unsigned long long maxkb = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; + + if (kb > maxkb) { + virReportError(VIR_ERR_INVALID_ARG, + _("Memory '%llu' must be less than %llu"), + kb, maxkb); + return -1; + } + + if (kb == maxkb) + return virCgroupSetValueI64(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.limit_in_bytes", + -1); + else + return virCgroupSetValueU64(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.limit_in_bytes", + kb << 10); +} + + virCgroupBackend virCgroupV1Backend = { .type = VIR_CGROUP_BACKEND_TYPE_V1, @@ -1414,6 +1440,8 @@ virCgroupBackend virCgroupV1Backend = { .getBlkioDeviceReadBps = virCgroupV1GetBlkioDeviceReadBps, .setBlkioDeviceWriteBps = virCgroupV1SetBlkioDeviceWriteBps, .getBlkioDeviceWriteBps = virCgroupV1GetBlkioDeviceWriteBps, + + .setMemory = virCgroupV1SetMemory, }; -- 2.22.0