extract and export the code to add the capabilities for a given QEMU binary in the capabilities cache. The intended use case is for testing, and make writing more test easier. --- src/qemu/qemu_capabilities.c | 31 +++++++++++++++++++++++++------ src/qemu/qemu_capabilities.h | 2 ++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 923b2a3..125869b 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2847,6 +2847,30 @@ error: return NULL; } +static virQEMUCapsPtr +virQEMUCapsCacheAddUnlocked(virQEMUCapsCachePtr cache, + const char *binary, virQEMUCapsPtr caps) +{ + virQEMUCapsPtr ret = caps; + + VIR_DEBUG("Caching capabilities %p for %s", caps, binary); + + if (virHashAddEntry(cache->binaries, binary, caps) < 0) { + virObjectUnref(caps); + ret = NULL; + } + + return ret; +} + +void +virQEMUCapsCacheAdd(virQEMUCapsCachePtr cache, + const char *binary, virQEMUCapsPtr caps) +{ + virMutexLock(&cache->lock); + virQEMUCapsCacheAddUnlocked(cache, binary, caps); + virMutexUnlock(&cache->lock); +} virQEMUCapsPtr virQEMUCapsCacheLookup(virQEMUCapsCachePtr cache, const char *binary) @@ -2867,12 +2891,7 @@ virQEMUCapsCacheLookup(virQEMUCapsCachePtr cache, const char *binary) ret = virQEMUCapsNewForBinary(binary, cache->libDir, cache->runUid, cache->runGid); if (ret) { - VIR_DEBUG("Caching capabilities %p for %s", - ret, binary); - if (virHashAddEntry(cache->binaries, binary, ret) < 0) { - virObjectUnref(ret); - ret = NULL; - } + ret = virQEMUCapsCacheAddUnlocked(cache, binary, ret); } } VIR_DEBUG("Returning caps %p for %s", ret, binary); diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index efb3f43..1814bf7 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -260,6 +260,8 @@ bool virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps); virQEMUCapsCachePtr virQEMUCapsCacheNew(const char *libDir, uid_t uid, gid_t gid); +void virQEMUCapsCacheAdd(virQEMUCapsCachePtr cache, + const char *binary, virQEMUCapsPtr caps); virQEMUCapsPtr virQEMUCapsCacheLookup(virQEMUCapsCachePtr cache, const char *binary); virQEMUCapsPtr virQEMUCapsCacheLookupCopy(virQEMUCapsCachePtr cache, -- 1.8.4.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list