mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-30 09:53:10 +00:00
qemu: setvcpus: Simplify altering the persistent config
Do this by adding a helper function to get the persistent domain config. This should be useful for other functions that may eventually want to alter the persistent domain config (attach/detach device). Also make similar changes to the test drivers setvcpus command. A caveat is that the function will return the running config for a transient domain, rather than error. This simplifies callers, as long as they use other methods to ensure the guest is persistent.
This commit is contained in:
parent
d75202915e
commit
39b6265476
@ -1007,6 +1007,27 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the persistent domain configuration. If domain is transient,
|
||||||
|
* return the running config.
|
||||||
|
*
|
||||||
|
* @param caps pointer to capabilities info
|
||||||
|
* @param domain domain object pointer
|
||||||
|
* @return NULL on error, virDOmainDefPtr on success
|
||||||
|
*/
|
||||||
|
virDomainDefPtr
|
||||||
|
virDomainObjGetPersistentDef(virCapsPtr caps,
|
||||||
|
virDomainObjPtr domain)
|
||||||
|
{
|
||||||
|
if (virDomainObjSetDefTransient(caps, domain) < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (domain->newDef)
|
||||||
|
return domain->newDef;
|
||||||
|
else
|
||||||
|
return domain->def;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The caller must hold a lock on the driver owning 'doms',
|
* The caller must hold a lock on the driver owning 'doms',
|
||||||
* and must also have locked 'dom', to ensure no one else
|
* and must also have locked 'dom', to ensure no one else
|
||||||
|
@ -1094,6 +1094,9 @@ void virDomainObjAssignDef(virDomainObjPtr domain,
|
|||||||
bool live);
|
bool live);
|
||||||
int virDomainObjSetDefTransient(virCapsPtr caps,
|
int virDomainObjSetDefTransient(virCapsPtr caps,
|
||||||
virDomainObjPtr domain);
|
virDomainObjPtr domain);
|
||||||
|
virDomainDefPtr
|
||||||
|
virDomainObjGetPersistentDef(virCapsPtr caps,
|
||||||
|
virDomainObjPtr domain);
|
||||||
void virDomainRemoveInactive(virDomainObjListPtr doms,
|
void virDomainRemoveInactive(virDomainObjListPtr doms,
|
||||||
virDomainObjPtr dom);
|
virDomainObjPtr dom);
|
||||||
|
|
||||||
|
@ -226,6 +226,7 @@ virDomainNetDefFree;
|
|||||||
virDomainNetTypeToString;
|
virDomainNetTypeToString;
|
||||||
virDomainObjAssignDef;
|
virDomainObjAssignDef;
|
||||||
virDomainObjSetDefTransient;
|
virDomainObjSetDefTransient;
|
||||||
|
virDomainObjGetPersistentDef;
|
||||||
virDomainObjIsDuplicate;
|
virDomainObjIsDuplicate;
|
||||||
virDomainObjListDeinit;
|
virDomainObjListDeinit;
|
||||||
virDomainObjListGetActiveIDs;
|
virDomainObjListGetActiveIDs;
|
||||||
|
@ -6264,7 +6264,7 @@ qemudDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
|||||||
{
|
{
|
||||||
struct qemud_driver *driver = dom->conn->privateData;
|
struct qemud_driver *driver = dom->conn->privateData;
|
||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
virDomainDefPtr def;
|
virDomainDefPtr persistentDef;
|
||||||
const char * type;
|
const char * type;
|
||||||
int max;
|
int max;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -6309,6 +6309,12 @@ qemudDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
|||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!vm->persistent && (flags & VIR_DOMAIN_VCPU_CONFIG)) {
|
||||||
|
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
|
_("cannot change persistent config of a transient domain"));
|
||||||
|
goto endjob;
|
||||||
|
}
|
||||||
|
|
||||||
if (!(type = virDomainVirtTypeToString(vm->def->virtType))) {
|
if (!(type = virDomainVirtTypeToString(vm->def->virtType))) {
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("unknown virt type in domain definition '%d'"),
|
_("unknown virt type in domain definition '%d'"),
|
||||||
@ -6333,36 +6339,19 @@ qemudDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
|||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(persistentDef = virDomainObjGetPersistentDef(driver->caps, vm)))
|
||||||
|
goto endjob;
|
||||||
|
|
||||||
switch (flags) {
|
switch (flags) {
|
||||||
case VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_VCPU_CONFIG:
|
case VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_VCPU_CONFIG:
|
||||||
def = vm->def;
|
persistentDef->maxvcpus = nvcpus;
|
||||||
if (virDomainObjIsActive(vm)) {
|
if (nvcpus < persistentDef->vcpus)
|
||||||
if (vm->newDef)
|
persistentDef->vcpus = nvcpus;
|
||||||
def = vm->newDef;
|
|
||||||
else{
|
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
||||||
_("no persistent state"));
|
|
||||||
goto endjob;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
def->maxvcpus = nvcpus;
|
|
||||||
if (nvcpus < vm->newDef->vcpus)
|
|
||||||
def->vcpus = nvcpus;
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_VCPU_CONFIG:
|
case VIR_DOMAIN_VCPU_CONFIG:
|
||||||
def = vm->def;
|
persistentDef->vcpus = nvcpus;
|
||||||
if (virDomainObjIsActive(vm)) {
|
|
||||||
if (vm->newDef)
|
|
||||||
def = vm->newDef;
|
|
||||||
else {
|
|
||||||
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
||||||
_("no persistent state"));
|
|
||||||
goto endjob;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
def->vcpus = nvcpus;
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -6372,8 +6361,9 @@ qemudDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
|||||||
|
|
||||||
case VIR_DOMAIN_VCPU_LIVE | VIR_DOMAIN_VCPU_CONFIG:
|
case VIR_DOMAIN_VCPU_LIVE | VIR_DOMAIN_VCPU_CONFIG:
|
||||||
ret = qemudDomainHotplugVcpus(vm, nvcpus);
|
ret = qemudDomainHotplugVcpus(vm, nvcpus);
|
||||||
if (ret == 0 && vm->newDef)
|
if (ret == 0) {
|
||||||
vm->newDef->vcpus = nvcpus;
|
persistentDef->vcpus = nvcpus;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2095,7 +2095,7 @@ testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus,
|
|||||||
{
|
{
|
||||||
testConnPtr privconn = domain->conn->privateData;
|
testConnPtr privconn = domain->conn->privateData;
|
||||||
virDomainObjPtr privdom = NULL;
|
virDomainObjPtr privdom = NULL;
|
||||||
virDomainDefPtr def;
|
virDomainDefPtr persistentDef;
|
||||||
int ret = -1, maxvcpus;
|
int ret = -1, maxvcpus;
|
||||||
|
|
||||||
virCheckFlags(VIR_DOMAIN_VCPU_LIVE |
|
virCheckFlags(VIR_DOMAIN_VCPU_LIVE |
|
||||||
@ -2145,36 +2145,20 @@ testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(persistentDef = virDomainObjGetPersistentDef(privconn->caps,
|
||||||
|
privdom)))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
switch (flags) {
|
switch (flags) {
|
||||||
case VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_VCPU_CONFIG:
|
case VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_VCPU_CONFIG:
|
||||||
def = privdom->def;
|
persistentDef->maxvcpus = nrCpus;
|
||||||
if (virDomainObjIsActive(privdom)) {
|
if (nrCpus < persistentDef->vcpus)
|
||||||
if (privdom->newDef)
|
persistentDef->vcpus = nrCpus;
|
||||||
def = privdom->newDef;
|
|
||||||
else {
|
|
||||||
testError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
||||||
_("no persistent state"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
def->maxvcpus = nrCpus;
|
|
||||||
if (nrCpus < def->vcpus)
|
|
||||||
def->vcpus = nrCpus;
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_VCPU_CONFIG:
|
case VIR_DOMAIN_VCPU_CONFIG:
|
||||||
def = privdom->def;
|
persistentDef->vcpus = nrCpus;
|
||||||
if (virDomainObjIsActive(privdom)) {
|
|
||||||
if (privdom->newDef)
|
|
||||||
def = privdom->newDef;
|
|
||||||
else {
|
|
||||||
testError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
||||||
_("no persistent state"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
def->vcpus = nrCpus;
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -2184,8 +2168,9 @@ testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus,
|
|||||||
|
|
||||||
case VIR_DOMAIN_VCPU_LIVE | VIR_DOMAIN_VCPU_CONFIG:
|
case VIR_DOMAIN_VCPU_LIVE | VIR_DOMAIN_VCPU_CONFIG:
|
||||||
ret = testDomainUpdateVCPUs(domain->conn, privdom, nrCpus, 0);
|
ret = testDomainUpdateVCPUs(domain->conn, privdom, nrCpus, 0);
|
||||||
if (ret == 0 && privdom->newDef)
|
if (ret == 0) {
|
||||||
privdom->newDef->vcpus = nrCpus;
|
persistentDef->vcpus = nrCpus;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user