vircgroupmock: mock virCgroupV2DevicesAvailable

We need to mock virCgroupV2DevicesAvailable() in order to remove any
dependency on kernel as BPF devices might not be available.

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 15:13:37 +02:00
parent c359cb9aee
commit 8addef2bef
4 changed files with 14 additions and 4 deletions

View File

@ -20,10 +20,13 @@
#include <sys/types.h>
#include "internal.h"
#include "vircgroup.h"
bool
virCgroupV2DevicesAvailable(virCgroupPtr group);
virCgroupV2DevicesAvailable(virCgroupPtr group)
G_GNUC_NO_INLINE;
int
virCgroupV2DevicesAttachProg(virCgroupPtr group,

View File

@ -2,7 +2,7 @@ cpu <null>
cpuacct <null>
cpuset /not/really/sys/fs/cgroup/cpuset
memory <null>
devices /not/really/sys/fs/cgroup/devices
devices <null>
freezer /not/really/sys/fs/cgroup/freezer
blkio <null>
net_cls /not/really/sys/fs/cgroup/net_cls

View File

@ -35,6 +35,7 @@
# include "virstring.h"
# include "virfile.h"
# include "viralloc.h"
# include "vircgroupv2devices.h"
static int (*real_open)(const char *path, int flags, ...);
static FILE *(*real_fopen)(const char *path, const char *mode);
@ -597,6 +598,12 @@ int open(const char *path, int flags, ...)
free(newpath);
return ret;
}
bool
virCgroupV2DevicesAvailable(virCgroupPtr group G_GNUC_UNUSED)
{
return true;
}
#else
/* Nothing to override on non-__linux__ platforms */
#endif

View File

@ -582,6 +582,7 @@ static int testCgroupNewForSelfUnified(const void *args G_GNUC_UNUSED)
(1 << VIR_CGROUP_CONTROLLER_CPU) |
(1 << VIR_CGROUP_CONTROLLER_CPUACCT) |
(1 << VIR_CGROUP_CONTROLLER_MEMORY) |
(1 << VIR_CGROUP_CONTROLLER_DEVICES) |
(1 << VIR_CGROUP_CONTROLLER_BLKIO);
if (virCgroupNewSelf(&cgroup) < 0) {
@ -604,14 +605,12 @@ static int testCgroupNewForSelfHybrid(const void *args G_GNUC_UNUSED)
const char *empty[VIR_CGROUP_CONTROLLER_LAST] = { 0 };
const char *mounts[VIR_CGROUP_CONTROLLER_LAST] = {
[VIR_CGROUP_CONTROLLER_CPUSET] = "/not/really/sys/fs/cgroup/cpuset",
[VIR_CGROUP_CONTROLLER_DEVICES] = "/not/really/sys/fs/cgroup/devices",
[VIR_CGROUP_CONTROLLER_FREEZER] = "/not/really/sys/fs/cgroup/freezer",
[VIR_CGROUP_CONTROLLER_NET_CLS] = "/not/really/sys/fs/cgroup/net_cls",
[VIR_CGROUP_CONTROLLER_PERF_EVENT] = "/not/really/sys/fs/cgroup/perf_event",
};
const char *placement[VIR_CGROUP_CONTROLLER_LAST] = {
[VIR_CGROUP_CONTROLLER_CPUSET] = "/",
[VIR_CGROUP_CONTROLLER_DEVICES] = "/",
[VIR_CGROUP_CONTROLLER_FREEZER] = "/",
[VIR_CGROUP_CONTROLLER_NET_CLS] = "/",
[VIR_CGROUP_CONTROLLER_PERF_EVENT] = "/",
@ -620,6 +619,7 @@ static int testCgroupNewForSelfHybrid(const void *args G_GNUC_UNUSED)
(1 << VIR_CGROUP_CONTROLLER_CPU) |
(1 << VIR_CGROUP_CONTROLLER_CPUACCT) |
(1 << VIR_CGROUP_CONTROLLER_MEMORY) |
(1 << VIR_CGROUP_CONTROLLER_DEVICES) |
(1 << VIR_CGROUP_CONTROLLER_BLKIO);
if (virCgroupNewSelf(&cgroup) < 0) {