vircgroup: introduce virCgroupV2DeviceGetPerms

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Pavel Hrdina 2019-06-24 14:41:50 +02:00
parent 6a24bd75ed
commit 63cfe7b84d
3 changed files with 41 additions and 0 deletions

View File

@ -1721,6 +1721,7 @@ virCgroupV2DevicesAttachProg;
virCgroupV2DevicesAvailable;
virCgroupV2DevicesCreateProg;
virCgroupV2DevicesDetectProg;
virCgroupV2DevicesGetPerms;
virCgroupV2DevicesPrepareProg;
virCgroupV2DevicesRemoveProg;

View 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 */

View 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);