[libvirt] [PATCH RFC 5/8] qemu: hook up qemuCapsProbeMachineTypes

Lee Schermerhorn lee.schermerhorn at hp.com
Sun Mar 11 18:45:18 UTC 2012


Hook up qemuCapsProbeMachineTypes capabilities api to the emulator
cache framework:

  - qemuCapsProbeMachineTypes() looks up emulator in cache and
    returns the version and flags.
  - wrap the part of the original qemuCapsProbeMachineTypes() with
    qemuCapsCacheMachineTypes() to run the specified binary and update
    the cached machine types supported by this binary.
---
 src/qemu/qemu_capabilities.c |   39 ++++++++++++++++++++++++++++++++-------
 1 file changed, 32 insertions(+), 7 deletions(-)

Index: libvirt-0.9.10/src/qemu/qemu_capabilities.c
===================================================================
--- libvirt-0.9.10.orig/src/qemu/qemu_capabilities.c
+++ libvirt-0.9.10/src/qemu/qemu_capabilities.c
@@ -307,6 +307,11 @@ qemuCapsParseMachineTypesStr(const char
         }
     } while ((p = next));
 
+    /*
+     * Free in case of possible cache refresh
+     */
+    virCapabilitiesFreeMachines(*machines, *nmachines);
+
     *machines = list;
     *nmachines = nitems;
 
@@ -323,10 +328,36 @@ qemuCapsProbeMachineTypes(const char *bi
                           virCapsGuestMachinePtr **machines,
                           int *nmachines)
 {
+    qemuEmulatorCachePtr emulator;
+    int ret = -1;
+
+    emulator = qemuEmulatorCachedInfoGet(QEMU_PROBE_MACHINE_TYPES, binary, NULL);
+    if (emulator) {
+        ret = 0;
+        if (machines)
+            *machines = virCapabilitiesDupMachines(emulator->machines, emulator->nmachines);
+        if (nmachines)
+            *nmachines = emulator->nmachines;
+    } else {
+        if (machines)
+            *machines = NULL;
+        if (nmachines)
+            *nmachines = 0;
+    }
+
+    qemuEmulatorCachedInfoRelease(emulator);
+    return ret;
+}
+
+static int
+qemuCapsCacheMachineTypes(qemuEmulatorCachePtr emulator)
+{
+    char *binary = emulator->path;
     char *output;
     int ret = -1;
     virCommandPtr cmd;
     int status;
+    VIR_DEBUG("Caching Machine Types for %s", binary);
 
     /* Make sure the binary we are about to try exec'ing exists.
      * Technically we could catch the exec() failure, but that's
@@ -346,7 +377,7 @@ qemuCapsProbeMachineTypes(const char *bi
     if (virCommandRun(cmd, &status) < 0)
         goto cleanup;
 
-    if (qemuCapsParseMachineTypesStr(output, machines, nmachines) < 0)
+    if (qemuCapsParseMachineTypesStr(output, &emulator->machines, &emulator->nmachines) < 0)
         goto cleanup;
 
     ret = 0;
@@ -359,12 +390,6 @@ cleanup:
 }
 
 static int
-qemuCapsCacheMachineTypes(qemuEmulatorCachePtr emulator)
-{
-	return emulator ? 0 : 1;
-}
-
-static int
 qemuCapsGetOldMachinesFromInfo(virCapsGuestDomainInfoPtr info,
                                const char *emulator,
                                time_t emulator_mtime,




More information about the libvir-list mailing list