[PATCH 0/2] qemu: Match firmware with fully resolved and canonicalized paths

As promised, this is a resend of previous patches: https://lists.libvirt.org/archives/list/devel@lists.libvirt.org/thread/XVHIW... Diff to v1: - new patch 1/2 which fixes the mocking. James Le Cuirot (1): qemu: Match firmware with fully resolved and canonicalized paths Michal Prívozník (1): qemuxml2argvmock: Pretend FW blobs are always present src/qemu/qemu_firmware.c | 11 ++++++----- tests/qemuxml2argvmock.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-) -- 2.49.1

From: Michal Privoznik <mprivozn@redhat.com> Soon, the QEMU driver, specifically the part that picks firmware based on firmware descriptor files (qemu_firmware.c) is going to check for the presence of those firmware blobs (well, for their realpath()). Just collect the list of all blobs we use in our tests and mock virFileCanonicalizePath() so that for any path on that list its strdup()-ed version is returned. This means, qemuxmlconftest won't touch host files really. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemuxml2argvmock.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/qemuxml2argvmock.c b/tests/qemuxml2argvmock.c index e3f933c44f..9d10b5655f 100644 --- a/tests/qemuxml2argvmock.c +++ b/tests/qemuxml2argvmock.c @@ -33,6 +33,7 @@ #include "virscsivhost.h" #include "virtpm.h" #include "virutil.h" +#include "virfile.h" #include "qemu/qemu_interface.h" #include "qemu/qemu_command.h" #include "domain_interface.h" @@ -296,3 +297,37 @@ virNetDevSetMTU(const char *ifname G_GNUC_UNUSED, { return 0; } + +static char *(*real_virFileCanonicalizePath)(const char *path); + +char * +virFileCanonicalizePath(const char *path) +{ + size_t i; + const char *fws[] = { + /* These are locations from our firmware descriptors + * stored in qemufirmwaredata/. */ + "/usr/share/edk2/", + "/usr/share/OVMF/", + "/usr/share/AAVMF/", + "/usr/share/seabios/", + + /* These are 'random' locations from domain XMLs stored + * in qemuxmlconfdata/. */ + "/path/to/OVMF_CODE.fd", + "/path/to/guest_BOTH.fd", + "/path/to/OVMF_VARS.fd", + }; + + for (i = 0; i < G_N_ELEMENTS(fws); i++) { + if (STRPREFIX(path, fws[i])) { + return g_strdup(path); + } + } + + if (!real_virFileCanonicalizePath) { + VIR_MOCK_REAL_INIT(virFileCanonicalizePath); + } + + return real_virFileCanonicalizePath(path); +} -- 2.49.1

From: James Le Cuirot <jlecuirot@microsoft.com> Distros may provide compatibility symlinks after moving firmware files around, but they won't work for existing VMs when doing a straight string comparison. I tried to compare inodes instead, but even glib doesn't provide a straightforward cross-platform method to do this. Resolves: https://bugs.gentoo.org/960591 Signed-off-by: James Le Cuirot <jlecuirot@microsoft.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_firmware.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c index f10137144e..69e77d66f5 100644 --- a/src/qemu/qemu_firmware.c +++ b/src/qemu/qemu_firmware.c @@ -33,6 +33,7 @@ #include "viralloc.h" #include "virenum.h" #include "virstring.h" +#include "virfile.h" #define VIR_FROM_THIS VIR_FROM_QEMU @@ -939,23 +940,23 @@ qemuFirmwareMatchesPaths(const qemuFirmware *fw, switch (fw->mapping.device) { case QEMU_FIRMWARE_DEVICE_FLASH: if (loader && loader->path && - STRNEQ(loader->path, flash->executable.filename)) + !virFileComparePaths(loader->path, flash->executable.filename)) return false; if (loader && loader->nvramTemplate) { if (flash->mode != QEMU_FIRMWARE_FLASH_MODE_SPLIT) return false; - if (STRNEQ(loader->nvramTemplate, flash->nvram_template.filename)) + if (!virFileComparePaths(loader->nvramTemplate, flash->nvram_template.filename)) return false; } break; case QEMU_FIRMWARE_DEVICE_MEMORY: if (loader && loader->path && - STRNEQ(loader->path, memory->filename)) + !virFileComparePaths(loader->path, memory->filename)) return false; break; case QEMU_FIRMWARE_DEVICE_KERNEL: if (kernelPath && - STRNEQ(kernelPath, kernel->filename)) + !virFileComparePaths(kernelPath, kernel->filename)) return false; break; case QEMU_FIRMWARE_DEVICE_NONE: @@ -1676,7 +1677,7 @@ qemuFirmwareFillDomainLegacy(virQEMUDriver *driver, for (i = 0; i < cfg->nfirmwares; i++) { virFirmware *fw = cfg->firmwares[i]; - if (STRNEQ(fw->name, loader->path)) { + if (!virFileComparePaths(fw->name, loader->path)) { VIR_DEBUG("Not matching loader path '%s' for user provided path '%s'", fw->name, loader->path); continue; -- 2.49.1

On a Friday in 2025, Michal Privoznik via Devel wrote:
As promised, this is a resend of previous patches:
https://lists.libvirt.org/archives/list/devel@lists.libvirt.org/thread/XVHIW...
Diff to v1: - new patch 1/2 which fixes the mocking.
James Le Cuirot (1): qemu: Match firmware with fully resolved and canonicalized paths
Michal Prívozník (1): qemuxml2argvmock: Pretend FW blobs are always present
src/qemu/qemu_firmware.c | 11 ++++++----- tests/qemuxml2argvmock.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (2)
-
Ján Tomko
-
Michal Privoznik