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