mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-07-31 22:17:17 +00:00
vircgroup: refactor virCgroupNewPartition
The old code passed an absolute path to virCgroupNewFromParent() which is not necessary. The code can take the current placement of parent cgroup and append a relative path. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
14674ad436
commit
6f0aa96f41
@ -896,6 +896,7 @@ virCgroupNewPartition(const char *path,
|
|||||||
g_autofree char *newPath = NULL;
|
g_autofree char *newPath = NULL;
|
||||||
g_autoptr(virCgroup) parent = NULL;
|
g_autoptr(virCgroup) parent = NULL;
|
||||||
g_autoptr(virCgroup) newGroup = NULL;
|
g_autoptr(virCgroup) newGroup = NULL;
|
||||||
|
char *partition = NULL;
|
||||||
|
|
||||||
VIR_DEBUG("path=%s create=%d controllers=%x",
|
VIR_DEBUG("path=%s create=%d controllers=%x",
|
||||||
path, create, controllers);
|
path, create, controllers);
|
||||||
@ -914,17 +915,26 @@ virCgroupNewPartition(const char *path,
|
|||||||
|
|
||||||
if (STRNEQ(newPath, "/")) {
|
if (STRNEQ(newPath, "/")) {
|
||||||
char *tmp;
|
char *tmp;
|
||||||
g_autofree char *parentPath = g_strdup(newPath);
|
const char *parentPath;
|
||||||
|
|
||||||
tmp = strrchr(parentPath, '/');
|
tmp = strrchr(newPath, '/');
|
||||||
tmp++;
|
|
||||||
*tmp = '\0';
|
*tmp = '\0';
|
||||||
|
|
||||||
|
if (tmp == newPath) {
|
||||||
|
parentPath = "/";
|
||||||
|
} else {
|
||||||
|
parentPath = newPath;
|
||||||
|
}
|
||||||
|
|
||||||
if (virCgroupNew(parentPath, controllers, &parent) < 0)
|
if (virCgroupNew(parentPath, controllers, &parent) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
partition = tmp + 1;
|
||||||
|
} else {
|
||||||
|
partition = newPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virCgroupNewFromParent(parent, newPath, controllers, &newGroup) < 0)
|
if (virCgroupNewFromParent(parent, partition, controllers, &newGroup) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (parent) {
|
if (parent) {
|
||||||
|
Loading…
Reference in New Issue
Block a user