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>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Pavel Hrdina 2019-06-24 14:39:23 +02:00
parent ef747499a5
commit 6a24bd75ed
4 changed files with 33 additions and 0 deletions

View File

@ -1722,6 +1722,7 @@ virCgroupV2DevicesAvailable;
virCgroupV2DevicesCreateProg;
virCgroupV2DevicesDetectProg;
virCgroupV2DevicesPrepareProg;
virCgroupV2DevicesRemoveProg;
# util/virclosecallbacks.h
virCloseCallbacksGet;

View 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);
}

View 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 */

View File

@ -36,3 +36,6 @@ virCgroupV2DevicesCreateProg(virCgroupPtr group);
int
virCgroupV2DevicesPrepareProg(virCgroupPtr group);
int
virCgroupV2DevicesRemoveProg(virCgroupPtr group);