]> xenbits.xensource.com Git - libvirt.git/commitdiff
vircgroup: introduce virCgroupV2DevicesRemoveProg
authorPavel Hrdina <phrdina@redhat.com>
Mon, 24 Jun 2019 12:39:23 +0000 (14:39 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Fri, 15 Nov 2019 11:58:34 +0000 (12:58 +0100)
We need to close our FD that we have for BPF program and map in order
to let kernel remove all resources once the cgroup is removed as well.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/libvirt_private.syms
src/util/vircgroupv2.c
src/util/vircgroupv2devices.c
src/util/vircgroupv2devices.h

index 2ec9f067302779a32cddbab99ab7a4c76990c9b3..3553e82f5c3b4c3786bb17f59aae58df414bced5 100644 (file)
@@ -1722,6 +1722,7 @@ virCgroupV2DevicesAvailable;
 virCgroupV2DevicesCreateProg;
 virCgroupV2DevicesDetectProg;
 virCgroupV2DevicesPrepareProg;
+virCgroupV2DevicesRemoveProg;
 
 # util/virclosecallbacks.h
 virCloseCallbacksGet;
index cb5d9946a0b6d5f3e6b10550950361970f0da1d9..6bce9012ae3885bafb367069ab8c34db76fed26b 100644 (file)
@@ -488,6 +488,9 @@ virCgroupV2Remove(virCgroupPtr group)
     if (virCgroupV2PathOfController(group, controller, "", &grppath) < 0)
         return 0;
 
+    if (virCgroupV2DevicesRemoveProg(group) < 0)
+        return -1;
+
     return virCgroupRemoveRecursively(grppath);
 }
 
index 7e537f5368589ed7e66c63729d3f3a3dc182d68e..980d8a2b7c6d559b4c3b7537bef5e432ba80eb99 100644 (file)
@@ -538,6 +538,25 @@ virCgroupV2DevicesPrepareProg(virCgroupPtr group)
 
     return 0;
 }
+
+
+int
+virCgroupV2DevicesRemoveProg(virCgroupPtr 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)
+        VIR_FORCE_CLOSE(group->unified.devices.mapfd);
+
+    if (group->unified.devices.progfd >= 0)
+        VIR_FORCE_CLOSE(group->unified.devices.progfd);
+
+    return 0;
+}
 #else /* !HAVE_DECL_BPF_CGROUP_DEVICE */
 bool
 virCgroupV2DevicesAvailable(virCgroupPtr group G_GNUC_UNUSED)
@@ -586,4 +605,11 @@ virCgroupV2DevicesPrepareProg(virCgroupPtr group G_GNUC_UNUSED)
                            "with this kernel"));
     return -1;
 }
+
+
+int
+virCgroupV2DevicesRemoveProg(virCgroupPtr group G_GNUC_UNUSED)
+{
+    return 0;
+}
 #endif /* !HAVE_DECL_BPF_CGROUP_DEVICE */
index 357ed0c8bf3038297e27387aa7d4439747a4bf54..879d9cb77b9b29324b1c60de6af24db8c54c8870 100644 (file)
@@ -36,3 +36,6 @@ virCgroupV2DevicesCreateProg(virCgroupPtr group);
 
 int
 virCgroupV2DevicesPrepareProg(virCgroupPtr group);
+
+int
+virCgroupV2DevicesRemoveProg(virCgroupPtr group);