This patch enables cgroup controllers as much as possible by skipping the creation of blkio controller when running with old kenels that doesn't support multi-level directory for blkio controller. Signed-off-by: Hu Tao <hutao@xxxxxxxxxxxxxx> --- src/util/cgroup.c | 28 +++++++++++++++++++++++----- 1 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/util/cgroup.c b/src/util/cgroup.c index c5b8cdd..3fad480 100644 --- a/src/util/cgroup.c +++ b/src/util/cgroup.c @@ -527,9 +527,19 @@ static int virCgroupMakeGroup(virCgroupPtr parent, virCgroupPtr group, if (access(path, F_OK) != 0) { if (!create || mkdir(path, 0755) < 0) { - rc = -errno; - VIR_FREE(path); - break; + /* With a kernel that doesn't support multi-level directory + * for blkio controller, libvirt will fail and disable all + * other controllers even though they are available. So skip + * blkio here if mkdir fails. */ + if (i == VIR_CGROUP_CONTROLLER_BLKIO) { + rc = 0; + VIR_FREE(path); + continue; + } else { + rc = -errno; + VIR_FREE(path); + break; + } } if (group->controllers[VIR_CGROUP_CONTROLLER_CPUSET].mountPoint != NULL && (i == VIR_CGROUP_CONTROLLER_CPUSET || @@ -751,8 +761,16 @@ int virCgroupAddTask(virCgroupPtr group, pid_t pid) continue; rc = virCgroupSetValueU64(group, i, "tasks", (unsigned long long)pid); - if (rc != 0) - break; + + /* See virCgroupMakeGroup() for the reason why check BLKIO here */ + if (rc != 0) { + if (i != VIR_CGROUP_CONTROLLER_BLKIO) + break; + else { + rc = 0; + continue; + } + } } return rc; -- 1.7.3.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list