]> xenbits.xensource.com Git - people/aperard/libvirt.git/commitdiff
qemu: Move memory device coldplug into a separate function
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 4 Dec 2023 08:33:36 +0000 (09:33 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 5 Dec 2023 15:36:46 +0000 (16:36 +0100)
The code that handles coldplug of a memory device is pretty
trivial and such could continue to live in the huge switch()
where other devices are handled. But the code is about to get
more complicated. To help with code readability, move it into a
separate function.

And while at it, make the function accept a double pointer to the
memory device definition to make the ownership transfer obvious
(the device is part of the domain on successful run).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
src/qemu/qemu_driver.c

index d00d2a27c69d6a244e33b9bc4f1f24317a6658c8..cad52b7150fe1a9828769b57aac51f54edcc19ed 100644 (file)
@@ -6627,6 +6627,26 @@ qemuCheckDiskConfigAgainstDomain(const virDomainDef *def,
 }
 
 
+static int
+qemuDomainAttachMemoryConfig(virDomainDef *vmdef,
+                             virDomainMemoryDef **mem)
+{
+    if (vmdef->nmems == vmdef->mem.memory_slots) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("no free memory device slot available"));
+        return -1;
+    }
+
+    vmdef->mem.cur_balloon += (*mem)->size;
+
+    if (virDomainMemoryInsert(vmdef, *mem) < 0)
+        return -1;
+
+    *mem = NULL;
+    return 0;
+}
+
+
 static int
 qemuDomainAttachDeviceConfig(virDomainDef *vmdef,
                              virDomainDeviceDef *dev,
@@ -6747,17 +6767,8 @@ qemuDomainAttachDeviceConfig(virDomainDef *vmdef,
         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;
-        }
-
-        vmdef->mem.cur_balloon += dev->data.memory->size;
-
-        if (virDomainMemoryInsert(vmdef, dev->data.memory) < 0)
+        if (qemuDomainAttachMemoryConfig(vmdef, &dev->data.memory) < 0)
             return -1;
-        dev->data.memory = NULL;
         break;
 
     case VIR_DOMAIN_DEVICE_REDIRDEV: