vircgroup: extract virCgroupV1PathOfController

Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Pavel Hrdina 2018-08-19 19:24:58 +02:00
parent d6564037e8
commit 57890b2ab4
3 changed files with 39 additions and 21 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -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,
};