A new function qemuDomainDeviceDefValidateNVRAM() was created to validate the NVRAM in domain define time. Unit test was adjusted to account for the extra QEMU_CAPS_DEVICE_NVRAM required during domain define. Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx> --- src/qemu/qemu_command.c | 41 +++++++++++------------------------------ src/qemu/qemu_domain.c | 38 +++++++++++++++++++++++++++++++++++++- tests/qemuxml2xmltest.c | 3 ++- 3 files changed, 50 insertions(+), 32 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index f0f245d730..58d7aa697e 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4098,15 +4098,8 @@ qemuBuildNVRAMDevStr(virDomainNVRAMDefPtr dev) { g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; - if (dev->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO && - dev->info.addr.spaprvio.has_reg) { - virBufferAsprintf(&buf, "spapr-nvram.reg=0x%llx", - dev->info.addr.spaprvio.reg); - } else { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("nvram address type must be spaprvio")); - return NULL; - } + virBufferAsprintf(&buf, "spapr-nvram.reg=0x%llx", + dev->info.addr.spaprvio.reg); return virBufferContentAndReset(&buf); } @@ -4114,31 +4107,19 @@ qemuBuildNVRAMDevStr(virDomainNVRAMDefPtr dev) static int qemuBuildNVRAMCommandLine(virCommandPtr cmd, - const virDomainDef *def, - virQEMUCapsPtr qemuCaps) + const virDomainDef *def) { + g_autofree char *optstr = NULL; + if (!def->nvram) return 0; - if (qemuDomainIsPSeries(def)) { - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_NVRAM)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("nvram device is not supported by " - "this QEMU binary")); - return -1; - } - - g_autofree char *optstr = NULL; - virCommandAddArg(cmd, "-global"); - optstr = qemuBuildNVRAMDevStr(def->nvram); - if (!optstr) - return -1; - virCommandAddArg(cmd, optstr); - } else { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("nvram device is only supported for PPC64")); + virCommandAddArg(cmd, "-global"); + optstr = qemuBuildNVRAMDevStr(def->nvram); + if (!optstr) return -1; - } + + virCommandAddArg(cmd, optstr); return 0; } @@ -10261,7 +10242,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver, chardevStdioLogd) < 0) return NULL; - if (qemuBuildNVRAMCommandLine(cmd, def, qemuCaps) < 0) + if (qemuBuildNVRAMCommandLine(cmd, def) < 0) return NULL; if (qemuBuildVMCoreInfoCommandLine(cmd, def, qemuCaps) < 0) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 503892a40f..35ef2ae47d 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -5191,6 +5191,39 @@ qemuDomainValidateCpuCount(const virDomainDef *def, } +static int +qemuDomainDeviceDefValidateNVRAM(virDomainNVRAMDefPtr nvram, + const virDomainDef *def, + virQEMUCapsPtr qemuCaps) +{ + if (!nvram) + return 0; + + if (qemuDomainIsPSeries(def)) { + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_NVRAM)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("nvram device is not supported by " + "this QEMU binary")); + return -1; + } + } else { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("nvram device is only supported for PPC64")); + return -1; + } + + if (!(nvram->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO && + nvram->info.addr.spaprvio.has_reg)) { + + virReportError(VIR_ERR_XML_ERROR, "%s", + _("nvram address type must be spaprvio")); + return -1; + } + + return 0; +} + + static int qemuDomainDefValidate(const virDomainDef *def, void *opaque) @@ -7632,10 +7665,13 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev, ret = qemuDomainDeviceDefValidateFS(dev->data.fs, def, qemuCaps); break; + case VIR_DOMAIN_DEVICE_NVRAM: + ret = qemuDomainDeviceDefValidateNVRAM(dev->data.nvram, def, qemuCaps); + break; + case VIR_DOMAIN_DEVICE_LEASE: case VIR_DOMAIN_DEVICE_SOUND: case VIR_DOMAIN_DEVICE_HUB: - case VIR_DOMAIN_DEVICE_NVRAM: case VIR_DOMAIN_DEVICE_SHMEM: case VIR_DOMAIN_DEVICE_MEMORY: case VIR_DOMAIN_DEVICE_PANIC: diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 215d6b78cd..3d4959a05c 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -562,7 +562,8 @@ mymain(void) QEMU_CAPS_DEVICE_VIRTIO_RNG); DO_TEST("pseries-nvram", - QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE); + QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE, + QEMU_CAPS_DEVICE_NVRAM); DO_TEST("pseries-panic-missing", QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE); DO_TEST("pseries-panic-no-address", -- 2.23.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list