[PATCH v2 10/31] qemu: Refresh caps in virQEMUCapsCacheLookupByArch

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

 



The function just returned cached capabilities without checking whether
they are still valid. We should check that and refresh the capabilities
to make sure we don't return stale data. In other words, we should do
what all other lookup functions do.

Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
---
 src/qemu/qemu_capabilities.c | 19 ++++++++++++++++++-
 src/qemu/qemu_capabilities.h |  3 ++-
 src/qemu/qemu_driver.c       |  3 ++-
 3 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 904289b..913a22a 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -4624,7 +4624,8 @@ virQEMUCapsCompareArch(const void *payload,
 
 
 virQEMUCapsPtr
-virQEMUCapsCacheLookupByArch(virQEMUCapsCachePtr cache,
+virQEMUCapsCacheLookupByArch(virCapsPtr caps,
+                             virQEMUCapsCachePtr cache,
                              virArch arch)
 {
     virQEMUCapsPtr ret = NULL;
@@ -4642,6 +4643,22 @@ virQEMUCapsCacheLookupByArch(virQEMUCapsCachePtr cache,
             ret = virHashSearch(cache->binaries, virQEMUCapsCompareArch, &data);
         }
     }
+
+    if (ret) {
+        char *binary;
+
+        if (VIR_STRDUP(binary, ret->binary) < 0) {
+            ret = NULL;
+        } else {
+            virQEMUCapsCacheValidate(cache, binary, caps, &ret);
+            VIR_FREE(binary);
+        }
+    } else {
+        virReportError(VIR_ERR_INVALID_ARG,
+                       _("unable to find any emulator to serve '%s' "
+                         "architecture"), virArchToString(arch));
+    }
+
     virObjectRef(ret);
     virMutexUnlock(&cache->lock);
 
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 8bd5eca..beeed2e 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -473,7 +473,8 @@ virQEMUCapsPtr virQEMUCapsCacheLookupCopy(virCapsPtr caps,
                                           virQEMUCapsCachePtr cache,
                                           const char *binary,
                                           const char *machineType);
-virQEMUCapsPtr virQEMUCapsCacheLookupByArch(virQEMUCapsCachePtr cache,
+virQEMUCapsPtr virQEMUCapsCacheLookupByArch(virCapsPtr caps,
+                                            virQEMUCapsCachePtr cache,
                                             virArch arch);
 void virQEMUCapsCacheFree(virQEMUCapsCachePtr cache);
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 09a8d06..17bba48 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -18778,7 +18778,8 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn,
             goto cleanup;
         }
     } else {
-        if (!(qemuCaps = virQEMUCapsCacheLookupByArch(driver->qemuCapsCache,
+        if (!(qemuCaps = virQEMUCapsCacheLookupByArch(caps,
+                                                      driver->qemuCapsCache,
                                                       arch))) {
             virReportError(VIR_ERR_INVALID_ARG,
                            _("unable to find any emulator to serve '%s' "
-- 
2.10.2

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