[PATCH 1/1] vircgroup: Cleanup nested cgroups

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The introduction of nested cgroups used a little macro
virCgroupGetNested() to retrieve the nested cgroup
pointer, if one exists. But this macro isn't used when
removing cgroups, resulting in some messages:

  Mar 25 20:55:17 fedora33 libvirtd[955]: unable to open '/sys/fs/cgroup/machine.slice/machine-qemu\x2d1\x2dguest.scope/': No such file or directory
  Mar 25 20:55:17 fedora33 libvirtd[955]: Failed to remove cgroup for guest

That directory exists while the guest is running, as it
was created by systemd/machined, so the code probably meant
to open the libvirt/ subdirectory from that point.

Similarly, there happen to be BPF-related file descriptors
that don't get cleaned up in this process too, because they
are anchored off the nested cgroup location:

  [test@fedora33 ~]# ls /proc/$(pgrep libvirtd)/fd/* | wc -l
  35
  [test@fedora33 ~]# virsh create guest.xml
  Domain 'guest' created from guest.xml

  [test@fedora33 ~]# ls /proc/$(pgrep libvirtd)/fd/* | wc -l
  42
  [test@fedora33 ~]# virsh shutdown guest
  Domain 'guest' is being shutdown

  [test@fedora33 ~]# ls /proc/$(pgrep libvirtd)/fd/* | wc -l
  37
  [test@fedora33 ~]# virsh create guest.xml
  Domain 'guest' created from guest.xml

  [test@fedora33 ~]# ls /proc/$(pgrep libvirtd)/fd/* | wc -l
  44
  [test@fedora33 ~]# virsh shutdown guest
  Domain 'guest' is being shutdown

  [test@fedora33 ~]# ls /proc/$(pgrep libvirtd)/fd/* | wc -l
  39

Let's fix this by using the same macro when removing cgroups,
so that it picks up the right structure and can remove the
associated resources properly.

Fixes: 184245f53b94 ("vircgroup: introduce nested cgroup to properly work with systemd")
Signed-off-by: Eric Farman <farman@xxxxxxxxxxxxx>
---
 src/util/vircgroup.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 5b6097c335..e606cbfe0b 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -2613,11 +2613,12 @@ virCgroupRemoveRecursively(char *grppath)
 int
 virCgroupRemove(virCgroupPtr group)
 {
+    virCgroupPtr parent = virCgroupGetNested(group);
     size_t i;
 
     for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
-        if (group->backends[i]) {
-            int rc = group->backends[i]->remove(group);
+        if (parent->backends[i]) {
+            int rc = parent->backends[i]->remove(parent);
             if (rc < 0)
                 return rc;
         }
-- 
2.25.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux