提交 d6564037 编写于 作者: P Pavel Hrdina

vircgroup: extract virCgroupV1GetAnyController

Reviewed-by: NFabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
Signed-off-by: NPavel Hrdina <phrdina@redhat.com>
上级 5e2df3d0
......@@ -3169,19 +3169,11 @@ virCgroupPathOfAnyController(virCgroupPtr group,
const char *name,
char **keypath)
{
size_t i;
int controller;
for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
/* Reject any controller with a placement
* of '/' to avoid doing bad stuff to the root
* cgroup
*/
if (group->controllers[i].mountPoint &&
group->controllers[i].placement &&
STRNEQ(group->controllers[i].placement, "/")) {
return virCgroupPathOfController(group, i, name, keypath);
}
}
controller = group->backend->getAnyController(group);
if (controller >= 0)
return virCgroupPathOfController(group, controller, name, keypath);
virReportSystemError(ENOSYS, "%s",
_("No controllers are mounted"));
......
......@@ -77,6 +77,9 @@ typedef bool
(*virCgroupHasControllerCB)(virCgroupPtr cgroup,
int controller);
typedef int
(*virCgroupGetAnyControllerCB)(virCgroupPtr group);
struct _virCgroupBackend {
virCgroupBackendType type;
......@@ -91,6 +94,7 @@ struct _virCgroupBackend {
virCgroupStealPlacementCB stealPlacement;
virCgroupDetectControllersCB detectControllers;
virCgroupHasControllerCB hasController;
virCgroupGetAnyControllerCB getAnyController;
};
typedef struct _virCgroupBackend virCgroupBackend;
typedef virCgroupBackend *virCgroupBackendPtr;
......
......@@ -485,6 +485,27 @@ virCgroupV1HasController(virCgroupPtr group,
}
static int
virCgroupV1GetAnyController(virCgroupPtr group)
{
size_t i;
for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
/* Reject any controller with a placement
* of '/' to avoid doing bad stuff to the root
* cgroup
*/
if (group->controllers[i].mountPoint &&
group->controllers[i].placement &&
STRNEQ(group->controllers[i].placement, "/")) {
return i;
}
}
return -1;
}
virCgroupBackend virCgroupV1Backend = {
.type = VIR_CGROUP_BACKEND_TYPE_V1,
......@@ -498,6 +519,7 @@ virCgroupBackend virCgroupV1Backend = {
.stealPlacement = virCgroupV1StealPlacement,
.detectControllers = virCgroupV1DetectControllers,
.hasController = virCgroupV1HasController,
.getAnyController = virCgroupV1GetAnyController,
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册