[PATCH for 1.2.7 5/8] qemu_capabilities: Introduce virQEMUCapsCacheLookupByArch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]