Commit d3016e47be5f removed a hunk very similar to the one we're adding with the rationale that there is no actual requirement for the NVRAM file and the NVRAM template to have the same format, which is completely correct: while libvirt will not perform the format conversion itself, the user can do that on their own and everything (except RESET_NVRAM) will work just fine.
That said, we also need <nvram format='foo'/> specified on its own with no <loader> element to result in a firmware build with a foo-formatted NVRAM template to be picked. Right now this works thanks to the hack at the top of qemuFirmwareFillDomain() which copies nvram.format to loader.format, but we want to get rid of that because it has additional side effects that can lead to confusing outcomes in certain specific scenarios. So reintroduce this check, but make it extremely narrow: if any other information that can influence firmware selection is present in the domain XML, ignore the NVRAM format entirely; if however the NVRAM format is the only information that was provided, consider it when looking for a match. Signed-off-by: Andrea Bolognani <[email protected]> --- src/qemu/qemu_firmware.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c index e13cce0887..8714538ba3 100644 --- a/src/qemu/qemu_firmware.c +++ b/src/qemu/qemu_firmware.c @@ -1304,6 +1304,21 @@ qemuFirmwareMatchDomain(const virDomainDef *def, virStorageFileFormatTypeToString(loader->nvramTemplateFormat)); return false; } + /* If nvram.format was specified and no other information + * that can influence firmware selection was, then treat it + * the same as if nvram.templateFormat had been specified. + * This ensures that <nvram format='foo'/> continues to work + * as a shorthand while not getting in the way otherwise */ + if (loader && loader->nvram && loader->nvram->format && + !loader->readonly && !loader->type && !loader->secure && + !loader->stateless && !loader->format && !loader->path && + !loader->nvramTemplateFormat && !loader->nvramTemplate && + STRNEQ(flash->nvram_template.format, virStorageFileFormatTypeToString(loader->nvram->format))) { + VIR_DEBUG("Discarding loader with mismatching nvram template format '%s' != '%s'", + flash->nvram_template.format, + virStorageFileFormatTypeToString(loader->nvram->format)); + return false; + } } else { if (loader && loader->nvram && (loader->nvram->path || loader->nvram->format)) { -- 2.52.0
