This part of the code will be reused later.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/qemu/qemu_firmware.c | 47 +++++++++++++++++++++++++---------------
1 file changed, 29 insertions(+), 18 deletions(-)
diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c
index 065e0d11aa..8e9a225982 100644
--- a/src/qemu/qemu_firmware.c
+++ b/src/qemu/qemu_firmware.c
@@ -1054,6 +1054,34 @@ qemuFirmwareFetchConfigs(char ***firmwares,
}
+static bool
+qemuFirmwareMatchesMachineArch(const qemuFirmware *fw,
+ const char *machine,
+ virArch arch)
+{
+ size_t i;
+
+ for (i = 0; i < fw->ntargets; i++) {
+ size_t j;
+
+ if (arch != fw->targets[i]->architecture)
+ continue;
+
+ for (j = 0; j < fw->targets[i]->nmachines; j++) {
+ if (fnmatch(fw->targets[i]->machines[j], machine, 0) == 0)
+ break;
+ }
+
+ if (j == fw->targets[i]->nmachines)
+ continue;
+
+ break;
+ }
+
+ return i != fw->ntargets;
+}
+
+
static bool
qemuFirmwareMatchDomain(const virDomainDef *def,
const qemuFirmware *fw,
@@ -1078,24 +1106,7 @@ qemuFirmwareMatchDomain(const virDomainDef *def,
return false;
}
- for (i = 0; i < fw->ntargets; i++) {
- size_t j;
-
- if (def->os.arch != fw->targets[i]->architecture)
- continue;
-
- for (j = 0; j < fw->targets[i]->nmachines; j++) {
- if (fnmatch(fw->targets[i]->machines[j], def->os.machine, 0) == 0)
- break;
- }
-
- if (j == fw->targets[i]->nmachines)
- continue;
-
- break;
- }
-
- if (i == fw->ntargets) {
+ if (!qemuFirmwareMatchesMachineArch(fw, def->os.machine, def->os.arch)) {
VIR_DEBUG("No matching machine type in '%s'", path);
return false;
}
--
2.21.0