[PATCH v2 2/4] qemu_firmware: Separate machine and arch matching into a function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This part of the code will be reused later.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/qemu/qemu_firmware.c | 47 +++++++++++++++++++++++++---------------
 1 file changed, 29 insertions(+), 18 deletions(-)

diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c
index 065e0d11aa..8e9a225982 100644
--- a/src/qemu/qemu_firmware.c
+++ b/src/qemu/qemu_firmware.c
@@ -1054,6 +1054,34 @@ qemuFirmwareFetchConfigs(char ***firmwares,
 }
 
 
+static bool
+qemuFirmwareMatchesMachineArch(const qemuFirmware *fw,
+                               const char *machine,
+                               virArch arch)
+{
+    size_t i;
+
+    for (i = 0; i < fw->ntargets; i++) {
+        size_t j;
+
+        if (arch != fw->targets[i]->architecture)
+            continue;
+
+        for (j = 0; j < fw->targets[i]->nmachines; j++) {
+            if (fnmatch(fw->targets[i]->machines[j], machine, 0) == 0)
+                break;
+        }
+
+        if (j == fw->targets[i]->nmachines)
+            continue;
+
+        break;
+    }
+
+    return i != fw->ntargets;
+}
+
+
 static bool
 qemuFirmwareMatchDomain(const virDomainDef *def,
                         const qemuFirmware *fw,
@@ -1078,24 +1106,7 @@ qemuFirmwareMatchDomain(const virDomainDef *def,
         return false;
     }
 
-    for (i = 0; i < fw->ntargets; i++) {
-        size_t j;
-
-        if (def->os.arch != fw->targets[i]->architecture)
-            continue;
-
-        for (j = 0; j < fw->targets[i]->nmachines; j++) {
-            if (fnmatch(fw->targets[i]->machines[j], def->os.machine, 0) == 0)
-                break;
-        }
-
-        if (j == fw->targets[i]->nmachines)
-            continue;
-
-        break;
-    }
-
-    if (i == fw->ntargets) {
+    if (!qemuFirmwareMatchesMachineArch(fw, def->os.machine, def->os.arch)) {
         VIR_DEBUG("No matching machine type in '%s'", path);
         return false;
     }
-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux