From: Pavel Hrdina Date: Mon, 24 Jun 2019 12:39:23 +0000 (+0200) Subject: vircgroup: introduce virCgroupV2DevicesRemoveProg X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=6a24bd75ede9e7cc3f707fbd8e2075eb28118811;p=libvirt.git 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 Reviewed-by: Ján Tomko --- diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 2ec9f06730..3553e82f5c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1722,6 +1722,7 @@ virCgroupV2DevicesAvailable; virCgroupV2DevicesCreateProg; virCgroupV2DevicesDetectProg; virCgroupV2DevicesPrepareProg; +virCgroupV2DevicesRemoveProg; # util/virclosecallbacks.h virCloseCallbacksGet; diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index cb5d9946a0..6bce9012ae 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -488,6 +488,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 7e537f5368..980d8a2b7c 100644 --- a/src/util/vircgroupv2devices.c +++ b/src/util/vircgroupv2devices.c @@ -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 */ diff --git a/src/util/vircgroupv2devices.h b/src/util/vircgroupv2devices.h index 357ed0c8bf..879d9cb77b 100644 --- a/src/util/vircgroupv2devices.h +++ b/src/util/vircgroupv2devices.h @@ -36,3 +36,6 @@ virCgroupV2DevicesCreateProg(virCgroupPtr group); int virCgroupV2DevicesPrepareProg(virCgroupPtr group); + +int +virCgroupV2DevicesRemoveProg(virCgroupPtr group);