The algorithm is quite simple:
If the emulator matches a guest's domain:
if domain has machine type info:
check the domain's machine type info
else
check the guest's default machine type info
else if the emulator matches the guest's default emulator:
check the guest's default machine type info
The previous implementation was incorrectly falling back to the default
machine type info if the domain's machine type info didn't have an
alias.
* src/qemu_driver.c: simplify and fix qemudCanonicalizeMachine()
---
src/qemu_driver.c | 33 +++++++++++++++------------------
1 files changed, 15 insertions(+), 18 deletions(-)
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index f2b0bec..fad3939 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -4789,30 +4789,27 @@ qemudCanonicalizeMachine(struct qemud_driver *driver,
virDomainDefPtr def)
for (i = 0; i < driver->caps->nguests; i++) {
virCapsGuestPtr guest = driver->caps->guests[i];
+ virCapsGuestDomainInfoPtr info;
int j;
for (j = 0; j < guest->arch.ndomains; j++) {
- virCapsGuestDomainPtr dom = guest->arch.domains[j];
+ info = &guest->arch.domains[j]->info;
- if (dom->info.emulator &&
- STREQ(dom->info.emulator, def->emulator)) {
- if (qemudCanonicalizeMachineFromInfo(def, &dom->info,
- &canonical) < 0)
- return -1;
- if (canonical)
- goto out;
- break;
- }
+ if (!info->emulator || !STREQ(info->emulator, def->emulator))
+ continue;
+
+ if (!info->nmachines)
+ info = &guest->arch.defaultInfo;
+
+ if (qemudCanonicalizeMachineFromInfo(def, info, &canonical) < 0)
+ return -1;
+ goto out;
}
- /* if we matched one of the domain's emulators, or if
- * we match the default emulator
- */
- if (j < guest->arch.ndomains ||
- (guest->arch.defaultInfo.emulator &&
- STREQ(guest->arch.defaultInfo.emulator, def->emulator))) {
- if (qemudCanonicalizeMachineFromInfo(def, &guest->arch.defaultInfo,
- &canonical) < 0)
+ info = &guest->arch.defaultInfo;
+
+ if (info->emulator && STREQ(info->emulator, def->emulator)) {
+ if (qemudCanonicalizeMachineFromInfo(def, info, &canonical) < 0)
return -1;
goto out;
}
--
1.6.2.5