qemu: Abstract code for the cpu controller setting into a helper

This commit is contained in:
Osier Yang 2013-05-24 17:08:27 +08:00
parent 38b90e4df3
commit 8da9516a84

View File

@ -676,6 +676,36 @@ cleanup:
} }
static int
qemuSetupCpuCgroup(virDomainObjPtr vm)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
int rc = -1;
if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU)) {
if (vm->def->cputune.shares) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("CPU tuning is not available on this host"));
return -1;
} else {
return 0;
}
}
if (vm->def->cputune.shares) {
rc = virCgroupSetCpuShares(priv->cgroup, vm->def->cputune.shares);
if (rc != 0) {
virReportSystemError(-rc,
_("Unable to set io cpu shares for domain %s"),
vm->def->name);
return -1;
}
}
return 0;
}
int qemuInitCgroup(virQEMUDriverPtr driver, int qemuInitCgroup(virQEMUDriverPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
bool startup) bool startup)
@ -789,14 +819,14 @@ int qemuSetupCgroup(virQEMUDriverPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
virBitmapPtr nodemask) virBitmapPtr nodemask)
{ {
int rc = -1;
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
int ret = -1;
if (qemuInitCgroup(driver, vm, true) < 0) if (qemuInitCgroup(driver, vm, true) < 0)
return -1; return -1;
if (!priv->cgroup) if (!priv->cgroup)
goto done; return 0;
if (qemuSetupDevicesCgroup(driver, vm) < 0) if (qemuSetupDevicesCgroup(driver, vm) < 0)
goto cleanup; goto cleanup;
@ -807,28 +837,15 @@ int qemuSetupCgroup(virQEMUDriverPtr driver,
if (qemuSetupMemoryCgroup(vm) < 0) if (qemuSetupMemoryCgroup(vm) < 0)
goto cleanup; goto cleanup;
if (vm->def->cputune.shares != 0) { if (qemuSetupCpuCgroup(vm) < 0)
if (virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU)) { goto cleanup;
rc = virCgroupSetCpuShares(priv->cgroup, vm->def->cputune.shares);
if (rc != 0) {
virReportSystemError(-rc,
_("Unable to set io cpu shares for domain %s"),
vm->def->name);
goto cleanup;
}
} else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("CPU tuning is not available on this host"));
}
}
if (qemuSetupCpusetCgroup(vm, nodemask) < 0) if (qemuSetupCpusetCgroup(vm, nodemask) < 0)
goto cleanup; goto cleanup;
done: ret = 0;
rc = 0;
cleanup: cleanup:
return rc == 0 ? 0 : -1; return ret;
} }
int qemuSetupCgroupVcpuBW(virCgroupPtr cgroup, unsigned long long period, int qemuSetupCgroupVcpuBW(virCgroupPtr cgroup, unsigned long long period,