--- src/conf/domain_conf.c | 25 +++++++++++++++++++------ src/conf/domain_conf.h | 1 + src/hyperv/hyperv_driver.c | 5 ++++- src/libvirt_private.syms | 1 + src/libxl/libxl_driver.c | 14 +++++++++----- src/openvz/openvz_conf.c | 3 ++- src/openvz/openvz_driver.c | 4 +++- src/phyp/phyp_driver.c | 3 ++- src/qemu/qemu_command.c | 9 ++++++--- src/qemu/qemu_driver.c | 8 +++++--- src/test/test_driver.c | 8 +++++--- src/vbox/vbox_common.c | 6 ++++-- src/vmx/vmx.c | 3 ++- src/vz/vz_sdk.c | 3 ++- src/xen/xm_internal.c | 3 ++- src/xenapi/xenapi_driver.c | 3 ++- src/xenconfig/xen_common.c | 5 ++++- src/xenconfig/xen_sxpr.c | 10 +++++++--- 18 files changed, 80 insertions(+), 34 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4e5b7b6..d8c1068 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1435,7 +1435,7 @@ virDomainDefSetVCpusMax(virDomainDefPtr def, } if (vcpus < def->vcpus) - def->vcpus = vcpus; + virDomainDefSetVCpus(def, vcpus); def->maxvcpus = vcpus; @@ -1457,6 +1457,16 @@ virDomainDefGetVCpusMax(const virDomainDef *def) } +int +virDomainDefSetVCpus(virDomainDefPtr def, + unsigned int vcpus) +{ + def->vcpus = vcpus; + + return 0; +} + + virDomainDiskDefPtr virDomainDiskDefNew(virDomainXMLOptionPtr xmlopt) { @@ -2711,11 +2721,10 @@ virDomainDefNew(void) goto error; /* assume at least 1 cpu for every config */ - if (virDomainDefSetVCpusMax(ret, 1) < 0) + if (virDomainDefSetVCpusMax(ret, 1) < 0 || + virDomainDefSetVCpus(ret, 1) < 0) goto error; - ret->vcpus = 1; - ret->mem.hard_limit = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; ret->mem.soft_limit = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; ret->mem.swap_hard_limit = VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; @@ -14685,6 +14694,7 @@ virDomainVcpuParse(virDomainDefPtr def, int n; char *tmp = NULL; unsigned int maxvcpus; + unsigned int vcpus; int ret = -1; if ((n = virXPathUInt("string(./vcpu[1])", ctxt, &maxvcpus)) < 0) { @@ -14700,16 +14710,19 @@ virDomainVcpuParse(virDomainDefPtr def, if (virDomainDefSetVCpusMax(def, maxvcpus) < 0) goto cleanup; - if ((n = virXPathUInt("string(./vcpu[1]/@current)", ctxt, &def->vcpus)) < 0) { + if ((n = virXPathUInt("string(./vcpu[1]/@current)", ctxt, &vcpus)) < 0) { if (n == -2) { virReportError(VIR_ERR_XML_ERROR, "%s", _("current vcpus count must be an integer")); goto cleanup; } - def->vcpus = maxvcpus; + vcpus = maxvcpus; } + if (virDomainDefSetVCpus(def, vcpus) < 0) + goto cleanup; + if (maxvcpus < def->vcpus) { virReportError(VIR_ERR_INTERNAL_ERROR, _("maxvcpus must not be less than current vcpus " diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 433e5c9..44f707f 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2328,6 +2328,7 @@ struct _virDomainDef { int virDomainDefSetVCpusMax(virDomainDefPtr def, unsigned int vcpus); bool virDomainDefHasVCpusOffline(const virDomainDef *def); unsigned int virDomainDefGetVCpusMax(const virDomainDef *def); +int virDomainDefSetVCpus(virDomainDefPtr def, unsigned int vcpus); unsigned long long virDomainDefGetMemoryInitial(const virDomainDef *def); void virDomainDefSetMemoryTotal(virDomainDefPtr def, unsigned long long size); diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 61e06b0..690bee7 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -877,7 +877,10 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) processorSettingData->data->VirtualQuantity) < 0) goto cleanup; - def->vcpus = processorSettingData->data->VirtualQuantity; + if (virDomainDefSetVCpus(def, + processorSettingData->data->VirtualQuantity) < 0) + goto cleanup; + 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 d2993c1..b08c9c7 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -232,6 +232,7 @@ virDomainDefParseString; virDomainDefPostParse; virDomainDefSetMemoryInitial; virDomainDefSetMemoryTotal; +virDomainDefSetVCpus; virDomainDefSetVCpusMax; virDomainDeleteConfig; virDomainDeviceAddressIsValid; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 8b0fd39..8b225a4 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -555,7 +555,8 @@ libxlAddDom0(libxlDriverPrivatePtr driver) if (virDomainDefSetVCpusMax(vm->def, d_info.vcpu_max_id + 1)) goto cleanup; - vm->def->vcpus = d_info.vcpu_online; + if (virDomainDefSetVCpus(vm->def, d_info.vcpu_online) < 0) + goto cleanup; vm->def->mem.cur_balloon = d_info.current_memkb; virDomainDefSetMemoryTotal(vm->def, d_info.max_memkb); @@ -2191,7 +2192,8 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus, break; case VIR_DOMAIN_VCPU_CONFIG: - def->vcpus = nvcpus; + if (virDomainDefSetVCpus(def, nvcpus) < 0) + goto cleanup; break; case VIR_DOMAIN_VCPU_LIVE: @@ -2201,7 +2203,8 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus, " with libxenlight"), vm->def->id); goto endjob; } - vm->def->vcpus = nvcpus; + if (virDomainDefSetVCpus(vm->def, nvcpus) < 0) + goto endjob; break; case VIR_DOMAIN_VCPU_LIVE | VIR_DOMAIN_VCPU_CONFIG: @@ -2211,8 +2214,9 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus, " with libxenlight"), vm->def->id); goto endjob; } - vm->def->vcpus = nvcpus; - def->vcpus = nvcpus; + if (virDomainDefSetVCpus(vm->def, nvcpus) < 0 || + virDomainDefSetVCpus(def, nvcpus) < 0) + goto endjob; break; } diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index aabb7c4..74f496e 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -585,7 +585,8 @@ int openvzLoadDomains(struct openvz_driver *driver) if (virDomainDefSetVCpusMax(def, vcpus) < 0) goto cleanup; - def->vcpus = vcpus; + if (virDomainDefSetVCpus(def, vcpus) < 0) + goto cleanup; /* XXX load rest of VM config data .... */ diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 90e2aad..37c00b2 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -1367,7 +1367,9 @@ static int openvzDomainSetVcpusInternal(virDomainObjPtr vm, if (virDomainDefSetVCpusMax(vm->def, nvcpus) < 0) return -1; - vm->def->vcpus = nvcpus; + if (virDomainDefSetVCpus(vm->def, nvcpus) < 0) + return -1; + return 0; } diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 7c77e23..a60b8b2 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -3298,7 +3298,8 @@ phypDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) if (virDomainDefSetVCpusMax(&def, vcpus) < 0) goto err; - def.vcpus = vcpus; + if (virDomainDefSetVCpus(&def, vcpus) < 0) + goto err; return virDomainDefFormat(&def, virDomainDefFormatConvertXMLFlags(flags)); diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index b136314..4a67361 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -12543,6 +12543,7 @@ qemuParseCommandLineSmp(virDomainDefPtr dom, unsigned int cores = 0; unsigned int threads = 0; unsigned int maxcpus = 0; + unsigned int vcpus = 0; size_t i; int nkws; char **kws; @@ -12557,9 +12558,8 @@ qemuParseCommandLineSmp(virDomainDefPtr dom, for (i = 0; i < nkws; i++) { if (vals[i] == NULL) { if (i > 0 || - virStrToLong_i(kws[i], &end, 10, &n) < 0 || *end != '\0') + virStrToLong_ui(kws[i], &end, 10, &vcpus) < 0 || *end != '\0') goto syntax; - dom->vcpus = n; } else { if (virStrToLong_i(vals[i], &end, 10, &n) < 0 || *end != '\0') goto syntax; @@ -12577,11 +12577,14 @@ qemuParseCommandLineSmp(virDomainDefPtr dom, } if (maxcpus == 0) - maxcpus = dom->vcpus; + maxcpus = vcpus; if (virDomainDefSetVCpusMax(dom, maxcpus) < 0) goto error; + if (virDomainDefSetVCpus(dom, vcpus) < 0) + goto error; + if (sockets && cores && threads) { virCPUDefPtr cpu; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index da66ee7..632ffb5 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4835,8 +4835,9 @@ qemuDomainHotplugVcpus(virQEMUDriverPtr driver, cleanup: VIR_FREE(cpupids); VIR_FREE(mem_mask); - if (virDomainObjIsActive(vm)) - vm->def->vcpus = vcpus; + if (virDomainObjIsActive(vm) && + virDomainDefSetVCpus(vm->def, vcpus) < 0) + ret = -1; virDomainAuditVcpu(vm, oldvcpus, nvcpus, "update", rc == 1); if (cgroup_vcpu) virCgroupFree(&cgroup_vcpu); @@ -4982,7 +4983,8 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus, if (virDomainDefSetVCpusMax(persistentDef, nvcpus) < 0) goto endjob; } else { - persistentDef->vcpus = nvcpus; + if (virDomainDefSetVCpus(persistentDef, nvcpus) < 0) + goto endjob; } if (virDomainSaveConfig(cfg->configDir, persistentDef) < 0) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 4043928..00f5c1e 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2374,15 +2374,17 @@ testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus, goto cleanup; } - if (def) - def->vcpus = nrCpus; + if (def && + virDomainDefSetVCpus(def, nrCpus) < 0) + goto cleanup; if (persistentDef) { if (flags & VIR_DOMAIN_VCPU_MAXIMUM) { if (virDomainDefSetVCpusMax(persistentDef, nrCpus) < 0) goto cleanup; } else { - persistentDef->vcpus = nrCpus; + if (virDomainDefSetVCpus(persistentDef, nrCpus) < 0) + goto cleanup; } } diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index a05b438..b240e04 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -3904,7 +3904,8 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) if (virDomainDefSetVCpusMax(def, CPUCount) < 0) goto cleanup; - def->vcpus = CPUCount; + if (virDomainDefSetVCpus(def, CPUCount) < 0) + goto cleanup; /* Skip cpumasklen, cpumask, onReboot, onPoweroff, onCrash */ @@ -6061,7 +6062,8 @@ static char *vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, if (virDomainDefSetVCpusMax(def->dom, CPUCount) < 0) goto cleanup; - def->dom->vcpus = CPUCount; + if (virDomainDefSetVCpus(def->dom, CPUCount) < 0) + goto cleanup; 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 44f76f2..62636a9 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -1460,7 +1460,8 @@ virVMXParseConfig(virVMXContext *ctx, if (virDomainDefSetVCpusMax(def, numvcpus) < 0) goto cleanup; - def->vcpus = numvcpus; + if (virDomainDefSetVCpus(def, numvcpus) < 0) + goto cleanup; /* 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 d3aa3e2..68c51a8 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -1153,7 +1153,8 @@ prlsdkConvertCpuInfo(PRL_HANDLE sdkdom, if (virDomainDefSetVCpusMax(def, cpuCount) < 0) goto cleanup; - def->vcpus = cpuCount; + if (virDomainDefSetVCpus(def, cpuCount) < 0) + goto cleanup; pret = PrlVmCfg_GetCpuMask(sdkdom, NULL, &buflen); prlsdkCheckRetGoto(pret, cleanup); diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c index b7b78d7..374cc41 100644 --- a/src/xen/xm_internal.c +++ b/src/xen/xm_internal.c @@ -708,7 +708,8 @@ xenXMDomainSetVcpusFlags(virConnectPtr conn, if (virDomainDefSetVCpusMax(entry->def, vcpus) < 0) goto cleanup; } else { - entry->def->vcpus = vcpus; + if (virDomainDefSetVCpus(entry->def, vcpus) < 0) + goto cleanup; } /* If this fails, should we try to undo our changes to the diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index 11cace1..df2ed1b 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -1505,7 +1505,8 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) if (virDomainDefSetVCpusMax(defPtr, vcpus) < 0) goto error; - defPtr->vcpus = vcpus; + if (virDomainDefSetVCpus(defPtr, vcpus) < 0) + goto error; enum xen_on_normal_exit action; if (xen_vm_get_actions_after_shutdown(session, &action, vm)) diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index deea68b..d617773 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -508,7 +508,10 @@ xenParseCPUFeatures(virConfPtr conf, virDomainDefPtr def) if (xenConfigGetULong(conf, "vcpu_avail", &count, -1) < 0) return -1; - def->vcpus = MIN(count_one_bits_l(count), virDomainDefGetVCpusMax(def)); + if (virDomainDefSetVCpus(def, MIN(count_one_bits_l(count), + virDomainDefGetVCpusMax(def))) < 0) + return -1; + if (xenConfigGetString(conf, "cpus", &str, NULL) < 0) return -1; diff --git a/src/xenconfig/xen_sxpr.c b/src/xenconfig/xen_sxpr.c index d984305..534130e 100644 --- a/src/xenconfig/xen_sxpr.c +++ b/src/xenconfig/xen_sxpr.c @@ -1092,6 +1092,7 @@ xenParseSxpr(const struct sexpr *root, const char *tmp; virDomainDefPtr def; int hvm = 0, vmlocaltime; + unsigned int vcpus; if (!(def = virDomainDefNew())) goto error; @@ -1175,9 +1176,12 @@ xenParseSxpr(const struct sexpr *root, 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 || virDomainDefGetVCpusMax(def) < def->vcpus) - def->vcpus = virDomainDefGetVCpusMax(def); + vcpus = count_one_bits_l(sexpr_u64(root, "domain/vcpu_avail")); + if (!vcpus || virDomainDefGetVCpusMax(def) < vcpus) + vcpus = virDomainDefGetVCpusMax(def); + + if (virDomainDefSetVCpus(def, vcpus) < 0) + goto error; tmp = sexpr_node(root, "domain/on_poweroff"); if (tmp != NULL) { -- 2.6.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list