[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH v2 17/17] 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>
---
 src/util/vircgroupv2devices.h     | 5 ++++-
 tests/vircgroupdata/hybrid.parsed | 2 +-
 tests/vircgroupmock.c             | 7 +++++++
 tests/vircgrouptest.c             | 4 ++--
 4 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/util/vircgroupv2devices.h b/src/util/vircgroupv2devices.h
index d717c9755f..5fc35942ef 100644
--- a/src/util/vircgroupv2devices.h
+++ b/src/util/vircgroupv2devices.h
@@ -21,10 +21,13 @@
 
 # include <sys/types.h>
 
+# include "internal.h"
+
 # include "vircgroup.h"
 
 bool
-virCgroupV2DevicesAvailable(virCgroupPtr group);
+virCgroupV2DevicesAvailable(virCgroupPtr group)
+    ATTRIBUTE_NOINLINE;
 
 int
 virCgroupV2DevicesAttachProg(virCgroupPtr group,
diff --git a/tests/vircgroupdata/hybrid.parsed b/tests/vircgroupdata/hybrid.parsed
index 7600de5f45..f755eed465 100644
--- a/tests/vircgroupdata/hybrid.parsed
+++ b/tests/vircgroupdata/hybrid.parsed
@@ -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
diff --git a/tests/vircgroupmock.c b/tests/vircgroupmock.c
index 06bd0a5f29..97f98e91ee 100644
--- a/tests/vircgroupmock.c
+++ b/tests/vircgroupmock.c
@@ -34,6 +34,7 @@
 # include "testutilslxc.h"
 # include "virstring.h"
 # include "virfile.h"
+# include "vircgroupv2devices.h"
 
 static int (*real_open)(const char *path, int flags, ...);
 static FILE *(*real_fopen)(const char *path, const char *mode);
@@ -701,6 +702,12 @@ int open(const char *path, int flags, ...)
     free(newpath);
     return ret;
 }
+
+bool
+virCgroupV2DevicesAvailable(virCgroupPtr group ATTRIBUTE_UNUSED)
+{
+    return true;
+}
 #else
 /* Nothing to override on non-__linux__ platforms */
 #endif
diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c
index 20f4c57b04..4c1f53d924 100644
--- a/tests/vircgrouptest.c
+++ b/tests/vircgrouptest.c
@@ -587,6 +587,7 @@ static int testCgroupNewForSelfUnified(const void *args ATTRIBUTE_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) {
@@ -609,14 +610,12 @@ static int testCgroupNewForSelfHybrid(const void *args ATTRIBUTE_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] = "/",
@@ -625,6 +624,7 @@ static int testCgroupNewForSelfHybrid(const void *args ATTRIBUTE_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) {
-- 
2.20.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]