mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 22:55:23 +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:
|
* virCgroupDetectPlacement:
|
||||||
* @group: the group to process
|
* @group: the group to process
|
||||||
@ -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
|
|||||||
(*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 {
|
|||||||
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,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 = {
|
|||||||
.available = virCgroupV1Available,
|
.available = virCgroupV1Available,
|
||||||
.validateMachineGroup = virCgroupV1ValidateMachineGroup,
|
.validateMachineGroup = virCgroupV1ValidateMachineGroup,
|
||||||
.copyMounts = virCgroupV1CopyMounts,
|
.copyMounts = virCgroupV1CopyMounts,
|
||||||
|
.copyPlacement = virCgroupV1CopyPlacement,
|
||||||
.detectMounts = virCgroupV1DetectMounts,
|
.detectMounts = virCgroupV1DetectMounts,
|
||||||
.detectPlacement = virCgroupV1DetectPlacement,
|
.detectPlacement = virCgroupV1DetectPlacement,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user