|
|
7548c0 |
From c94691d796682d951ffa8fb3a4fcb985aae17d9b Mon Sep 17 00:00:00 2001
|
|
|
7548c0 |
Message-Id: <c94691d796682d951ffa8fb3a4fcb985aae17d9b@dist-git>
|
|
|
7548c0 |
From: Pavel Hrdina <phrdina@redhat.com>
|
|
|
7548c0 |
Date: Fri, 19 Feb 2021 13:34:00 +0100
|
|
|
7548c0 |
Subject: [PATCH] tests: add cgroup nested tests
|
|
|
7548c0 |
MIME-Version: 1.0
|
|
|
7548c0 |
Content-Type: text/plain; charset=UTF-8
|
|
|
7548c0 |
Content-Transfer-Encoding: 8bit
|
|
|
7548c0 |
|
|
|
7548c0 |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
|
7548c0 |
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
7548c0 |
(cherry picked from commit 85099c339346e41f457234e8ad831841aef1d5e3)
|
|
|
7548c0 |
|
|
|
7548c0 |
Conflicts:
|
|
|
7548c0 |
tests/vircgrouptest.c
|
|
|
7548c0 |
- missing upstream g_autofree rewrite
|
|
|
7548c0 |
|
|
|
7548c0 |
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1798463
|
|
|
7548c0 |
|
|
|
7548c0 |
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
|
|
|
7548c0 |
Message-Id: <abf8f7673bd59c6e3d9b596cf9a86029b1f1e9c1.1613737828.git.phrdina@redhat.com>
|
|
|
7548c0 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
7548c0 |
---
|
|
|
7548c0 |
tests/vircgroupdata/systemd-legacy.cgroups | 12 +++
|
|
|
7548c0 |
tests/vircgroupdata/systemd-legacy.mounts | 11 +++
|
|
|
7548c0 |
.../vircgroupdata/systemd-legacy.self.cgroup | 11 +++
|
|
|
7548c0 |
tests/vircgroupdata/systemd-unified.cgroups | 13 +++
|
|
|
7548c0 |
tests/vircgroupdata/systemd-unified.mounts | 1 +
|
|
|
7548c0 |
.../vircgroupdata/systemd-unified.self.cgroup | 1 +
|
|
|
7548c0 |
tests/vircgrouptest.c | 82 +++++++++++++++++++
|
|
|
7548c0 |
7 files changed, 131 insertions(+)
|
|
|
7548c0 |
create mode 100644 tests/vircgroupdata/systemd-legacy.cgroups
|
|
|
7548c0 |
create mode 100644 tests/vircgroupdata/systemd-legacy.mounts
|
|
|
7548c0 |
create mode 100644 tests/vircgroupdata/systemd-legacy.self.cgroup
|
|
|
7548c0 |
create mode 100644 tests/vircgroupdata/systemd-unified.cgroups
|
|
|
7548c0 |
create mode 100644 tests/vircgroupdata/systemd-unified.mounts
|
|
|
7548c0 |
create mode 100644 tests/vircgroupdata/systemd-unified.self.cgroup
|
|
|
7548c0 |
|
|
|
7548c0 |
diff --git a/tests/vircgroupdata/systemd-legacy.cgroups b/tests/vircgroupdata/systemd-legacy.cgroups
|
|
|
7548c0 |
new file mode 100644
|
|
|
7548c0 |
index 0000000000..444354e3c8
|
|
|
7548c0 |
--- /dev/null
|
|
|
7548c0 |
+++ b/tests/vircgroupdata/systemd-legacy.cgroups
|
|
|
7548c0 |
@@ -0,0 +1,12 @@
|
|
|
7548c0 |
+#subsys_name hierarchy num_cgroups enabled
|
|
|
7548c0 |
+blkio 1 1 1
|
|
|
7548c0 |
+cpu 2 1 1
|
|
|
7548c0 |
+cpuacct 3 1 1
|
|
|
7548c0 |
+cpuset 4 1 1
|
|
|
7548c0 |
+devices 5 1 1
|
|
|
7548c0 |
+freezer 6 1 1
|
|
|
7548c0 |
+hugetlb 7 1 1
|
|
|
7548c0 |
+memory 8 1 1
|
|
|
7548c0 |
+net_cls 9 1 1
|
|
|
7548c0 |
+perf_event 10 1 1
|
|
|
7548c0 |
+pids 11 1 1
|
|
|
7548c0 |
diff --git a/tests/vircgroupdata/systemd-legacy.mounts b/tests/vircgroupdata/systemd-legacy.mounts
|
|
|
7548c0 |
new file mode 100644
|
|
|
7548c0 |
index 0000000000..23462e9e68
|
|
|
7548c0 |
--- /dev/null
|
|
|
7548c0 |
+++ b/tests/vircgroupdata/systemd-legacy.mounts
|
|
|
7548c0 |
@@ -0,0 +1,11 @@
|
|
|
7548c0 |
+cgroup /not/really/sys/fs/cgroup/blkio cgroup rw,seclabel,nosuid,nodev,noexec,relatime,blkio 0 0
|
|
|
7548c0 |
+cgroup /not/really/sys/fs/cgroup/cpu cgroup rw,seclabel,nosuid,nodev,noexec,relatime,cpu 0 0
|
|
|
7548c0 |
+cgroup /not/really/sys/fs/cgroup/cpuacct cgroup rw,seclabel,nosuid,nodev,noexec,relatime,cpuacct 0 0
|
|
|
7548c0 |
+cgroup /not/really/sys/fs/cgroup/cpuset cgroup rw,seclabel,nosuid,nodev,noexec,relatime,cpuset 0 0
|
|
|
7548c0 |
+cgroup /not/really/sys/fs/cgroup/devices cgroup rw,seclabel,nosuid,nodev,noexec,relatime,devices 0 0
|
|
|
7548c0 |
+cgroup /not/really/sys/fs/cgroup/freezer cgroup rw,seclabel,nosuid,nodev,noexec,relatime,freezer 0 0
|
|
|
7548c0 |
+cgroup /not/really/sys/fs/cgroup/hugetlb cgroup rw,seclabel,nosuid,nodev,noexec,relatime,hugetlb 0 0
|
|
|
7548c0 |
+cgroup /not/really/sys/fs/cgroup/memory cgroup rw,seclabel,nosuid,nodev,noexec,relatime,memory 0 0
|
|
|
7548c0 |
+cgroup /not/really/sys/fs/cgroup/net_cls cgroup rw,seclabel,nosuid,nodev,noexec,relatime,net_cls 0 0
|
|
|
7548c0 |
+cgroup /not/really/sys/fs/cgroup/perf_event cgroup rw,seclabel,nosuid,nodev,noexec,relatime,perf_event 0 0
|
|
|
7548c0 |
+cgroup /not/really/sys/fs/cgroup/pids cgroup rw,seclabel,nosuid,nodev,noexec,relatime,pids 0 0
|
|
|
7548c0 |
diff --git a/tests/vircgroupdata/systemd-legacy.self.cgroup b/tests/vircgroupdata/systemd-legacy.self.cgroup
|
|
|
7548c0 |
new file mode 100644
|
|
|
7548c0 |
index 0000000000..5c133a3c08
|
|
|
7548c0 |
--- /dev/null
|
|
|
7548c0 |
+++ b/tests/vircgroupdata/systemd-legacy.self.cgroup
|
|
|
7548c0 |
@@ -0,0 +1,11 @@
|
|
|
7548c0 |
+1:blkio:/libvirt
|
|
|
7548c0 |
+2:cpu:/libvirt/emulator
|
|
|
7548c0 |
+3:cpuacct:/libvirt/emulator
|
|
|
7548c0 |
+4:cpuset:/libvirt/emulator
|
|
|
7548c0 |
+5:devices:/libvirt
|
|
|
7548c0 |
+6:freezer:/libvirt
|
|
|
7548c0 |
+7:hugetlb:/
|
|
|
7548c0 |
+8:memory:/libvirt
|
|
|
7548c0 |
+9:net_cls:/libvirt
|
|
|
7548c0 |
+10:perf_event:/libvirt
|
|
|
7548c0 |
+11:pids:/
|
|
|
7548c0 |
diff --git a/tests/vircgroupdata/systemd-unified.cgroups b/tests/vircgroupdata/systemd-unified.cgroups
|
|
|
7548c0 |
new file mode 100644
|
|
|
7548c0 |
index 0000000000..e0d8a3561c
|
|
|
7548c0 |
--- /dev/null
|
|
|
7548c0 |
+++ b/tests/vircgroupdata/systemd-unified.cgroups
|
|
|
7548c0 |
@@ -0,0 +1,13 @@
|
|
|
7548c0 |
+#subsys_name hierarchy num_cgroups enabled
|
|
|
7548c0 |
+cpuset 0 1 1
|
|
|
7548c0 |
+cpu 0 1 1
|
|
|
7548c0 |
+cpuacct 0 1 1
|
|
|
7548c0 |
+blkio 0 1 1
|
|
|
7548c0 |
+memory 0 1 1
|
|
|
7548c0 |
+devices 0 1 1
|
|
|
7548c0 |
+freezer 0 1 1
|
|
|
7548c0 |
+net_cls 0 1 1
|
|
|
7548c0 |
+perf_event 0 1 1
|
|
|
7548c0 |
+net_prio 0 1 1
|
|
|
7548c0 |
+hugetlb 0 1 1
|
|
|
7548c0 |
+pids 0 1 1
|
|
|
7548c0 |
diff --git a/tests/vircgroupdata/systemd-unified.mounts b/tests/vircgroupdata/systemd-unified.mounts
|
|
|
7548c0 |
new file mode 100644
|
|
|
7548c0 |
index 0000000000..8225f37f45
|
|
|
7548c0 |
--- /dev/null
|
|
|
7548c0 |
+++ b/tests/vircgroupdata/systemd-unified.mounts
|
|
|
7548c0 |
@@ -0,0 +1 @@
|
|
|
7548c0 |
+cgroup2 /not/really/sys/fs/cgroup cgroup2 rw,seclabel,nosuid,nodev,noexec,relatime,nsdelegate 0 0
|
|
|
7548c0 |
diff --git a/tests/vircgroupdata/systemd-unified.self.cgroup b/tests/vircgroupdata/systemd-unified.self.cgroup
|
|
|
7548c0 |
new file mode 100644
|
|
|
7548c0 |
index 0000000000..6007ce7e18
|
|
|
7548c0 |
--- /dev/null
|
|
|
7548c0 |
+++ b/tests/vircgroupdata/systemd-unified.self.cgroup
|
|
|
7548c0 |
@@ -0,0 +1 @@
|
|
|
7548c0 |
+0::/libvirt/emulator
|
|
|
7548c0 |
diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c
|
|
|
7548c0 |
index 2d6f52fb6e..aebb90c16c 100644
|
|
|
7548c0 |
--- a/tests/vircgrouptest.c
|
|
|
7548c0 |
+++ b/tests/vircgrouptest.c
|
|
|
7548c0 |
@@ -636,6 +636,74 @@ static int testCgroupNewForSelfHybrid(const void *args G_GNUC_UNUSED)
|
|
|
7548c0 |
}
|
|
|
7548c0 |
|
|
|
7548c0 |
|
|
|
7548c0 |
+static int testCgroupNewForSelfSystemdLegacy(const void *args G_GNUC_UNUSED)
|
|
|
7548c0 |
+{
|
|
|
7548c0 |
+ virCgroupPtr cgroup = NULL;
|
|
|
7548c0 |
+ int ret = -1;
|
|
|
7548c0 |
+ const char *empty[VIR_CGROUP_CONTROLLER_LAST] = { 0 };
|
|
|
7548c0 |
+ const char *mounts[VIR_CGROUP_CONTROLLER_LAST] = {
|
|
|
7548c0 |
+ [VIR_CGROUP_CONTROLLER_BLKIO] = "/not/really/sys/fs/cgroup/blkio",
|
|
|
7548c0 |
+ [VIR_CGROUP_CONTROLLER_CPU] = "/not/really/sys/fs/cgroup/cpu",
|
|
|
7548c0 |
+ [VIR_CGROUP_CONTROLLER_CPUACCT] = "/not/really/sys/fs/cgroup/cpuacct",
|
|
|
7548c0 |
+ [VIR_CGROUP_CONTROLLER_CPUSET] = "/not/really/sys/fs/cgroup/cpuset",
|
|
|
7548c0 |
+ [VIR_CGROUP_CONTROLLER_DEVICES] = "/not/really/sys/fs/cgroup/devices",
|
|
|
7548c0 |
+ [VIR_CGROUP_CONTROLLER_FREEZER] = "/not/really/sys/fs/cgroup/freezer",
|
|
|
7548c0 |
+ [VIR_CGROUP_CONTROLLER_MEMORY] = "/not/really/sys/fs/cgroup/memory",
|
|
|
7548c0 |
+ [VIR_CGROUP_CONTROLLER_NET_CLS] = "/not/really/sys/fs/cgroup/net_cls",
|
|
|
7548c0 |
+ [VIR_CGROUP_CONTROLLER_PERF_EVENT] = "/not/really/sys/fs/cgroup/perf_event",
|
|
|
7548c0 |
+ };
|
|
|
7548c0 |
+ const char *placement[VIR_CGROUP_CONTROLLER_LAST] = {
|
|
|
7548c0 |
+ [VIR_CGROUP_CONTROLLER_BLKIO] = "",
|
|
|
7548c0 |
+ [VIR_CGROUP_CONTROLLER_CPU] = "",
|
|
|
7548c0 |
+ [VIR_CGROUP_CONTROLLER_CPUACCT] = "",
|
|
|
7548c0 |
+ [VIR_CGROUP_CONTROLLER_CPUSET] = "",
|
|
|
7548c0 |
+ [VIR_CGROUP_CONTROLLER_DEVICES] = "",
|
|
|
7548c0 |
+ [VIR_CGROUP_CONTROLLER_FREEZER] = "",
|
|
|
7548c0 |
+ [VIR_CGROUP_CONTROLLER_MEMORY] = "",
|
|
|
7548c0 |
+ [VIR_CGROUP_CONTROLLER_NET_CLS] = "",
|
|
|
7548c0 |
+ [VIR_CGROUP_CONTROLLER_PERF_EVENT] = "",
|
|
|
7548c0 |
+ };
|
|
|
7548c0 |
+
|
|
|
7548c0 |
+ if (virCgroupNewSelf(&cgroup) < 0) {
|
|
|
7548c0 |
+ fprintf(stderr, "Cannot create cgroup for self\n");
|
|
|
7548c0 |
+ goto cleanup;
|
|
|
7548c0 |
+ }
|
|
|
7548c0 |
+
|
|
|
7548c0 |
+ ret = validateCgroup(cgroup, "", mounts, empty, placement, NULL, NULL, 0);
|
|
|
7548c0 |
+
|
|
|
7548c0 |
+ cleanup:
|
|
|
7548c0 |
+ virCgroupFree(&cgroup);
|
|
|
7548c0 |
+ return ret;
|
|
|
7548c0 |
+}
|
|
|
7548c0 |
+
|
|
|
7548c0 |
+
|
|
|
7548c0 |
+static int testCgroupNewForSelfSystemdUnified(const void *args G_GNUC_UNUSED)
|
|
|
7548c0 |
+{
|
|
|
7548c0 |
+ virCgroupPtr cgroup = NULL;
|
|
|
7548c0 |
+ int ret = -1;
|
|
|
7548c0 |
+ const char *empty[VIR_CGROUP_CONTROLLER_LAST] = { 0 };
|
|
|
7548c0 |
+ unsigned int controllers =
|
|
|
7548c0 |
+ (1 << VIR_CGROUP_CONTROLLER_CPU) |
|
|
|
7548c0 |
+ (1 << VIR_CGROUP_CONTROLLER_CPUACCT) |
|
|
|
7548c0 |
+ (1 << VIR_CGROUP_CONTROLLER_MEMORY) |
|
|
|
7548c0 |
+ (1 << VIR_CGROUP_CONTROLLER_DEVICES) |
|
|
|
7548c0 |
+ (1 << VIR_CGROUP_CONTROLLER_BLKIO);
|
|
|
7548c0 |
+
|
|
|
7548c0 |
+ if (virCgroupNewSelf(&cgroup) < 0) {
|
|
|
7548c0 |
+ fprintf(stderr, "Cannot create cgroup for self\n");
|
|
|
7548c0 |
+ goto cleanup;
|
|
|
7548c0 |
+ }
|
|
|
7548c0 |
+
|
|
|
7548c0 |
+ ret = validateCgroup(cgroup, "", empty, empty, empty,
|
|
|
7548c0 |
+ "/not/really/sys/fs/cgroup", "",
|
|
|
7548c0 |
+ controllers);
|
|
|
7548c0 |
+
|
|
|
7548c0 |
+ cleanup:
|
|
|
7548c0 |
+ virCgroupFree(&cgroup);
|
|
|
7548c0 |
+ return ret;
|
|
|
7548c0 |
+}
|
|
|
7548c0 |
+
|
|
|
7548c0 |
+
|
|
|
7548c0 |
static int testCgroupAvailable(const void *args)
|
|
|
7548c0 |
{
|
|
|
7548c0 |
bool got = virCgroupAvailable();
|
|
|
7548c0 |
@@ -1125,6 +1193,20 @@ mymain(void)
|
|
|
7548c0 |
ret = -1;
|
|
|
7548c0 |
cleanupFakeFS(fakerootdir);
|
|
|
7548c0 |
|
|
|
7548c0 |
+ fakerootdir = initFakeFS("legacy", "systemd-legacy");
|
|
|
7548c0 |
+ if (virTestRun("New cgroup for self (systemd-legacy)",
|
|
|
7548c0 |
+ testCgroupNewForSelfSystemdLegacy, NULL) < 0) {
|
|
|
7548c0 |
+ ret = -1;
|
|
|
7548c0 |
+ }
|
|
|
7548c0 |
+ cleanupFakeFS(fakerootdir);
|
|
|
7548c0 |
+
|
|
|
7548c0 |
+ fakerootdir = initFakeFS("unified", "systemd-unified");
|
|
|
7548c0 |
+ if (virTestRun("New cgroup for self (systemd-unified)",
|
|
|
7548c0 |
+ testCgroupNewForSelfSystemdUnified, NULL) < 0) {
|
|
|
7548c0 |
+ ret = -1;
|
|
|
7548c0 |
+ }
|
|
|
7548c0 |
+ cleanupFakeFS(fakerootdir);
|
|
|
7548c0 |
+
|
|
|
7548c0 |
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
7548c0 |
}
|
|
|
7548c0 |
|
|
|
7548c0 |
--
|
|
|
7548c0 |
2.30.0
|
|
|
7548c0 |
|