]> xenbits.xensource.com Git - libvirt.git/commitdiff
vircgroup: introduce virCgroupV2DeviceGetPerms
authorPavel Hrdina <phrdina@redhat.com>
Mon, 24 Jun 2019 12:41:50 +0000 (14:41 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Fri, 15 Nov 2019 11:58:37 +0000 (12:58 +0100)
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

index 3553e82f5c3b4c3786bb17f59aae58df414bced5..88b0a3869672d9c5a58f8193b156c9cc4908e731 100644 (file)
@@ -1721,6 +1721,7 @@ virCgroupV2DevicesAttachProg;
 virCgroupV2DevicesAvailable;
 virCgroupV2DevicesCreateProg;
 virCgroupV2DevicesDetectProg;
+virCgroupV2DevicesGetPerms;
 virCgroupV2DevicesPrepareProg;
 virCgroupV2DevicesRemoveProg;
 
index 980d8a2b7c6d559b4c3b7537bef5e432ba80eb99..43ae14d2a516ab6ad4056caa2a7a5b7479bfa018 100644 (file)
@@ -557,6 +557,32 @@ virCgroupV2DevicesRemoveProg(virCgroupPtr group)
 
     return 0;
 }
+
+
+uint32_t
+virCgroupV2DevicesGetPerms(int perms,
+                           char type)
+{
+    uint32_t ret = 0;
+
+    if (perms & VIR_CGROUP_DEVICE_MKNOD)
+        ret |= BPF_DEVCG_ACC_MKNOD << 16;
+
+    if (perms & VIR_CGROUP_DEVICE_READ)
+        ret |= BPF_DEVCG_ACC_READ << 16;
+
+    if (perms & VIR_CGROUP_DEVICE_WRITE)
+        ret |= BPF_DEVCG_ACC_WRITE << 16;
+
+    if (type == 'b')
+        ret |= BPF_DEVCG_DEV_BLOCK;
+    else if (type == 'c')
+        ret |= BPF_DEVCG_DEV_CHAR;
+    else
+        ret |= BPF_DEVCG_DEV_BLOCK | BPF_DEVCG_DEV_CHAR;
+
+    return ret;
+}
 #else /* !HAVE_DECL_BPF_CGROUP_DEVICE */
 bool
 virCgroupV2DevicesAvailable(virCgroupPtr group G_GNUC_UNUSED)
@@ -612,4 +638,12 @@ virCgroupV2DevicesRemoveProg(virCgroupPtr group G_GNUC_UNUSED)
 {
     return 0;
 }
+
+
+uint32_t
+virCgroupV2DevicesGetPerms(int perms G_GNUC_UNUSED,
+                           char type G_GNUC_UNUSED)
+{
+    return 0;
+}
 #endif /* !HAVE_DECL_BPF_CGROUP_DEVICE */
index 879d9cb77b9b29324b1c60de6af24db8c54c8870..e00da25c1e3b03c5ae3873731528e4ba502ee57f 100644 (file)
@@ -18,6 +18,8 @@
 
 #pragma once
 
+#include <sys/types.h>
+
 #include "vircgroup.h"
 
 bool
@@ -39,3 +41,7 @@ virCgroupV2DevicesPrepareProg(virCgroupPtr group);
 
 int
 virCgroupV2DevicesRemoveProg(virCgroupPtr group);
+
+uint32_t
+virCgroupV2DevicesGetPerms(int perms,
+                           char type);