mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
conf: turn def->vcpus into a structure
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.
This commit is contained in:
parent
9d5ac29eef
commit
4e86838d89
@ -1284,14 +1284,32 @@ void virDomainLeaseDefFree(virDomainLeaseDefPtr def)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
virDomainVcpuInfoClear(virDomainVcpuInfoPtr info)
|
||||||
|
{
|
||||||
|
if (!info)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
virDomainDefSetVcpusMax(virDomainDefPtr def,
|
virDomainDefSetVcpusMax(virDomainDefPtr def,
|
||||||
unsigned int maxvcpus)
|
unsigned int maxvcpus)
|
||||||
{
|
{
|
||||||
if (maxvcpus < def->vcpus)
|
size_t i;
|
||||||
virDomainDefSetVcpus(def, maxvcpus);
|
|
||||||
|
|
||||||
def->maxvcpus = maxvcpus;
|
if (def->maxvcpus == maxvcpus)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (def->maxvcpus < maxvcpus) {
|
||||||
|
if (VIR_EXPAND_N(def->vcpus, def->maxvcpus, maxvcpus - def->maxvcpus) < 0)
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
for (i = maxvcpus; i < def->maxvcpus; i++)
|
||||||
|
virDomainVcpuInfoClear(&def->vcpus[i]);
|
||||||
|
|
||||||
|
VIR_SHRINK_N(def->vcpus, def->maxvcpus, def->maxvcpus - maxvcpus);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1300,7 +1318,14 @@ virDomainDefSetVcpusMax(virDomainDefPtr def,
|
|||||||
bool
|
bool
|
||||||
virDomainDefHasVcpusOffline(const virDomainDef *def)
|
virDomainDefHasVcpusOffline(const virDomainDef *def)
|
||||||
{
|
{
|
||||||
return def->vcpus < def->maxvcpus;
|
size_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < def->maxvcpus; i++) {
|
||||||
|
if (!def->vcpus[i].online)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1315,6 +1340,8 @@ int
|
|||||||
virDomainDefSetVcpus(virDomainDefPtr def,
|
virDomainDefSetVcpus(virDomainDefPtr def,
|
||||||
unsigned int vcpus)
|
unsigned int vcpus)
|
||||||
{
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
if (vcpus > def->maxvcpus) {
|
if (vcpus > def->maxvcpus) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
_("maxvcpus must not be less than current vcpus (%u < %zu)"),
|
_("maxvcpus must not be less than current vcpus (%u < %zu)"),
|
||||||
@ -1322,7 +1349,11 @@ virDomainDefSetVcpus(virDomainDefPtr def,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
def->vcpus = vcpus;
|
for (i = 0; i < vcpus; i++)
|
||||||
|
def->vcpus[i].online = true;
|
||||||
|
|
||||||
|
for (i = vcpus; i < def->maxvcpus; i++)
|
||||||
|
def->vcpus[i].online = false;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1331,7 +1362,15 @@ virDomainDefSetVcpus(virDomainDefPtr def,
|
|||||||
unsigned int
|
unsigned int
|
||||||
virDomainDefGetVcpus(const virDomainDef *def)
|
virDomainDefGetVcpus(const virDomainDef *def)
|
||||||
{
|
{
|
||||||
return def->vcpus;
|
size_t i;
|
||||||
|
unsigned int ret = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < def->maxvcpus; i++) {
|
||||||
|
if (def->vcpus[i].online)
|
||||||
|
ret++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2359,6 +2398,10 @@ void virDomainDefFree(virDomainDefPtr def)
|
|||||||
|
|
||||||
virDomainResourceDefFree(def->resource);
|
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 must be freed before nets (or any future "intelligent
|
||||||
* hostdevs") because the pointer to the hostdev is really
|
* hostdevs") because the pointer to the hostdev is really
|
||||||
* pointing into the middle of the higher level device's object,
|
* pointing into the middle of the higher level device's object,
|
||||||
|
@ -2145,6 +2145,14 @@ struct _virDomainCputune {
|
|||||||
virDomainThreadSchedParamPtr iothreadsched;
|
virDomainThreadSchedParamPtr iothreadsched;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct _virDomainVcpuInfo virDomainVcpuInfo;
|
||||||
|
typedef virDomainVcpuInfo *virDomainVcpuInfoPtr;
|
||||||
|
|
||||||
|
struct _virDomainVcpuInfo {
|
||||||
|
bool online;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct _virDomainBlkiotune virDomainBlkiotune;
|
typedef struct _virDomainBlkiotune virDomainBlkiotune;
|
||||||
typedef virDomainBlkiotune *virDomainBlkiotunePtr;
|
typedef virDomainBlkiotune *virDomainBlkiotunePtr;
|
||||||
|
|
||||||
@ -2218,7 +2226,7 @@ struct _virDomainDef {
|
|||||||
virDomainBlkiotune blkio;
|
virDomainBlkiotune blkio;
|
||||||
virDomainMemtune mem;
|
virDomainMemtune mem;
|
||||||
|
|
||||||
unsigned int vcpus;
|
virDomainVcpuInfoPtr vcpus;
|
||||||
size_t maxvcpus;
|
size_t maxvcpus;
|
||||||
int placement_mode;
|
int placement_mode;
|
||||||
virBitmapPtr cpumask;
|
virBitmapPtr cpumask;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user