|
Pablo Greco |
40546a |
From d323cd99b256b368c37f0a36eef8b3b2d6213346 Mon Sep 17 00:00:00 2001
|
|
Pablo Greco |
40546a |
Message-Id: <d323cd99b256b368c37f0a36eef8b3b2d6213346@dist-git>
|
|
Pablo Greco |
40546a |
From: Pavel Hrdina <phrdina@redhat.com>
|
|
Pablo Greco |
40546a |
Date: Mon, 1 Jul 2019 17:06:18 +0200
|
|
Pablo Greco |
40546a |
Subject: [PATCH] vircgroupmock: rewrite cgroup fopen mocking
|
|
Pablo Greco |
40546a |
MIME-Version: 1.0
|
|
Pablo Greco |
40546a |
Content-Type: text/plain; charset=UTF-8
|
|
Pablo Greco |
40546a |
Content-Transfer-Encoding: 8bit
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
Move all the cgroup data into separate files out of vircgroupmock.c
|
|
Pablo Greco |
40546a |
and rework the fopen function to load data from files. This will
|
|
Pablo Greco |
40546a |
make it easier to add more test cases.
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
|
|
Pablo Greco |
40546a |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
Pablo Greco |
40546a |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
Pablo Greco |
40546a |
(cherry picked from commit 5cf1b25708328ad4006572801d0829548418cfe7)
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
Pablo Greco |
40546a |
Message-Id: <efee26b41a026de90498f4abd724f1c7d85d6731.1561993099.git.phrdina@redhat.com>
|
|
Pablo Greco |
40546a |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
Pablo Greco |
40546a |
---
|
|
Pablo Greco |
40546a |
tests/vircgroupdata/all-in-one.cgroups | 7 ++
|
|
Pablo Greco |
40546a |
tests/vircgroupdata/all-in-one.mounts | 2 +-
|
|
Pablo Greco |
40546a |
tests/vircgroupdata/all-in-one.parsed | 12 +-
|
|
Pablo Greco |
40546a |
tests/vircgroupdata/all-in-one.self.cgroup | 1 +
|
|
Pablo Greco |
40546a |
tests/vircgroupdata/logind.cgroups | 10 ++
|
|
Pablo Greco |
40546a |
tests/vircgroupdata/logind.mounts | 2 +
|
|
Pablo Greco |
40546a |
tests/vircgroupdata/logind.self.cgroup | 1 +
|
|
Pablo Greco |
40546a |
tests/vircgroupdata/systemd.cgroups | 8 ++
|
|
Pablo Greco |
40546a |
tests/vircgroupdata/systemd.mounts | 11 ++
|
|
Pablo Greco |
40546a |
tests/vircgroupdata/systemd.self.cgroup | 6 +
|
|
Pablo Greco |
40546a |
tests/vircgroupmock.c | 136 +++------------------
|
|
Pablo Greco |
40546a |
tests/vircgrouptest.c | 10 +-
|
|
Pablo Greco |
40546a |
12 files changed, 79 insertions(+), 127 deletions(-)
|
|
Pablo Greco |
40546a |
create mode 100644 tests/vircgroupdata/all-in-one.cgroups
|
|
Pablo Greco |
40546a |
create mode 100644 tests/vircgroupdata/all-in-one.self.cgroup
|
|
Pablo Greco |
40546a |
create mode 100644 tests/vircgroupdata/logind.cgroups
|
|
Pablo Greco |
40546a |
create mode 100644 tests/vircgroupdata/logind.mounts
|
|
Pablo Greco |
40546a |
create mode 100644 tests/vircgroupdata/logind.self.cgroup
|
|
Pablo Greco |
40546a |
create mode 100644 tests/vircgroupdata/systemd.cgroups
|
|
Pablo Greco |
40546a |
create mode 100644 tests/vircgroupdata/systemd.mounts
|
|
Pablo Greco |
40546a |
create mode 100644 tests/vircgroupdata/systemd.self.cgroup
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
diff --git a/tests/vircgroupdata/all-in-one.cgroups b/tests/vircgroupdata/all-in-one.cgroups
|
|
Pablo Greco |
40546a |
new file mode 100644
|
|
Pablo Greco |
40546a |
index 0000000000..7208e5a0b6
|
|
Pablo Greco |
40546a |
--- /dev/null
|
|
Pablo Greco |
40546a |
+++ b/tests/vircgroupdata/all-in-one.cgroups
|
|
Pablo Greco |
40546a |
@@ -0,0 +1,7 @@
|
|
Pablo Greco |
40546a |
+#subsys_name hierarchy num_cgroups enabled
|
|
Pablo Greco |
40546a |
+cpuset 6 1 1
|
|
Pablo Greco |
40546a |
+cpu 6 1 1
|
|
Pablo Greco |
40546a |
+cpuacct 6 1 1
|
|
Pablo Greco |
40546a |
+memory 6 1 1
|
|
Pablo Greco |
40546a |
+devices 6 1 1
|
|
Pablo Greco |
40546a |
+blkio 6 1 1
|
|
Pablo Greco |
40546a |
diff --git a/tests/vircgroupdata/all-in-one.mounts b/tests/vircgroupdata/all-in-one.mounts
|
|
Pablo Greco |
40546a |
index 14093b961c..76c579ff69 100644
|
|
Pablo Greco |
40546a |
--- a/tests/vircgroupdata/all-in-one.mounts
|
|
Pablo Greco |
40546a |
+++ b/tests/vircgroupdata/all-in-one.mounts
|
|
Pablo Greco |
40546a |
@@ -4,4 +4,4 @@ proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
|
|
Pablo Greco |
40546a |
udev /dev devtmpfs rw,relatime,size=16458560k,nr_inodes=4114640,mode=755 0 0
|
|
Pablo Greco |
40546a |
devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
|
|
Pablo Greco |
40546a |
nfsd /proc/fs/nfsd nfsd rw,relatime 0 0
|
|
Pablo Greco |
40546a |
-cgroup /sys/fs/cgroup cgroup rw,relatime,blkio,devices,memory,cpuacct,cpu,cpuset 0 0
|
|
Pablo Greco |
40546a |
+cgroup /not/really/sys/fs/cgroup cgroup rw,relatime,blkio,devices,memory,cpuacct,cpu,cpuset 0 0
|
|
Pablo Greco |
40546a |
diff --git a/tests/vircgroupdata/all-in-one.parsed b/tests/vircgroupdata/all-in-one.parsed
|
|
Pablo Greco |
40546a |
index 2701778fea..d703d08fb9 100644
|
|
Pablo Greco |
40546a |
--- a/tests/vircgroupdata/all-in-one.parsed
|
|
Pablo Greco |
40546a |
+++ b/tests/vircgroupdata/all-in-one.parsed
|
|
Pablo Greco |
40546a |
@@ -1,10 +1,10 @@
|
|
Pablo Greco |
40546a |
-cpu /sys/fs/cgroup
|
|
Pablo Greco |
40546a |
-cpuacct /sys/fs/cgroup
|
|
Pablo Greco |
40546a |
-cpuset /sys/fs/cgroup
|
|
Pablo Greco |
40546a |
-memory /sys/fs/cgroup
|
|
Pablo Greco |
40546a |
-devices /sys/fs/cgroup
|
|
Pablo Greco |
40546a |
+cpu /not/really/sys/fs/cgroup
|
|
Pablo Greco |
40546a |
+cpuacct /not/really/sys/fs/cgroup
|
|
Pablo Greco |
40546a |
+cpuset /not/really/sys/fs/cgroup
|
|
Pablo Greco |
40546a |
+memory /not/really/sys/fs/cgroup
|
|
Pablo Greco |
40546a |
+devices /not/really/sys/fs/cgroup
|
|
Pablo Greco |
40546a |
freezer <null>
|
|
Pablo Greco |
40546a |
-blkio /sys/fs/cgroup
|
|
Pablo Greco |
40546a |
+blkio /not/really/sys/fs/cgroup
|
|
Pablo Greco |
40546a |
net_cls <null>
|
|
Pablo Greco |
40546a |
perf_event <null>
|
|
Pablo Greco |
40546a |
name=systemd <null>
|
|
Pablo Greco |
40546a |
diff --git a/tests/vircgroupdata/all-in-one.self.cgroup b/tests/vircgroupdata/all-in-one.self.cgroup
|
|
Pablo Greco |
40546a |
new file mode 100644
|
|
Pablo Greco |
40546a |
index 0000000000..cf237502e9
|
|
Pablo Greco |
40546a |
--- /dev/null
|
|
Pablo Greco |
40546a |
+++ b/tests/vircgroupdata/all-in-one.self.cgroup
|
|
Pablo Greco |
40546a |
@@ -0,0 +1 @@
|
|
Pablo Greco |
40546a |
+6:blkio,devices,memory,cpuacct,cpu,cpuset:/
|
|
Pablo Greco |
40546a |
diff --git a/tests/vircgroupdata/logind.cgroups b/tests/vircgroupdata/logind.cgroups
|
|
Pablo Greco |
40546a |
new file mode 100644
|
|
Pablo Greco |
40546a |
index 0000000000..9d46f130e0
|
|
Pablo Greco |
40546a |
--- /dev/null
|
|
Pablo Greco |
40546a |
+++ b/tests/vircgroupdata/logind.cgroups
|
|
Pablo Greco |
40546a |
@@ -0,0 +1,10 @@
|
|
Pablo Greco |
40546a |
+#subsys_name hierarchy num_cgroups enabled
|
|
Pablo Greco |
40546a |
+cpuset 0 1 1
|
|
Pablo Greco |
40546a |
+cpu 0 1 1
|
|
Pablo Greco |
40546a |
+cpuacct 0 1 1
|
|
Pablo Greco |
40546a |
+memory 0 1 0
|
|
Pablo Greco |
40546a |
+devices 0 1 1
|
|
Pablo Greco |
40546a |
+freezer 0 1 1
|
|
Pablo Greco |
40546a |
+net_cls 0 1 1
|
|
Pablo Greco |
40546a |
+blkio 0 1 1
|
|
Pablo Greco |
40546a |
+perf_event 0 1 1
|
|
Pablo Greco |
40546a |
diff --git a/tests/vircgroupdata/logind.mounts b/tests/vircgroupdata/logind.mounts
|
|
Pablo Greco |
40546a |
new file mode 100644
|
|
Pablo Greco |
40546a |
index 0000000000..3ab908aee9
|
|
Pablo Greco |
40546a |
--- /dev/null
|
|
Pablo Greco |
40546a |
+++ b/tests/vircgroupdata/logind.mounts
|
|
Pablo Greco |
40546a |
@@ -0,0 +1,2 @@
|
|
Pablo Greco |
40546a |
+none /not/really/sys/fs/cgroup tmpfs rw,rootcontext=system_u:object_r:sysfs_t:s0,seclabel,relatime,size=4k,mode=755 0 0
|
|
Pablo Greco |
40546a |
+systemd /not/really/sys/fs/cgroup/systemd cgroup rw,nosuid,nodev,noexec,relatime,name=systemd 0 0
|
|
Pablo Greco |
40546a |
diff --git a/tests/vircgroupdata/logind.self.cgroup b/tests/vircgroupdata/logind.self.cgroup
|
|
Pablo Greco |
40546a |
new file mode 100644
|
|
Pablo Greco |
40546a |
index 0000000000..31e0cfe8eb
|
|
Pablo Greco |
40546a |
--- /dev/null
|
|
Pablo Greco |
40546a |
+++ b/tests/vircgroupdata/logind.self.cgroup
|
|
Pablo Greco |
40546a |
@@ -0,0 +1 @@
|
|
Pablo Greco |
40546a |
+0:name=systemd:/
|
|
Pablo Greco |
40546a |
diff --git a/tests/vircgroupdata/systemd.cgroups b/tests/vircgroupdata/systemd.cgroups
|
|
Pablo Greco |
40546a |
new file mode 100644
|
|
Pablo Greco |
40546a |
index 0000000000..d32dfab222
|
|
Pablo Greco |
40546a |
--- /dev/null
|
|
Pablo Greco |
40546a |
+++ b/tests/vircgroupdata/systemd.cgroups
|
|
Pablo Greco |
40546a |
@@ -0,0 +1,8 @@
|
|
Pablo Greco |
40546a |
+#subsys_name hierarchy num_cgroups enabled
|
|
Pablo Greco |
40546a |
+cpuset 2 4 1
|
|
Pablo Greco |
40546a |
+cpu 3 48 1
|
|
Pablo Greco |
40546a |
+cpuacct 3 48 1
|
|
Pablo Greco |
40546a |
+memory 4 4 1
|
|
Pablo Greco |
40546a |
+devices 5 4 1
|
|
Pablo Greco |
40546a |
+freezer 6 4 1
|
|
Pablo Greco |
40546a |
+blkio 8 4 1
|
|
Pablo Greco |
40546a |
diff --git a/tests/vircgroupdata/systemd.mounts b/tests/vircgroupdata/systemd.mounts
|
|
Pablo Greco |
40546a |
new file mode 100644
|
|
Pablo Greco |
40546a |
index 0000000000..75572c86f7
|
|
Pablo Greco |
40546a |
--- /dev/null
|
|
Pablo Greco |
40546a |
+++ b/tests/vircgroupdata/systemd.mounts
|
|
Pablo Greco |
40546a |
@@ -0,0 +1,11 @@
|
|
Pablo Greco |
40546a |
+rootfs / rootfs rw 0 0
|
|
Pablo Greco |
40546a |
+tmpfs /run tmpfs rw,seclabel,nosuid,nodev,mode=755 0 0
|
|
Pablo Greco |
40546a |
+tmpfs /not/really/sys/fs/cgroup tmpfs rw,seclabel,nosuid,nodev,noexec,mode=755 0 0
|
|
Pablo Greco |
40546a |
+cgroup /not/really/sys/fs/cgroup/systemd cgroup rw,nosuid,nodev,noexec,relatime,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd 0 0
|
|
Pablo Greco |
40546a |
+cgroup /not/really/sys/fs/cgroup/cpuset cgroup rw,nosuid,nodev,noexec,relatime,cpuset 0 0
|
|
Pablo Greco |
40546a |
+cgroup /not/really/sys/fs/cgroup/cpu,cpuacct cgroup rw,nosuid,nodev,noexec,relatime,cpuacct,cpu 0 0
|
|
Pablo Greco |
40546a |
+cgroup /not/really/sys/fs/cgroup/freezer cgroup rw,nosuid,nodev,noexec,relatime,freezer 0 0
|
|
Pablo Greco |
40546a |
+cgroup /not/really/sys/fs/cgroup/blkio cgroup rw,nosuid,nodev,noexec,relatime,blkio 0 0
|
|
Pablo Greco |
40546a |
+cgroup /not/really/sys/fs/cgroup/memory cgroup rw,nosuid,nodev,noexec,relatime,memory 0 0
|
|
Pablo Greco |
40546a |
+/dev/sda1 /boot ext4 rw,seclabel,relatime,data=ordered 0 0
|
|
Pablo Greco |
40546a |
+tmpfs /tmp tmpfs rw,seclabel,relatime,size=1024000k 0 0
|
|
Pablo Greco |
40546a |
diff --git a/tests/vircgroupdata/systemd.self.cgroup b/tests/vircgroupdata/systemd.self.cgroup
|
|
Pablo Greco |
40546a |
new file mode 100644
|
|
Pablo Greco |
40546a |
index 0000000000..2b95af79d2
|
|
Pablo Greco |
40546a |
--- /dev/null
|
|
Pablo Greco |
40546a |
+++ b/tests/vircgroupdata/systemd.self.cgroup
|
|
Pablo Greco |
40546a |
@@ -0,0 +1,6 @@
|
|
Pablo Greco |
40546a |
+115:memory:/
|
|
Pablo Greco |
40546a |
+8:blkio:/
|
|
Pablo Greco |
40546a |
+6:freezer:/
|
|
Pablo Greco |
40546a |
+3:cpuacct,cpu:/system
|
|
Pablo Greco |
40546a |
+2:cpuset:/
|
|
Pablo Greco |
40546a |
+1:name=systemd:/user/berrange/123
|
|
Pablo Greco |
40546a |
diff --git a/tests/vircgroupmock.c b/tests/vircgroupmock.c
|
|
Pablo Greco |
40546a |
index cd5422dcba..3afe2fe192 100644
|
|
Pablo Greco |
40546a |
--- a/tests/vircgroupmock.c
|
|
Pablo Greco |
40546a |
+++ b/tests/vircgroupmock.c
|
|
Pablo Greco |
40546a |
@@ -81,85 +81,6 @@ const char *fakedevicedir1 = FAKEDEVDIR1;
|
|
Pablo Greco |
40546a |
* of files beneath it
|
|
Pablo Greco |
40546a |
*/
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
-/*
|
|
Pablo Greco |
40546a |
- * Intentionally missing the 'devices' mount.
|
|
Pablo Greco |
40546a |
- * Co-mounting cpu & cpuacct controllers
|
|
Pablo Greco |
40546a |
- * An anonymous controller for systemd
|
|
Pablo Greco |
40546a |
- */
|
|
Pablo Greco |
40546a |
-const char *procmounts =
|
|
Pablo Greco |
40546a |
- "rootfs / rootfs rw 0 0\n"
|
|
Pablo Greco |
40546a |
- "tmpfs /run tmpfs rw,seclabel,nosuid,nodev,mode=755 0 0\n"
|
|
Pablo Greco |
40546a |
- "tmpfs /not/really/sys/fs/cgroup tmpfs rw,seclabel,nosuid,nodev,noexec,mode=755 0 0\n"
|
|
Pablo Greco |
40546a |
- "cgroup /not/really/sys/fs/cgroup/systemd cgroup rw,nosuid,nodev,noexec,relatime,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd 0 0\n"
|
|
Pablo Greco |
40546a |
- "cgroup /not/really/sys/fs/cgroup/cpuset cgroup rw,nosuid,nodev,noexec,relatime,cpuset 0 0\n"
|
|
Pablo Greco |
40546a |
- "cgroup /not/really/sys/fs/cgroup/cpu,cpuacct cgroup rw,nosuid,nodev,noexec,relatime,cpuacct,cpu 0 0\n"
|
|
Pablo Greco |
40546a |
- "cgroup /not/really/sys/fs/cgroup/freezer cgroup rw,nosuid,nodev,noexec,relatime,freezer 0 0\n"
|
|
Pablo Greco |
40546a |
- "cgroup /not/really/sys/fs/cgroup/blkio cgroup rw,nosuid,nodev,noexec,relatime,blkio 0 0\n"
|
|
Pablo Greco |
40546a |
- "cgroup /not/really/sys/fs/cgroup/memory cgroup rw,nosuid,nodev,noexec,relatime,memory 0 0\n"
|
|
Pablo Greco |
40546a |
- "/dev/sda1 /boot ext4 rw,seclabel,relatime,data=ordered 0 0\n"
|
|
Pablo Greco |
40546a |
- "tmpfs /tmp tmpfs rw,seclabel,relatime,size=1024000k 0 0\n";
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
-const char *procselfcgroups =
|
|
Pablo Greco |
40546a |
- "115:memory:/\n"
|
|
Pablo Greco |
40546a |
- "8:blkio:/\n"
|
|
Pablo Greco |
40546a |
- "6:freezer:/\n"
|
|
Pablo Greco |
40546a |
- "3:cpuacct,cpu:/system\n"
|
|
Pablo Greco |
40546a |
- "2:cpuset:/\n"
|
|
Pablo Greco |
40546a |
- "1:name=systemd:/user/berrange/123\n";
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
-const char *proccgroups =
|
|
Pablo Greco |
40546a |
- "#subsys_name hierarchy num_cgroups enabled\n"
|
|
Pablo Greco |
40546a |
- "cpuset 2 4 1\n"
|
|
Pablo Greco |
40546a |
- "cpu 3 48 1\n"
|
|
Pablo Greco |
40546a |
- "cpuacct 3 48 1\n"
|
|
Pablo Greco |
40546a |
- "memory 4 4 1\n"
|
|
Pablo Greco |
40546a |
- "devices 5 4 1\n"
|
|
Pablo Greco |
40546a |
- "freezer 6 4 1\n"
|
|
Pablo Greco |
40546a |
- "blkio 8 4 1\n";
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
-const char *procmountsallinone =
|
|
Pablo Greco |
40546a |
- "rootfs / rootfs rw 0 0\n"
|
|
Pablo Greco |
40546a |
- "sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0\n"
|
|
Pablo Greco |
40546a |
- "proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0\n"
|
|
Pablo Greco |
40546a |
- "udev /dev devtmpfs rw,relatime,size=16458560k,nr_inodes=4114640,mode=755 0 0\n"
|
|
Pablo Greco |
40546a |
- "devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0\n"
|
|
Pablo Greco |
40546a |
- "nfsd /proc/fs/nfsd nfsd rw,relatime 0 0\n"
|
|
Pablo Greco |
40546a |
- "cgroup /not/really/sys/fs/cgroup cgroup rw,relatime,blkio,devices,memory,cpuacct,cpu,cpuset 0 0\n";
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
-const char *procselfcgroupsallinone =
|
|
Pablo Greco |
40546a |
- "6:blkio,devices,memory,cpuacct,cpu,cpuset:/";
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
-const char *proccgroupsallinone =
|
|
Pablo Greco |
40546a |
- "#subsys_name hierarchy num_cgroups enabled\n"
|
|
Pablo Greco |
40546a |
- "cpuset 6 1 1\n"
|
|
Pablo Greco |
40546a |
- "cpu 6 1 1\n"
|
|
Pablo Greco |
40546a |
- "cpuacct 6 1 1\n"
|
|
Pablo Greco |
40546a |
- "memory 6 1 1\n"
|
|
Pablo Greco |
40546a |
- "devices 6 1 1\n"
|
|
Pablo Greco |
40546a |
- "blkio 6 1 1\n";
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
-const char *procmountslogind =
|
|
Pablo Greco |
40546a |
- "none /not/really/sys/fs/cgroup tmpfs rw,rootcontext=system_u:object_r:sysfs_t:s0,seclabel,relatime,size=4k,mode=755 0 0\n"
|
|
Pablo Greco |
40546a |
- "systemd /not/really/sys/fs/cgroup/systemd cgroup rw,nosuid,nodev,noexec,relatime,name=systemd 0 0\n";
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
-const char *procselfcgroupslogind =
|
|
Pablo Greco |
40546a |
- "1:name=systemd:/\n";
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
-const char *proccgroupslogind =
|
|
Pablo Greco |
40546a |
- "#subsys_name hierarchy num_cgroups enabled\n"
|
|
Pablo Greco |
40546a |
- "cpuset 0 1 1\n"
|
|
Pablo Greco |
40546a |
- "cpu 0 1 1\n"
|
|
Pablo Greco |
40546a |
- "cpuacct 0 1 1\n"
|
|
Pablo Greco |
40546a |
- "memory 0 1 0\n"
|
|
Pablo Greco |
40546a |
- "devices 0 1 1\n"
|
|
Pablo Greco |
40546a |
- "freezer 0 1 1\n"
|
|
Pablo Greco |
40546a |
- "net_cls 0 1 1\n"
|
|
Pablo Greco |
40546a |
- "blkio 0 1 1\n"
|
|
Pablo Greco |
40546a |
- "perf_event 0 1 1\n";
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
-
|
|
Pablo Greco |
40546a |
static int make_file(const char *path,
|
|
Pablo Greco |
40546a |
const char *name,
|
|
Pablo Greco |
40546a |
const char *value)
|
|
Pablo Greco |
40546a |
@@ -379,29 +300,16 @@ static void init_sysfs(void)
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
FILE *fopen(const char *path, const char *mode)
|
|
Pablo Greco |
40546a |
{
|
|
Pablo Greco |
40546a |
- const char *mock;
|
|
Pablo Greco |
40546a |
- bool allinone = false, logind = false;
|
|
Pablo Greco |
40546a |
- init_syms();
|
|
Pablo Greco |
40546a |
+ char *filepath = NULL;
|
|
Pablo Greco |
40546a |
+ const char *type = NULL;
|
|
Pablo Greco |
40546a |
+ FILE *rc = NULL;
|
|
Pablo Greco |
40546a |
+ const char *filename = getenv("VIR_CGROUP_MOCK_FILENAME");
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
- mock = getenv("VIR_CGROUP_MOCK_MODE");
|
|
Pablo Greco |
40546a |
- if (mock) {
|
|
Pablo Greco |
40546a |
- if (STREQ(mock, "allinone"))
|
|
Pablo Greco |
40546a |
- allinone = true;
|
|
Pablo Greco |
40546a |
- else if (STREQ(mock, "logind"))
|
|
Pablo Greco |
40546a |
- logind = true;
|
|
Pablo Greco |
40546a |
- }
|
|
Pablo Greco |
40546a |
+ init_syms();
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
if (STREQ(path, "/proc/mounts")) {
|
|
Pablo Greco |
40546a |
if (STREQ(mode, "r")) {
|
|
Pablo Greco |
40546a |
- if (allinone)
|
|
Pablo Greco |
40546a |
- return fmemopen((void *)procmountsallinone,
|
|
Pablo Greco |
40546a |
- strlen(procmountsallinone) + 1, mode);
|
|
Pablo Greco |
40546a |
- else if (logind)
|
|
Pablo Greco |
40546a |
- return fmemopen((void *)procmountslogind,
|
|
Pablo Greco |
40546a |
- strlen(procmountslogind) + 1, mode);
|
|
Pablo Greco |
40546a |
- else
|
|
Pablo Greco |
40546a |
- return fmemopen((void *)procmounts,
|
|
Pablo Greco |
40546a |
- strlen(procmounts) + 1, mode);
|
|
Pablo Greco |
40546a |
+ type = "mounts";
|
|
Pablo Greco |
40546a |
} else {
|
|
Pablo Greco |
40546a |
errno = EACCES;
|
|
Pablo Greco |
40546a |
return NULL;
|
|
Pablo Greco |
40546a |
@@ -409,15 +317,7 @@ FILE *fopen(const char *path, const char *mode)
|
|
Pablo Greco |
40546a |
}
|
|
Pablo Greco |
40546a |
if (STREQ(path, "/proc/cgroups")) {
|
|
Pablo Greco |
40546a |
if (STREQ(mode, "r")) {
|
|
Pablo Greco |
40546a |
- if (allinone)
|
|
Pablo Greco |
40546a |
- return fmemopen((void *)proccgroupsallinone,
|
|
Pablo Greco |
40546a |
- strlen(proccgroupsallinone) + 1, mode);
|
|
Pablo Greco |
40546a |
- else if (logind)
|
|
Pablo Greco |
40546a |
- return fmemopen((void *)proccgroupslogind,
|
|
Pablo Greco |
40546a |
- strlen(proccgroupslogind) + 1, mode);
|
|
Pablo Greco |
40546a |
- else
|
|
Pablo Greco |
40546a |
- return fmemopen((void *)proccgroups,
|
|
Pablo Greco |
40546a |
- strlen(proccgroups) + 1, mode);
|
|
Pablo Greco |
40546a |
+ type = "cgroups";
|
|
Pablo Greco |
40546a |
} else {
|
|
Pablo Greco |
40546a |
errno = EACCES;
|
|
Pablo Greco |
40546a |
return NULL;
|
|
Pablo Greco |
40546a |
@@ -425,21 +325,25 @@ FILE *fopen(const char *path, const char *mode)
|
|
Pablo Greco |
40546a |
}
|
|
Pablo Greco |
40546a |
if (STREQ(path, "/proc/self/cgroup")) {
|
|
Pablo Greco |
40546a |
if (STREQ(mode, "r")) {
|
|
Pablo Greco |
40546a |
- if (allinone)
|
|
Pablo Greco |
40546a |
- return fmemopen((void *)procselfcgroupsallinone,
|
|
Pablo Greco |
40546a |
- strlen(procselfcgroupsallinone) + 1, mode);
|
|
Pablo Greco |
40546a |
- else if (logind)
|
|
Pablo Greco |
40546a |
- return fmemopen((void *)procselfcgroupslogind,
|
|
Pablo Greco |
40546a |
- strlen(procselfcgroupslogind) + 1, mode);
|
|
Pablo Greco |
40546a |
- else
|
|
Pablo Greco |
40546a |
- return fmemopen((void *)procselfcgroups,
|
|
Pablo Greco |
40546a |
- strlen(procselfcgroups) + 1, mode);
|
|
Pablo Greco |
40546a |
+ type = "self.cgroup";
|
|
Pablo Greco |
40546a |
} else {
|
|
Pablo Greco |
40546a |
errno = EACCES;
|
|
Pablo Greco |
40546a |
return NULL;
|
|
Pablo Greco |
40546a |
}
|
|
Pablo Greco |
40546a |
}
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
+ if (type) {
|
|
Pablo Greco |
40546a |
+ if (!filename)
|
|
Pablo Greco |
40546a |
+ abort();
|
|
Pablo Greco |
40546a |
+ if (virAsprintfQuiet(&filepath, "%s/vircgroupdata/%s.%s",
|
|
Pablo Greco |
40546a |
+ abs_srcdir, filename, type) < 0) {
|
|
Pablo Greco |
40546a |
+ abort();
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+ rc = real_fopen(filepath, mode);
|
|
Pablo Greco |
40546a |
+ free(filepath);
|
|
Pablo Greco |
40546a |
+ return rc;
|
|
Pablo Greco |
40546a |
+ }
|
|
Pablo Greco |
40546a |
+
|
|
Pablo Greco |
40546a |
return real_fopen(path, mode);
|
|
Pablo Greco |
40546a |
}
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c
|
|
Pablo Greco |
40546a |
index be50f3e73c..7968903cad 100644
|
|
Pablo Greco |
40546a |
--- a/tests/vircgrouptest.c
|
|
Pablo Greco |
40546a |
+++ b/tests/vircgrouptest.c
|
|
Pablo Greco |
40546a |
@@ -890,6 +890,7 @@ mymain(void)
|
|
Pablo Greco |
40546a |
DETECT_MOUNTS("no-cgroups");
|
|
Pablo Greco |
40546a |
DETECT_MOUNTS("kubevirt");
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
+ setenv("VIR_CGROUP_MOCK_FILENAME", "systemd", 1);
|
|
Pablo Greco |
40546a |
if (virTestRun("New cgroup for self", testCgroupNewForSelf, NULL) < 0)
|
|
Pablo Greco |
40546a |
ret = -1;
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
@@ -925,20 +926,21 @@ mymain(void)
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
if (virTestRun("virCgroupGetPercpuStats works", testCgroupGetPercpuStats, NULL) < 0)
|
|
Pablo Greco |
40546a |
ret = -1;
|
|
Pablo Greco |
40546a |
+ unsetenv("VIR_CGROUP_MOCK_FILENAME");
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
- setenv("VIR_CGROUP_MOCK_MODE", "allinone", 1);
|
|
Pablo Greco |
40546a |
+ setenv("VIR_CGROUP_MOCK_FILENAME", "all-in-one", 1);
|
|
Pablo Greco |
40546a |
if (virTestRun("New cgroup for self (allinone)", testCgroupNewForSelfAllInOne, NULL) < 0)
|
|
Pablo Greco |
40546a |
ret = -1;
|
|
Pablo Greco |
40546a |
if (virTestRun("Cgroup available", testCgroupAvailable, (void*)0x1) < 0)
|
|
Pablo Greco |
40546a |
ret = -1;
|
|
Pablo Greco |
40546a |
- unsetenv("VIR_CGROUP_MOCK_MODE");
|
|
Pablo Greco |
40546a |
+ unsetenv("VIR_CGROUP_MOCK_FILENAME");
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
- setenv("VIR_CGROUP_MOCK_MODE", "logind", 1);
|
|
Pablo Greco |
40546a |
+ setenv("VIR_CGROUP_MOCK_FILENAME", "logind", 1);
|
|
Pablo Greco |
40546a |
if (virTestRun("New cgroup for self (logind)", testCgroupNewForSelfLogind, NULL) < 0)
|
|
Pablo Greco |
40546a |
ret = -1;
|
|
Pablo Greco |
40546a |
if (virTestRun("Cgroup available", testCgroupAvailable, (void*)0x0) < 0)
|
|
Pablo Greco |
40546a |
ret = -1;
|
|
Pablo Greco |
40546a |
- unsetenv("VIR_CGROUP_MOCK_MODE");
|
|
Pablo Greco |
40546a |
+ unsetenv("VIR_CGROUP_MOCK_FILENAME");
|
|
Pablo Greco |
40546a |
|
|
Pablo Greco |
40546a |
if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
|
|
Pablo Greco |
40546a |
virFileDeleteTree(fakerootdir);
|
|
Pablo Greco |
40546a |
--
|
|
Pablo Greco |
40546a |
2.22.0
|
|
Pablo Greco |
40546a |
|