From 57890b2ab49b27ca9dc8a3922fe61e586aca8f77 Mon Sep 17 00:00:00 2001 From: Pavel Hrdina Date: Sun, 19 Aug 2018 19:24:58 +0200 Subject: [PATCH] vircgroup: extract virCgroupV1PathOfController 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 | 22 +--------------------- src/util/vircgroupbackend.h | 7 +++++++ src/util/vircgroupv1.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 733bbe68fb..ffbbb8e7dd 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1456,27 +1456,7 @@ virCgroupPathOfController(virCgroupPtr group, return -1; } - if (group->controllers[controller].mountPoint == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Controller '%s' is not mounted"), - virCgroupControllerTypeToString(controller)); - return -1; - } - - if (group->controllers[controller].placement == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Controller '%s' is not enabled for group"), - virCgroupControllerTypeToString(controller)); - return -1; - } - - if (virAsprintf(path, "%s%s/%s", - group->controllers[controller].mountPoint, - group->controllers[controller].placement, - key ? key : "") < 0) - return -1; - - return 0; + return group->backend->pathOfController(group, controller, key, path); } diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index b4eaa89021..916227ba6a 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -80,6 +80,12 @@ typedef bool typedef int (*virCgroupGetAnyControllerCB)(virCgroupPtr group); +typedef int +(*virCgroupPathOfControllerCB)(virCgroupPtr group, + int controller, + const char *key, + char **path); + struct _virCgroupBackend { virCgroupBackendType type; @@ -95,6 +101,7 @@ struct _virCgroupBackend { virCgroupDetectControllersCB detectControllers; virCgroupHasControllerCB hasController; virCgroupGetAnyControllerCB getAnyController; + virCgroupPathOfControllerCB pathOfController; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index d07eb494a3..5832c937f1 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -506,6 +506,36 @@ virCgroupV1GetAnyController(virCgroupPtr group) } +static int +virCgroupV1PathOfController(virCgroupPtr group, + int controller, + const char *key, + char **path) +{ + if (group->controllers[controller].mountPoint == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("v1 controller '%s' is not mounted"), + virCgroupV1ControllerTypeToString(controller)); + return -1; + } + + if (group->controllers[controller].placement == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("v1 controller '%s' is not enabled for group"), + virCgroupV1ControllerTypeToString(controller)); + return -1; + } + + if (virAsprintf(path, "%s%s/%s", + group->controllers[controller].mountPoint, + group->controllers[controller].placement, + key ? key : "") < 0) + return -1; + + return 0; +} + + virCgroupBackend virCgroupV1Backend = { .type = VIR_CGROUP_BACKEND_TYPE_V1, @@ -520,6 +550,7 @@ virCgroupBackend virCgroupV1Backend = { .detectControllers = virCgroupV1DetectControllers, .hasController = virCgroupV1HasController, .getAnyController = virCgroupV1GetAnyController, + .pathOfController = virCgroupV1PathOfController, }; -- GitLab