vircgrouptest: call virCgroupNewSelf instead virCgroupDetectMounts

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>
This commit is contained in:
Pavel Hrdina 2018-09-14 13:17:07 +02:00
parent 4988f4b347
commit 8b62008d2b
25 changed files with 217 additions and 31 deletions

View File

@ -1513,7 +1513,6 @@ virCgroupDelThread;
virCgroupDenyAllDevices;
virCgroupDenyDevice;
virCgroupDenyDevicePath;
virCgroupDetectMounts;
virCgroupFree;
virCgroupGetBlkioDeviceReadBps;
virCgroupGetBlkioDeviceReadIops;

View 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,

View 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,

View File

@ -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

View File

@ -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:/

View File

@ -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

View File

@ -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:/

View File

@ -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

View File

@ -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:/

View File

@ -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

View File

@ -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:/

View File

@ -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

View File

@ -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:/

View File

@ -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

View File

@ -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:/

View File

@ -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

View File

@ -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>

View File

@ -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

View File

@ -0,0 +1,8 @@
7:blkio:/
6:net_cls:/
5:freezer:/
4:devices:/
3:memory:/
2:cpuacct:/
1:cpu:/
0:cpuset:/

View File

@ -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

View File

@ -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:/

View File

@ -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

View File

@ -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:/

View 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);