In near future we will want to check whether capabilities for
given virtType exist, but report an error on our own. Introduce
reportError argument which makes the function report an error iff
set.
In one specific case (virQEMUCapsGetDefaultVersion()) we were
even overwriting (more specific) error message reportd by
virCapabilitiesDomainDataLookup(). Drop that too.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/conf/capabilities.c | 20 +++++++++++++++-----
src/conf/capabilities.h | 3 ++-
src/conf/domain_conf.c | 5 ++++-
src/libxl/xen_common.c | 5 ++++-
src/qemu/qemu_capabilities.c | 10 +++++-----
5 files changed, 30 insertions(+), 13 deletions(-)
diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index 02298e40a3..5a0c7de646 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -591,7 +591,8 @@ virCapabilitiesDomainDataLookupInternal(virCaps *caps,
virArch arch,
virDomainVirtType domaintype,
const char *emulator,
- const char *machinetype)
+ const char *machinetype,
+ bool reportError)
{
virCapsGuest *foundguest = NULL;
virCapsGuestDomain *founddomain = NULL;
@@ -680,6 +681,10 @@ virCapabilitiesDomainDataLookupInternal(virCaps *caps,
/* XXX check default_emulator, see how it uses this */
if (!foundguest) {
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
+
+ if (!reportError)
+ return NULL;
+
if (ostype)
virBufferAsprintf(&buf, "ostype=%s ",
virDomainOSTypeToString(ostype));
@@ -726,6 +731,7 @@ virCapabilitiesDomainDataLookupInternal(virCaps *caps,
* @domaintype: domain type to search for, of enum virDomainVirtType
* @emulator: Emulator path to search for
* @machinetype: Machine type to search for
+ * @reportError: whether to report error if no match is found
*
* Search capabilities for the passed values, and if found return
* virCapabilitiesDomainDataLookup filled in with the default values
@@ -736,7 +742,8 @@ virCapabilitiesDomainDataLookup(virCaps *caps,
virArch arch,
int domaintype,
const char *emulator,
- const char *machinetype)
+ const char *machinetype,
+ bool reportError)
{
virCapsDomainData *ret;
@@ -745,14 +752,16 @@ virCapabilitiesDomainDataLookup(virCaps *caps,
ret = virCapabilitiesDomainDataLookupInternal(caps, ostype,
caps->host.arch,
domaintype,
- emulator, machinetype);
+ emulator, machinetype,
+ reportError);
if (ret)
return ret;
}
return virCapabilitiesDomainDataLookupInternal(caps, ostype,
arch, domaintype,
- emulator, machinetype);
+ emulator, machinetype,
+ reportError);
}
@@ -767,7 +776,8 @@ virCapabilitiesDomainSupported(virCaps *caps,
capsdata = virCapabilitiesDomainDataLookup(caps, ostype,
arch,
virttype,
- NULL, NULL);
+ NULL, NULL,
+ true);
return capsdata != NULL;
}
diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h
index 52e395de14..c67b3ce397 100644
--- a/src/conf/capabilities.h
+++ b/src/conf/capabilities.h
@@ -309,7 +309,8 @@ virCapabilitiesDomainDataLookup(virCaps *caps,
virArch arch,
int domaintype,
const char *emulator,
- const char *machinetype);
+ const char *machinetype,
+ bool reportError);
bool
virCapabilitiesDomainSupported(virCaps *caps,
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 3597959e33..2a64a4a1ad 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -15811,8 +15811,11 @@ virDomainDefGetDefaultEmulator(virDomainDef *def,
g_autofree virCapsDomainData *capsdata = NULL;
if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type,
- def->os.arch, def->virtType, NULL, NULL)))
+ def->os.arch,
+ def->virtType, NULL, NULL,
+ true))) {
return NULL;
+ }
retemu = g_strdup(capsdata->emulator);
diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c
index d5a0399613..79eb593432 100644
--- a/src/libxl/xen_common.c
+++ b/src/libxl/xen_common.c
@@ -1387,8 +1387,11 @@ xenParseGeneralMeta(virConf *conf, virDomainDef *def, virCaps
*caps)
}
if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type,
- VIR_ARCH_NONE, def->virtType, NULL, NULL)))
+ VIR_ARCH_NONE,
+ def->virtType, NULL,
+ NULL, true))) {
goto out;
+ }
def->os.arch = capsdata->arch;
def->os.machine = g_strdup(capsdata->machinetype);
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index ab11a929a3..9de2626b9b 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1782,11 +1782,11 @@ int virQEMUCapsGetDefaultVersion(virCaps *caps,
hostarch = virArchFromHost();
if (!(capsdata = virCapabilitiesDomainDataLookup(caps,
- VIR_DOMAIN_OSTYPE_HVM, hostarch, VIR_DOMAIN_VIRT_NONE,
- NULL, NULL))) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Cannot find suitable emulator for %1$s"),
- virArchToString(hostarch));
+ VIR_DOMAIN_OSTYPE_HVM,
+ hostarch,
+ VIR_DOMAIN_VIRT_NONE,
+ NULL, NULL,
+ true))) {
return -1;
}
--
2.43.0