To support further refactors replace all write access to def->maxvcpus
with a accessor function.
---
src/conf/domain_conf.c | 18 ++++++++++++++++--
src/conf/domain_conf.h | 2 ++
src/hyperv/hyperv_driver.c | 5 ++++-
src/libvirt_private.syms | 1 +
src/libxl/libxl_driver.c | 8 ++++++--
src/lxc/lxc_native.c | 4 +++-
src/openvz/openvz_conf.c | 4 +++-
src/openvz/openvz_driver.c | 5 ++++-
src/phyp/phyp_driver.c | 4 +++-
src/qemu/qemu_command.c | 9 +++++++--
src/qemu/qemu_driver.c | 4 +++-
src/test/test_driver.c | 4 +++-
src/vbox/vbox_common.c | 11 +++++++++--
src/vmx/vmx.c | 5 ++++-
src/vz/vz_sdk.c | 4 +++-
src/xen/xm_internal.c | 4 +++-
src/xenapi/xenapi_driver.c | 4 +++-
src/xenconfig/xen_common.c | 4 +++-
src/xenconfig/xen_sxpr.c | 3 ++-
19 files changed, 82 insertions(+), 21 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a744412..e0fc09c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1424,6 +1424,16 @@ void virDomainLeaseDefFree(virDomainLeaseDefPtr def)
}
+int
+virDomainDefSetVCpusMax(virDomainDefPtr def,
+ unsigned int vcpus)
+{
+ def->maxvcpus = vcpus;
+
+ return 0;
+}
+
+
virDomainDiskDefPtr
virDomainDiskDefNew(virDomainXMLOptionPtr xmlopt)
{
@@ -14645,18 +14655,22 @@ virDomainVcpuParse(virDomainDefPtr def,
{
int n;
char *tmp = NULL;
+ unsigned int maxvcpus;
int ret = -1;
- if ((n = virXPathUInt("string(./vcpu[1])", ctxt, &def->maxvcpus))
< 0) {
+ if ((n = virXPathUInt("string(./vcpu[1])", ctxt, &maxvcpus)) < 0) {
if (n == -2) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("maximum vcpus count must be an integer"));
goto cleanup;
}
- def->maxvcpus = 1;
+ maxvcpus = 1;
}
+ if (virDomainDefSetVCpusMax(def, maxvcpus) < 0)
+ goto cleanup;
+
if ((n = virXPathUInt("string(./vcpu[1]/@current)", ctxt,
&def->vcpus)) < 0) {
if (n == -2) {
virReportError(VIR_ERR_XML_ERROR, "%s",
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 8d43ee6..498ca99 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2325,6 +2325,8 @@ struct _virDomainDef {
xmlNodePtr metadata;
};
+int virDomainDefSetVCpusMax(virDomainDefPtr def, unsigned int vcpus);
+
unsigned long long virDomainDefGetMemoryInitial(const virDomainDef *def);
void virDomainDefSetMemoryTotal(virDomainDefPtr def, unsigned long long size);
void virDomainDefSetMemoryInitial(virDomainDefPtr def, unsigned long long size);
diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 72261df..61e06b0 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -873,8 +873,11 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
virDomainDefSetMemoryTotal(def, memorySettingData->data->Limit * 1024); /*
megabyte to kilobyte */
def->mem.cur_balloon = memorySettingData->data->VirtualQuantity * 1024; /*
megabyte to kilobyte */
+ if (virDomainDefSetVCpusMax(def,
+ processorSettingData->data->VirtualQuantity) <
0)
+ goto cleanup;
+
def->vcpus = processorSettingData->data->VirtualQuantity;
- def->maxvcpus = processorSettingData->data->VirtualQuantity;
def->os.type = VIR_DOMAIN_OSTYPE_HVM;
/* FIXME: devices section is totally missing */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 7e60d87..321f926 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -230,6 +230,7 @@ virDomainDefParseString;
virDomainDefPostParse;
virDomainDefSetMemoryInitial;
virDomainDefSetMemoryTotal;
+virDomainDefSetVCpusMax;
virDomainDeleteConfig;
virDomainDeviceAddressIsValid;
virDomainDeviceAddressTypeToString;
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index d77a0e4..5ef0784 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -552,8 +552,10 @@ libxlAddDom0(libxlDriverPrivatePtr driver)
def = NULL;
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BOOTED);
+ if (virDomainDefSetVCpusMax(vm->def, d_info.vcpu_max_id + 1))
+ goto cleanup;
+
vm->def->vcpus = d_info.vcpu_online;
- vm->def->maxvcpus = d_info.vcpu_max_id + 1;
vm->def->mem.cur_balloon = d_info.current_memkb;
virDomainDefSetMemoryTotal(vm->def, d_info.max_memkb);
@@ -2184,7 +2186,9 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
switch (flags) {
case VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_VCPU_CONFIG:
- def->maxvcpus = nvcpus;
+ if (virDomainDefSetVCpusMax(def, nvcpus) < 0)
+ goto cleanup;
+
if (nvcpus < def->vcpus)
def->vcpus = nvcpus;
break;
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index 2f95597..d4a72c1 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -1019,7 +1019,9 @@ lxcParseConfigString(const char *config)
/* Value not handled by the LXC driver, setting to
* minimum required to make XML parsing pass */
- vmdef->maxvcpus = 1;
+ if (virDomainDefSetVCpusMax(vmdef, 1) < 0)
+ goto error;
+
vmdef->vcpus = 1;
vmdef->nfss = 0;
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index c0f65c9..aabb7c4 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -582,7 +582,9 @@ int openvzLoadDomains(struct openvz_driver *driver)
if (ret == 0 || vcpus == 0)
vcpus = openvzGetNodeCPUs();
- def->maxvcpus = vcpus;
+ if (virDomainDefSetVCpusMax(def, vcpus) < 0)
+ goto cleanup;
+
def->vcpus = vcpus;
/* XXX load rest of VM config data .... */
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index b8c0f50..60b40d5 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -1368,7 +1368,10 @@ static int openvzDomainSetVcpusInternal(virDomainObjPtr vm,
if (virRun(prog, NULL) < 0)
return -1;
- vm->def->maxvcpus = vm->def->vcpus = nvcpus;
+ if (virDomainDefSetVCpusMax(vm->def, nvcpus) < 0)
+ return -1;
+
+ vm->def->vcpus = nvcpus;
return 0;
}
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index 14264c0..7c77e23 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -3295,7 +3295,9 @@ phypDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
goto err;
}
- def.maxvcpus = vcpus;
+ if (virDomainDefSetVCpusMax(&def, vcpus) < 0)
+ goto err;
+
def.vcpus = vcpus;
return virDomainDefFormat(&def,
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index ef5ef93..af283af 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -12576,7 +12576,11 @@ qemuParseCommandLineSmp(virDomainDefPtr dom,
}
}
- dom->maxvcpus = maxcpus ? maxcpus : dom->vcpus;
+ if (maxcpus == 0)
+ maxcpus = dom->vcpus;
+
+ if (virDomainDefSetVCpusMax(dom, maxcpus) < 0)
+ goto error;
if (sockets && cores && threads) {
virCPUDefPtr cpu;
@@ -12690,7 +12694,8 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
def->id = -1;
def->mem.cur_balloon = 64 * 1024;
virDomainDefSetMemoryTotal(def, def->mem.cur_balloon);
- def->maxvcpus = 1;
+ if (virDomainDefSetVCpusMax(def, 1) < 0)
+ goto error;
def->vcpus = 1;
def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_UTC;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 65ccf99..8ab3209 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4979,7 +4979,9 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
}
if (flags & VIR_DOMAIN_VCPU_MAXIMUM) {
- persistentDef->maxvcpus = nvcpus;
+ if (virDomainDefSetVCpusMax(persistentDef, nvcpus) < 0)
+ goto endjob;
+
if (nvcpus < persistentDef->vcpus)
persistentDef->vcpus = nvcpus;
} else {
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 9ccd567..53d9338 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -2376,7 +2376,9 @@ testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus,
if (persistentDef) {
if (flags & VIR_DOMAIN_VCPU_MAXIMUM) {
- persistentDef->maxvcpus = nrCpus;
+ if (virDomainDefSetVCpusMax(persistentDef, nrCpus) < 0)
+ goto cleanup;
+
if (nrCpus < persistentDef->vcpus)
persistentDef->vcpus = nrCpus;
} else {
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 3e6ed7a..20f44e9 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -3901,7 +3901,10 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int
flags)
virDomainDefSetMemoryTotal(def, memorySize * 1024);
gVBoxAPI.UIMachine.GetCPUCount(machine, &CPUCount);
- def->maxvcpus = def->vcpus = CPUCount;
+ if (virDomainDefSetVCpusMax(def, CPUCount) < 0)
+ goto cleanup;
+
+ def->vcpus = CPUCount;
/* Skip cpumasklen, cpumask, onReboot, onPoweroff, onCrash */
@@ -6055,7 +6058,11 @@ static char *vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr
snapshot,
def->dom->os.type = VIR_DOMAIN_OSTYPE_HVM;
def->dom->os.arch = virArchFromHost();
gVBoxAPI.UIMachine.GetCPUCount(machine, &CPUCount);
- def->dom->maxvcpus = def->dom->vcpus = CPUCount;
+ if (virDomainDefSetVCpusMax(def->dom, CPUCount) < 0)
+ goto cleanup;
+
+ def->dom->vcpus = CPUCount;
+
if (vboxSnapshotGetReadWriteDisks(def, snapshot) < 0)
VIR_DEBUG("Could not get read write disks for snapshot");
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 7c3c10a..41a872a 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -1457,7 +1457,10 @@ virVMXParseConfig(virVMXContext *ctx,
goto cleanup;
}
- def->maxvcpus = def->vcpus = numvcpus;
+ if (virDomainDefSetVCpusMax(def, numvcpus) < 0)
+ goto cleanup;
+
+ def->vcpus = numvcpus;
/* vmx:sched.cpu.affinity -> def:cpumask */
/* NOTE: maps to VirtualMachine:config.cpuAffinity.affinitySet */
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index 750133d..bef5146 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -1150,8 +1150,10 @@ prlsdkConvertCpuInfo(PRL_HANDLE sdkdom,
if (cpuCount > hostcpus)
cpuCount = hostcpus;
+ if (virDomainDefSetVCpusMax(def, cpuCount) < 0)
+ goto cleanup;
+
def->vcpus = cpuCount;
- def->maxvcpus = cpuCount;
pret = PrlVmCfg_GetCpuMask(sdkdom, NULL, &buflen);
prlsdkCheckRetGoto(pret, cleanup);
diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c
index 75f98b1..7321b9f 100644
--- a/src/xen/xm_internal.c
+++ b/src/xen/xm_internal.c
@@ -704,7 +704,9 @@ xenXMDomainSetVcpusFlags(virConnectPtr conn,
}
if (flags & VIR_DOMAIN_VCPU_MAXIMUM) {
- entry->def->maxvcpus = vcpus;
+ if (virDomainDefSetVCpusMax(entry->def, vcpus) < 0)
+ goto cleanup;
+
if (entry->def->vcpus > vcpus)
entry->def->vcpus = vcpus;
} else {
diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c
index e503974..11cace1 100644
--- a/src/xenapi/xenapi_driver.c
+++ b/src/xenapi/xenapi_driver.c
@@ -1502,7 +1502,9 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
vcpus = xenapiDomainGetMaxVcpus(dom);
- defPtr->maxvcpus = vcpus;
+ if (virDomainDefSetVCpusMax(defPtr, vcpus) < 0)
+ goto error;
+
defPtr->vcpus = vcpus;
enum xen_on_normal_exit action;
diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index 0890c73..05fc76c 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -502,7 +502,9 @@ xenParseCPUFeatures(virConfPtr conf, virDomainDefPtr def)
MAX_VIRT_CPUS < count)
return -1;
- def->maxvcpus = count;
+ if (virDomainDefSetVCpusMax(def, count) < 0)
+ return -1;
+
if (xenConfigGetULong(conf, "vcpu_avail", &count, -1) < 0)
return -1;
diff --git a/src/xenconfig/xen_sxpr.c b/src/xenconfig/xen_sxpr.c
index 7fc9c9d..64a317d 100644
--- a/src/xenconfig/xen_sxpr.c
+++ b/src/xenconfig/xen_sxpr.c
@@ -1173,7 +1173,8 @@ xenParseSxpr(const struct sexpr *root,
}
}
- def->maxvcpus = sexpr_int(root, "domain/vcpus");
+ if (virDomainDefSetVCpusMax(def, sexpr_int(root, "domain/vcpus")) < 0)
+ goto error;
def->vcpus = count_one_bits_l(sexpr_u64(root, "domain/vcpu_avail"));
if (!def->vcpus || def->maxvcpus < def->vcpus)
def->vcpus = def->maxvcpus;
--
2.6.2