mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
vircgroup: refactor virCgroupEnableMissingControllers
Use virStringSplit() to get the list of directories needed to be created. This improves readability of the code and stops passing absolute path to virCgroupNewFromParent(). Signed-off-by: Pavel Hrdina <phrdina@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
99d2c6519a
commit
77291414c7
@ -1131,21 +1131,18 @@ virCgroupEnableMissingControllers(char *path,
|
|||||||
virCgroupPtr *group)
|
virCgroupPtr *group)
|
||||||
{
|
{
|
||||||
g_autoptr(virCgroup) parent = NULL;
|
g_autoptr(virCgroup) parent = NULL;
|
||||||
char *offset = path;
|
VIR_AUTOSTRINGLIST tokens = virStringSplit(path, "/", 0);
|
||||||
|
size_t i;
|
||||||
|
|
||||||
if (virCgroupNew("/",
|
if (virCgroupNew("/", controllers, &parent) < 0)
|
||||||
controllers,
|
|
||||||
&parent) < 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (;;) {
|
/* Skip the first token as it is empty string. */
|
||||||
|
for (i = 1; tokens[i]; i++) {
|
||||||
g_autoptr(virCgroup) tmp = NULL;
|
g_autoptr(virCgroup) tmp = NULL;
|
||||||
char *t = strchr(offset + 1, '/');
|
|
||||||
if (t)
|
|
||||||
*t = '\0';
|
|
||||||
|
|
||||||
if (virCgroupNewFromParent(parent,
|
if (virCgroupNewFromParent(parent,
|
||||||
path,
|
tokens[i],
|
||||||
controllers,
|
controllers,
|
||||||
&tmp) < 0)
|
&tmp) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -1153,17 +1150,10 @@ virCgroupEnableMissingControllers(char *path,
|
|||||||
if (virCgroupMakeGroup(parent, tmp, true, VIR_CGROUP_SYSTEMD) < 0)
|
if (virCgroupMakeGroup(parent, tmp, true, VIR_CGROUP_SYSTEMD) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (t) {
|
|
||||||
*t = '/';
|
|
||||||
offset = t;
|
|
||||||
virCgroupFree(parent);
|
|
||||||
parent = g_steal_pointer(&tmp);
|
parent = g_steal_pointer(&tmp);
|
||||||
} else {
|
|
||||||
*group = g_steal_pointer(&tmp);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*group = g_steal_pointer(&parent);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user