[PATCH 19/19] vircgroupmock: mock virBPFQueryProg

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

 



We need to mock virBPFQueryProg() in order to prevent extra syscall
which tries to detect whether we can list cgroup BPF programs.

Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 src/util/virbpf.h                 |  5 ++++-
 tests/vircgroupdata/hybrid.parsed |  2 +-
 tests/vircgroupmock.c             | 11 +++++++++++
 tests/vircgrouptest.c             |  4 ++--
 4 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/util/virbpf.h b/src/util/virbpf.h
index 7085edaacc..35e89e965c 100644
--- a/src/util/virbpf.h
+++ b/src/util/virbpf.h
@@ -23,6 +23,8 @@
 
 # include <linux/bpf.h>
 
+# include "internal.h"
+
 /* ALU ops on registers, bpf_add|sub|...: dst_reg += src_reg */
 
 # define VIR_BPF_ALU64_REG(op, dst, src) \
@@ -211,7 +213,8 @@ virBPFQueryProg(int targetfd,
                 unsigned int maxprogids,
                 int attachType,
                 unsigned int *progcnt,
-                void *progids);
+                void *progids)
+    ATTRIBUTE_NOINLINE;
 
 int
 virBPFGetProg(unsigned int id);
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..0e5a7b0917 100644
--- a/tests/vircgroupmock.c
+++ b/tests/vircgroupmock.c
@@ -34,6 +34,7 @@
 # include "testutilslxc.h"
 # include "virstring.h"
 # include "virfile.h"
+# include "virbpf.h"
 
 static int (*real_open)(const char *path, int flags, ...);
 static FILE *(*real_fopen)(const char *path, const char *mode);
@@ -701,6 +702,16 @@ int open(const char *path, int flags, ...)
     free(newpath);
     return ret;
 }
+
+int
+virBPFQueryProg(int targetfd ATTRIBUTE_UNUSED,
+                unsigned int maxprogids ATTRIBUTE_UNUSED,
+                int attachType ATTRIBUTE_UNUSED,
+                unsigned int *progcnt ATTRIBUTE_UNUSED,
+                void *progids ATTRIBUTE_UNUSED)
+{
+    return 0;
+}
 #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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux