diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b33801a04a9bc5bf386d44cd1dcaceb0f46209cf..09f0017bee8aab7145019bb5ce50ceb37aafbe8c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1513,7 +1513,6 @@ virCgroupDelThread; virCgroupDenyAllDevices; virCgroupDenyDevice; virCgroupDenyDevicePath; -virCgroupDetectMounts; virCgroupFree; virCgroupGetBlkioDeviceReadBps; virCgroupGetBlkioDeviceReadIops; diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 205510a1d48a02d05bf186a56d6dc10d9adfd1fb..bfc2129a32c193bd5b94a147e2c214d132e64525 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -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, diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index f78fe8bb9c18e0b1d19b6138f9dedf81ef887557..046c96c52c39fca3e09deb7243098cf464a170aa 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 0000000000000000000000000000000000000000..a03c290a9832c0ae887ee4ee5e1059f0e5b3f54d --- /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 0000000000000000000000000000000000000000..181f0c22f87b2989a2833fac6917a0a0e5d8a743 --- /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 0000000000000000000000000000000000000000..f0a769955901317b94a28260fa634e4bab782dfe --- /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 0000000000000000000000000000000000000000..3d0e793e5a740e1ad9c97dd15fbee79e8b4ad611 --- /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 0000000000000000000000000000000000000000..294d95dedf5130c68661b881c8f3c00d1eb4df85 --- /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 0000000000000000000000000000000000000000..bf346abdf9efcb89e1a8094bf47b647a8c4c2440 --- /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 0000000000000000000000000000000000000000..8eb41087f3532ce35f8c9822795cf35a987d00b9 --- /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 0000000000000000000000000000000000000000..da9ad8ad4d790af528ad07919b547d9091e9c0ab --- /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 0000000000000000000000000000000000000000..3e1401ee98899d99ffb3ef5885dabcff0d6f418a --- /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 0000000000000000000000000000000000000000..4c666bd59ee03b242ddca3221c3b141ed80a632e --- /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 0000000000000000000000000000000000000000..f0a769955901317b94a28260fa634e4bab782dfe --- /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 0000000000000000000000000000000000000000..3d0e793e5a740e1ad9c97dd15fbee79e8b4ad611 --- /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 0000000000000000000000000000000000000000..3ed1d4e45ef13933e475f91237abc2f00cf6f0f7 --- /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 bf4eea085f86789b44d4da32021a0f2c872f180c..0000000000000000000000000000000000000000 --- a/tests/vircgroupdata/no-cgroups.parsed +++ /dev/null @@ -1,10 +0,0 @@ -cpu -cpuacct -cpuset -memory -devices -freezer -blkio -net_cls -perf_event -name=systemd diff --git a/tests/vircgroupdata/no-cgroups.self.cgroup b/tests/vircgroupdata/no-cgroups.self.cgroup new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/vircgroupdata/ovirt-node-6.6.cgroups b/tests/vircgroupdata/ovirt-node-6.6.cgroups new file mode 100644 index 0000000000000000000000000000000000000000..aaabf11a44855b4dfc97a457343218f3734f90a4 --- /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 0000000000000000000000000000000000000000..dadc8155fa75b05bbfc4d4dca33802858e0640f2 --- /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 0000000000000000000000000000000000000000..687297ad4aa0e43516510deeee061c1030ec57e0 --- /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 0000000000000000000000000000000000000000..f07e8e20f5ce8f6578787c17310b8b40c855afc7 --- /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 0000000000000000000000000000000000000000..687297ad4aa0e43516510deeee061c1030ec57e0 --- /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 0000000000000000000000000000000000000000..f07e8e20f5ce8f6578787c17310b8b40c855afc7 --- /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 54945eea2dc77a643c67461c6d4150d2efbebac4..b6564bdd451191bb2814b49a4f4175f7185dceed 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -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);