qemu: Validate available slot count for memory devices

While qemu would reject the configuration we can check whether it makes
sense to plug the device upfront.
This commit is contained in:
Peter Krempa 2015-04-28 17:33:54 +02:00
parent 6705d828fc
commit a83b2e253f
3 changed files with 20 additions and 0 deletions

View File

@ -8822,6 +8822,14 @@ qemuBuildCommandLine(virConnectPtr conn,
/* memory hotplug requires NUMA to be enabled - we already checked
* that memory devices are present only when NUMA is */
if (def->nmems > def->mem.memory_slots) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("memory device count '%zu' exceeds slots count '%u'"),
def->nmems, def->mem.memory_slots);
goto error;
}
for (i = 0; i < def->nmems; i++) {
char *backStr;
char *dimmStr;

View File

@ -8489,6 +8489,12 @@ qemuDomainAttachDeviceConfig(virQEMUCapsPtr qemuCaps,
break;
case VIR_DOMAIN_DEVICE_MEMORY:
if (vmdef->nmems == vmdef->mem.memory_slots) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("no free memory device slot available"));
return -1;
}
if (virDomainMemoryInsert(vmdef, dev->data.memory) < 0)
return -1;
dev->data.memory = NULL;

View File

@ -1730,6 +1730,12 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
int id;
int ret = -1;
if (vm->def->nmems == vm->def->mem.memory_slots) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("no free memory device slot available"));
goto cleanup;
}
if (virAsprintf(&mem->info.alias, "dimm%zu", vm->def->nmems) < 0)
goto cleanup;