Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx> --- 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 817ee8f6ca..55122a5ab9 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1454,27 +1454,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 933f59151a..cf000529c4 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 105024ddde..7d92150dc3 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, }; -- 2.17.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list