mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
vircgroupv2: properly detect placement of running VM
When libvirtd starts a VM it internally stores a path to the main cgroup. When we restart libvirtd we should get to the same state. When we start a VM on host with systemd the cgroup is created for us and the process is already placed into that cgroup and we detect the path created by systemd using /proc/$PID/cgroup. After that we create sub-cgroups and move all threads there. Once libvirtd is restarted we again detect the cgroup path using /proc/$PID/cgroup, but in this case we will get a different path because the main thread was moved to a "emulator" cgroup. Instead of ignoring the "emulator" directory when validating cgroups remove it completely when detecting cgroup otherwise cgroups will not work properly when libvirtd is restarted. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
e85cfb095a
commit
902c6644a8
@ -122,12 +122,6 @@ virCgroupV2ValidateMachineGroup(virCgroupPtr group,
|
|||||||
if (!(tmp = strrchr(group->unified.placement, '/')))
|
if (!(tmp = strrchr(group->unified.placement, '/')))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (STREQ(tmp, "/emulator")) {
|
|
||||||
*tmp = '\0';
|
|
||||||
|
|
||||||
if (!(tmp = strrchr(group->unified.placement, '/')))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
tmp++;
|
tmp++;
|
||||||
|
|
||||||
if (STRNEQ(tmp, partmachinename) &&
|
if (STRNEQ(tmp, partmachinename) &&
|
||||||
@ -198,6 +192,9 @@ virCgroupV2DetectPlacement(virCgroupPtr group,
|
|||||||
const char *controllers,
|
const char *controllers,
|
||||||
const char *selfpath)
|
const char *selfpath)
|
||||||
{
|
{
|
||||||
|
g_autofree char *placement = g_strdup(selfpath);
|
||||||
|
char *tmp = NULL;
|
||||||
|
|
||||||
if (group->unified.placement)
|
if (group->unified.placement)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -208,12 +205,18 @@ virCgroupV2DetectPlacement(virCgroupPtr group,
|
|||||||
if (STRNEQ(controllers, ""))
|
if (STRNEQ(controllers, ""))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
/* Running VM will have the main thread placed in emulator cgroup
|
||||||
|
* but we need to get the main cgroup. */
|
||||||
|
tmp = g_strrstr(placement, "/emulator");
|
||||||
|
if (tmp)
|
||||||
|
*tmp = '\0';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* selfpath == "/" + path="" -> "/"
|
* selfpath == "/" + path="" -> "/"
|
||||||
* selfpath == "/libvirt.service" + path == "" -> "/libvirt.service"
|
* selfpath == "/libvirt.service" + path == "" -> "/libvirt.service"
|
||||||
* selfpath == "/libvirt.service" + path == "foo" -> "/libvirt.service/foo"
|
* selfpath == "/libvirt.service" + path == "foo" -> "/libvirt.service/foo"
|
||||||
*/
|
*/
|
||||||
group->unified.placement = g_strdup_printf("%s%s%s", selfpath,
|
group->unified.placement = g_strdup_printf("%s%s%s", placement,
|
||||||
(STREQ(selfpath, "/") || STREQ(path, "") ? "" : "/"), path);
|
(STREQ(selfpath, "/") || STREQ(path, "") ? "" : "/"), path);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user