mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
qemu: driver: Split out regular vcpu hotplug code into a function
All other modes of qemuDomainSetVcpusFlags have helpers so finish the work by splitting the regular code into a new function. This patch also touches up the coding (spacing) style.
This commit is contained in:
parent
2fa7db93de
commit
c6f26fc207
@ -4858,7 +4858,53 @@ qemuDomainSetVcpusLive(virQEMUDriverPtr driver,
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
qemuDomainSetVcpusInternal(virQEMUDriverPtr driver,
|
||||||
|
virDomainObjPtr vm,
|
||||||
|
virDomainDefPtr def,
|
||||||
|
virDomainDefPtr persistentDef,
|
||||||
|
unsigned int nvcpus)
|
||||||
|
{
|
||||||
|
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (def && nvcpus > virDomainDefGetVcpusMax(def)) {
|
||||||
|
virReportError(VIR_ERR_INVALID_ARG,
|
||||||
|
_("requested vcpus is greater than max allowable"
|
||||||
|
" vcpus for the live domain: %u > %u"),
|
||||||
|
nvcpus, virDomainDefGetVcpusMax(def));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (persistentDef && nvcpus > virDomainDefGetVcpusMax(persistentDef)) {
|
||||||
|
virReportError(VIR_ERR_INVALID_ARG,
|
||||||
|
_("requested vcpus is greater than max allowable"
|
||||||
|
" vcpus for the persistent domain: %u > %u"),
|
||||||
|
nvcpus, virDomainDefGetVcpusMax(persistentDef));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (def && qemuDomainSetVcpusLive(driver, cfg, vm, nvcpus) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (persistentDef) {
|
||||||
|
if (virDomainDefSetVcpus(persistentDef, nvcpus) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
virObjectUnref(cfg);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
qemuDomainSetVcpusFlags(virDomainPtr dom,
|
||||||
|
unsigned int nvcpus,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
virQEMUDriverPtr driver = dom->conn->privateData;
|
virQEMUDriverPtr driver = dom->conn->privateData;
|
||||||
@ -4866,7 +4912,6 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
|||||||
virDomainDefPtr def;
|
virDomainDefPtr def;
|
||||||
virDomainDefPtr persistentDef;
|
virDomainDefPtr persistentDef;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
virQEMUDriverConfigPtr cfg = NULL;
|
|
||||||
|
|
||||||
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
||||||
VIR_DOMAIN_AFFECT_CONFIG |
|
VIR_DOMAIN_AFFECT_CONFIG |
|
||||||
@ -4876,70 +4921,31 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
|||||||
if (!(vm = qemuDomObjFromDomain(dom)))
|
if (!(vm = qemuDomObjFromDomain(dom)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
cfg = virQEMUDriverGetConfig(driver);
|
|
||||||
|
|
||||||
if (virDomainSetVcpusFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
|
if (virDomainSetVcpusFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
|
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_VCPU_GUEST) {
|
|
||||||
ret = qemuDomainSetVcpusAgent(vm, nvcpus);
|
|
||||||
goto endjob;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
|
if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_VCPU_MAXIMUM) {
|
if (flags & VIR_DOMAIN_VCPU_GUEST)
|
||||||
|
ret = qemuDomainSetVcpusAgent(vm, nvcpus);
|
||||||
|
else if (flags & VIR_DOMAIN_VCPU_MAXIMUM)
|
||||||
ret = qemuDomainSetVcpusMax(driver, def, persistentDef, nvcpus);
|
ret = qemuDomainSetVcpusMax(driver, def, persistentDef, nvcpus);
|
||||||
goto endjob;
|
else
|
||||||
}
|
ret = qemuDomainSetVcpusInternal(driver, vm, def, persistentDef, nvcpus);
|
||||||
|
|
||||||
if (def) {
|
|
||||||
if (nvcpus > virDomainDefGetVcpusMax(def)) {
|
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
|
||||||
_("requested vcpus is greater than max allowable"
|
|
||||||
" vcpus for the live domain: %u > %u"),
|
|
||||||
nvcpus, virDomainDefGetVcpusMax(def));
|
|
||||||
goto endjob;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (persistentDef) {
|
|
||||||
if (nvcpus > virDomainDefGetVcpusMax(persistentDef)) {
|
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
|
||||||
_("requested vcpus is greater than max allowable"
|
|
||||||
" vcpus for the persistent domain: %u > %u"),
|
|
||||||
nvcpus, virDomainDefGetVcpusMax(persistentDef));
|
|
||||||
goto endjob;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (def && qemuDomainSetVcpusLive(driver, cfg, vm, nvcpus) < 0)
|
|
||||||
goto endjob;
|
|
||||||
|
|
||||||
if (persistentDef) {
|
|
||||||
if (virDomainDefSetVcpus(persistentDef, nvcpus) < 0)
|
|
||||||
goto endjob;
|
|
||||||
|
|
||||||
if (virDomainSaveConfig(cfg->configDir, driver->caps,
|
|
||||||
persistentDef) < 0)
|
|
||||||
goto endjob;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
endjob:
|
endjob:
|
||||||
qemuDomainObjEndJob(driver, vm);
|
qemuDomainObjEndJob(driver, vm);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virDomainObjEndAPI(&vm);
|
virDomainObjEndAPI(&vm);
|
||||||
virObjectUnref(cfg);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus)
|
qemuDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user