Add a parameter to virCgroupForDomain to indicate which cgroup controllers to create for domain. The value of the parameter is read from user config. --- src/lxc/lxc_cgroup.c | 2 +- src/lxc/lxc_driver.c | 20 +++++++++--------- src/lxc/lxc_process.c | 4 ++-- src/qemu/qemu_cgroup.c | 10 ++++----- src/qemu/qemu_driver.c | 53 ++++++++++++++++++++++++++++++----------------- src/qemu/qemu_hotplug.c | 9 +++++--- src/qemu/qemu_migration.c | 2 +- src/util/cgroup.c | 9 ++++++-- src/util/cgroup.h | 3 ++- 9 files changed, 68 insertions(+), 44 deletions(-) diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index a5e2e97..b636db7 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -237,7 +237,7 @@ int virLXCCgroupSetup(virDomainDefPtr def) return rc; } - rc = virCgroupForDomain(driver, def->name, &cgroup, 1); + rc = virCgroupForDomain(driver, def->name, &cgroup, 1, ~0); if (rc != 0) { virReportSystemError(-rc, _("Unable to create cgroup for domain %s"), diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 5401fe7..8a08404 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -541,7 +541,7 @@ static int lxcDomainGetInfo(virDomainPtr dom, info->cpuTime = 0; info->memory = vm->def->mem.cur_balloon; } else { - if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) != 0) { + if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0, ~0) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to get cgroup for %s"), vm->def->name); goto cleanup; @@ -734,7 +734,7 @@ static int lxcDomainSetMemory(virDomainPtr dom, unsigned long newmem) { goto cleanup; } - if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) != 0) { + if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0, ~0) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to get cgroup for %s"), vm->def->name); goto cleanup; @@ -791,7 +791,7 @@ lxcDomainSetMemoryParameters(virDomainPtr dom, goto cleanup; } - if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) != 0) { + if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0, ~0) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot find cgroup for domain %s"), vm->def->name); goto cleanup; @@ -868,7 +868,7 @@ lxcDomainGetMemoryParameters(virDomainPtr dom, goto cleanup; } - if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) != 0) { + if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0, ~0) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to get cgroup for %s"), vm->def->name); goto cleanup; @@ -1810,7 +1810,7 @@ lxcSetSchedulerParametersFlags(virDomainPtr dom, "%s", _("cgroup CPU controller is not mounted")); goto cleanup; } - if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) { + if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0, ~0) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot find cgroup for domain %s"), vm->def->name); @@ -1954,7 +1954,7 @@ lxcGetSchedulerParametersFlags(virDomainPtr dom, goto cleanup; } - if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) { + if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0, ~0) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot find cgroup for domain %s"), vm->def->name); goto cleanup; @@ -2059,7 +2059,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, goto cleanup; } - if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) { + if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0, ~0) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot find cgroup for domain %s"), vm->def->name); goto cleanup; @@ -2164,7 +2164,7 @@ lxcDomainGetBlkioParameters(virDomainPtr dom, goto cleanup; } - if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) { + if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0, ~0) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot find cgroup for domain %s"), vm->def->name); goto cleanup; @@ -2398,7 +2398,7 @@ static int lxcFreezeContainer(virLXCDriverPtr driver, virDomainObjPtr vm) virCgroupPtr cgroup = NULL; if (!(driver->cgroup && - virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) == 0)) + virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0, ~0) == 0)) return -1; /* From here on, we know that cgroup != NULL. */ @@ -2536,7 +2536,7 @@ static int lxcUnfreezeContainer(virLXCDriverPtr driver, virDomainObjPtr vm) virCgroupPtr cgroup = NULL; if (!(driver->cgroup && - virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) == 0)) + virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0, ~0) == 0)) return -1; ret = virCgroupSetFreezerState(cgroup, "THAWED"); diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 079bc3a..b35ed0e 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -266,7 +266,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver, virDomainConfVMNWFilterTeardown(vm); if (driver->cgroup && - virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) == 0) { + virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0, ~0) == 0) { virCgroupRemove(cgroup); virCgroupFree(&cgroup); } @@ -699,7 +699,7 @@ int virLXCProcessStop(virLXCDriverPtr driver, VIR_FREE(vm->def->seclabels[0]->imagelabel); } - if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) == 0) { + if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0, ~0) == 0) { rc = virCgroupKillPainfully(group); if (rc < 0) { virReportSystemError(-rc, "%s", diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 288187c..ba54a68 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -203,7 +203,7 @@ int qemuSetupCgroup(struct qemud_driver *driver, if (driver->cgroup == NULL) return 0; /* Not supported, so claim success */ - rc = virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 1); + rc = virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 1, driver->cgroupControllers); if (rc != 0) { virReportSystemError(-rc, _("Unable to create cgroup for %s"), @@ -558,7 +558,7 @@ int qemuSetupCgroupForVcpu(struct qemud_driver *driver, virDomainObjPtr vm) if (driver->cgroup == NULL) return 0; - rc = virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0); + rc = virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0, driver->cgroupControllers); if (rc != 0) { virReportSystemError(-rc, _("Unable to find cgroup for %s"), @@ -661,7 +661,7 @@ int qemuSetupCgroupForEmulator(struct qemud_driver *driver, if (driver->cgroup == NULL) return 0; /* Not supported, so claim success */ - rc = virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0); + rc = virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0, driver->cgroupControllers); if (rc != 0) { virReportSystemError(-rc, _("Unable to find cgroup for %s"), @@ -748,7 +748,7 @@ int qemuRemoveCgroup(struct qemud_driver *driver, if (driver->cgroup == NULL) return 0; /* Not supported, so claim success */ - rc = virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0); + rc = virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0, driver->cgroupControllers); if (rc != 0) { if (!quiet) virReportError(VIR_ERR_INTERNAL_ERROR, @@ -772,7 +772,7 @@ int qemuAddToCgroup(struct qemud_driver *driver, if (driver->cgroup == NULL) return 0; /* Not supported, so claim success */ - rc = virCgroupForDomain(driver->cgroup, def->name, &cgroup, 0); + rc = virCgroupForDomain(driver->cgroup, def->name, &cgroup, 0, driver->cgroupControllers); if (rc != 0) { virReportSystemError(-rc, _("unable to find cgroup for domain %s"), diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 007fea9..cc532c7 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3709,7 +3709,7 @@ static int qemudDomainHotplugVcpus(struct qemud_driver *driver, } cgroup_available = (virCgroupForDomain(driver->cgroup, vm->def->name, - &cgroup, 0) == 0); + &cgroup, 0, driver->cgroupControllers) == 0); if (nvcpus > oldvcpus) { for (i = oldvcpus; i < nvcpus; i++) { @@ -4035,7 +4035,8 @@ qemudDomainPinVcpuFlags(virDomainPtr dom, /* Configure the corresponding cpuset cgroup before set affinity. */ if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_CPUSET)) { - if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup_dom, 0) == 0 && + if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup_dom, 0, + driver->cgroupControllers) == 0 && virCgroupForVcpu(cgroup_dom, vcpu, &cgroup_vcpu, 0) == 0 && qemuSetupCgroupVcpuPin(cgroup_vcpu, newVcpuPin, newVcpuPinNum, vcpu) < 0) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -4301,7 +4302,7 @@ qemudDomainPinEmulator(virDomainPtr dom, * If no cgroup for domain or hypervisor exists, do nothing. */ if (virCgroupForDomain(driver->cgroup, vm->def->name, - &cgroup_dom, 0) == 0) { + &cgroup_dom, 0, driver->cgroupControllers) == 0) { if (virCgroupForEmulator(cgroup_dom, &cgroup_emulator, 0) == 0) { if (qemuSetupCgroupEmulatorPin(cgroup_emulator, newVcpuPin[0]->cpumask) < 0) { @@ -5888,7 +5889,8 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn, goto end; if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_DEVICES)) { - if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0)) { + if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0, + driver->cgroupControllers)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to find cgroup for %s"), vm->def->name); @@ -6119,8 +6121,8 @@ qemuDomainChangeDiskMediaLive(virDomainObjPtr vm, goto end; if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_DEVICES)) { - if (virCgroupForDomain(driver->cgroup, - vm->def->name, &cgroup, 0) != 0) { + if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0, + driver->cgroupControllers) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to find cgroup for %s"), vm->def->name); @@ -6984,7 +6986,8 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, goto cleanup; } - if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) { + if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0, + driver->cgroupControllers) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot find cgroup for domain %s"), vm->def->name); @@ -7145,7 +7148,8 @@ qemuDomainGetBlkioParameters(virDomainPtr dom, goto cleanup; } - if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) { + if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0, + driver->cgroupControllers) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot find cgroup for domain %s"), vm->def->name); goto cleanup; @@ -7334,7 +7338,8 @@ qemuDomainSetMemoryParameters(virDomainPtr dom, goto cleanup; } - if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) { + if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0, + driver->cgroupControllers) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot find cgroup for domain %s"), vm->def->name); goto cleanup; @@ -7491,7 +7496,8 @@ qemuDomainGetMemoryParameters(virDomainPtr dom, goto cleanup; } - if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) { + if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0, + driver->cgroupControllers) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot find cgroup for domain %s"), vm->def->name); goto cleanup; @@ -7653,7 +7659,8 @@ qemuDomainSetNumaParameters(virDomainPtr dom, goto cleanup; } - if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) { + if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0, + driver->cgroupControllers) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot find cgroup for domain %s"), vm->def->name); @@ -7809,7 +7816,8 @@ qemuDomainGetNumaParameters(virDomainPtr dom, goto cleanup; } - if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) { + if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0, + driver->cgroupControllers) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot find cgroup for domain %s"), vm->def->name); @@ -8014,7 +8022,8 @@ qemuSetSchedulerParametersFlags(virDomainPtr dom, "%s", _("cgroup CPU controller is not mounted")); goto cleanup; } - if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) { + if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0, + driver->cgroupControllers) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot find cgroup for domain %s"), vm->def->name); @@ -8301,7 +8310,8 @@ qemuGetSchedulerParametersFlags(virDomainPtr dom, goto cleanup; } - if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) { + if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0, + driver->cgroupControllers) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot find cgroup for domain %s"), vm->def->name); goto cleanup; @@ -11029,7 +11039,8 @@ qemuDomainSnapshotCreateDiskActive(struct qemud_driver *driver, } if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_DEVICES) && - virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0)) { + virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0, + driver->cgroupControllers)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to find cgroup for %s"), vm->def->name); @@ -12748,7 +12759,8 @@ qemuDomainBlockPivot(virConnectPtr conn, * we know for sure that there is a backing chain. */ if (disk->mirrorFormat && disk->mirrorFormat != VIR_STORAGE_FILE_RAW && qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_DEVICES) && - virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) < 0) { + virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0, + driver->cgroupControllers) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to find cgroup for %s"), vm->def->name); @@ -13054,7 +13066,8 @@ qemuDomainBlockCopy(virDomainPtr dom, const char *path, goto cleanup; } if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_DEVICES) && - virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) < 0) { + virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0, + driver->cgroupControllers) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to find cgroup for %s"), vm->def->name); @@ -13338,7 +13351,8 @@ qemuDomainBlockCommit(virDomainPtr dom, const char *path, const char *base, * operation succeeds, but doing that requires tracking the * operation in XML across libvirtd restarts. */ if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_DEVICES) && - virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) < 0) { + virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0, + driver->cgroupControllers) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to find cgroup for %s"), vm->def->name); @@ -14270,7 +14284,8 @@ qemuDomainGetCPUStats(virDomainPtr domain, goto cleanup; } - if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) { + if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0, + driver->cgroupControllers) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot find cgroup for domain %s"), vm->def->name); goto cleanup; diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index ae8381e..b955c5b 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1097,7 +1097,8 @@ int qemuDomainAttachHostUsbDevice(struct qemud_driver *driver, usbDevice *usb; qemuCgroupData data; - if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) != 0) { + if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0, + driver->cgroupControllers) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to find cgroup for %s"), vm->def->name); @@ -1946,7 +1947,8 @@ int qemuDomainDetachPciDiskDevice(struct qemud_driver *driver, } if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_DEVICES)) { - if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) != 0) { + if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0, + driver->cgroupControllers) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to find cgroup for %s"), vm->def->name); @@ -2057,7 +2059,8 @@ int qemuDomainDetachDiskDevice(struct qemud_driver *driver, } if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_DEVICES)) { - if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0) != 0) { + if (virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0, + driver->cgroupControllers) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to find cgroup for %s"), vm->def->name); diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 5f8a9c5..e36bece 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -3510,7 +3510,7 @@ qemuMigrationToFile(struct qemud_driver *driver, virDomainObjPtr vm, if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_DEVICES)) { if (virCgroupForDomain(driver->cgroup, vm->def->name, - &cgroup, 0) != 0) { + &cgroup, 0, driver->cgroupControllers) != 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to find cgroup for %s"), vm->def->name); diff --git a/src/util/cgroup.c b/src/util/cgroup.c index 02fc24a..d07a66a 100644 --- a/src/util/cgroup.c +++ b/src/util/cgroup.c @@ -992,14 +992,19 @@ int virCgroupForDriver(const char *name ATTRIBUTE_UNUSED, int virCgroupForDomain(virCgroupPtr driver, const char *name, virCgroupPtr *group, - int create) + int create, + int controllers) { + unsigned flags = VIR_CGROUP_MEM_HIERACHY; int rc; char *path; if (driver == NULL) return -EINVAL; + if (!(controllers & (1UL << VIR_CGROUP_CONTROLLER_CPUSET))) + flags |= VIR_CGROUP_DISABLE_CPUSET; + if (virAsprintf(&path, "%s/%s", driver->path, name) < 0) return -ENOMEM; @@ -1017,7 +1022,7 @@ int virCgroupForDomain(virCgroupPtr driver, * a group for driver, is to avoid overhead to track * cumulative usage that we don't need. */ - rc = virCgroupMakeGroup(driver, *group, create, VIR_CGROUP_MEM_HIERACHY); + rc = virCgroupMakeGroup(driver, *group, create, flags); if (rc != 0) virCgroupFree(group); } diff --git a/src/util/cgroup.h b/src/util/cgroup.h index f0945f1..b121bca 100644 --- a/src/util/cgroup.h +++ b/src/util/cgroup.h @@ -51,7 +51,8 @@ int virCgroupForDriver(const char *name, int virCgroupForDomain(virCgroupPtr driver, const char *name, virCgroupPtr *group, - int create); + int create, + int controllers); int virCgroupForVcpu(virCgroupPtr driver, int vcpuid, -- 1.7.11.7 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list