The QEMU impl of the callback can directly use the QEMU capabilities
cache to resolve the emulator binary name, allowing virCapsPtr to be
dropped.
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
src/conf/domain_conf.c | 2 +-
src/conf/domain_conf.h | 1 -
src/qemu/qemu_capabilities.c | 28 ++++++++++++++++++++--------
src/qemu/qemu_capabilities.h | 2 ++
src/qemu/qemu_domain.c | 11 +++++++----
tests/testutilsqemu.c | 16 ++++++++++++++++
6 files changed, 46 insertions(+), 14 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 8dd1ff1017..7327752810 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5824,7 +5824,7 @@ virDomainDefPostParse(virDomainDefPtr def,
/* call the basic post parse callback */
if (xmlopt->config.domainPostParseBasicCallback) {
- ret = xmlopt->config.domainPostParseBasicCallback(def, caps,
+ ret = xmlopt->config.domainPostParseBasicCallback(def,
xmlopt->config.priv);
if (virDomainDefPostParseCheckFailure(def, parseFlags, ret) < 0)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 7e925f45d8..cdbd42351f 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2627,7 +2627,6 @@ typedef enum {
* parseOpaque is used. This callback is run prior to
* virDomainDefPostParseCallback. */
typedef int (*virDomainDefPostParseBasicCallback)(virDomainDefPtr def,
- virCapsPtr caps,
void *opaque);
/* Called once after everything else has been parsed, for adjusting
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 7a62dfb1a2..bfe59a1eff 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -799,16 +799,12 @@ virQEMUCapsFindBinaryForArch(virArch hostarch,
return ret;
}
-static int
-virQEMUCapsInitGuest(virCapsPtr caps,
- virFileCachePtr cache,
- virArch hostarch,
- virArch guestarch)
+
+char *
+virQEMUCapsGetDefaultEmulator(virArch hostarch,
+ virArch guestarch)
{
char *binary = NULL;
- virQEMUCapsPtr qemuCaps = NULL;
- int ret = -1;
-
/* Check for existence of base emulator, or alternate base
* which can be used with magic cpu choice
*/
@@ -819,6 +815,22 @@ virQEMUCapsInitGuest(virCapsPtr caps,
if (virQEMUCapsGuestIsNative(hostarch, guestarch) && !binary)
binary = g_strdup("/usr/libexec/qemu-kvm");
+ return binary;
+}
+
+
+static int
+virQEMUCapsInitGuest(virCapsPtr caps,
+ virFileCachePtr cache,
+ virArch hostarch,
+ virArch guestarch)
+{
+ char *binary = NULL;
+ virQEMUCapsPtr qemuCaps = NULL;
+ int ret = -1;
+
+ binary = virQEMUCapsGetDefaultEmulator(hostarch, guestarch);
+
/* Ignore binary if extracting version info fails */
if (binary) {
if (!(qemuCaps = virQEMUCapsCacheLookup(cache, binary))) {
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index a8a5c38d73..9b380574f5 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -627,6 +627,8 @@ const char *virQEMUCapsGetMachineDefaultCPU(virQEMUCapsPtr qemuCaps,
void virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps,
virDomainVirtType virtType,
const char *machineType);
+char * virQEMUCapsGetDefaultEmulator(virArch hostarch,
+ virArch guestarch);
virFileCachePtr virQEMUCapsCacheNew(const char *libDir,
const char *cacheDir,
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 362d644475..3c06b8a104 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4677,13 +4677,16 @@ qemuDomainDefTsegPostParse(virDomainDefPtr def,
static int
qemuDomainDefPostParseBasic(virDomainDefPtr def,
- virCapsPtr caps,
void *opaque G_GNUC_UNUSED)
{
+ virQEMUDriverPtr driver = opaque;
+
/* check for emulator and create a default one if needed */
- if (!def->emulator &&
- !(def->emulator = virDomainDefGetDefaultEmulator(def, caps)))
- return 1;
+ if (!def->emulator) {
+ if (!(def->emulator = virQEMUCapsGetDefaultEmulator(
+ driver->hostarch, def->os.arch)))
+ return 1;
+ }
return 0;
}
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index c24b3098a5..38be2cfe42 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -93,6 +93,22 @@ static const char *const *kvm_machines[VIR_ARCH_LAST] = {
[VIR_ARCH_S390X] = s390x_machines,
};
+
+char *
+virFindFileInPath(const char *file)
+{
+ if (g_str_has_prefix(file, "qemu-system") ||
+ g_str_equal(file, "qemu-kvm")) {
+ return g_strdup_printf("/usr/bin/%s", file);
+ }
+
+ /* Nothing in tests should be relying on real files
+ * in host OS, so we return NULL as to try to force
+ * an error in such a case
+ */
+ return NULL;
+}
+
static int
testQemuAddGuest(virCapsPtr caps,
virArch arch)
--
2.23.0