[RFC PATCH 1/3] Implement virQEMUCapsCache mockup

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

 



This patch introduces qemuTestMakeCapsCache() function, which creates
capability cache containing predefined set of capabilities associated
with predefined binary.

For simplicity of integration binary name is deduced from test name,
which follows a simple scheme of being prefixed with architecture
name, with some exceptions.

Signed-off-by: Pavel Fedin <p.fedin@xxxxxxxxxxx>
---
 src/qemu/qemu_capabilities.c | 10 +---------
 src/qemu/qemu_capspriv.h     | 36 +++++++++++++++++++++++++++++++++++
 tests/testutilsqemu.c        | 45 ++++++++++++++++++++++++++++++++++++++++++++
 tests/testutilsqemu.h        |  3 +++
 4 files changed, 85 insertions(+), 9 deletions(-)
 create mode 100644 src/qemu/qemu_capspriv.h
 mode change 100644 => 100755 tests/testutilsqemu.c

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 43d11af..62b1aea 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -42,6 +42,7 @@
 #include "virstring.h"
 #include "qemu_hostdev.h"
 #include "qemu_domain.h"
+#include "qemu_capspriv.h"
 
 #include <fcntl.h>
 #include <sys/stat.h>
@@ -327,15 +328,6 @@ struct _virQEMUCaps {
     unsigned int *machineMaxCpus;
 };
 
-struct _virQEMUCapsCache {
-    virMutex lock;
-    virHashTablePtr binaries;
-    char *libDir;
-    char *cacheDir;
-    uid_t runUid;
-    gid_t runGid;
-};
-
 struct virQEMUCapsSearchData {
     virArch arch;
 };
diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h
new file mode 100644
index 0000000..f915ea9
--- /dev/null
+++ b/src/qemu/qemu_capspriv.h
@@ -0,0 +1,36 @@
+/*
+ * qemu_capspriv.h: private declarations for QEMU capabilities generation
+ *
+ * Copyright (C) 2015 Samsung Electronics Co. Ltd
+ * Copyright (C) 2015 Pavel Fedin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Author: Pavel Fedin <p.fedin@xxxxxxxxxxx>
+ */
+
+#ifndef __QEMU_CAPSPRIV_H__
+#define __QEMU_CAPSPRIV_H__
+
+struct _virQEMUCapsCache {
+    virMutex lock;
+    virHashTablePtr binaries;
+    char *libDir;
+    char *cacheDir;
+    uid_t runUid;
+    gid_t runGid;
+};
+
+#endif
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
old mode 100644
new mode 100755
index a2f4299..3dc50f2
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -8,6 +8,7 @@
 # include "cpu_conf.h"
 # include "qemu/qemu_driver.h"
 # include "qemu/qemu_domain.h"
+# include "qemu/qemu_capspriv.h"
 # include "virstring.h"
 
 # define VIR_FROM_THIS VIR_FROM_QEMU
@@ -526,4 +527,48 @@ qemuTestParseCapabilities(const char *capsFile)
     xmlXPathFreeContext(ctxt);
     return NULL;
 }
+
+virQEMUCapsCachePtr
+qemuTestMakeCapsCache(const char *test, virQEMUCapsPtr caps)
+{
+    virQEMUCapsCachePtr cache;
+    const char *binary;
+
+    cache = virQEMUCapsCacheNew("/dev/null", "/dev/null",  0, 0);
+    if (!cache)
+        return NULL;
+
+    if (caps) {
+        /* Our caps were created artificially, so we don't want
+         * virQEMUCapsCacheFree() to attempt to deallocate them */
+        virObjectRef(caps);
+    } else {
+        caps = virQEMUCapsNew();
+        if (!caps) {
+            virQEMUCapsCacheFree(cache);
+            return NULL;
+        }
+    }
+
+    if (STRPREFIX(test, "aarch64-"))
+        binary = "/usr/bin/qemu-system-aarch64";
+    else if (STRPREFIX(test, "arm-"))
+        binary = "/usr/bin/qemu-system-arm";
+    else if (STRPREFIX(test, "pseries-"))
+        binary = "/usr/bin/qemu-system-ppc64";
+    else if (STRPREFIX(test, "s390-"))
+        binary = "/usr/bin/qemu-system-s390x";
+    else if (strstr(test, "keywrap-")) /* May be rename these ? */
+        binary = "/usr/bin/qemu-system-s390x";
+    else
+        binary = "/usr/bin/qemu";
+
+    if (virHashAddEntry(cache->binaries, binary, caps) < 0) {
+        virQEMUCapsCacheFree(cache);
+        virObjectUnref(caps);
+        return NULL;
+    }
+
+    return cache;
+}
 #endif
diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h
index 0ec5dad..6fe923b 100644
--- a/tests/testutilsqemu.h
+++ b/tests/testutilsqemu.h
@@ -16,4 +16,7 @@ extern virCPUDefPtr cpuHaswell;
 void testQemuCapsSetCPU(virCapsPtr caps,
                         virCPUDefPtr hostCPU);
 
+virQEMUCapsCachePtr qemuTestMakeCapsCache(const char *test,
+                                          virQEMUCapsPtr caps);
+
 #endif
-- 
2.1.4

--
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]