unsigned int maxvcpus)
{
if (maxvcpus < def->vcpus)
- def->vcpus = maxvcpus;
+ virDomainDefSetVcpus(def, maxvcpus);
def->maxvcpus = maxvcpus;
}
+int
+virDomainDefSetVcpus(virDomainDefPtr def,
+ unsigned int vcpus)
+{
+ def->vcpus = vcpus;
+
+ return 0;
+}
+
+
virDomainDiskDefPtr
virDomainDiskDefNew(virDomainXMLOptionPtr xmlopt)
{
int n;
char *tmp = NULL;
unsigned int maxvcpus;
+ unsigned int vcpus;
int ret = -1;
if ((n = virXPathUInt("string(./vcpu[1])", ctxt, &maxvcpus)) < 0) {
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 "
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);
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 */
virDomainDefPostParse;
virDomainDefSetMemoryInitial;
virDomainDefSetMemoryTotal;
+virDomainDefSetVcpus;
virDomainDefSetVcpusMax;
virDomainDeleteConfig;
virDomainDeviceAddressIsValid;
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);
break;
case VIR_DOMAIN_VCPU_CONFIG:
- def->vcpus = nvcpus;
+ if (virDomainDefSetVcpus(def, nvcpus) < 0)
+ goto cleanup;
break;
case VIR_DOMAIN_VCPU_LIVE:
" 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:
" 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;
}
if (virDomainDefSetVcpusMax(vmdef, 1) < 0)
goto error;
- vmdef->vcpus = 1;
+ if (virDomainDefSetVcpus(vmdef, 1) < 0)
+ goto error;
vmdef->nfss = 0;
vmdef->os.type = VIR_DOMAIN_OSTYPE_EXE;
if (virDomainDefSetVcpusMax(def, vcpus) < 0)
goto cleanup;
- def->vcpus = vcpus;
+ if (virDomainDefSetVcpus(def, vcpus) < 0)
+ goto cleanup;
/* XXX load rest of VM config data .... */
if (virDomainDefSetVcpusMax(vm->def, nvcpus) < 0)
return -1;
- vm->def->vcpus = nvcpus;
+ if (virDomainDefSetVcpus(vm->def, nvcpus) < 0)
+ return -1;
+
return 0;
}
if (virDomainDefSetVcpusMax(&def, vcpus) < 0)
goto err;
- def.vcpus = vcpus;
+ if (virDomainDefSetVcpus(&def, vcpus) < 0)
+ goto err;
return virDomainDefFormat(&def,
virDomainDefFormatConvertXMLFlags(flags));
unsigned int cores = 0;
unsigned int threads = 0;
unsigned int maxcpus = 0;
+ unsigned int vcpus = 0;
size_t i;
int nkws;
char **kws;
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;
}
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;
virDomainDefSetMemoryTotal(def, def->mem.cur_balloon);
if (virDomainDefSetVcpusMax(def, 1) < 0)
goto error;
- def->vcpus = 1;
+ if (virDomainDefSetVcpus(def, 1) < 0)
+ goto error;
def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_UTC;
def->onReboot = VIR_DOMAIN_LIFECYCLE_RESTART;
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);
if (virDomainDefSetVcpusMax(persistentDef, nvcpus) < 0)
goto endjob;
} else {
- persistentDef->vcpus = nvcpus;
+ if (virDomainDefSetVcpus(persistentDef, nvcpus) < 0)
+ goto endjob;
}
if (virDomainSaveConfig(cfg->configDir, persistentDef) < 0)
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;
}
}
if (virDomainDefSetVcpusMax(def, CPUCount) < 0)
goto cleanup;
- def->vcpus = CPUCount;
+ if (virDomainDefSetVcpus(def, CPUCount) < 0)
+ goto cleanup;
/* Skip cpumasklen, cpumask, onReboot, onPoweroff, onCrash */
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");
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 */
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);
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
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))
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;
const char *tmp;
virDomainDefPtr def;
int hvm = 0, vmlocaltime;
+ unsigned int vcpus;
if (!(def = virDomainDefNew()))
goto error;
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) {