[PATCH 0/2] qemu: Relax check for memory device coldplug

*** BLURB HERE *** Michal Prívozník (2): qemu: Move memory device coldplug into a separate function qemu: Relax check for memory device coldplug src/qemu/qemu_driver.c | 45 ++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) -- 2.41.0

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> --- 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

When cold plugging a memory device we check whether there's enough free memory slots to accommodate new module. Well, this checks makes sense only for those memory devices that are plugged into DIMM slots (DIMM and NVDIMM models). Other memory device models, like VIRTIO_MEM, VIRTIO_PMEM or SGX_EPC are attached into PCI bus, or no bus at all. Resolves: https://issues.redhat.com/browse/RHEL-15480 Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_driver.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index cad52b7150..64afae6450 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6631,9 +6631,23 @@ 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")); + switch ((*mem)->model) { + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + if (vmdef->nmems == vmdef->mem.memory_slots) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("no free memory device slot available")); + return -1; + } + break; + + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: + case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC: + break; + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + virReportEnumRangeError(virDomainMemoryModel, (*mem)->model); return -1; } -- 2.41.0

On Tue, Dec 05, 2023 at 10:57:50AM +0100, Michal Privoznik wrote:
*** BLURB HERE ***
Michal Prívozník (2): qemu: Move memory device coldplug into a separate function qemu: Relax check for memory device coldplug
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
src/qemu/qemu_driver.c | 45 ++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-)
-- 2.41.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org
participants (2)
-
Martin Kletzander
-
Michal Privoznik