diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 733bbe68fbcb914718712ba4806ccc97a72e55ea..ffbbb8e7ddc6a5cca2466d5e5a50ae9d7d8ba392 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 b4eaa890214aced5b6be130bf7bd5036acd9f9a6..916227ba6a4d8f53d511a66f04c2c09e959b62cb 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 d07eb494a3906de95e691bac6a0a472369a17ccc..5832c937f1454b08b5e5571ac273ae7c7e362b33 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, };