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@xxxxxxxxxx> --- src/qemu/qemu_driver.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d00d2a27c6..cad52b7150 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -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")); + if (qemuDomainAttachMemoryConfig(vmdef, &dev->data.memory) < 0) return -1; - } - - vmdef->mem.cur_balloon += dev->data.memory->size; - - if (virDomainMemoryInsert(vmdef, dev->data.memory) < 0) - return -1; - dev->data.memory = NULL; break; case VIR_DOMAIN_DEVICE_REDIRDEV: -- 2.41.0 _______________________________________________ Devel mailing list -- devel@xxxxxxxxxxxxxxxxx To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx