Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx> --- 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 ab50342dbb..b1c1bc9cf0 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1595,25 +1595,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 b59462d6ab..2d59e4af20 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -202,6 +202,10 @@ typedef int const char *path, unsigned long long *wbps); +typedef int +(*virCgroupSetMemoryCB)(virCgroupPtr group, + unsigned long long kb); + struct _virCgroupBackend { virCgroupBackendType type; @@ -240,6 +244,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 4f6d20e31f..3235ef3d2d 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1377,6 +1377,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, @@ -1413,6 +1439,8 @@ virCgroupBackend virCgroupV1Backend = { .getBlkioDeviceReadBps = virCgroupV1GetBlkioDeviceReadBps, .setBlkioDeviceWriteBps = virCgroupV1SetBlkioDeviceWriteBps, .getBlkioDeviceWriteBps = virCgroupV1GetBlkioDeviceWriteBps, + + .setMemory = virCgroupV1SetMemory, }; -- 2.17.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list