vircgroup: introduce virCgroupSetPlacement

Currently this task is done by virCgroupCopyPlacement when the @path
starts with "/".

virCgroupNew is always called with @path starting with "/" and there is
no parent to copy path from. To make it obvious what the code is doing
introduce new helper.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Pavel Hrdina 2020-10-21 14:35:48 +02:00
parent ca7b305631
commit 085590fee4
4 changed files with 55 additions and 1 deletions

View File

@ -393,6 +393,23 @@ virCgroupDetectPlacement(virCgroupPtr group,
}
static int
virCgroupSetPlacement(virCgroupPtr group,
const char *path)
{
size_t i;
for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
if (group->backends[i] &&
group->backends[i]->setPlacement(group, path) < 0) {
return -1;
}
}
return 0;
}
static int
virCgroupValidatePlacement(virCgroupPtr group,
pid_t pid)
@ -689,7 +706,7 @@ virCgroupNew(const char *path,
if (virCgroupDetectMounts(newGroup) < 0)
return -1;
if (virCgroupCopyPlacement(newGroup, path, NULL) < 0)
if (virCgroupSetPlacement(newGroup, path) < 0)
return -1;
/* ... but use /proc/cgroups to fill in the rest */

View File

@ -88,6 +88,10 @@ typedef int
const char *controllers,
const char *selfpath);
typedef int
(*virCgroupSetPlacementCB)(virCgroupPtr group,
const char *path);
typedef int
(*virCgroupValidatePlacementCB)(virCgroupPtr group,
pid_t pid);
@ -369,6 +373,7 @@ struct _virCgroupBackend {
virCgroupCopyPlacementCB copyPlacement;
virCgroupDetectMountsCB detectMounts;
virCgroupDetectPlacementCB detectPlacement;
virCgroupSetPlacementCB setPlacement;
virCgroupValidatePlacementCB validatePlacement;
virCgroupStealPlacementCB stealPlacement;
virCgroupDetectControllersCB detectControllers;

View File

@ -364,6 +364,26 @@ virCgroupV1DetectPlacement(virCgroupPtr group,
}
static int
virCgroupV1SetPlacement(virCgroupPtr group,
const char *path)
{
size_t i;
for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
if (!group->legacy[i].mountPoint)
continue;
if (i == VIR_CGROUP_CONTROLLER_SYSTEMD)
continue;
group->legacy[i].placement = g_strdup(path);
}
return 0;
}
static int
virCgroupV1ValidatePlacement(virCgroupPtr group,
pid_t pid)
@ -2101,6 +2121,7 @@ virCgroupBackend virCgroupV1Backend = {
.copyPlacement = virCgroupV1CopyPlacement,
.detectMounts = virCgroupV1DetectMounts,
.detectPlacement = virCgroupV1DetectPlacement,
.setPlacement = virCgroupV1SetPlacement,
.validatePlacement = virCgroupV1ValidatePlacement,
.stealPlacement = virCgroupV1StealPlacement,
.detectControllers = virCgroupV1DetectControllers,

View File

@ -223,6 +223,16 @@ virCgroupV2DetectPlacement(virCgroupPtr group,
}
static int
virCgroupV2SetPlacement(virCgroupPtr group,
const char *path)
{
group->unified.placement = g_strdup(path);
return 0;
}
static int
virCgroupV2ValidatePlacement(virCgroupPtr group,
pid_t pid G_GNUC_UNUSED)
@ -1845,6 +1855,7 @@ virCgroupBackend virCgroupV2Backend = {
.copyPlacement = virCgroupV2CopyPlacement,
.detectMounts = virCgroupV2DetectMounts,
.detectPlacement = virCgroupV2DetectPlacement,
.setPlacement = virCgroupV2SetPlacement,
.validatePlacement = virCgroupV2ValidatePlacement,
.stealPlacement = virCgroupV2StealPlacement,
.detectControllers = virCgroupV2DetectControllers,