提交 229a8b5d 编写于 作者: P Pavel Hrdina

vircgroup: extract virCgroupV1CopyPlacement

Reviewed-by: NFabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
Signed-off-by: NPavel Hrdina <phrdina@redhat.com>
上级 42a3fcc0
...@@ -265,42 +265,6 @@ virCgroupDetectMounts(virCgroupPtr group) ...@@ -265,42 +265,6 @@ virCgroupDetectMounts(virCgroupPtr group)
} }
static int
virCgroupCopyPlacement(virCgroupPtr group,
const char *path,
virCgroupPtr parent)
{
size_t i;
for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
if (!group->controllers[i].mountPoint)
continue;
if (i == VIR_CGROUP_CONTROLLER_SYSTEMD)
continue;
if (path[0] == '/') {
if (VIR_STRDUP(group->controllers[i].placement, path) < 0)
return -1;
} else {
/*
* parent == "/" + path="" => "/"
* parent == "/libvirt.service" + path == "" => "/libvirt.service"
* parent == "/libvirt.service" + path == "foo" => "/libvirt.service/foo"
*/
if (virAsprintf(&group->controllers[i].placement,
"%s%s%s",
parent->controllers[i].placement,
(STREQ(parent->controllers[i].placement, "/") ||
STREQ(path, "") ? "" : "/"),
path) < 0)
return -1;
}
}
return 0;
}
/* /*
* virCgroupDetectPlacement: * virCgroupDetectPlacement:
* @group: the group to process * @group: the group to process
...@@ -528,7 +492,7 @@ virCgroupDetect(virCgroupPtr group, ...@@ -528,7 +492,7 @@ virCgroupDetect(virCgroupPtr group,
* based on the parent cgroup... * based on the parent cgroup...
*/ */
if ((parent || path[0] == '/') && if ((parent || path[0] == '/') &&
virCgroupCopyPlacement(group, path, parent) < 0) group->backend->copyPlacement(group, path, parent) < 0)
return -1; return -1;
/* ... but use /proc/cgroups to fill in the rest */ /* ... but use /proc/cgroups to fill in the rest */
......
...@@ -45,6 +45,11 @@ typedef int ...@@ -45,6 +45,11 @@ typedef int
(*virCgroupCopyMountsCB)(virCgroupPtr group, (*virCgroupCopyMountsCB)(virCgroupPtr group,
virCgroupPtr parent); virCgroupPtr parent);
typedef int
(*virCgroupCopyPlacementCB)(virCgroupPtr group,
const char *path,
virCgroupPtr parent);
typedef int typedef int
(*virCgroupDetectMountsCB)(virCgroupPtr group, (*virCgroupDetectMountsCB)(virCgroupPtr group,
const char *mntType, const char *mntType,
...@@ -64,6 +69,7 @@ struct _virCgroupBackend { ...@@ -64,6 +69,7 @@ struct _virCgroupBackend {
virCgroupAvailableCB available; virCgroupAvailableCB available;
virCgroupValidateMachineGroupCB validateMachineGroup; virCgroupValidateMachineGroupCB validateMachineGroup;
virCgroupCopyMountsCB copyMounts; virCgroupCopyMountsCB copyMounts;
virCgroupCopyPlacementCB copyPlacement;
virCgroupDetectMountsCB detectMounts; virCgroupDetectMountsCB detectMounts;
virCgroupDetectPlacementCB detectPlacement; virCgroupDetectPlacementCB detectPlacement;
}; };
......
...@@ -182,6 +182,42 @@ virCgroupV1CopyMounts(virCgroupPtr group, ...@@ -182,6 +182,42 @@ virCgroupV1CopyMounts(virCgroupPtr group,
} }
static int
virCgroupV1CopyPlacement(virCgroupPtr group,
const char *path,
virCgroupPtr parent)
{
size_t i;
for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
if (!group->controllers[i].mountPoint)
continue;
if (i == VIR_CGROUP_CONTROLLER_SYSTEMD)
continue;
if (path[0] == '/') {
if (VIR_STRDUP(group->controllers[i].placement, path) < 0)
return -1;
} else {
/*
* parent == "/" + path="" => "/"
* parent == "/libvirt.service" + path == "" => "/libvirt.service"
* parent == "/libvirt.service" + path == "foo" => "/libvirt.service/foo"
*/
if (virAsprintf(&group->controllers[i].placement,
"%s%s%s",
parent->controllers[i].placement,
(STREQ(parent->controllers[i].placement, "/") ||
STREQ(path, "") ? "" : "/"),
path) < 0)
return -1;
}
}
return 0;
}
static int static int
virCgroupV1ResolveMountLink(const char *mntDir, virCgroupV1ResolveMountLink(const char *mntDir,
const char *typeStr, const char *typeStr,
...@@ -342,6 +378,7 @@ virCgroupBackend virCgroupV1Backend = { ...@@ -342,6 +378,7 @@ virCgroupBackend virCgroupV1Backend = {
.available = virCgroupV1Available, .available = virCgroupV1Available,
.validateMachineGroup = virCgroupV1ValidateMachineGroup, .validateMachineGroup = virCgroupV1ValidateMachineGroup,
.copyMounts = virCgroupV1CopyMounts, .copyMounts = virCgroupV1CopyMounts,
.copyPlacement = virCgroupV1CopyPlacement,
.detectMounts = virCgroupV1DetectMounts, .detectMounts = virCgroupV1DetectMounts,
.detectPlacement = virCgroupV1DetectPlacement, .detectPlacement = virCgroupV1DetectPlacement,
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册