1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-26 03:21:44 +03:00

qemu: Refactor virQEMUCapsCacheLookupByArch()

The new implementation contains less duplicated code and
is easier to extend.

This commit is best viewed with 'git show -w'.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
This commit is contained in:
Andrea Bolognani 2018-09-14 14:29:51 +02:00
parent e9e3a3c0fe
commit 7948ad4129

View File

@ -4752,26 +4752,27 @@ virQEMUCapsCacheLookupByArch(virFileCachePtr cache,
virArch arch)
{
virQEMUCapsPtr ret = NULL;
virArch target;
struct virQEMUCapsSearchData data = { .arch = arch };
virArch archs[] = {
arch,
virQEMUCapsFindTarget(virArchFromHost(), arch),
};
size_t j;
ret = virFileCacheLookupByFunc(cache, virQEMUCapsCompareArch, &data);
if (!ret) {
/* If the first attempt at finding capabilities has failed, try
* again using the QEMU target as lookup key instead */
target = virQEMUCapsFindTarget(virArchFromHost(), data.arch);
if (target != data.arch) {
data.arch = target;
ret = virFileCacheLookupByFunc(cache, virQEMUCapsCompareArch, &data);
}
for (j = 0; j < ARRAY_CARDINALITY(archs); j++) {
struct virQEMUCapsSearchData data = {
.arch = archs[j],
};
ret = virFileCacheLookupByFunc(cache, virQEMUCapsCompareArch, &data);
if (ret)
goto done;
}
if (!ret) {
virReportError(VIR_ERR_INVALID_ARG,
_("unable to find any emulator to serve '%s' "
"architecture"), virArchToString(arch));
}
virReportError(VIR_ERR_INVALID_ARG,
_("unable to find any emulator to serve '%s' "
"architecture"), virArchToString(arch));
done:
VIR_DEBUG("Returning caps %p for arch %s", ret, virArchToString(arch));
return ret;