mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
conf: Add helper to check whether domain has offline vCPUs
The new helper will simplify checking whether the domain config contains inactive vCPUs.
This commit is contained in:
parent
4a194c55af
commit
c970c4a5ea
@ -1297,6 +1297,13 @@ virDomainDefSetVcpusMax(virDomainDefPtr def,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
virDomainDefHasVcpusOffline(const virDomainDef *def)
|
||||||
|
{
|
||||||
|
return def->vcpus < def->maxvcpus;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
virDomainDiskDefPtr
|
virDomainDiskDefPtr
|
||||||
virDomainDiskDefNew(virDomainXMLOptionPtr xmlopt)
|
virDomainDiskDefNew(virDomainXMLOptionPtr xmlopt)
|
||||||
{
|
{
|
||||||
@ -21521,7 +21528,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
|
|||||||
virBufferAsprintf(buf, " cpuset='%s'", cpumask);
|
virBufferAsprintf(buf, " cpuset='%s'", cpumask);
|
||||||
VIR_FREE(cpumask);
|
VIR_FREE(cpumask);
|
||||||
}
|
}
|
||||||
if (def->vcpus != def->maxvcpus)
|
if (virDomainDefHasVcpusOffline(def))
|
||||||
virBufferAsprintf(buf, " current='%u'", def->vcpus);
|
virBufferAsprintf(buf, " current='%u'", def->vcpus);
|
||||||
virBufferAsprintf(buf, ">%u</vcpu>\n", def->maxvcpus);
|
virBufferAsprintf(buf, ">%u</vcpu>\n", def->maxvcpus);
|
||||||
|
|
||||||
|
@ -2344,6 +2344,7 @@ struct _virDomainDef {
|
|||||||
};
|
};
|
||||||
|
|
||||||
int virDomainDefSetVcpusMax(virDomainDefPtr def, unsigned int vcpus);
|
int virDomainDefSetVcpusMax(virDomainDefPtr def, unsigned int vcpus);
|
||||||
|
bool virDomainDefHasVcpusOffline(const virDomainDef *def);
|
||||||
|
|
||||||
unsigned long long virDomainDefGetMemoryInitial(const virDomainDef *def);
|
unsigned long long virDomainDefGetMemoryInitial(const virDomainDef *def);
|
||||||
void virDomainDefSetMemoryTotal(virDomainDefPtr def, unsigned long long size);
|
void virDomainDefSetMemoryTotal(virDomainDefPtr def, unsigned long long size);
|
||||||
|
@ -219,6 +219,7 @@ virDomainDefGetMemoryInitial;
|
|||||||
virDomainDefGetSecurityLabelDef;
|
virDomainDefGetSecurityLabelDef;
|
||||||
virDomainDefHasDeviceAddress;
|
virDomainDefHasDeviceAddress;
|
||||||
virDomainDefHasMemoryHotplug;
|
virDomainDefHasMemoryHotplug;
|
||||||
|
virDomainDefHasVcpusOffline;
|
||||||
virDomainDefMaybeAddController;
|
virDomainDefMaybeAddController;
|
||||||
virDomainDefMaybeAddInput;
|
virDomainDefMaybeAddInput;
|
||||||
virDomainDefNeedsPlacementAdvice;
|
virDomainDefNeedsPlacementAdvice;
|
||||||
|
@ -1030,7 +1030,7 @@ openvzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int fla
|
|||||||
if (openvzDomainSetNetworkConfig(conn, vm->def) < 0)
|
if (openvzDomainSetNetworkConfig(conn, vm->def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (vm->def->vcpus != vm->def->maxvcpus) {
|
if (virDomainDefHasVcpusOffline(vm->def)) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
_("current vcpu count must equal maximum"));
|
_("current vcpu count must equal maximum"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -7962,7 +7962,7 @@ qemuBuildSmpArgStr(const virDomainDef *def,
|
|||||||
virBufferAsprintf(&buf, "%u", def->vcpus);
|
virBufferAsprintf(&buf, "%u", def->vcpus);
|
||||||
|
|
||||||
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_SMP_TOPOLOGY)) {
|
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_SMP_TOPOLOGY)) {
|
||||||
if (def->vcpus != def->maxvcpus)
|
if (virDomainDefHasVcpusOffline(def))
|
||||||
virBufferAsprintf(&buf, ",maxcpus=%u", def->maxvcpus);
|
virBufferAsprintf(&buf, ",maxcpus=%u", def->maxvcpus);
|
||||||
/* sockets, cores, and threads are either all zero
|
/* sockets, cores, and threads are either all zero
|
||||||
* or all non-zero, thus checking one of them is enough */
|
* or all non-zero, thus checking one of them is enough */
|
||||||
@ -7975,7 +7975,7 @@ qemuBuildSmpArgStr(const virDomainDef *def,
|
|||||||
virBufferAsprintf(&buf, ",cores=%u", 1);
|
virBufferAsprintf(&buf, ",cores=%u", 1);
|
||||||
virBufferAsprintf(&buf, ",threads=%u", 1);
|
virBufferAsprintf(&buf, ",threads=%u", 1);
|
||||||
}
|
}
|
||||||
} else if (def->vcpus != def->maxvcpus) {
|
} else if (virDomainDefHasVcpusOffline(def)) {
|
||||||
virBufferFreeAndReset(&buf);
|
virBufferFreeAndReset(&buf);
|
||||||
/* FIXME - consider hot-unplugging cpus after boot for older qemu */
|
/* FIXME - consider hot-unplugging cpus after boot for older qemu */
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
|
@ -1895,7 +1895,7 @@ vboxDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags
|
|||||||
def->mem.cur_balloon, (unsigned)rc);
|
def->mem.cur_balloon, (unsigned)rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (def->vcpus != def->maxvcpus) {
|
if (virDomainDefHasVcpusOffline(def)) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
_("current vcpu count must equal maximum"));
|
_("current vcpu count must equal maximum"));
|
||||||
}
|
}
|
||||||
|
@ -3180,7 +3180,7 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* def:maxvcpus -> vmx:numvcpus */
|
/* def:maxvcpus -> vmx:numvcpus */
|
||||||
if (def->vcpus != def->maxvcpus) {
|
if (virDomainDefHasVcpusOffline(def)) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
_("No support for domain XML entry 'vcpu' attribute "
|
_("No support for domain XML entry 'vcpu' attribute "
|
||||||
"'current'"));
|
"'current'"));
|
||||||
|
@ -1933,7 +1933,7 @@ prlsdkCheckUnsupportedParams(PRL_HANDLE sdkdom, virDomainDefPtr def)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (def->vcpus != def->maxvcpus) {
|
if (virDomainDefHasVcpusOffline(def)) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
_("current vcpus must be equal to maxvcpus"));
|
_("current vcpus must be equal to maxvcpus"));
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1533,7 +1533,7 @@ xenFormatCPUAllocation(virConfPtr conf, virDomainDefPtr def)
|
|||||||
|
|
||||||
/* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is
|
/* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is
|
||||||
either 32, or 64 on a platform where long is big enough. */
|
either 32, or 64 on a platform where long is big enough. */
|
||||||
if (def->vcpus < def->maxvcpus &&
|
if (virDomainDefHasVcpusOffline(def) &&
|
||||||
xenConfigSetInt(conf, "vcpu_avail", (1UL << def->vcpus) - 1) < 0)
|
xenConfigSetInt(conf, "vcpu_avail", (1UL << def->vcpus) - 1) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
@ -2240,7 +2240,7 @@ xenFormatSxpr(virConnectPtr conn,
|
|||||||
virBufferAsprintf(&buf, "(vcpus %u)", def->maxvcpus);
|
virBufferAsprintf(&buf, "(vcpus %u)", def->maxvcpus);
|
||||||
/* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is
|
/* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is
|
||||||
either 32, or 64 on a platform where long is big enough. */
|
either 32, or 64 on a platform where long is big enough. */
|
||||||
if (def->vcpus < def->maxvcpus)
|
if (virDomainDefHasVcpusOffline(def))
|
||||||
virBufferAsprintf(&buf, "(vcpu_avail %lu)", (1UL << def->vcpus) - 1);
|
virBufferAsprintf(&buf, "(vcpu_avail %lu)", (1UL << def->vcpus) - 1);
|
||||||
|
|
||||||
if (def->cpumask) {
|
if (def->cpumask) {
|
||||||
@ -2322,7 +2322,7 @@ xenFormatSxpr(virConnectPtr conn,
|
|||||||
virBufferEscapeSexpr(&buf, "(kernel '%s')", def->os.loader->path);
|
virBufferEscapeSexpr(&buf, "(kernel '%s')", def->os.loader->path);
|
||||||
|
|
||||||
virBufferAsprintf(&buf, "(vcpus %u)", def->maxvcpus);
|
virBufferAsprintf(&buf, "(vcpus %u)", def->maxvcpus);
|
||||||
if (def->vcpus < def->maxvcpus)
|
if (virDomainDefHasVcpusOffline(def))
|
||||||
virBufferAsprintf(&buf, "(vcpu_avail %lu)",
|
virBufferAsprintf(&buf, "(vcpu_avail %lu)",
|
||||||
(1UL << def->vcpus) - 1);
|
(1UL << def->vcpus) - 1);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user