mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 17:34:18 +03:00
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.
This commit is contained in:
parent
3f9868a57e
commit
747761a79a
@ -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,
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -51,9 +51,6 @@ virCapabilitiesAddHostMigrateTransport;
|
||||
virCapabilitiesAddHostNUMACell;
|
||||
virCapabilitiesAllocMachines;
|
||||
virCapabilitiesClearHostNUMACellCPUTopology;
|
||||
virCapabilitiesDefaultGuestArch;
|
||||
virCapabilitiesDefaultGuestEmulator;
|
||||
virCapabilitiesDefaultGuestMachine;
|
||||
virCapabilitiesDomainDataLookup;
|
||||
virCapabilitiesFormatXML;
|
||||
virCapabilitiesFreeMachines;
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
<uuid>c7b3edbd-edaf-9455-926a-d65c16db1800</uuid>
|
||||
<memory unit='KiB'>219200</memory>
|
||||
<os>
|
||||
<type arch='i686' machine='pc-1.0'>hvm</type>
|
||||
<type arch='x86_64' machine='pc-1.0'>hvm</type>
|
||||
<boot dev='cdrom'/>
|
||||
</os>
|
||||
<devices>
|
||||
|
@ -3,7 +3,7 @@
|
||||
<uuid>c7b3edbd-edaf-9455-926a-d65c16db1800</uuid>
|
||||
<memory unit='KiB'>219200</memory>
|
||||
<os>
|
||||
<type arch='i686' machine='pc-1.0'>hvm</type>
|
||||
<type arch='x86_64' machine='pc-1.0'>hvm</type>
|
||||
<boot dev='cdrom'/>
|
||||
</os>
|
||||
<devices>
|
||||
|
@ -3,7 +3,7 @@
|
||||
<uuid>c7b3edbd-edaf-9455-926a-d65c16db1800</uuid>
|
||||
<memory unit='KiB'>219200</memory>
|
||||
<os>
|
||||
<type arch='i686' machine='pc-1.0'>hvm</type>
|
||||
<type arch='x86_64' machine='pc-1.0'>hvm</type>
|
||||
<kernel>/vmlinuz.raw</kernel>
|
||||
<initrd>/initrd.raw</initrd>
|
||||
</os>
|
||||
|
@ -3,7 +3,7 @@
|
||||
<uuid>c7b3edbd-edaf-9455-926a-d65c16db1800</uuid>
|
||||
<memory unit='KiB'>219200</memory>
|
||||
<os>
|
||||
<type arch='i686' machine='pc-1.0'>hvm</type>
|
||||
<type arch='x86_64' machine='pc-1.0'>hvm</type>
|
||||
<boot dev='cdrom'/>
|
||||
</os>
|
||||
<devices>
|
||||
|
Loading…
Reference in New Issue
Block a user