From ac37b7c9693d27c9c20f87b3fd077bf55ac1d34f Mon Sep 17 00:00:00 2001 Message-Id: From: Pavel Hrdina Date: Mon, 1 Jul 2019 17:06:26 +0200 Subject: [PATCH] vircgroup: extract virCgroupV1CopyMounts 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 47941ea7f52be44f609a6b6acc8895644039e617) 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 | 23 +---------------------- src/util/vircgroupbackend.h | 5 +++++ src/util/vircgroupv1.c | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 6825623478..9d644d37d1 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -235,27 +235,6 @@ virCgroupPartitionEscape(char **path) } -static int -virCgroupCopyMounts(virCgroupPtr group, - virCgroupPtr parent) -{ - size_t i; - for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - if (!parent->controllers[i].mountPoint) - continue; - - if (VIR_STRDUP(group->controllers[i].mountPoint, - parent->controllers[i].mountPoint) < 0) - return -1; - - if (VIR_STRDUP(group->controllers[i].linkPoint, - parent->controllers[i].linkPoint) < 0) - return -1; - } - return 0; -} - - static int virCgroupResolveMountLink(const char *mntDir, const char *typeStr, @@ -653,7 +632,7 @@ virCgroupDetect(virCgroupPtr group, } if (parent) { - if (virCgroupCopyMounts(group, parent) < 0) + if (group->backend->copyMounts(group, parent) < 0) return -1; } else { if (virCgroupDetectMounts(group) < 0) diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index daf47bac09..81ee597fc8 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -41,12 +41,17 @@ typedef bool const char *drivername, const char *machinename); +typedef int +(*virCgroupCopyMountsCB)(virCgroupPtr group, + virCgroupPtr parent); + struct _virCgroupBackend { virCgroupBackendType type; /* Mandatory callbacks that need to be implemented for every backend. */ virCgroupAvailableCB available; virCgroupValidateMachineGroupCB validateMachineGroup; + virCgroupCopyMountsCB copyMounts; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index b78cdcab53..50b58ab413 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -160,11 +160,33 @@ virCgroupV1ValidateMachineGroup(virCgroupPtr group, } +static int +virCgroupV1CopyMounts(virCgroupPtr group, + virCgroupPtr parent) +{ + size_t i; + for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + if (!parent->controllers[i].mountPoint) + continue; + + if (VIR_STRDUP(group->controllers[i].mountPoint, + parent->controllers[i].mountPoint) < 0) + return -1; + + if (VIR_STRDUP(group->controllers[i].linkPoint, + parent->controllers[i].linkPoint) < 0) + return -1; + } + return 0; +} + + virCgroupBackend virCgroupV1Backend = { .type = VIR_CGROUP_BACKEND_TYPE_V1, .available = virCgroupV1Available, .validateMachineGroup = virCgroupV1ValidateMachineGroup, + .copyMounts = virCgroupV1CopyMounts, }; -- 2.22.0