Blob Blame History Raw
From e3b6a0736a5b8e23041006ac004cccf1e48ae528 Mon Sep 17 00:00:00 2001
Message-Id: <e3b6a0736a5b8e23041006ac004cccf1e48ae528@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:06:20 +0200
Subject: [PATCH] vircgrouptest: call virCgroupNewSelf instead
 virCgroupDetectMounts
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This will be required once cgroup v2 is introduced.  The cgroup
detection is not simple and we will have multiple backends so we
should not just jump into the middle of the detection code.

In order to use virCgroupNewSelf we need to create all the remaining
data files:

    - {name}.cgroups represents /proc/cgroups, it is a list of cgroup
      controllers compiled into kernel

    - {name}.self.cgroup represents /proc/self/cgroup, it describes
      cgroups to which the process belongs

For "no-cgroups" we need to modify the expected behavior because
virCgroupNewSelf() will fail if there are no controllers available.

Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit 8b62008d2bc5442f7755e579ea754ffd5e3f9691)

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <3d1ddcca1a1e323e607445c5d1089698122efdd8.1561993099.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/libvirt_private.syms                      |  1 -
 src/util/vircgroup.c                          | 11 +------
 src/util/vircgrouppriv.h                      |  2 --
 tests/vircgroupdata/cgroups1.cgroups          | 11 +++++++
 tests/vircgroupdata/cgroups1.self.cgroup      | 11 +++++++
 tests/vircgroupdata/cgroups2.cgroups          | 10 +++++++
 tests/vircgroupdata/cgroups2.self.cgroup      | 10 +++++++
 tests/vircgroupdata/cgroups3.cgroups          | 12 ++++++++
 tests/vircgroupdata/cgroups3.self.cgroup      | 12 ++++++++
 tests/vircgroupdata/fedora-18.cgroups         | 10 +++++++
 tests/vircgroupdata/fedora-18.self.cgroup     |  9 ++++++
 tests/vircgroupdata/fedora-21.cgroups         | 12 ++++++++
 tests/vircgroupdata/fedora-21.self.cgroup     | 10 +++++++
 tests/vircgroupdata/kubevirt.cgroups          | 10 +++++++
 tests/vircgroupdata/kubevirt.self.cgroup      | 10 +++++++
 tests/vircgroupdata/no-cgroups.cgroups        |  8 +++++
 tests/vircgroupdata/no-cgroups.parsed         | 10 -------
 tests/vircgroupdata/no-cgroups.self.cgroup    |  0
 tests/vircgroupdata/ovirt-node-6.6.cgroups    |  9 ++++++
 .../vircgroupdata/ovirt-node-6.6.self.cgroup  |  8 +++++
 tests/vircgroupdata/ovirt-node-7.1.cgroups    | 11 +++++++
 .../vircgroupdata/ovirt-node-7.1.self.cgroup  | 10 +++++++
 tests/vircgroupdata/rhel-7.1.cgroups          | 11 +++++++
 tests/vircgroupdata/rhel-7.1.self.cgroup      | 10 +++++++
 tests/vircgrouptest.c                         | 30 ++++++++++++++-----
 25 files changed, 217 insertions(+), 31 deletions(-)
 create mode 100644 tests/vircgroupdata/cgroups1.cgroups
 create mode 100644 tests/vircgroupdata/cgroups1.self.cgroup
 create mode 100644 tests/vircgroupdata/cgroups2.cgroups
 create mode 100644 tests/vircgroupdata/cgroups2.self.cgroup
 create mode 100644 tests/vircgroupdata/cgroups3.cgroups
 create mode 100644 tests/vircgroupdata/cgroups3.self.cgroup
 create mode 100644 tests/vircgroupdata/fedora-18.cgroups
 create mode 100644 tests/vircgroupdata/fedora-18.self.cgroup
 create mode 100644 tests/vircgroupdata/fedora-21.cgroups
 create mode 100644 tests/vircgroupdata/fedora-21.self.cgroup
 create mode 100644 tests/vircgroupdata/kubevirt.cgroups
 create mode 100644 tests/vircgroupdata/kubevirt.self.cgroup
 create mode 100644 tests/vircgroupdata/no-cgroups.cgroups
 delete mode 100644 tests/vircgroupdata/no-cgroups.parsed
 create mode 100644 tests/vircgroupdata/no-cgroups.self.cgroup
 create mode 100644 tests/vircgroupdata/ovirt-node-6.6.cgroups
 create mode 100644 tests/vircgroupdata/ovirt-node-6.6.self.cgroup
 create mode 100644 tests/vircgroupdata/ovirt-node-7.1.cgroups
 create mode 100644 tests/vircgroupdata/ovirt-node-7.1.self.cgroup
 create mode 100644 tests/vircgroupdata/rhel-7.1.cgroups
 create mode 100644 tests/vircgroupdata/rhel-7.1.self.cgroup

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index b66beb7f91..8c4be84fd5 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1528,7 +1528,6 @@ virCgroupDelThread;
 virCgroupDenyAllDevices;
 virCgroupDenyDevice;
 virCgroupDenyDevicePath;
-virCgroupDetectMounts;
 virCgroupFree;
 virCgroupGetBlkioDeviceReadBps;
 virCgroupGetBlkioDeviceReadIops;
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 53f5faafd2..d55f411daa 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -429,7 +429,7 @@ virCgroupMountOptsMatchController(const char *mntOpts,
  * Process /proc/mounts figuring out what controllers are
  * mounted and where
  */
-int
+static int
 virCgroupDetectMounts(virCgroupPtr group)
 {
     size_t i;
@@ -4080,15 +4080,6 @@ virCgroupAvailable(void)
 }
 
 
-int
-virCgroupDetectMounts(virCgroupPtr group ATTRIBUTE_UNUSED)
-{
-    virReportSystemError(ENXIO, "%s",
-                         _("Control groups not supported on this platform"));
-    return -1;
-}
-
-
 int
 virCgroupNewPartition(const char *path ATTRIBUTE_UNUSED,
                       bool create ATTRIBUTE_UNUSED,
diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h
index f78fe8bb9c..046c96c52c 100644
--- a/src/util/vircgrouppriv.h
+++ b/src/util/vircgrouppriv.h
@@ -50,8 +50,6 @@ struct _virCgroup {
     virCgroupController controllers[VIR_CGROUP_CONTROLLER_LAST];
 };
 
-int virCgroupDetectMounts(virCgroupPtr group);
-
 int virCgroupNewPartition(const char *path,
                           bool create,
                           int controllers,
diff --git a/tests/vircgroupdata/cgroups1.cgroups b/tests/vircgroupdata/cgroups1.cgroups
new file mode 100644
index 0000000000..a03c290a98
--- /dev/null
+++ b/tests/vircgroupdata/cgroups1.cgroups
@@ -0,0 +1,11 @@
+#subsys_name    hierarchy       num_cgroups     enabled
+cpuset      1       1       1
+cpu         2       1       1
+cpuacct     3       1       1
+blkio       8       1       1
+memory      4       1       1
+devices     5       1       1
+freezer     6       1       1
+net_cls     7       1       1
+net_prio    9       1       1
+hugetlb     10      1       1
diff --git a/tests/vircgroupdata/cgroups1.self.cgroup b/tests/vircgroupdata/cgroups1.self.cgroup
new file mode 100644
index 0000000000..181f0c22f8
--- /dev/null
+++ b/tests/vircgroupdata/cgroups1.self.cgroup
@@ -0,0 +1,11 @@
+10:hugetlb:/
+9:net_prio:/
+8:blkio:/
+7:net_cls:/
+6:freezer:/
+5:devices:/
+4:memory:/
+3:cpuacct:/
+2:cpu:/
+1:cpuset:/
+0:name=openrc:/
diff --git a/tests/vircgroupdata/cgroups2.cgroups b/tests/vircgroupdata/cgroups2.cgroups
new file mode 100644
index 0000000000..f0a7699559
--- /dev/null
+++ b/tests/vircgroupdata/cgroups2.cgroups
@@ -0,0 +1,10 @@
+#subsys_name    hierarchy       num_cgroups     enabled
+cpuset      1       1       1
+cpu         2       1       1
+cpuacct     3       1       1
+blkio       7       1       1
+memory      4       1       1
+devices     5       1       1
+freezer     6       1       1
+perf_event  8       1       1
+hugetlb     9       1       1
diff --git a/tests/vircgroupdata/cgroups2.self.cgroup b/tests/vircgroupdata/cgroups2.self.cgroup
new file mode 100644
index 0000000000..3d0e793e5a
--- /dev/null
+++ b/tests/vircgroupdata/cgroups2.self.cgroup
@@ -0,0 +1,10 @@
+9:hugetlb:/
+8:perf_event:/
+7:blkio:/
+6:freezer:/
+5:devices:/
+4:memory:/
+3:cpuacct:/
+2:cpu:/
+1:cpuset:/
+0:name=openrc:/
diff --git a/tests/vircgroupdata/cgroups3.cgroups b/tests/vircgroupdata/cgroups3.cgroups
new file mode 100644
index 0000000000..294d95dedf
--- /dev/null
+++ b/tests/vircgroupdata/cgroups3.cgroups
@@ -0,0 +1,12 @@
+#subsys_name    hierarchy       num_cgroups     enabled
+cpuset      1       1       1
+cpu         2       1       1
+cpuacct     3       1       1
+blkio       8       1       1
+memory      4       1       1
+devices     5       1       1
+freezer     6       1       1
+net_cls     7       1       1
+perf_event  9       1       1
+net_prio    10      1       1
+hugetlb     11      1       1
diff --git a/tests/vircgroupdata/cgroups3.self.cgroup b/tests/vircgroupdata/cgroups3.self.cgroup
new file mode 100644
index 0000000000..bf346abdf9
--- /dev/null
+++ b/tests/vircgroupdata/cgroups3.self.cgroup
@@ -0,0 +1,12 @@
+11:hugetlb:/
+10:net_prio:/
+9:perf_event:/
+8:blkio:/
+7:net_cls:/
+6:freezer:/
+5:devices:/
+4:memory:/
+3:cpuacct:/
+2:cpu:/
+1:cpuset:/
+0:name=openrc:/
diff --git a/tests/vircgroupdata/fedora-18.cgroups b/tests/vircgroupdata/fedora-18.cgroups
new file mode 100644
index 0000000000..8eb41087f3
--- /dev/null
+++ b/tests/vircgroupdata/fedora-18.cgroups
@@ -0,0 +1,10 @@
+#subsys_name    hierarchy       num_cgroups     enabled
+cpuset      1       1       1
+cpu         2       1       1
+cpuacct     2       1       1
+blkio       7       1       1
+memory      3       1       1
+devices     4       1       1
+freezer     5       1       1
+net_cls     6       1       1
+perf_event  8       1       1
diff --git a/tests/vircgroupdata/fedora-18.self.cgroup b/tests/vircgroupdata/fedora-18.self.cgroup
new file mode 100644
index 0000000000..da9ad8ad4d
--- /dev/null
+++ b/tests/vircgroupdata/fedora-18.self.cgroup
@@ -0,0 +1,9 @@
+8:perf_event:/
+7:blkio:/
+6:net_cls:/
+5:freezer:/
+4:devices:/
+3:memory:/
+2:cpu,cpuacct:/
+1:cpuset:/
+0:name=systemd:/
diff --git a/tests/vircgroupdata/fedora-21.cgroups b/tests/vircgroupdata/fedora-21.cgroups
new file mode 100644
index 0000000000..3e1401ee98
--- /dev/null
+++ b/tests/vircgroupdata/fedora-21.cgroups
@@ -0,0 +1,12 @@
+#subsys_name    hierarchy       num_cgroups     enabled
+cpuset      1       1       1
+cpu         2       1       1
+cpuacct     2       1       1
+blkio       7       1       1
+memory      3       1       1
+devices     4       1       1
+freezer     5       1       1
+net_cls     6       1       1
+perf_event  8       1       1
+net_prio    6       1       1
+hugetlb     9       1       1
diff --git a/tests/vircgroupdata/fedora-21.self.cgroup b/tests/vircgroupdata/fedora-21.self.cgroup
new file mode 100644
index 0000000000..4c666bd59e
--- /dev/null
+++ b/tests/vircgroupdata/fedora-21.self.cgroup
@@ -0,0 +1,10 @@
+9:hugetlb:/
+8:perf_event:/
+7:blkio:/
+6:net_cls,net_prio:/
+5:freezer:/
+4:devices:/
+3:memory:/
+2:cpu,cpuacct:/
+1:cpuset:/
+0:name=systemd:/
diff --git a/tests/vircgroupdata/kubevirt.cgroups b/tests/vircgroupdata/kubevirt.cgroups
new file mode 100644
index 0000000000..f0a7699559
--- /dev/null
+++ b/tests/vircgroupdata/kubevirt.cgroups
@@ -0,0 +1,10 @@
+#subsys_name    hierarchy       num_cgroups     enabled
+cpuset      1       1       1
+cpu         2       1       1
+cpuacct     3       1       1
+blkio       7       1       1
+memory      4       1       1
+devices     5       1       1
+freezer     6       1       1
+perf_event  8       1       1
+hugetlb     9       1       1
diff --git a/tests/vircgroupdata/kubevirt.self.cgroup b/tests/vircgroupdata/kubevirt.self.cgroup
new file mode 100644
index 0000000000..3d0e793e5a
--- /dev/null
+++ b/tests/vircgroupdata/kubevirt.self.cgroup
@@ -0,0 +1,10 @@
+9:hugetlb:/
+8:perf_event:/
+7:blkio:/
+6:freezer:/
+5:devices:/
+4:memory:/
+3:cpuacct:/
+2:cpu:/
+1:cpuset:/
+0:name=openrc:/
diff --git a/tests/vircgroupdata/no-cgroups.cgroups b/tests/vircgroupdata/no-cgroups.cgroups
new file mode 100644
index 0000000000..3ed1d4e45e
--- /dev/null
+++ b/tests/vircgroupdata/no-cgroups.cgroups
@@ -0,0 +1,8 @@
+#subsys_name    hierarchy       num_cgroups     enabled
+cpuset      0       1       1
+cpu         0       1       1
+cpuacct     0       1       1
+memory      0       1       1
+devices     0       1       1
+freezer     0       1       1
+blkio       0       1       1
diff --git a/tests/vircgroupdata/no-cgroups.parsed b/tests/vircgroupdata/no-cgroups.parsed
deleted file mode 100644
index bf4eea085f..0000000000
--- a/tests/vircgroupdata/no-cgroups.parsed
+++ /dev/null
@@ -1,10 +0,0 @@
-cpu          <null>
-cpuacct      <null>
-cpuset       <null>
-memory       <null>
-devices      <null>
-freezer      <null>
-blkio        <null>
-net_cls      <null>
-perf_event   <null>
-name=systemd <null>
diff --git a/tests/vircgroupdata/no-cgroups.self.cgroup b/tests/vircgroupdata/no-cgroups.self.cgroup
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/tests/vircgroupdata/ovirt-node-6.6.cgroups b/tests/vircgroupdata/ovirt-node-6.6.cgroups
new file mode 100644
index 0000000000..aaabf11a44
--- /dev/null
+++ b/tests/vircgroupdata/ovirt-node-6.6.cgroups
@@ -0,0 +1,9 @@
+#subsys_name    hierarchy       num_cgroups     enabled
+cpuset      0       1       1
+cpu         1       1       1
+cpuacct     2       1       1
+blkio       7       1       1
+memory      3       1       1
+devices     4       1       1
+freezer     5       1       1
+net_cls     6       1       1
diff --git a/tests/vircgroupdata/ovirt-node-6.6.self.cgroup b/tests/vircgroupdata/ovirt-node-6.6.self.cgroup
new file mode 100644
index 0000000000..dadc8155fa
--- /dev/null
+++ b/tests/vircgroupdata/ovirt-node-6.6.self.cgroup
@@ -0,0 +1,8 @@
+7:blkio:/
+6:net_cls:/
+5:freezer:/
+4:devices:/
+3:memory:/
+2:cpuacct:/
+1:cpu:/
+0:cpuset:/
diff --git a/tests/vircgroupdata/ovirt-node-7.1.cgroups b/tests/vircgroupdata/ovirt-node-7.1.cgroups
new file mode 100644
index 0000000000..687297ad4a
--- /dev/null
+++ b/tests/vircgroupdata/ovirt-node-7.1.cgroups
@@ -0,0 +1,11 @@
+#subsys_name    hierarchy       num_cgroups     enabled
+cpuset      1       1       1
+cpu         2       1       1
+cpuacct     2       1       1
+blkio       7       1       1
+memory      3       1       1
+devices     4       1       1
+freezer     5       1       1
+net_cls     6       1       1
+perf_event  8       1       1
+hugetlb     9       1       1
diff --git a/tests/vircgroupdata/ovirt-node-7.1.self.cgroup b/tests/vircgroupdata/ovirt-node-7.1.self.cgroup
new file mode 100644
index 0000000000..f07e8e20f5
--- /dev/null
+++ b/tests/vircgroupdata/ovirt-node-7.1.self.cgroup
@@ -0,0 +1,10 @@
+9:hugetlb:/
+8:perf_event:/
+7:blkio:/
+6:net_cls:/
+5:freezer:/
+4:devices:/
+3:memory:/
+2:cpu,cpuacct:/
+1:cpuset:/
+0:name=systemd:/
diff --git a/tests/vircgroupdata/rhel-7.1.cgroups b/tests/vircgroupdata/rhel-7.1.cgroups
new file mode 100644
index 0000000000..687297ad4a
--- /dev/null
+++ b/tests/vircgroupdata/rhel-7.1.cgroups
@@ -0,0 +1,11 @@
+#subsys_name    hierarchy       num_cgroups     enabled
+cpuset      1       1       1
+cpu         2       1       1
+cpuacct     2       1       1
+blkio       7       1       1
+memory      3       1       1
+devices     4       1       1
+freezer     5       1       1
+net_cls     6       1       1
+perf_event  8       1       1
+hugetlb     9       1       1
diff --git a/tests/vircgroupdata/rhel-7.1.self.cgroup b/tests/vircgroupdata/rhel-7.1.self.cgroup
new file mode 100644
index 0000000000..f07e8e20f5
--- /dev/null
+++ b/tests/vircgroupdata/rhel-7.1.self.cgroup
@@ -0,0 +1,10 @@
+9:hugetlb:/
+8:perf_event:/
+7:blkio:/
+6:net_cls:/
+5:freezer:/
+4:devices:/
+3:memory:/
+2:cpu,cpuacct:/
+1:cpuset:/
+0:name=systemd:/
diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c
index 6a38091a86..5031a2973d 100644
--- a/tests/vircgrouptest.c
+++ b/tests/vircgrouptest.c
@@ -159,26 +159,37 @@ const char *linksLogind[VIR_CGROUP_CONTROLLER_LAST] = {
 };
 
 
+struct _detectMountsData {
+    const char *file;
+    bool fail;
+};
+
+
 static int
 testCgroupDetectMounts(const void *args)
 {
     int result = -1;
-    const char *file = args;
+    const struct _detectMountsData *data = args;
     char *parsed = NULL;
     const char *actual;
     virCgroupPtr group = NULL;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
     size_t i;
 
-    setenv("VIR_CGROUP_MOCK_FILENAME", file, 1);
+    setenv("VIR_CGROUP_MOCK_FILENAME", data->file, 1);
 
-    if (virAsprintf(&parsed, "%s/vircgroupdata/%s.parsed", abs_srcdir, file) < 0)
+    if (virAsprintf(&parsed, "%s/vircgroupdata/%s.parsed",
+                    abs_srcdir, data->file) < 0) {
         goto cleanup;
+    }
 
-    if (VIR_ALLOC(group) < 0)
+    if (virCgroupNewSelf(&group) < 0) {
+        if (data->fail)
+            result = 0;
         goto cleanup;
+    }
 
-    if (virCgroupDetectMounts(group) < 0)
+    if (data->fail)
         goto cleanup;
 
     for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
@@ -870,13 +881,16 @@ mymain(void)
 
     setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1);
 
-# define DETECT_MOUNTS(file) \
+# define DETECT_MOUNTS_FULL(file, fail) \
     do { \
+        struct _detectMountsData data = { file, fail }; \
         if (virTestRun("Detect cgroup mounts for " file, \
                        testCgroupDetectMounts, \
-                       file) < 0) \
+                       &data) < 0) \
             ret = -1; \
     } while (0)
+# define DETECT_MOUNTS(file) DETECT_MOUNTS_FULL(file, false);
+# define DETECT_MOUNTS_FAIL(file) DETECT_MOUNTS_FULL(file, true);
 
     DETECT_MOUNTS("ovirt-node-6.6");
     DETECT_MOUNTS("ovirt-node-7.1");
@@ -887,7 +901,7 @@ mymain(void)
     DETECT_MOUNTS("cgroups2");
     DETECT_MOUNTS("cgroups3");
     DETECT_MOUNTS("all-in-one");
-    DETECT_MOUNTS("no-cgroups");
+    DETECT_MOUNTS_FAIL("no-cgroups");
     DETECT_MOUNTS("kubevirt");
 
     setenv("VIR_CGROUP_MOCK_FILENAME", "systemd", 1);
-- 
2.22.0