From 36c6d40943b10f498cb32e0827aa058565ae54d6 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Fri, 8 Mar 2024 14:43:13 +0100 Subject: [PATCH] capabilities: Allow suppressing error message from virCapabilitiesDomainDataLookup() 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 Reviewed-by: Peter Krempa --- src/conf/capabilities.c | 22 ++++++++++++++++------ 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, 31 insertions(+), 14 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 02298e40a3..88c6b84c7c 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)); @@ -699,7 +704,7 @@ virCapabilitiesDomainDataLookupInternal(virCaps *caps, virReportError(VIR_ERR_INVALID_ARG, _("could not find capabilities for %1$s"), virBufferCurrentContent(&buf)); - return ret; + return NULL; } ret = g_new0(virCapsDomainData, 1); @@ -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 60d9a57387..208b53fb5a 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -1784,11 +1784,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; }