[PATCH 10/11] qemu: Refactor virQEMUCapsCacheLookupByArch()

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

 



The new implementation contains less duplicated code and
is easier to extend.

This commit is best viewed with 'git show -w'.

Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx>
---
 src/qemu/qemu_capabilities.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index b78b935404..b621f39a82 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -4752,26 +4752,27 @@ virQEMUCapsCacheLookupByArch(virFileCachePtr cache,
                              virArch arch)
 {
     virQEMUCapsPtr ret = NULL;
-    virArch target;
-    struct virQEMUCapsSearchData data = { .arch = arch };
-
-    ret = virFileCacheLookupByFunc(cache, virQEMUCapsCompareArch, &data);
-    if (!ret) {
-        /* If the first attempt at finding capabilities has failed, try
-         * again using the QEMU target as lookup key instead */
-        target = virQEMUCapsFindTarget(virArchFromHost(), data.arch);
-        if (target != data.arch) {
-            data.arch = target;
-            ret = virFileCacheLookupByFunc(cache, virQEMUCapsCompareArch, &data);
-        }
-    }
+    virArch archs[] = {
+        arch,
+        virQEMUCapsFindTarget(virArchFromHost(), arch),
+    };
+    size_t j;
 
-    if (!ret) {
-        virReportError(VIR_ERR_INVALID_ARG,
-                       _("unable to find any emulator to serve '%s' "
-                         "architecture"), virArchToString(arch));
+    for (j = 0; j < ARRAY_CARDINALITY(archs); j++) {
+        struct virQEMUCapsSearchData data = {
+            .arch = archs[j],
+        };
+
+        ret = virFileCacheLookupByFunc(cache, virQEMUCapsCompareArch, &data);
+        if (ret)
+            goto done;
     }
 
+    virReportError(VIR_ERR_INVALID_ARG,
+                   _("unable to find any emulator to serve '%s' "
+                     "architecture"), virArchToString(arch));
+
+ done:
     VIR_DEBUG("Returning caps %p for arch %s", ret, virArchToString(arch));
 
     return ret;
-- 
2.17.1

--
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