]> git.ipfire.org Git - thirdparty/libvirt.git/commit
vircgroup: introduce virCgroupV2DevicesPrepareProg
authorPavel Hrdina <phrdina@redhat.com>
Mon, 24 Jun 2019 12:34:51 +0000 (14:34 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Fri, 15 Nov 2019 11:58:33 +0000 (12:58 +0100)
commitef747499a5e8900a84b40773c4b8b650e2cc93f5
tree5231870581c30f28ca5471858fbc4dba906fe7cb
parentafa2788662cc054a0b73a44799db575633424e93
vircgroup: introduce virCgroupV2DevicesPrepareProg

This function will be called for every virCgroup(Allow|Deny)* API in
order to prepare BPF program for guest.  Since libvirtd can be restarted
at any point we will first try to detect existing progam, if there is
none we will create a new empty BPF program and lastly if we don't have
any space left in the existing BPF map we will create a new copy of the
BPF map with more space and attach a new program with that map into the
guest cgroup.

This solution allows us to start with reasonably small BPF map consuming
only small amount of memory and if needed we can easily extend the BPF
map if there is a lot of host devices used in guest or if user wants to
hot-plug a lot of devices once the guest is running.

Since there is no way how to reallocate existing BPF map we need to
create a new copy if we run out of space in current BPF map.

This overcomes all the limitations in BPF:

    - map used in program has to be created before the program is loaded
      into kernel

    - once map is created you cannot change its size

    - you cannot replace map in existing program

    - you cannot use an array of maps because it can store FD to maps
      of one specific size so we would not be able to use it to overcome
      the second issue

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/libvirt_private.syms
src/util/vircgroupv2devices.c
src/util/vircgroupv2devices.h