mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
vircgroup: introduce virCgroupV2DevicesCreateProg
This function creates new BPF program with new empty BPF map with the default size and attaches it to the guest cgroup. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
ce11a5c59f
commit
afa2788662
@ -1719,6 +1719,7 @@ virCgroupV2Register;
|
|||||||
# util/vircgroupv2devices.h
|
# util/vircgroupv2devices.h
|
||||||
virCgroupV2DevicesAttachProg;
|
virCgroupV2DevicesAttachProg;
|
||||||
virCgroupV2DevicesAvailable;
|
virCgroupV2DevicesAvailable;
|
||||||
|
virCgroupV2DevicesCreateProg;
|
||||||
virCgroupV2DevicesDetectProg;
|
virCgroupV2DevicesDetectProg;
|
||||||
|
|
||||||
# util/virclosecallbacks.h
|
# util/virclosecallbacks.h
|
||||||
|
@ -426,6 +426,46 @@ virCgroupV2DevicesDetectProg(virCgroupPtr group)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# define VIR_CGROUP_V2_INITIAL_BPF_MAP_SIZE 64
|
||||||
|
|
||||||
|
static int
|
||||||
|
virCgroupV2DevicesCreateMap(size_t size)
|
||||||
|
{
|
||||||
|
int mapfd = virBPFCreateMap(BPF_MAP_TYPE_HASH, sizeof(uint64_t),
|
||||||
|
sizeof(uint32_t), size);
|
||||||
|
|
||||||
|
if (mapfd < 0) {
|
||||||
|
virReportSystemError(errno, "%s",
|
||||||
|
_("failed to initialize device BPF map"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return mapfd;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
virCgroupV2DevicesCreateProg(virCgroupPtr group)
|
||||||
|
{
|
||||||
|
VIR_AUTOCLOSE mapfd = -1;
|
||||||
|
|
||||||
|
if (group->unified.devices.progfd > 0 && group->unified.devices.mapfd > 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
mapfd = virCgroupV2DevicesCreateMap(VIR_CGROUP_V2_INITIAL_BPF_MAP_SIZE);
|
||||||
|
if (mapfd < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (virCgroupV2DevicesAttachProg(group, mapfd,
|
||||||
|
VIR_CGROUP_V2_INITIAL_BPF_MAP_SIZE) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
mapfd = -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#else /* !HAVE_DECL_BPF_CGROUP_DEVICE */
|
#else /* !HAVE_DECL_BPF_CGROUP_DEVICE */
|
||||||
bool
|
bool
|
||||||
virCgroupV2DevicesAvailable(virCgroupPtr group G_GNUC_UNUSED)
|
virCgroupV2DevicesAvailable(virCgroupPtr group G_GNUC_UNUSED)
|
||||||
@ -454,4 +494,14 @@ virCgroupV2DevicesDetectProg(virCgroupPtr group G_GNUC_UNUSED)
|
|||||||
"with this kernel"));
|
"with this kernel"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
virCgroupV2DevicesCreateProg(virCgroupPtr group G_GNUC_UNUSED)
|
||||||
|
{
|
||||||
|
virReportSystemError(ENOSYS, "%s",
|
||||||
|
_("cgroups v2 BPF devices not supported "
|
||||||
|
"with this kernel"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
#endif /* !HAVE_DECL_BPF_CGROUP_DEVICE */
|
#endif /* !HAVE_DECL_BPF_CGROUP_DEVICE */
|
||||||
|
@ -30,3 +30,6 @@ virCgroupV2DevicesAttachProg(virCgroupPtr group,
|
|||||||
|
|
||||||
int
|
int
|
||||||
virCgroupV2DevicesDetectProg(virCgroupPtr group);
|
virCgroupV2DevicesDetectProg(virCgroupPtr group);
|
||||||
|
|
||||||
|
int
|
||||||
|
virCgroupV2DevicesCreateProg(virCgroupPtr group);
|
||||||
|
Loading…
Reference in New Issue
Block a user