The API may come handy if somebody has an architecture and wants to
look through available qemus if the architecture is supported or not.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/qemu/qemu_capabilities.c | 33 +++++++++++++++++++++++++++++++++
src/qemu/qemu_capabilities.h | 2 ++
2 files changed, 35 insertions(+)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 8e0a550..b357255 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -299,6 +299,10 @@ struct _virQEMUCapsCache {
gid_t runGid;
};
+struct virQEMUCapsSearchData {
+ virArch arch;
+};
+
static virClassPtr virQEMUCapsClass;
static void virQEMUCapsDispose(void *obj);
@@ -3465,6 +3469,35 @@ virQEMUCapsCacheLookupCopy(virQEMUCapsCachePtr cache, const char
*binary)
}
+static int
+virQEMUCapsCompareArch(const void *payload,
+ const void *name ATTRIBUTE_UNUSED,
+ const void *opaque)
+{
+ struct virQEMUCapsSearchData *data = (struct virQEMUCapsSearchData *) opaque;
+ const virQEMUCaps *qemuCaps = payload;
+
+ return qemuCaps->arch == data->arch;
+}
+
+
+virQEMUCapsPtr
+virQEMUCapsCacheLookupByArch(virQEMUCapsCachePtr cache,
+ virArch arch)
+{
+ virQEMUCapsPtr ret = NULL;
+ struct virQEMUCapsSearchData data = { .arch = arch };
+
+ virMutexLock(&cache->lock);
+ ret = virHashSearch(cache->binaries, virQEMUCapsCompareArch, &data);
+ VIR_DEBUG("Returning caps %p for arch %s", ret, virArchToString(arch));
+ virObjectRef(ret);
+ virMutexUnlock(&cache->lock);
+
+ return ret;
+}
+
+
void
virQEMUCapsCacheFree(virQEMUCapsCachePtr cache)
{
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 53ebe90..1eb92b5 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -274,6 +274,8 @@ virQEMUCapsPtr virQEMUCapsCacheLookup(virQEMUCapsCachePtr cache,
const char *binary);
virQEMUCapsPtr virQEMUCapsCacheLookupCopy(virQEMUCapsCachePtr cache,
const char *binary);
+virQEMUCapsPtr virQEMUCapsCacheLookupByArch(virQEMUCapsCachePtr cache,
+ virArch arch);
void virQEMUCapsCacheFree(virQEMUCapsCachePtr cache);
virCapsPtr virQEMUCapsInit(virQEMUCapsCachePtr cache);
--
1.8.5.5