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

[libvirt] [PATCH v2 07/17] vircgroup: introduce virCgroupV2DevicesRemoveProg



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 1d1f8bf478..c4f5cdea46 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1617,6 +1617,7 @@ virCgroupV2DevicesAvailable;
 virCgroupV2DevicesCreateProg;
 virCgroupV2DevicesDetectProg;
 virCgroupV2DevicesPrepareProg;
+virCgroupV2DevicesRemoveProg;
 
 # util/virclosecallbacks.h
 virCloseCallbacksGet;
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index a56f3443e3..b5d4776d14 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -439,6 +439,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 e3a415d615..e7f8c048fc 100644
--- a/src/util/vircgroupv2devices.c
+++ b/src/util/vircgroupv2devices.c
@@ -415,6 +415,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)
@@ -463,4 +482,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


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