mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
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 <mprivozn@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
1cc5d7df9a
commit
36c6d40943
@ -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;
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user