提交 7948ad41 编写于 作者: A Andrea Bolognani

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: NAndrea Bolognani <abologna@redhat.com>
上级 e9e3a3c0
......@@ -4752,26 +4752,27 @@ virQEMUCapsCacheLookupByArch(virFileCachePtr cache,
virArch arch)
{
virQEMUCapsPtr ret = NULL;
virArch target;
struct virQEMUCapsSearchData data = { .arch = arch };
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);
}
}
virArch archs[] = {
arch,
virQEMUCapsFindTarget(virArchFromHost(), arch),
};
size_t j;
if (!ret) {
virReportError(VIR_ERR_INVALID_ARG,
_("unable to find any emulator to serve '%s' "
"architecture"), virArchToString(arch));
for (j = 0; j < ARRAY_CARDINALITY(archs); j++) {
struct virQEMUCapsSearchData data = {
.arch = archs[j],
};
ret = virFileCacheLookupByFunc(cache, virQEMUCapsCompareArch, &data);
if (ret)
goto done;
}
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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册