On 11/20/2015 10:22 AM, Peter Krempa wrote: > To allow collecting all relevant data at one place let's make def->vcpus > a structure and then we can start moving stuff into it. > --- > src/conf/domain_conf.c | 55 ++++++++++++++++++++++++++++++++++++++++++++------ > src/conf/domain_conf.h | 10 ++++++++- > 2 files changed, 58 insertions(+), 7 deletions(-) > Well I have to assume at this point neither of us builds w/ bhyve or vz/parallels enabled! (true for me); otherwise, the build would have gone down in a flaming mess. > diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c > index 897b643..631e1db 100644 > --- a/src/conf/domain_conf.c > +++ b/src/conf/domain_conf.c > @@ -1424,20 +1424,38 @@ void virDomainLeaseDefFree(virDomainLeaseDefPtr def) > } > > > +static void > +virDomainVCpuInfoClear(virDomainVCpuInfoPtr info)' Use of "Vcpus" or "VCPUs" is preferred. > +{ > + if (!info) > + return; > +} > + > + > int > virDomainDefSetVCpusMax(virDomainDefPtr def, > unsigned int vcpus) Hmmmm. check that earlier thought... maybe "newvcpus"? I dunno, my eyes are getting tired though! > { > + size_t i; > + > + if (def->maxvcpus == vcpus) > + return 0; > + > if (vcpus == 0) { > virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", > _("domain config can't have 0 maximum vCPUs")); > return -1; > } > > - if (vcpus < def->vcpus) > - virDomainDefSetVCpus(def, vcpus); > + if (def->maxvcpus < vcpus) { > + if (VIR_EXPAND_N(def->vcpus, def->maxvcpus, vcpus - def->maxvcpus) < 0) > + return -1; > + } else { > + for (i = vcpus; i < def->maxvcpus; i++) > + virDomainVCpuInfoClear(&def->vcpus[i]); > > - def->maxvcpus = vcpus; > + VIR_SHRINK_N(def->vcpus, def->maxvcpus, def->maxvcpus - vcpus); > + } > > return 0; > } > @@ -1446,7 +1464,14 @@ virDomainDefSetVCpusMax(virDomainDefPtr def, > bool > virDomainDefHasVCpusOffline(const virDomainDef *def) > { > - return def->vcpus < def->maxvcpus; > + size_t i; > + > + for (i = 0; i < def->maxvcpus; i++) { Should there be an accessor to def->maxvcpus? > + if (!def->vcpus[i].online) > + return true; > + } > + > + return false; > } > > > @@ -1461,6 +1486,8 @@ int > virDomainDefSetVCpus(virDomainDefPtr def, > unsigned int vcpus) > { > + size_t i; > + > if (vcpus > def->maxvcpus) { > virReportError(VIR_ERR_CONFIG_UNSUPPORTED, > _("maxvcpus must not be less than current vcpus (%u < %zu)"), > @@ -1468,7 +1495,11 @@ virDomainDefSetVCpus(virDomainDefPtr def, > return -1; > } > > - def->vcpus = vcpus; > + for (i = 0; i < vcpus; i++) > + def->vcpus[i].online = true; > + > + for (i = vcpus; i < def->maxvcpus; i++) Should there be an accessor to def->maxvcpus? That'd be for both uses. > + def->vcpus[i].online = false; > > return 0; > } > @@ -1477,7 +1508,15 @@ virDomainDefSetVCpus(virDomainDefPtr def, > unsigned int > virDomainDefGetVCpus(const virDomainDef *def) > { > - return def->vcpus; > + size_t i; > + unsigned int ret = 0; > + > + for (i = 0; i < def->maxvcpus; i++) { Should there be accessor to "def->maxvcpus"? ACK with some adjustments... More importantly the "VCpus" change, but less so the accessor to ->maxvcpus John > + if (def->vcpus[i].online) > + ret++; > + } > + > + return ret; > } > > > @@ -2505,6 +2544,10 @@ void virDomainDefFree(virDomainDefPtr def) > > virDomainResourceDefFree(def->resource); > > + for (i = 0; i < def->maxvcpus; i++) > + virDomainVCpuInfoClear(&def->vcpus[i]); > + VIR_FREE(def->vcpus); > + > /* hostdevs must be freed before nets (or any future "intelligent > * hostdevs") because the pointer to the hostdev is really > * pointing into the middle of the higher level device's object, > diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h > index 3490f02..68f82c6 100644 > --- a/src/conf/domain_conf.h > +++ b/src/conf/domain_conf.h > @@ -2129,6 +2129,14 @@ struct _virDomainCputune { > virDomainThreadSchedParamPtr iothreadsched; > }; > > + > +typedef struct _virDomainVCpuInfo virDomainVCpuInfo; > +typedef virDomainVCpuInfo *virDomainVCpuInfoPtr; > + > +struct _virDomainVCpuInfo { > + bool online; > +}; > + > typedef struct _virDomainBlkiotune virDomainBlkiotune; > typedef virDomainBlkiotune *virDomainBlkiotunePtr; > > @@ -2202,7 +2210,7 @@ struct _virDomainDef { > virDomainBlkiotune blkio; > virDomainMemtune mem; > > - unsigned int vcpus; > + virDomainVCpuInfoPtr vcpus; > size_t maxvcpus; > int placement_mode; > virBitmapPtr cpumask; > -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list