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',
* and must also have locked 'dom', to ensure no one else
bool live);
int virDomainObjSetDefTransient(virCapsPtr caps,
virDomainObjPtr domain);
+virDomainDefPtr
+virDomainObjGetPersistentDef(virCapsPtr caps,
+ virDomainObjPtr domain);
void virDomainRemoveInactive(virDomainObjListPtr doms,
virDomainObjPtr dom);
virDomainNetTypeToString;
virDomainObjAssignDef;
virDomainObjSetDefTransient;
+virDomainObjGetPersistentDef;
virDomainObjIsDuplicate;
virDomainObjListDeinit;
virDomainObjListGetActiveIDs;
{
struct qemud_driver *driver = dom->conn->privateData;
virDomainObjPtr vm;
- virDomainDefPtr def;
+ virDomainDefPtr persistentDef;
const char * type;
int max;
int ret = -1;
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))) {
qemuReportError(VIR_ERR_INTERNAL_ERROR,
_("unknown virt type in domain definition '%d'"),
goto endjob;
}
+ if (!(persistentDef = virDomainObjGetPersistentDef(driver->caps, vm)))
+ goto endjob;
+
switch (flags) {
case VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_VCPU_CONFIG:
- def = vm->def;
- if (virDomainObjIsActive(vm)) {
- if (vm->newDef)
- 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;
+ persistentDef->maxvcpus = nvcpus;
+ if (nvcpus < persistentDef->vcpus)
+ persistentDef->vcpus = nvcpus;
ret = 0;
break;
case VIR_DOMAIN_VCPU_CONFIG:
- def = vm->def;
- if (virDomainObjIsActive(vm)) {
- if (vm->newDef)
- def = vm->newDef;
- else {
- qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
- _("no persistent state"));
- goto endjob;
- }
- }
- def->vcpus = nvcpus;
+ persistentDef->vcpus = nvcpus;
ret = 0;
break;
case VIR_DOMAIN_VCPU_LIVE | VIR_DOMAIN_VCPU_CONFIG:
ret = qemudDomainHotplugVcpus(vm, nvcpus);
- if (ret == 0 && vm->newDef)
- vm->newDef->vcpus = nvcpus;
+ if (ret == 0) {
+ persistentDef->vcpus = nvcpus;
+ }
break;
}
{
testConnPtr privconn = domain->conn->privateData;
virDomainObjPtr privdom = NULL;
- virDomainDefPtr def;
+ virDomainDefPtr persistentDef;
int ret = -1, maxvcpus;
virCheckFlags(VIR_DOMAIN_VCPU_LIVE |
goto cleanup;
}
+ if (!(persistentDef = virDomainObjGetPersistentDef(privconn->caps,
+ privdom)))
+ goto cleanup;
+
switch (flags) {
case VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_VCPU_CONFIG:
- def = privdom->def;
- if (virDomainObjIsActive(privdom)) {
- if (privdom->newDef)
- 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;
+ persistentDef->maxvcpus = nrCpus;
+ if (nrCpus < persistentDef->vcpus)
+ persistentDef->vcpus = nrCpus;
ret = 0;
break;
case VIR_DOMAIN_VCPU_CONFIG:
- def = privdom->def;
- if (virDomainObjIsActive(privdom)) {
- if (privdom->newDef)
- def = privdom->newDef;
- else {
- testError(VIR_ERR_OPERATION_INVALID, "%s",
- _("no persistent state"));
- goto cleanup;
- }
- }
- def->vcpus = nrCpus;
+ persistentDef->vcpus = nrCpus;
ret = 0;
break;
case VIR_DOMAIN_VCPU_LIVE | VIR_DOMAIN_VCPU_CONFIG:
ret = testDomainUpdateVCPUs(domain->conn, privdom, nrCpus, 0);
- if (ret == 0 && privdom->newDef)
- privdom->newDef->vcpus = nrCpus;
+ if (ret == 0) {
+ persistentDef->vcpus = nrCpus;
+ }
break;
}