[libvirt PATCH 3/3] qemu: split handling of distinct firmware enum conversions

Daniel P. Berrangé posted 3 patches 4 months, 1 week ago
[libvirt PATCH 3/3] qemu: split handling of distinct firmware enum conversions
Posted by Daniel P. Berrangé 4 months, 1 week ago
The qemuFirmwareOSInterfaceTypeFromOsDefFirmware method
was added to convert from virDomainOsDefFirmware to the
qemuFirmwareOSInterface enum.

It was later also used to convert from virDomainLoader
to qemuFirmwareOSInterface in:

  commit 8e1804f9f66f13ca1412d22bf1a957b6d55a2365
  Author: Michal Prívozník <mprivozn@redhat.com>
  Date:   Tue Dec 17 17:45:50 2019 +0100

    qemu_firmware: Try to autofill for old style UEFI specification

This caused compile errors with clang due to passing a
mis-matched enum type. These were later silenced by
stripping the enum types:

  commit 8fcee47807d29008632a7ad918cbe93ac0a20597
  Author: Michal Prívozník <mprivozn@redhat.com>
  Date:   Wed Jan 8 09:42:47 2020 +0100

    qemu_firmware: Accept int in qemuFirmwareOSInterfaceTypeFromOsDefFirmware()

This is still rather confusing to humans reading the
code. It is clearer to just define a separate helper
method for the virDomainLoader type conversion.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 src/conf/domain_conf.h   |  4 ++--
 src/qemu/qemu_firmware.c | 21 +++++++++++++++++++--
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 144ba4dd12..8a7e9a1668 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2292,8 +2292,8 @@ struct _virDomainOSEnv {
 
 typedef enum {
     VIR_DOMAIN_OS_DEF_FIRMWARE_NONE = 0,
-    VIR_DOMAIN_OS_DEF_FIRMWARE_BIOS = VIR_DOMAIN_LOADER_TYPE_ROM,
-    VIR_DOMAIN_OS_DEF_FIRMWARE_EFI = VIR_DOMAIN_LOADER_TYPE_PFLASH,
+    VIR_DOMAIN_OS_DEF_FIRMWARE_BIOS,
+    VIR_DOMAIN_OS_DEF_FIRMWARE_EFI,
 
     VIR_DOMAIN_OS_DEF_FIRMWARE_LAST
 } virDomainOsDefFirmware;
diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c
index 529ab8d68e..84c80eaacb 100644
--- a/src/qemu/qemu_firmware.c
+++ b/src/qemu/qemu_firmware.c
@@ -899,7 +899,7 @@ qemuFirmwareMatchesMachineArch(const qemuFirmware *fw,
 
 
 static qemuFirmwareOSInterface
-qemuFirmwareOSInterfaceTypeFromOsDefFirmware(int fw)
+qemuFirmwareOSInterfaceTypeFromOsDefFirmware(virDomainOsDefFirmware fw)
 {
     switch (fw) {
     case VIR_DOMAIN_OS_DEF_FIRMWARE_BIOS:
@@ -915,6 +915,23 @@ qemuFirmwareOSInterfaceTypeFromOsDefFirmware(int fw)
 }
 
 
+static qemuFirmwareOSInterface
+qemuFirmwareOSInterfaceTypeFromOsDefLoaderType(virDomainLoader type)
+{
+    switch (type) {
+    case VIR_DOMAIN_LOADER_TYPE_ROM:
+        return QEMU_FIRMWARE_OS_INTERFACE_BIOS;
+    case VIR_DOMAIN_LOADER_TYPE_PFLASH:
+        return QEMU_FIRMWARE_OS_INTERFACE_UEFI;
+    case VIR_DOMAIN_LOADER_TYPE_NONE:
+    case VIR_DOMAIN_LOADER_TYPE_LAST:
+        break;
+    }
+
+    return QEMU_FIRMWARE_OS_INTERFACE_NONE;
+}
+
+
 #define VIR_QEMU_FIRMWARE_AMD_SEV_ES_POLICY (1 << 2)
 
 
@@ -939,7 +956,7 @@ qemuFirmwareMatchDomain(const virDomainDef *def,
 
     if (want == QEMU_FIRMWARE_OS_INTERFACE_NONE &&
         def->os.loader) {
-        want = qemuFirmwareOSInterfaceTypeFromOsDefFirmware(def->os.loader->type);
+        want = qemuFirmwareOSInterfaceTypeFromOsDefLoaderType(def->os.loader->type);
 
         if (fw->mapping.device != QEMU_FIRMWARE_DEVICE_FLASH ||
             STRNEQ(def->os.loader->path, fw->mapping.data.flash.executable.filename)) {
-- 
2.33.1