]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: caps: Use unique key for domCaps caching
authorCole Robinson <crobinso@redhat.com>
Tue, 15 Oct 2019 15:47:10 +0000 (11:47 -0400)
committerCole Robinson <crobinso@redhat.com>
Thu, 17 Oct 2019 18:59:41 +0000 (14:59 -0400)
When searching qemuCaps->domCapsCache for existing domCaps data,
we check for a matching pair of arch+virttype+machine+emulator. However
for the hash table key we only use the machine string. So if the
cache already contains:

  x86_64 + kvm + pc + /usr/bin/qemu-kvm

But a new VM is defined with

  x86_64 + qemu + pc + /usr/bin/qemu-kvm

We correctly fail to find matching cached domCaps, but then attempt
to use a colliding key with virHashAddEntry

Fix this by building a hash key from the 4 values, not just machine

Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
src/qemu/qemu_conf.c

index 01ac6faed8b0de70db25b67746af1eaa75937aec..65cd959cf8d045b443a1024c738270d13faa9774 100644 (file)
@@ -1396,6 +1396,8 @@ virQEMUDriverGetDomainCapabilities(virQEMUDriverPtr driver,
     domCaps = virHashSearch(domCapsCache,
                             virQEMUDriverSearchDomcaps, &data, NULL);
     if (!domCaps) {
+        g_autofree char *key = NULL;
+
         /* hash miss, build new domcaps */
         if (!(domCaps = virDomainCapsNew(data.path, data.machine,
                                          data.arch, data.virttype)))
@@ -1406,7 +1408,14 @@ virQEMUDriverGetDomainCapabilities(virQEMUDriverPtr driver,
                                       cfg->firmwares, cfg->nfirmwares) < 0)
             return NULL;
 
-        if (virHashAddEntry(domCapsCache, machine, domCaps) < 0)
+        if (virAsprintf(&key, "%d:%d:%s:%s",
+                        data.arch,
+                        data.virttype,
+                        NULLSTR(data.machine),
+                        NULLSTR(data.path)) < 0)
+            return NULL;
+
+        if (virHashAddEntry(domCapsCache, key, domCaps) < 0)
             return NULL;
     }