diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c index b08fb95585..dca0a79868 100644 --- a/src/qemu/qemu_firmware.c +++ b/src/qemu/qemu_firmware.c @@ -971,6 +971,7 @@ qemuFirmwareEnsureNVRAM(virDomainDef *def, { g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver); virDomainLoaderDef *loader = def->os.loader; + virStorageFileFormat nvramFormat = VIR_STORAGE_FILE_NONE; const char *ext = NULL; if (!loader) @@ -999,19 +1000,26 @@ qemuFirmwareEnsureNVRAM(virDomainDef *def, return; } - /* otherwise we want to reset and re-populate the definition */ + /* Otherwise we want to reset and re-populate the definition. + * In this case we still retain a single piece of information: + * the user-provided NVRAM format */ + nvramFormat = loader->nvram->format; + virObjectUnref(loader->nvram); } loader->nvram = virStorageSourceNew(); loader->nvram->type = VIR_STORAGE_TYPE_FILE; + loader->nvram->format = nvramFormat; /* The nvram template format should be always present but as a failsafe, * duplicate the loader format if it is not available. */ - if (loader->nvramTemplateFormat > VIR_STORAGE_FILE_NONE) - loader->nvram->format = loader->nvramTemplateFormat; - else - loader->nvram->format = loader->format; + if (!loader->nvram->format) { + if (loader->nvramTemplateFormat) + loader->nvram->format = loader->nvramTemplateFormat; + else + loader->nvram->format = loader->format; + } if (loader->nvram->format == VIR_STORAGE_FILE_RAW) { /* The extension used by raw edk2 builds has historically diff --git a/tests/qemuxmlconfdata/firmware-auto-efi-format-mismatch.x86_64-latest.args b/tests/qemuxmlconfdata/firmware-auto-efi-format-mismatch.x86_64-latest.args index e7c9110c95..468d7ee048 100644 --- a/tests/qemuxmlconfdata/firmware-auto-efi-format-mismatch.x86_64-latest.args +++ b/tests/qemuxmlconfdata/firmware-auto-efi-format-mismatch.x86_64-latest.args @@ -12,8 +12,9 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-guest/.config \ -object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/var/lib/libvirt/qemu/domain--1-guest/master-key.aes"}' \ -blockdev '{"driver":"file","filename":"/usr/share/edk2/ovmf/OVMF_CODE.secboot.fd","node-name":"libvirt-pflash0-storage","auto-read-only":true,"discard":"unmap"}' \ -blockdev '{"node-name":"libvirt-pflash0-format","read-only":true,"driver":"raw","file":"libvirt-pflash0-storage"}' \ --blockdev '{"driver":"file","filename":"/var/lib/libvirt/qemu/nvram/guest_VARS.fd","node-name":"libvirt-pflash1-storage","read-only":false}' \ --machine pc-q35-10.0,usb=off,smm=on,dump-guest-core=off,memory-backend=pc.ram,pflash0=libvirt-pflash0-format,pflash1=libvirt-pflash1-storage,acpi=on \ +-blockdev '{"driver":"file","filename":"/var/lib/libvirt/qemu/nvram/guest_VARS.qcow2","node-name":"libvirt-pflash1-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-pflash1-format","read-only":false,"driver":"qcow2","file":"libvirt-pflash1-storage","backing":null}' \ +-machine pc-q35-10.0,usb=off,smm=on,dump-guest-core=off,memory-backend=pc.ram,pflash0=libvirt-pflash0-format,pflash1=libvirt-pflash1-format,acpi=on \ -accel kvm \ -cpu qemu64 \ -global driver=cfi.pflash01,property=secure,value=on \ diff --git a/tests/qemuxmlconfdata/firmware-auto-efi-format-mismatch.x86_64-latest.xml b/tests/qemuxmlconfdata/firmware-auto-efi-format-mismatch.x86_64-latest.xml index f4df8c07ed..3a7536db2a 100644 --- a/tests/qemuxmlconfdata/firmware-auto-efi-format-mismatch.x86_64-latest.xml +++ b/tests/qemuxmlconfdata/firmware-auto-efi-format-mismatch.x86_64-latest.xml @@ -11,7 +11,7 @@ /usr/share/edk2/ovmf/OVMF_CODE.secboot.fd - /var/lib/libvirt/qemu/nvram/guest_VARS.fd + /var/lib/libvirt/qemu/nvram/guest_VARS.qcow2