mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-23 13:05:27 +00:00
qemu: Move memory device coldplug into a separate function
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>
This commit is contained in:
parent
6beeca77be
commit
b41f730c33
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user