[libvirt PATCH] vircgroupv2devices: fix counting entries in BPF map

Pavel Hrdina posted 1 patch 3 years, 8 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/0b0e49844a24582f899eb5d666af4d1096d667b3.1597140817.git.phrdina@redhat.com
src/util/vircgroupv2devices.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[libvirt PATCH] vircgroupv2devices: fix counting entries in BPF map
Posted by Pavel Hrdina 3 years, 8 months ago
BPF syscall BPF_MAP_GET_NEXT_KEY returns -1 if something fails but it
will also return -1 if trying to get next key using the last key in the
map with errno set to ENOENT.

If there are VMs running and libvirtd is restarted and user tries to
call some cgroup devices operation on a VM we need to get the count of
entries in BPF map and it fails which will result in error when trying
to attach/detech devices.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1833321

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 src/util/vircgroupv2devices.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/util/vircgroupv2devices.c b/src/util/vircgroupv2devices.c
index d62ee12a05..234e0f2278 100644
--- a/src/util/vircgroupv2devices.c
+++ b/src/util/vircgroupv2devices.c
@@ -342,7 +342,7 @@ virCgroupV2DevicesCountMapEntries(int mapfd)
         prevKey = key;
     }
 
-    if (rc < 0)
+    if (rc < 0 && errno != ENOENT)
         return -1;
 
     return ret;
-- 
2.26.2

Re: [libvirt PATCH] vircgroupv2devices: fix counting entries in BPF map
Posted by Erik Skultety 3 years, 8 months ago
On Tue, Aug 11, 2020 at 12:13:47PM +0200, Pavel Hrdina wrote:
> BPF syscall BPF_MAP_GET_NEXT_KEY returns -1 if something fails but it
> will also return -1 if trying to get next key using the last key in the
> map with errno set to ENOENT.
>
> If there are VMs running and libvirtd is restarted and user tries to
> call some cgroup devices operation on a VM we need to get the count of
> entries in BPF map and it fails which will result in error when trying
> to attach/detech devices.
>
> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1833321
>
> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> ---
Reviewed-by: Erik Skultety <eskultet@redhat.com>