]> xenbits.xensource.com Git - libvirt.git/commitdiff
vircgrouptest: call virCgroupNewSelf instead virCgroupDetectMounts
authorPavel Hrdina <phrdina@redhat.com>
Fri, 14 Sep 2018 11:17:07 +0000 (13:17 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Tue, 25 Sep 2018 07:59:23 +0000 (09:59 +0200)
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>
25 files changed:
src/libvirt_private.syms
src/util/vircgroup.c
src/util/vircgrouppriv.h
tests/vircgroupdata/cgroups1.cgroups [new file with mode: 0644]
tests/vircgroupdata/cgroups1.self.cgroup [new file with mode: 0644]
tests/vircgroupdata/cgroups2.cgroups [new file with mode: 0644]
tests/vircgroupdata/cgroups2.self.cgroup [new file with mode: 0644]
tests/vircgroupdata/cgroups3.cgroups [new file with mode: 0644]
tests/vircgroupdata/cgroups3.self.cgroup [new file with mode: 0644]
tests/vircgroupdata/fedora-18.cgroups [new file with mode: 0644]
tests/vircgroupdata/fedora-18.self.cgroup [new file with mode: 0644]
tests/vircgroupdata/fedora-21.cgroups [new file with mode: 0644]
tests/vircgroupdata/fedora-21.self.cgroup [new file with mode: 0644]
tests/vircgroupdata/kubevirt.cgroups [new file with mode: 0644]
tests/vircgroupdata/kubevirt.self.cgroup [new file with mode: 0644]
tests/vircgroupdata/no-cgroups.cgroups [new file with mode: 0644]
tests/vircgroupdata/no-cgroups.parsed [deleted file]
tests/vircgroupdata/no-cgroups.self.cgroup [new file with mode: 0644]
tests/vircgroupdata/ovirt-node-6.6.cgroups [new file with mode: 0644]
tests/vircgroupdata/ovirt-node-6.6.self.cgroup [new file with mode: 0644]
tests/vircgroupdata/ovirt-node-7.1.cgroups [new file with mode: 0644]
tests/vircgroupdata/ovirt-node-7.1.self.cgroup [new file with mode: 0644]
tests/vircgroupdata/rhel-7.1.cgroups [new file with mode: 0644]
tests/vircgroupdata/rhel-7.1.self.cgroup [new file with mode: 0644]
tests/vircgrouptest.c

index b33801a04a9bc5bf386d44cd1dcaceb0f46209cf..09f0017bee8aab7145019bb5ce50ceb37aafbe8c 100644 (file)
@@ -1513,7 +1513,6 @@ virCgroupDelThread;
 virCgroupDenyAllDevices;
 virCgroupDenyDevice;
 virCgroupDenyDevicePath;
-virCgroupDetectMounts;
 virCgroupFree;
 virCgroupGetBlkioDeviceReadBps;
 virCgroupGetBlkioDeviceReadIops;
index 205510a1d48a02d05bf186a56d6dc10d9adfd1fb..bfc2129a32c193bd5b94a147e2c214d132e64525 100644 (file)
@@ -425,7 +425,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;
@@ -4076,15 +4076,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,
index f78fe8bb9c18e0b1d19b6138f9dedf81ef887557..046c96c52c39fca3e09deb7243098cf464a170aa 100644 (file)
@@ -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 (file)
index 0000000..a03c290
--- /dev/null
@@ -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 (file)
index 0000000..181f0c2
--- /dev/null
@@ -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 (file)
index 0000000..f0a7699
--- /dev/null
@@ -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 (file)
index 0000000..3d0e793
--- /dev/null
@@ -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 (file)
index 0000000..294d95d
--- /dev/null
@@ -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 (file)
index 0000000..bf346ab
--- /dev/null
@@ -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 (file)
index 0000000..8eb4108
--- /dev/null
@@ -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 (file)
index 0000000..da9ad8a
--- /dev/null
@@ -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 (file)
index 0000000..3e1401e
--- /dev/null
@@ -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 (file)
index 0000000..4c666bd
--- /dev/null
@@ -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 (file)
index 0000000..f0a7699
--- /dev/null
@@ -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 (file)
index 0000000..3d0e793
--- /dev/null
@@ -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 (file)
index 0000000..3ed1d4e
--- /dev/null
@@ -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 (file)
index bf4eea0..0000000
+++ /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 (file)
index 0000000..e69de29
diff --git a/tests/vircgroupdata/ovirt-node-6.6.cgroups b/tests/vircgroupdata/ovirt-node-6.6.cgroups
new file mode 100644 (file)
index 0000000..aaabf11
--- /dev/null
@@ -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 (file)
index 0000000..dadc815
--- /dev/null
@@ -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 (file)
index 0000000..687297a
--- /dev/null
@@ -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 (file)
index 0000000..f07e8e2
--- /dev/null
@@ -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 (file)
index 0000000..687297a
--- /dev/null
@@ -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 (file)
index 0000000..f07e8e2
--- /dev/null
@@ -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:/
index 54945eea2dc77a643c67461c6d4150d2efbebac4..b6564bdd451191bb2814b49a4f4175f7185dceed 100644 (file)
@@ -158,26 +158,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++) {
@@ -869,13 +880,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");
@@ -886,7 +900,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);