Device rules are stored in BPF map that is a hash type, this function
will create a key based on major and minor id of device.
Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
src/libvirt_private.syms | 1 +
src/util/vircgroupv2devices.c | 8 ++++++++
src/util/vircgroupv2devices.h | 4 ++++
3 files changed, 13 insertions(+)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 469a1cdbe0..18cb3715a2 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1657,6 +1657,7 @@ virCgroupV2DevicesAttachProg;
virCgroupV2DevicesAvailable;
virCgroupV2DevicesCreateProg;
virCgroupV2DevicesDetectProg;
+virCgroupV2DevicesGetKey;
virCgroupV2DevicesGetPerms;
virCgroupV2DevicesPrepareProg;
virCgroupV2DevicesRemoveProg;
diff --git a/src/util/vircgroupv2devices.c b/src/util/vircgroupv2devices.c
index 0455ff6b24..9b154ccb5d 100644
--- a/src/util/vircgroupv2devices.c
+++ b/src/util/vircgroupv2devices.c
@@ -660,3 +660,11 @@ virCgroupV2DevicesGetPerms(int perms ATTRIBUTE_UNUSED,
return 0;
}
#endif /* !HAVE_DECL_BPF_CGROUP_DEVICE */
+
+
+uint64_t
+virCgroupV2DevicesGetKey(int major,
+ int minor)
+{
+ return (uint64_t)major << 32 | ((uint64_t)minor & 0x00000000ffffffff);
+}
diff --git a/src/util/vircgroupv2devices.h b/src/util/vircgroupv2devices.h
index cbfd9ae119..d717c9755f 100644
--- a/src/util/vircgroupv2devices.h
+++ b/src/util/vircgroupv2devices.h
@@ -47,4 +47,8 @@ uint32_t
virCgroupV2DevicesGetPerms(int perms,
char type);
+uint64_t
+virCgroupV2DevicesGetKey(int major,
+ int minor);
+
#endif /* LIBVIRT_VIRCGROUPV2DEVICES_H */
--
2.20.1