[libvirt] [PATCH v3 07/15] vircgroup: introduce virCgroupV2DevicesRemoveProg

Pavel Hrdina posted 15 patches 6 years, 9 months ago
[libvirt] [PATCH v3 07/15] vircgroup: introduce virCgroupV2DevicesRemoveProg
Posted by Pavel Hrdina 6 years, 9 months ago
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>
---
 src/libvirt_private.syms      |  1 +
 src/util/vircgroupv2.c        |  3 +++
 src/util/vircgroupv2devices.c | 26 ++++++++++++++++++++++++++
 src/util/vircgroupv2devices.h |  3 +++
 4 files changed, 33 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 9ab07de06d..f42bdad9ef 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1658,6 +1658,7 @@ virCgroupV2DevicesAvailable;
 virCgroupV2DevicesCreateProg;
 virCgroupV2DevicesDetectProg;
 virCgroupV2DevicesPrepareProg;
+virCgroupV2DevicesRemoveProg;
 
 # util/virclosecallbacks.h
 virCloseCallbacksGet;
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index dc7573e05c..ce19169fe7 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -448,6 +448,9 @@ virCgroupV2Remove(virCgroupPtr group)
     if (virCgroupV2PathOfController(group, controller, "", &grppath) < 0)
         return 0;
 
+    if (virCgroupV2DevicesRemoveProg(group) < 0)
+        return -1;
+
     return virCgroupRemoveRecursively(grppath);
 }
 
diff --git a/src/util/vircgroupv2devices.c b/src/util/vircgroupv2devices.c
index e8c6f74091..70e29b8470 100644
--- a/src/util/vircgroupv2devices.c
+++ b/src/util/vircgroupv2devices.c
@@ -551,6 +551,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 ATTRIBUTE_UNUSED)
@@ -599,4 +618,11 @@ virCgroupV2DevicesPrepareProg(virCgroupPtr group ATTRIBUTE_UNUSED)
                            "with this kernel"));
     return -1;
 }
+
+
+int
+virCgroupV2DevicesRemoveProg(virCgroupPtr group ATTRIBUTE_UNUSED)
+{
+    return 0;
+}
 #endif /* !HAVE_DECL_BPF_CGROUP_DEVICE */
diff --git a/src/util/vircgroupv2devices.h b/src/util/vircgroupv2devices.h
index 10c80c8ae4..ae02f9c334 100644
--- a/src/util/vircgroupv2devices.h
+++ b/src/util/vircgroupv2devices.h
@@ -38,4 +38,7 @@ virCgroupV2DevicesCreateProg(virCgroupPtr group);
 int
 virCgroupV2DevicesPrepareProg(virCgroupPtr group);
 
+int
+virCgroupV2DevicesRemoveProg(virCgroupPtr group);
+
 #endif /* LIBVIRT_VIRCGROUPV2DEVICES_H */
-- 
2.20.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v3 07/15] vircgroup: introduce virCgroupV2DevicesRemoveProg
Posted by Ján Tomko 6 years, 7 months ago
On Thu, Apr 25, 2019 at 09:44:24AM +0200, Pavel Hrdina wrote:
>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>
>---
> src/libvirt_private.syms      |  1 +
> src/util/vircgroupv2.c        |  3 +++
> src/util/vircgroupv2devices.c | 26 ++++++++++++++++++++++++++
> src/util/vircgroupv2devices.h |  3 +++
> 4 files changed, 33 insertions(+)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list