]> xenbits.xensource.com Git - libvirt.git/commitdiff
vircgroupv2devices: refactor virCgroupV2DevicesRemoveProg
authorPavel Hrdina <phrdina@redhat.com>
Wed, 14 Apr 2021 10:01:23 +0000 (12:01 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Wed, 14 Apr 2021 10:06:16 +0000 (12:06 +0200)
When running on systemd host the cgroup itself is removed by machined
so when we reach this code the directory no longer exist. If libvirtd
was running the whole time between starting and destroying VM the
detection is skipped because we still have both FD in memory. But if
libvirtd was restarted and no operation requiring cgroup devices
executed the FDs would be 0 and libvirt would try to detect them using
the cgroup directory. This results in reporting following errors:

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

When running on non-systemd host where we handle cgroups manually this
would not happen.

When destroying VM it is not necessary to detect the BPF prog and map
because the following code only closes the FDs without doing anything
else. We could run code that would try to detach the BPF prog from the
cgroup but that is not necessary as well. If the cgroup is removed and
there is no other FD open to the prog kernel will cleanup the prog and
map eventually.

Reported-by: Eric Farman <farman@linux.ibm.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Tested-by: Eric Farman <farman@linux.ibm.com>
Reviewed-by: Eric Farman <farman@linux.ibm.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/libvirt_private.syms
src/util/vircgroupv2.c
src/util/vircgroupv2devices.c
src/util/vircgroupv2devices.h

index b3f9c9681a202f22cbd6d379a3d2437eaf97a950..a727537c76c1c613987ec22a7f1837b30444d7ba 100644 (file)
@@ -1963,12 +1963,12 @@ virCgroupV2Register;
 
 # util/vircgroupv2devices.h
 virCgroupV2DevicesAvailable;
+virCgroupV2DevicesCloseProg;
 virCgroupV2DevicesCreateProg;
 virCgroupV2DevicesDetectProg;
 virCgroupV2DevicesGetKey;
 virCgroupV2DevicesGetPerms;
 virCgroupV2DevicesPrepareProg;
-virCgroupV2DevicesRemoveProg;
 
 # util/vircommand.h
 virCommandAbort;
index 1c3a78427cccb25747753ac3d09fc849759bb946..e55521735503f466cfba3ffb9f5a77bbefaca8dd 100644 (file)
@@ -535,7 +535,7 @@ virCgroupV2Remove(virCgroup *group)
     if (virCgroupV2PathOfController(group, controller, "", &grppath) < 0)
         return 0;
 
-    if (virCgroupV2DevicesRemoveProg(parent) < 0)
+    if (virCgroupV2DevicesCloseProg(parent) < 0)
         return -1;
 
     return virCgroupRemoveRecursively(grppath);
index 2c6e083132a0c7dfcb35348652989ef96a233f5e..ffa65bdd00f3db0ace7b8e065f563f4af250ac7d 100644 (file)
@@ -548,18 +548,12 @@ virCgroupV2DevicesPrepareProg(virCgroup *group)
 
 
 int
-virCgroupV2DevicesRemoveProg(virCgroup *group)
+virCgroupV2DevicesCloseProg(virCgroup *group)
 {
-    if (virCgroupV2DevicesDetectProg(group) < 0)
-        return -1;
-
-    if (group->unified.devices.progfd <= 0 && group->unified.devices.mapfd <= 0)
-        return 0;
-
-    if (group->unified.devices.mapfd >= 0)
+    if (group->unified.devices.mapfd > 0)
         VIR_FORCE_CLOSE(group->unified.devices.mapfd);
 
-    if (group->unified.devices.progfd >= 0)
+    if (group->unified.devices.progfd > 0)
         VIR_FORCE_CLOSE(group->unified.devices.progfd);
 
     return 0;
@@ -629,7 +623,7 @@ virCgroupV2DevicesPrepareProg(virCgroup *group G_GNUC_UNUSED)
 
 
 int
-virCgroupV2DevicesRemoveProg(virCgroup *group G_GNUC_UNUSED)
+virCgroupV2DevicesCloseProg(virCgroup *group G_GNUC_UNUSED)
 {
     return 0;
 }
index 21f1d882f7c17dac6866d91b0fcd2c34637570ec..1ff46987e89a637853300a02420f371b05871b77 100644 (file)
@@ -38,7 +38,7 @@ int
 virCgroupV2DevicesPrepareProg(virCgroup *group);
 
 int
-virCgroupV2DevicesRemoveProg(virCgroup *group);
+virCgroupV2DevicesCloseProg(virCgroup *group);
 
 uint32_t
 virCgroupV2DevicesGetPerms(int perms,