Hook up qemuCapsExtractVersionInfo capabilities api to the emulator cache framework by splitting into two parts: - qemuCapsExtractVersionInfo() looks up emulator in cache and returns the cached version and flags. Cache look up may fill or refresh the cache. - wrap the part of the original qemuCapsExtractVersionInfo() with qemuCapsCacheVersionInfo() to run the specified binary and update the cached information for this binary. --- src/qemu/qemu_capabilities.c | 51 ++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 19 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 @@ -1498,16 +1498,37 @@ int qemuCapsExtractVersionInfo(const cha unsigned int *retversion, virBitmapPtr *retflags) { + qemuEmulatorCachePtr emulator; + int ret = -1; + + emulator = qemuEmulatorCachedInfoGet(QEMU_PROBE_VERSION_INFO, qemu, arch); + if (emulator) { + if (retflags) + *retflags = virBitmapDup(emulator->caps); + if (retversion) + *retversion = emulator->version; + ret = 0; + } else { + if (retflags) + *retflags = 0; + if (retversion) + *retversion = 0; + } + + qemuEmulatorCachedInfoRelease(emulator); + return ret; +} + +static int +qemuCapsCacheVersionInfo(qemuEmulatorCachePtr emulator) +{ int ret = -1; unsigned int version, is_kvm, kvm_version; virBitmapPtr flags = NULL; char *help = NULL; + char *qemu = emulator->path, *arch = emulator->arch; virCommandPtr cmd; - - if (retflags) - *retflags = NULL; - if (retversion) - *retversion = 0; + VIR_DEBUG("Caching Version Info for %s - %s", qemu, arch ?: "no-arch"); /* Make sure the binary we are about to try exec'ing exists. * Technically we could catch the exec() failure, but that's @@ -1532,8 +1553,8 @@ int qemuCapsExtractVersionInfo(const cha goto cleanup; /* Currently only x86_64 and i686 support PCI-multibus. */ - if (STREQLEN(arch, "x86_64", 6) || - STREQLEN(arch, "i686", 4)) { + if (arch && (STREQLEN(arch, "x86_64", 6) || + STREQLEN(arch, "i686", 4))) { qemuCapsSet(flags, QEMU_CAPS_PCI_MULTIBUS); } @@ -1544,12 +1565,10 @@ int qemuCapsExtractVersionInfo(const cha qemuCapsExtractDeviceStr(qemu, flags) < 0) goto cleanup; - if (retversion) - *retversion = version; - if (retflags) { - *retflags = flags; - flags = NULL; - } + emulator->version = version; + qemuCapsFree(emulator->caps); /* for possible refresh */ + emulator->caps = flags; + flags = NULL; ret = 0; @@ -1561,12 +1580,6 @@ cleanup: return ret; } -static int -qemuCapsCacheVersionInfo(qemuEmulatorCachePtr emulator) -{ - return emulator ? 0 : 1; -} - static void uname_normalize (struct utsname *ut) { -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list