[libvirt] [PATCH] qemu: extract function qemuDomainDefIsUEFI()

Jonathon Jongsma posted 1 patch 4 years, 7 months ago
Test syntax-check passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20190829141156.14609-1-jjongsma@redhat.com
src/qemu/qemu_domain.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
[libvirt] [PATCH] qemu: extract function qemuDomainDefIsUEFI()
Posted by Jonathon Jongsma 4 years, 7 months ago
Rather than repeating the conditions in a couple places, extract it into
a separate function for detecting whether a domain definition uses UEFI.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
---
As requested by Andrea, I've extracted this little bit of refactoring from my
bochs display patch and am sending it separately.

 src/qemu/qemu_domain.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 4998474dc9..ed4b5c666d 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4584,6 +4584,14 @@ qemuDomainValidateCpuCount(const virDomainDef *def,
 }
 
 
+static bool
+qemuDomainDefIsUEFI(const virDomainDef *def)
+{
+    return ((def->os.firmware == VIR_DOMAIN_OS_DEF_FIRMWARE_EFI ||
+             (def->os.loader && def->os.loader->type ==
+              VIR_DOMAIN_LOADER_TYPE_PFLASH)));
+}
+
 static int
 qemuDomainDefValidate(const virDomainDef *def,
                       virCapsPtr caps ATTRIBUTE_UNUSED,
@@ -4606,10 +4614,7 @@ qemuDomainDefValidate(const virDomainDef *def,
     }
 
     /* On x86, UEFI requires ACPI */
-    if ((def->os.firmware == VIR_DOMAIN_OS_DEF_FIRMWARE_EFI ||
-         (def->os.loader &&
-          def->os.loader->type == VIR_DOMAIN_LOADER_TYPE_PFLASH)) &&
-        ARCH_IS_X86(def->os.arch) &&
+    if (qemuDomainDefIsUEFI(def) && ARCH_IS_X86(def->os.arch) &&
         def->features[VIR_DOMAIN_FEATURE_ACPI] != VIR_TRISTATE_SWITCH_ON) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("UEFI requires ACPI on this architecture"));
@@ -4619,9 +4624,7 @@ qemuDomainDefValidate(const virDomainDef *def,
     /* On aarch64, ACPI requires UEFI */
     if (def->features[VIR_DOMAIN_FEATURE_ACPI] == VIR_TRISTATE_SWITCH_ON &&
         def->os.arch == VIR_ARCH_AARCH64 &&
-        (def->os.firmware != VIR_DOMAIN_OS_DEF_FIRMWARE_EFI &&
-         (!def->os.loader ||
-          def->os.loader->type != VIR_DOMAIN_LOADER_TYPE_PFLASH))) {
+        !qemuDomainDefIsUEFI(def)) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("ACPI requires UEFI on this architecture"));
         goto cleanup;
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu: extract function qemuDomainDefIsUEFI()
Posted by Martin Kletzander 4 years, 7 months ago
On Thu, Aug 29, 2019 at 09:11:56AM -0500, Jonathon Jongsma wrote:
>Rather than repeating the conditions in a couple places, extract it into
>a separate function for detecting whether a domain definition uses UEFI.
>
>Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
>---
>As requested by Andrea, I've extracted this little bit of refactoring from my
>bochs display patch and am sending it separately.
>

Yeah, this is way more readable =)

Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list