While qemu would reject the configuration we can check whether it makes
sense to plug the device upfront.
---
src/qemu/qemu_command.c | 8 ++++++++
src/qemu/qemu_driver.c | 6 ++++++
src/qemu/qemu_hotplug.c | 6 ++++++
3 files changed, 20 insertions(+)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 21daf18..e62833f 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -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;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 80463f2..d181439 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -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;
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index ba92320..613b728 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -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;
--
2.3.5