From 47941ea7f52be44f609a6b6acc8895644039e617 Mon Sep 17 00:00:00 2001 From: Pavel Hrdina Date: Fri, 17 Aug 2018 09:46:10 +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 --- 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 6358a25367..ec4a878614 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -231,27 +231,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, @@ -649,7 +628,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 d3879f9061..d164c20dc5 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -159,11 +159,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, };