mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 22:25:25 +00:00
vircgroup: extract virCgroupV1CopyPlacement
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:
parent
42a3fcc02b
commit
229a8b5d35
@ -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:
|
||||
* @group: the group to process
|
||||
@ -528,7 +492,7 @@ virCgroupDetect(virCgroupPtr group,
|
||||
* based on the parent cgroup...
|
||||
*/
|
||||
if ((parent || path[0] == '/') &&
|
||||
virCgroupCopyPlacement(group, path, parent) < 0)
|
||||
group->backend->copyPlacement(group, path, parent) < 0)
|
||||
return -1;
|
||||
|
||||
/* ... but use /proc/cgroups to fill in the rest */
|
||||
|
@ -45,6 +45,11 @@ typedef int
|
||||
(*virCgroupCopyMountsCB)(virCgroupPtr group,
|
||||
virCgroupPtr parent);
|
||||
|
||||
typedef int
|
||||
(*virCgroupCopyPlacementCB)(virCgroupPtr group,
|
||||
const char *path,
|
||||
virCgroupPtr parent);
|
||||
|
||||
typedef int
|
||||
(*virCgroupDetectMountsCB)(virCgroupPtr group,
|
||||
const char *mntType,
|
||||
@ -64,6 +69,7 @@ struct _virCgroupBackend {
|
||||
virCgroupAvailableCB available;
|
||||
virCgroupValidateMachineGroupCB validateMachineGroup;
|
||||
virCgroupCopyMountsCB copyMounts;
|
||||
virCgroupCopyPlacementCB copyPlacement;
|
||||
virCgroupDetectMountsCB detectMounts;
|
||||
virCgroupDetectPlacementCB detectPlacement;
|
||||
};
|
||||
|
@ -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
|
||||
virCgroupV1ResolveMountLink(const char *mntDir,
|
||||
const char *typeStr,
|
||||
@ -342,6 +378,7 @@ virCgroupBackend virCgroupV1Backend = {
|
||||
.available = virCgroupV1Available,
|
||||
.validateMachineGroup = virCgroupV1ValidateMachineGroup,
|
||||
.copyMounts = virCgroupV1CopyMounts,
|
||||
.copyPlacement = virCgroupV1CopyPlacement,
|
||||
.detectMounts = virCgroupV1DetectMounts,
|
||||
.detectPlacement = virCgroupV1DetectPlacement,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user