mirror of https://gitee.com/openkylin/libvirt.git
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;
|
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
|
static int
|
||||||
virCapabilitiesFormatNUMATopology(virBufferPtr buf,
|
virCapabilitiesFormatNUMATopology(virBufferPtr buf,
|
||||||
size_t ncells,
|
size_t ncells,
|
||||||
|
|
|
@ -284,21 +284,6 @@ void
|
||||||
virCapabilitiesClearHostNUMACellCPUTopology(virCapsHostNUMACellCPUPtr cpu,
|
virCapabilitiesClearHostNUMACellCPUTopology(virCapsHostNUMACellCPUPtr cpu,
|
||||||
size_t ncpus);
|
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 *
|
extern char *
|
||||||
virCapabilitiesFormatXML(virCapsPtr caps);
|
virCapabilitiesFormatXML(virCapsPtr caps);
|
||||||
|
|
||||||
|
|
|
@ -12959,25 +12959,18 @@ char *
|
||||||
virDomainDefGetDefaultEmulator(virDomainDefPtr def,
|
virDomainDefGetDefaultEmulator(virDomainDefPtr def,
|
||||||
virCapsPtr caps)
|
virCapsPtr caps)
|
||||||
{
|
{
|
||||||
const char *emulator;
|
|
||||||
char *retemu;
|
char *retemu;
|
||||||
|
virCapsDomainDataPtr capsdata;
|
||||||
|
|
||||||
emulator = virCapabilitiesDefaultGuestEmulator(caps,
|
if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type,
|
||||||
def->os.type,
|
def->os.arch, def->virtType, NULL, NULL)))
|
||||||
def->os.arch,
|
return NULL;
|
||||||
def->virtType);
|
|
||||||
|
|
||||||
if (!emulator) {
|
if (VIR_STRDUP(retemu, capsdata->emulator) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
VIR_FREE(capsdata);
|
||||||
_("no emulator for domain %s os type %s "
|
|
||||||
"on architecture %s"),
|
|
||||||
virDomainVirtTypeToString(def->virtType),
|
|
||||||
virDomainOSTypeToString(def->os.type),
|
|
||||||
virArchToString(def->os.arch));
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
VIR_FREE(capsdata);
|
||||||
ignore_value(VIR_STRDUP(retemu, emulator));
|
|
||||||
return retemu;
|
return retemu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,9 +51,6 @@ virCapabilitiesAddHostMigrateTransport;
|
||||||
virCapabilitiesAddHostNUMACell;
|
virCapabilitiesAddHostNUMACell;
|
||||||
virCapabilitiesAllocMachines;
|
virCapabilitiesAllocMachines;
|
||||||
virCapabilitiesClearHostNUMACellCPUTopology;
|
virCapabilitiesClearHostNUMACellCPUTopology;
|
||||||
virCapabilitiesDefaultGuestArch;
|
|
||||||
virCapabilitiesDefaultGuestEmulator;
|
|
||||||
virCapabilitiesDefaultGuestMachine;
|
|
||||||
virCapabilitiesDomainDataLookup;
|
virCapabilitiesDomainDataLookup;
|
||||||
virCapabilitiesFormatXML;
|
virCapabilitiesFormatXML;
|
||||||
virCapabilitiesFreeMachines;
|
virCapabilitiesFreeMachines;
|
||||||
|
|
|
@ -1888,25 +1888,26 @@ int virQEMUCapsGetDefaultVersion(virCapsPtr caps,
|
||||||
virQEMUCapsCachePtr capsCache,
|
virQEMUCapsCachePtr capsCache,
|
||||||
unsigned int *version)
|
unsigned int *version)
|
||||||
{
|
{
|
||||||
const char *binary;
|
|
||||||
virQEMUCapsPtr qemucaps;
|
virQEMUCapsPtr qemucaps;
|
||||||
virArch hostarch;
|
virArch hostarch;
|
||||||
|
virCapsDomainDataPtr capsdata;
|
||||||
|
|
||||||
if (*version > 0)
|
if (*version > 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
hostarch = virArchFromHost();
|
hostarch = virArchFromHost();
|
||||||
if ((binary = virCapabilitiesDefaultGuestEmulator(caps,
|
if (!(capsdata = virCapabilitiesDomainDataLookup(caps,
|
||||||
VIR_DOMAIN_OSTYPE_HVM,
|
VIR_DOMAIN_OSTYPE_HVM, hostarch, VIR_DOMAIN_VIRT_QEMU,
|
||||||
hostarch,
|
NULL, NULL))) {
|
||||||
VIR_DOMAIN_VIRT_QEMU)) == NULL) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Cannot find suitable emulator for %s"),
|
_("Cannot find suitable emulator for %s"),
|
||||||
virArchToString(hostarch));
|
virArchToString(hostarch));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(qemucaps = virQEMUCapsCacheLookup(capsCache, binary)))
|
qemucaps = virQEMUCapsCacheLookup(capsCache, capsdata->emulator);
|
||||||
|
VIR_FREE(capsdata);
|
||||||
|
if (!qemucaps)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
*version = virQEMUCapsGetVersion(qemucaps);
|
*version = virQEMUCapsGetVersion(qemucaps);
|
||||||
|
|
|
@ -13145,14 +13145,17 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!def->os.machine) {
|
if (!def->os.machine) {
|
||||||
const char *defaultMachine =
|
virCapsDomainDataPtr capsdata;
|
||||||
virCapabilitiesDefaultGuestMachine(qemuCaps,
|
|
||||||
def->os.type,
|
if (!(capsdata = virCapabilitiesDomainDataLookup(qemuCaps, def->os.type,
|
||||||
def->os.arch,
|
def->os.arch, def->virtType, NULL, NULL)))
|
||||||
def->virtType);
|
|
||||||
if (defaultMachine != NULL)
|
|
||||||
if (VIR_STRDUP(def->os.machine, defaultMachine) < 0)
|
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
if (VIR_STRDUP(def->os.machine, capsdata->machinetype) < 0) {
|
||||||
|
VIR_FREE(capsdata);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
VIR_FREE(capsdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nographics && def->ngraphics == 0) {
|
if (!nographics && def->ngraphics == 0) {
|
||||||
|
|
|
@ -983,15 +983,15 @@ xenParseEmulatedDevices(virConfPtr conf, virDomainDefPtr def)
|
||||||
static int
|
static int
|
||||||
xenParseGeneralMeta(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps)
|
xenParseGeneralMeta(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps)
|
||||||
{
|
{
|
||||||
const char *defaultMachine;
|
virCapsDomainDataPtr capsdata = NULL;
|
||||||
const char *str;
|
const char *str;
|
||||||
int hvm = 0;
|
int hvm = 0, ret = -1;
|
||||||
|
|
||||||
if (xenConfigCopyString(conf, "name", &def->name) < 0)
|
if (xenConfigCopyString(conf, "name", &def->name) < 0)
|
||||||
return -1;
|
goto out;
|
||||||
|
|
||||||
if (xenConfigGetUUID(conf, "uuid", def->uuid) < 0)
|
if (xenConfigGetUUID(conf, "uuid", def->uuid) < 0)
|
||||||
return -1;
|
goto out;
|
||||||
|
|
||||||
if ((xenConfigGetString(conf, "builder", &str, "linux") == 0) &&
|
if ((xenConfigGetString(conf, "builder", &str, "linux") == 0) &&
|
||||||
STREQ(str, "hvm"))
|
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.type = (hvm ? VIR_DOMAIN_OSTYPE_HVM : VIR_DOMAIN_OSTYPE_XEN);
|
||||||
|
|
||||||
def->os.arch =
|
if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type,
|
||||||
virCapabilitiesDefaultGuestArch(caps,
|
VIR_ARCH_NONE, def->virtType, NULL, NULL)))
|
||||||
def->os.type,
|
goto out;
|
||||||
def->virtType);
|
|
||||||
if (!def->os.arch) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("no supported architecture for os type '%s'"),
|
|
||||||
virDomainOSTypeToString(def->os.type));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultMachine = virCapabilitiesDefaultGuestMachine(caps,
|
def->os.arch = capsdata->arch;
|
||||||
def->os.type,
|
if (VIR_STRDUP(def->os.machine, capsdata->machinetype) < 0)
|
||||||
def->os.arch,
|
goto out;
|
||||||
def->virtType);
|
|
||||||
if (defaultMachine != NULL) {
|
|
||||||
if (VIR_STRDUP(def->os.machine, defaultMachine) < 0)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
ret = 0;
|
||||||
|
out:
|
||||||
|
VIR_FREE(capsdata);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<uuid>c7b3edbd-edaf-9455-926a-d65c16db1800</uuid>
|
<uuid>c7b3edbd-edaf-9455-926a-d65c16db1800</uuid>
|
||||||
<memory unit='KiB'>219200</memory>
|
<memory unit='KiB'>219200</memory>
|
||||||
<os>
|
<os>
|
||||||
<type arch='i686' machine='pc-1.0'>hvm</type>
|
<type arch='x86_64' machine='pc-1.0'>hvm</type>
|
||||||
<boot dev='cdrom'/>
|
<boot dev='cdrom'/>
|
||||||
</os>
|
</os>
|
||||||
<devices>
|
<devices>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<uuid>c7b3edbd-edaf-9455-926a-d65c16db1800</uuid>
|
<uuid>c7b3edbd-edaf-9455-926a-d65c16db1800</uuid>
|
||||||
<memory unit='KiB'>219200</memory>
|
<memory unit='KiB'>219200</memory>
|
||||||
<os>
|
<os>
|
||||||
<type arch='i686' machine='pc-1.0'>hvm</type>
|
<type arch='x86_64' machine='pc-1.0'>hvm</type>
|
||||||
<boot dev='cdrom'/>
|
<boot dev='cdrom'/>
|
||||||
</os>
|
</os>
|
||||||
<devices>
|
<devices>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<uuid>c7b3edbd-edaf-9455-926a-d65c16db1800</uuid>
|
<uuid>c7b3edbd-edaf-9455-926a-d65c16db1800</uuid>
|
||||||
<memory unit='KiB'>219200</memory>
|
<memory unit='KiB'>219200</memory>
|
||||||
<os>
|
<os>
|
||||||
<type arch='i686' machine='pc-1.0'>hvm</type>
|
<type arch='x86_64' machine='pc-1.0'>hvm</type>
|
||||||
<kernel>/vmlinuz.raw</kernel>
|
<kernel>/vmlinuz.raw</kernel>
|
||||||
<initrd>/initrd.raw</initrd>
|
<initrd>/initrd.raw</initrd>
|
||||||
</os>
|
</os>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<uuid>c7b3edbd-edaf-9455-926a-d65c16db1800</uuid>
|
<uuid>c7b3edbd-edaf-9455-926a-d65c16db1800</uuid>
|
||||||
<memory unit='KiB'>219200</memory>
|
<memory unit='KiB'>219200</memory>
|
||||||
<os>
|
<os>
|
||||||
<type arch='i686' machine='pc-1.0'>hvm</type>
|
<type arch='x86_64' machine='pc-1.0'>hvm</type>
|
||||||
<boot dev='cdrom'/>
|
<boot dev='cdrom'/>
|
||||||
</os>
|
</os>
|
||||||
<devices>
|
<devices>
|
||||||
|
|
Loading…
Reference in New Issue