]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu_firmware: Retain user-specified NVRAM format
authorAndrea Bolognani <abologna@redhat.com>
Mon, 1 Dec 2025 15:30:43 +0000 (16:30 +0100)
committerAndrea Bolognani <abologna@redhat.com>
Thu, 8 Jan 2026 23:26:16 +0000 (00:26 +0100)
Right now we throw the entire definition away if the path is
not present, including the format. This effectively results in
discarding user-provided information.

This change fixes the firmware-auto-efi-format-mismatch test
case. Until now, the NVRAM format ended up being raw (matching
the NVRAM template) despite the user explicitly asking for it
to be qcow2 instead.

While this means that libvirt will no longer be able to start
such a VM without user intervention, since it does not
automatically perform conversion between formats, that's still
preferrable to silently overriding an explicit user's request.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_firmware.c
tests/qemuxmlconfdata/firmware-auto-efi-format-mismatch.x86_64-latest.args
tests/qemuxmlconfdata/firmware-auto-efi-format-mismatch.x86_64-latest.xml

index b08fb95585f28b77e8fa35e9bab17484013f562c..dca0a79868ee3f7bad46acba9407534c36a46c0b 100644 (file)
@@ -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
index e7c9110c95043e4b5eac2b50948495b149278199..468d7ee0482e4629b41ff7b74fdf09c71f1fa9a2 100644 (file)
@@ -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 \
index f4df8c07ed7015ae073d5ca45cc7849bd4ed4fca..3a7536db2ac4069773c08c5ce8809989277152c7 100644 (file)
@@ -11,7 +11,7 @@
       <feature enabled='yes' name='secure-boot'/>
     </firmware>
     <loader readonly='yes' secure='yes' type='pflash' format='raw'>/usr/share/edk2/ovmf/OVMF_CODE.secboot.fd</loader>
-    <nvram template='/usr/share/edk2/ovmf/OVMF_VARS.secboot.fd' templateFormat='raw' format='raw'>/var/lib/libvirt/qemu/nvram/guest_VARS.fd</nvram>
+    <nvram template='/usr/share/edk2/ovmf/OVMF_VARS.secboot.fd' templateFormat='raw' format='qcow2'>/var/lib/libvirt/qemu/nvram/guest_VARS.qcow2</nvram>
     <boot dev='hd'/>
   </os>
   <features>