"devices 6 1 1\n"
"blkio 6 1 1\n";
+const char *procmountslogind =
+ "none /not/really/sys/fs/cgroup tmpfs rw,rootcontext=system_u:object_r:sysfs_t:s0,seclabel,relatime,size=4k,mode=755 0 0\n"
+ "systemd /not/really/sys/fs/cgroup/systemd cgroup rw,nosuid,nodev,noexec,relatime,name=systemd 0 0\n";
+
+const char *procselfcgroupslogind =
+ "1:name=systemd:/\n";
+
+const char *proccgroupslogind =
+ "#subsys_name hierarchy num_cgroups enabled\n"
+ "cpuset 0 1 1\n"
+ "cpu 0 1 1\n"
+ "cpuacct 0 1 1\n"
+ "memory 0 1 0\n"
+ "devices 0 1 1\n"
+ "freezer 0 1 1\n"
+ "net_cls 0 1 1\n"
+ "blkio 0 1 1\n"
+ "perf_event 0 1 1\n";
+
+
+
static int make_file(const char *path,
const char *name,
const char *value)
FILE *fopen(const char *path, const char *mode)
{
const char *mock;
- bool allinone = false;
+ bool allinone = false, logind = false;
init_syms();
mock = getenv("VIR_CGROUP_MOCK_MODE");
- if (mock && STREQ(mock, "allinone"))
- allinone = true;
+ if (mock) {
+ if (STREQ(mock, "allinone"))
+ allinone = true;
+ else if (STREQ(mock, "logind"))
+ logind = true;
+ }
if (STREQ(path, "/proc/mounts")) {
if (STREQ(mode, "r")) {
if (allinone)
return fmemopen((void *)procmountsallinone,
strlen(procmountsallinone), mode);
+ else if (logind)
+ return fmemopen((void *)procmountslogind,
+ strlen(procmountslogind), mode);
else
return fmemopen((void *)procmounts, strlen(procmounts), mode);
} else {
if (allinone)
return fmemopen((void *)proccgroupsallinone,
strlen(proccgroupsallinone), mode);
+ else if (logind)
+ return fmemopen((void *)proccgroupslogind,
+ strlen(proccgroupslogind), mode);
else
return fmemopen((void *)proccgroups, strlen(proccgroups), mode);
} else {
if (allinone)
return fmemopen((void *)procselfcgroupsallinone,
strlen(procselfcgroupsallinone), mode);
+ else if (logind)
+ return fmemopen((void *)procselfcgroupslogind,
+ strlen(procselfcgroupslogind), mode);
else
return fmemopen((void *)procselfcgroups, strlen(procselfcgroups), mode);
} else {
[VIR_CGROUP_CONTROLLER_BLKIO] = "/not/really/sys/fs/cgroup",
[VIR_CGROUP_CONTROLLER_SYSTEMD] = NULL,
};
+const char *mountsLogind[VIR_CGROUP_CONTROLLER_LAST] = {
+ [VIR_CGROUP_CONTROLLER_CPU] = NULL,
+ [VIR_CGROUP_CONTROLLER_CPUACCT] = NULL,
+ [VIR_CGROUP_CONTROLLER_CPUSET] = NULL,
+ [VIR_CGROUP_CONTROLLER_MEMORY] = NULL,
+ [VIR_CGROUP_CONTROLLER_DEVICES] = NULL,
+ [VIR_CGROUP_CONTROLLER_FREEZER] = NULL,
+ [VIR_CGROUP_CONTROLLER_BLKIO] = NULL,
+ [VIR_CGROUP_CONTROLLER_SYSTEMD] = "/not/really/sys/fs/cgroup/systemd",
+};
const char *links[VIR_CGROUP_CONTROLLER_LAST] = {
[VIR_CGROUP_CONTROLLER_CPU] = "/not/really/sys/fs/cgroup/cpu",
[VIR_CGROUP_CONTROLLER_SYSTEMD] = NULL,
};
+const char *linksLogind[VIR_CGROUP_CONTROLLER_LAST] = {
+ [VIR_CGROUP_CONTROLLER_CPU] = NULL,
+ [VIR_CGROUP_CONTROLLER_CPUACCT] = NULL,
+ [VIR_CGROUP_CONTROLLER_CPUSET] = NULL,
+ [VIR_CGROUP_CONTROLLER_MEMORY] = NULL,
+ [VIR_CGROUP_CONTROLLER_DEVICES] = NULL,
+ [VIR_CGROUP_CONTROLLER_FREEZER] = NULL,
+ [VIR_CGROUP_CONTROLLER_BLKIO] = NULL,
+ [VIR_CGROUP_CONTROLLER_SYSTEMD] = NULL,
+};
+
static int testCgroupNewForSelf(const void *args ATTRIBUTE_UNUSED)
{
}
+static int testCgroupNewForSelfLogind(const void *args ATTRIBUTE_UNUSED)
+{
+ virCgroupPtr cgroup = NULL;
+ int ret = -1;
+ const char *placement[VIR_CGROUP_CONTROLLER_LAST] = {
+ [VIR_CGROUP_CONTROLLER_CPU] = NULL,
+ [VIR_CGROUP_CONTROLLER_CPUACCT] = NULL,
+ [VIR_CGROUP_CONTROLLER_CPUSET] = NULL,
+ [VIR_CGROUP_CONTROLLER_MEMORY] = NULL,
+ [VIR_CGROUP_CONTROLLER_DEVICES] = NULL,
+ [VIR_CGROUP_CONTROLLER_FREEZER] = NULL,
+ [VIR_CGROUP_CONTROLLER_BLKIO] = NULL,
+ [VIR_CGROUP_CONTROLLER_SYSTEMD] = "/",
+ };
+
+ if (virCgroupNewSelf(&cgroup) < 0) {
+ fprintf(stderr, "Cannot create cgroup for self\n");
+ goto cleanup;
+ }
+
+ ret = validateCgroup(cgroup, "", mountsLogind, linksLogind, placement);
+
+cleanup:
+ virCgroupFree(&cgroup);
+ return ret;
+}
+
+
+static int testCgroupAvailable(const void *args)
+{
+ bool got = virCgroupAvailable();
+ bool want = args == (void*)0x1;
+
+ if (got != want) {
+ fprintf(stderr, "Expected cgroup %savailable, but state was wrong\n",
+ want ? "" : "not ");
+ return -1;
+ }
+
+ return 0;
+}
+
# define FAKESYSFSDIRTEMPLATE abs_builddir "/fakesysfsdir-XXXXXX"
if (virtTestRun("New cgroup for domain partition escaped", 1, testCgroupNewForPartitionDomainEscaped, NULL) < 0)
ret = -1;
+ if (virtTestRun("Cgroup available", 1, testCgroupAvailable, (void*)0x1) < 0)
+ ret = -1;
+
setenv("VIR_CGROUP_MOCK_MODE", "allinone", 1);
if (virtTestRun("New cgroup for self (allinone)", 1, testCgroupNewForSelfAllInOne, NULL) < 0)
ret = -1;
+ if (virtTestRun("Cgroup available", 1, testCgroupAvailable, (void*)0x1) < 0)
+ ret = -1;
+ unsetenv("VIR_CGROUP_MOCK_MODE");
+
+ setenv("VIR_CGROUP_MOCK_MODE", "logind", 1);
+ if (virtTestRun("New cgroup for self (logind)", 1, testCgroupNewForSelfLogind, NULL) < 0)
+ ret = -1;
+ if (virtTestRun("Cgroup available", 1, testCgroupAvailable, (void*)0x0) < 0)
+ ret = -1;
unsetenv("VIR_CGROUP_MOCK_MODE");
if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)