]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
qemu: Validate available slot count for memory devices
authorPeter Krempa <pkrempa@redhat.com>
Tue, 28 Apr 2015 15:33:54 +0000 (17:33 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 29 Apr 2015 07:40:16 +0000 (09:40 +0200)
While qemu would reject the configuration we can check whether it makes
sense to plug the device upfront.

src/qemu/qemu_command.c
src/qemu/qemu_driver.c
src/qemu/qemu_hotplug.c

index 21daf18c6b85e95be66b7bdca27c9aac806c2106..e62833fb5998143b5d0d75c6b8eb55e061a18d89 100644 (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;
index 581211aabf454ce1c7338508ec58d078fd3da1b2..2fb4ac97f2b69b47b4b07b2d1ec41580b0c3c0d7 100644 (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;
index ba92320512cd83105825a9d1fe37a1776e18cf8d..613b728bf29b9e41f68c649a69732118c4561dca 100644 (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;