From 747761a79a1e9a1a441ffc7e647d39b8129cfcf4 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Fri, 17 Apr 2015 20:15:25 -0400 Subject: [PATCH] caps: Use DomainDataLookup to replace GuestDefault* This revealed that GuestDefaultEmulator was a bit buggy, capable of returning an emulator that didn't match the passed domain type. Fix up the test suite input to continue to pass. --- src/conf/capabilities.c | 122 --------------------- src/conf/capabilities.h | 15 --- src/conf/domain_conf.c | 21 ++-- src/libvirt_private.syms | 3 - src/qemu/qemu_capabilities.c | 13 ++- src/qemu/qemu_command.c | 19 ++-- src/xenconfig/xen_common.c | 37 +++---- tests/securityselinuxlabeldata/chardev.xml | 2 +- tests/securityselinuxlabeldata/disks.xml | 2 +- tests/securityselinuxlabeldata/kernel.xml | 2 +- tests/securityselinuxlabeldata/nfs.xml | 2 +- 11 files changed, 43 insertions(+), 195 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index f817ace986..2c674a8a70 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -729,128 +729,6 @@ virCapabilitiesDomainDataLookup(virCapsPtr caps, return ret; } -/** - * virCapabilitiesDefaultGuestArch: - * @caps: capabilities to query - * @ostype: guest operating system type, of enum VIR_DOMAIN_OSTYPE - * @domain: domain type to search for, of enum VIR_DOMAIN_VIRT - * - * Returns the first architecture able to run the - * requested operating system type - */ -extern virArch -virCapabilitiesDefaultGuestArch(virCapsPtr caps, - int ostype, - int domain) -{ - size_t i, j; - - /* First try to find one matching host arch */ - for (i = 0; i < caps->nguests; i++) { - if (caps->guests[i]->ostype == ostype) { - for (j = 0; j < caps->guests[i]->arch.ndomains; j++) { - if (caps->guests[i]->arch.domains[j]->type == domain && - caps->guests[i]->arch.id == caps->host.arch) - return caps->guests[i]->arch.id; - } - } - } - - /* Otherwise find the first match */ - for (i = 0; i < caps->nguests; i++) { - if (caps->guests[i]->ostype == ostype) { - for (j = 0; j < caps->guests[i]->arch.ndomains; j++) { - if (caps->guests[i]->arch.domains[j]->type == domain) - return caps->guests[i]->arch.id; - } - } - } - - return VIR_ARCH_NONE; -} - -/** - * virCapabilitiesDefaultGuestMachine: - * @caps: capabilities to query - * @ostype: guest operating system type, of enum VIR_DOMAIN_OSTYPE - * @arch: architecture to search for - * @domain: domain type to search for, of enum VIR_DOMAIN_VIRT - * - * Returns the first machine variant associated with - * the requested operating system type, architecture - * and domain type - */ -extern const char * -virCapabilitiesDefaultGuestMachine(virCapsPtr caps, - int ostype, - virArch arch, - int domain) -{ - size_t i; - - for (i = 0; i < caps->nguests; i++) { - virCapsGuestPtr guest = caps->guests[i]; - size_t j; - - if (guest->ostype != ostype || - guest->arch.id != arch) - continue; - - for (j = 0; j < guest->arch.ndomains; j++) { - virCapsGuestDomainPtr dom = guest->arch.domains[j]; - - if (dom->type != domain) - continue; - - if (!dom->info.nmachines) - break; - - return dom->info.machines[0]->name; - } - - if (guest->arch.defaultInfo.nmachines) - return caps->guests[i]->arch.defaultInfo.machines[0]->name; - } - - return NULL; -} - -/** - * virCapabilitiesDefaultGuestEmulator: - * @caps: capabilities to query - * @ostype: guest operating system type, of enum VIR_DOMAIN_OSTYPE - * @arch: architecture to search for - * @domain: domain type to search for, of enum VIR_DOMAIN_VIRT - * - * Returns the first emulator path associated with - * the requested operating system type, architecture - * and domain type - */ -extern const char * -virCapabilitiesDefaultGuestEmulator(virCapsPtr caps, - int ostype, - virArch arch, - int domain) -{ - size_t i, j; - - for (i = 0; i < caps->nguests; i++) { - char *emulator; - if (caps->guests[i]->ostype == ostype && - caps->guests[i]->arch.id == arch) { - emulator = caps->guests[i]->arch.defaultInfo.emulator; - for (j = 0; j < caps->guests[i]->arch.ndomains; j++) { - if (caps->guests[i]->arch.domains[j]->type == domain) { - if (caps->guests[i]->arch.domains[j]->info.emulator) - emulator = caps->guests[i]->arch.domains[j]->info.emulator; - } - } - return emulator; - } - } - return NULL; -} - static int virCapabilitiesFormatNUMATopology(virBufferPtr buf, size_t ncells, diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index 40221f4c58..c14fcf6765 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -284,21 +284,6 @@ void virCapabilitiesClearHostNUMACellCPUTopology(virCapsHostNUMACellCPUPtr cpu, size_t ncpus); -extern virArch -virCapabilitiesDefaultGuestArch(virCapsPtr caps, - int ostype, - int domain); -extern const char * -virCapabilitiesDefaultGuestMachine(virCapsPtr caps, - int ostype, - virArch arch, - int domain); -extern const char * -virCapabilitiesDefaultGuestEmulator(virCapsPtr caps, - int ostype, - virArch arch, - int domain); - extern char * virCapabilitiesFormatXML(virCapsPtr caps); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4d9d4b5c4a..911cee3e76 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -12959,25 +12959,18 @@ char * virDomainDefGetDefaultEmulator(virDomainDefPtr def, virCapsPtr caps) { - const char *emulator; char *retemu; + virCapsDomainDataPtr capsdata; - emulator = virCapabilitiesDefaultGuestEmulator(caps, - def->os.type, - def->os.arch, - def->virtType); + if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type, + def->os.arch, def->virtType, NULL, NULL))) + return NULL; - if (!emulator) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("no emulator for domain %s os type %s " - "on architecture %s"), - virDomainVirtTypeToString(def->virtType), - virDomainOSTypeToString(def->os.type), - virArchToString(def->os.arch)); + if (VIR_STRDUP(retemu, capsdata->emulator) < 0) { + VIR_FREE(capsdata); return NULL; } - - ignore_value(VIR_STRDUP(retemu, emulator)); + VIR_FREE(capsdata); return retemu; } diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 58430613f1..48785d1ddf 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -51,9 +51,6 @@ virCapabilitiesAddHostMigrateTransport; virCapabilitiesAddHostNUMACell; virCapabilitiesAllocMachines; virCapabilitiesClearHostNUMACellCPUTopology; -virCapabilitiesDefaultGuestArch; -virCapabilitiesDefaultGuestEmulator; -virCapabilitiesDefaultGuestMachine; virCapabilitiesDomainDataLookup; virCapabilitiesFormatXML; virCapabilitiesFreeMachines; diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index ad50360b30..01ed1e275f 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -1888,25 +1888,26 @@ int virQEMUCapsGetDefaultVersion(virCapsPtr caps, virQEMUCapsCachePtr capsCache, unsigned int *version) { - const char *binary; virQEMUCapsPtr qemucaps; virArch hostarch; + virCapsDomainDataPtr capsdata; if (*version > 0) return 0; hostarch = virArchFromHost(); - if ((binary = virCapabilitiesDefaultGuestEmulator(caps, - VIR_DOMAIN_OSTYPE_HVM, - hostarch, - VIR_DOMAIN_VIRT_QEMU)) == NULL) { + if (!(capsdata = virCapabilitiesDomainDataLookup(caps, + VIR_DOMAIN_OSTYPE_HVM, hostarch, VIR_DOMAIN_VIRT_QEMU, + NULL, NULL))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot find suitable emulator for %s"), virArchToString(hostarch)); return -1; } - if (!(qemucaps = virQEMUCapsCacheLookup(capsCache, binary))) + qemucaps = virQEMUCapsCacheLookup(capsCache, capsdata->emulator); + VIR_FREE(capsdata); + if (!qemucaps) return -1; *version = virQEMUCapsGetVersion(qemucaps); diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 8e7b689cc2..29b876ee18 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -13145,14 +13145,17 @@ qemuParseCommandLine(virCapsPtr qemuCaps, } if (!def->os.machine) { - const char *defaultMachine = - virCapabilitiesDefaultGuestMachine(qemuCaps, - def->os.type, - def->os.arch, - def->virtType); - if (defaultMachine != NULL) - if (VIR_STRDUP(def->os.machine, defaultMachine) < 0) - goto error; + virCapsDomainDataPtr capsdata; + + if (!(capsdata = virCapabilitiesDomainDataLookup(qemuCaps, def->os.type, + def->os.arch, def->virtType, NULL, NULL))) + goto error; + + if (VIR_STRDUP(def->os.machine, capsdata->machinetype) < 0) { + VIR_FREE(capsdata); + goto error; + } + VIR_FREE(capsdata); } if (!nographics && def->ngraphics == 0) { diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index 728b91011d..0dfe60e899 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -983,15 +983,15 @@ xenParseEmulatedDevices(virConfPtr conf, virDomainDefPtr def) static int xenParseGeneralMeta(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps) { - const char *defaultMachine; + virCapsDomainDataPtr capsdata = NULL; const char *str; - int hvm = 0; + int hvm = 0, ret = -1; if (xenConfigCopyString(conf, "name", &def->name) < 0) - return -1; + goto out; if (xenConfigGetUUID(conf, "uuid", def->uuid) < 0) - return -1; + goto out; if ((xenConfigGetString(conf, "builder", &str, "linux") == 0) && STREQ(str, "hvm")) @@ -999,27 +999,18 @@ xenParseGeneralMeta(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps) def->os.type = (hvm ? VIR_DOMAIN_OSTYPE_HVM : VIR_DOMAIN_OSTYPE_XEN); - def->os.arch = - virCapabilitiesDefaultGuestArch(caps, - def->os.type, - def->virtType); - if (!def->os.arch) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("no supported architecture for os type '%s'"), - virDomainOSTypeToString(def->os.type)); - return -1; - } + if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type, + VIR_ARCH_NONE, def->virtType, NULL, NULL))) + goto out; - defaultMachine = virCapabilitiesDefaultGuestMachine(caps, - def->os.type, - def->os.arch, - def->virtType); - if (defaultMachine != NULL) { - if (VIR_STRDUP(def->os.machine, defaultMachine) < 0) - return -1; - } + def->os.arch = capsdata->arch; + if (VIR_STRDUP(def->os.machine, capsdata->machinetype) < 0) + goto out; - return 0; + ret = 0; + out: + VIR_FREE(capsdata); + return ret; } diff --git a/tests/securityselinuxlabeldata/chardev.xml b/tests/securityselinuxlabeldata/chardev.xml index 64b6b5f068..33002e4a8e 100644 --- a/tests/securityselinuxlabeldata/chardev.xml +++ b/tests/securityselinuxlabeldata/chardev.xml @@ -3,7 +3,7 @@ c7b3edbd-edaf-9455-926a-d65c16db1800 219200 - hvm + hvm diff --git a/tests/securityselinuxlabeldata/disks.xml b/tests/securityselinuxlabeldata/disks.xml index 33e8763bfb..08f05876be 100644 --- a/tests/securityselinuxlabeldata/disks.xml +++ b/tests/securityselinuxlabeldata/disks.xml @@ -3,7 +3,7 @@ c7b3edbd-edaf-9455-926a-d65c16db1800 219200 - hvm + hvm diff --git a/tests/securityselinuxlabeldata/kernel.xml b/tests/securityselinuxlabeldata/kernel.xml index 0fd551da49..1e0cd1537f 100644 --- a/tests/securityselinuxlabeldata/kernel.xml +++ b/tests/securityselinuxlabeldata/kernel.xml @@ -3,7 +3,7 @@ c7b3edbd-edaf-9455-926a-d65c16db1800 219200 - hvm + hvm /vmlinuz.raw /initrd.raw diff --git a/tests/securityselinuxlabeldata/nfs.xml b/tests/securityselinuxlabeldata/nfs.xml index 46a14402e0..cac12ddb86 100644 --- a/tests/securityselinuxlabeldata/nfs.xml +++ b/tests/securityselinuxlabeldata/nfs.xml @@ -3,7 +3,7 @@ c7b3edbd-edaf-9455-926a-d65c16db1800 219200 - hvm + hvm