mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
qemu: Pass virDomainVirtType to APIs dealing with machine types
Signed-off-by: Jiri Denemark <jdenemar@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
4682197641
commit
de18836ea7
@ -2105,8 +2105,10 @@ virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps,
|
||||
* Resolves aliased machine names to the actual machine name. If qemuCaps isn't
|
||||
* present @name is returned.
|
||||
*/
|
||||
const char *virQEMUCapsGetCanonicalMachine(virQEMUCapsPtr qemuCaps,
|
||||
const char *name)
|
||||
const char *
|
||||
virQEMUCapsGetCanonicalMachine(virQEMUCapsPtr qemuCaps,
|
||||
virDomainVirtType virtType G_GNUC_UNUSED,
|
||||
const char *name)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@ -2124,8 +2126,10 @@ const char *virQEMUCapsGetCanonicalMachine(virQEMUCapsPtr qemuCaps,
|
||||
}
|
||||
|
||||
|
||||
int virQEMUCapsGetMachineMaxCpus(virQEMUCapsPtr qemuCaps,
|
||||
const char *name)
|
||||
int
|
||||
virQEMUCapsGetMachineMaxCpus(virQEMUCapsPtr qemuCaps,
|
||||
virDomainVirtType virtType G_GNUC_UNUSED,
|
||||
const char *name)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@ -2143,8 +2147,10 @@ int virQEMUCapsGetMachineMaxCpus(virQEMUCapsPtr qemuCaps,
|
||||
}
|
||||
|
||||
|
||||
bool virQEMUCapsGetMachineHotplugCpus(virQEMUCapsPtr qemuCaps,
|
||||
const char *name)
|
||||
bool
|
||||
virQEMUCapsGetMachineHotplugCpus(virQEMUCapsPtr qemuCaps,
|
||||
virDomainVirtType virtType G_GNUC_UNUSED,
|
||||
const char *name)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@ -2430,6 +2436,7 @@ virQEMUCapsProbeQMPMachineTypes(virQEMUCapsPtr qemuCaps,
|
||||
|
||||
static bool
|
||||
virQEMUCapsIsMachineSupported(virQEMUCapsPtr qemuCaps,
|
||||
virDomainVirtType virtType G_GNUC_UNUSED,
|
||||
const char *canonical_machine)
|
||||
{
|
||||
size_t i;
|
||||
@ -2444,6 +2451,7 @@ virQEMUCapsIsMachineSupported(virQEMUCapsPtr qemuCaps,
|
||||
|
||||
static int
|
||||
virQEMUCapsProbeQMPMachineProps(virQEMUCapsPtr qemuCaps,
|
||||
virDomainVirtType virtType,
|
||||
qemuMonitorPtr mon)
|
||||
{
|
||||
char **values;
|
||||
@ -2455,10 +2463,10 @@ virQEMUCapsProbeQMPMachineProps(virQEMUCapsPtr qemuCaps,
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS(virQEMUCapsMachineProps); i++) {
|
||||
virQEMUCapsObjectTypeProps props = virQEMUCapsMachineProps[i];
|
||||
const char *canon = virQEMUCapsGetCanonicalMachine(qemuCaps, props.type);
|
||||
const char *canon = virQEMUCapsGetCanonicalMachine(qemuCaps, virtType, props.type);
|
||||
g_autofree char *type = NULL;
|
||||
|
||||
if (!virQEMUCapsIsMachineSupported(qemuCaps, canon))
|
||||
if (!virQEMUCapsIsMachineSupported(qemuCaps, virtType, canon))
|
||||
continue;
|
||||
|
||||
/* The QOM type for machine types is the machine type name
|
||||
@ -4643,7 +4651,7 @@ virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps,
|
||||
return -1;
|
||||
if (virQEMUCapsProbeQMPMachineTypes(qemuCaps, mon) < 0)
|
||||
return -1;
|
||||
if (virQEMUCapsProbeQMPMachineProps(qemuCaps, mon) < 0)
|
||||
if (virQEMUCapsProbeQMPMachineProps(qemuCaps, type, mon) < 0)
|
||||
return -1;
|
||||
if (virQEMUCapsProbeQMPCPUDefinitions(qemuCaps, accel, mon) < 0)
|
||||
return -1;
|
||||
@ -4880,6 +4888,7 @@ static const struct virQEMUCapsMachineTypeFilter virQEMUCapsMachineFilter[] = {
|
||||
|
||||
void
|
||||
virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps,
|
||||
virDomainVirtType virtType,
|
||||
const char *machineType)
|
||||
{
|
||||
size_t i;
|
||||
@ -4898,7 +4907,7 @@ virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps,
|
||||
virQEMUCapsClear(qemuCaps, filter->flags[j]);
|
||||
}
|
||||
|
||||
if (!virQEMUCapsGetMachineHotplugCpus(qemuCaps, machineType))
|
||||
if (!virQEMUCapsGetMachineHotplugCpus(qemuCaps, virtType, machineType))
|
||||
virQEMUCapsClear(qemuCaps, QEMU_CAPS_QUERY_HOTPLUGGABLE_CPUS);
|
||||
}
|
||||
|
||||
@ -4972,6 +4981,7 @@ virQEMUCapsCacheLookup(virFileCachePtr cache,
|
||||
|
||||
virQEMUCapsPtr
|
||||
virQEMUCapsCacheLookupCopy(virFileCachePtr cache,
|
||||
virDomainVirtType virtType,
|
||||
const char *binary,
|
||||
const char *machineType)
|
||||
{
|
||||
@ -4987,7 +4997,7 @@ virQEMUCapsCacheLookupCopy(virFileCachePtr cache,
|
||||
if (!ret)
|
||||
return NULL;
|
||||
|
||||
virQEMUCapsFilterByMachineType(ret, machineType);
|
||||
virQEMUCapsFilterByMachineType(ret, virtType, machineType);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -5130,20 +5140,6 @@ virQEMUCapsCacheLookupDefault(virFileCachePtr cache,
|
||||
binary = virQEMUCapsGetBinary(qemuCaps);
|
||||
}
|
||||
|
||||
if (machine) {
|
||||
/* Turn @machine into canonical name */
|
||||
machine = virQEMUCapsGetCanonicalMachine(qemuCaps, machine);
|
||||
|
||||
if (!virQEMUCapsIsMachineSupported(qemuCaps, machine)) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("the machine '%s' is not supported by emulator '%s'"),
|
||||
machine, binary);
|
||||
goto cleanup;
|
||||
}
|
||||
} else {
|
||||
machine = virQEMUCapsGetPreferredMachine(qemuCaps);
|
||||
}
|
||||
|
||||
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM))
|
||||
capsType = VIR_DOMAIN_VIRT_KVM;
|
||||
else
|
||||
@ -5159,6 +5155,20 @@ virQEMUCapsCacheLookupDefault(virFileCachePtr cache,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (machine) {
|
||||
/* Turn @machine into canonical name */
|
||||
machine = virQEMUCapsGetCanonicalMachine(qemuCaps, virttype, machine);
|
||||
|
||||
if (!virQEMUCapsIsMachineSupported(qemuCaps, virttype, machine)) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("the machine '%s' is not supported by emulator '%s'"),
|
||||
machine, binary);
|
||||
goto cleanup;
|
||||
}
|
||||
} else {
|
||||
machine = virQEMUCapsGetPreferredMachine(qemuCaps, virttype);
|
||||
}
|
||||
|
||||
if (retArch)
|
||||
*retArch = arch;
|
||||
if (retVirttype)
|
||||
@ -5191,7 +5201,8 @@ virQEMUCapsSupportsVmport(virQEMUCapsPtr qemuCaps,
|
||||
* Note that this may differ from QEMU's own default machine
|
||||
*/
|
||||
const char *
|
||||
virQEMUCapsGetPreferredMachine(virQEMUCapsPtr qemuCaps)
|
||||
virQEMUCapsGetPreferredMachine(virQEMUCapsPtr qemuCaps,
|
||||
virDomainVirtType virtType G_GNUC_UNUSED)
|
||||
{
|
||||
if (!qemuCaps->nmachineTypes)
|
||||
return NULL;
|
||||
@ -5649,6 +5660,7 @@ virQEMUCapsFillDomainCaps(virCapsPtr caps,
|
||||
virQEMUCapsFillDomainFeaturesFromQEMUCaps(qemuCaps, domCaps);
|
||||
|
||||
domCaps->maxvcpus = virQEMUCapsGetMachineMaxCpus(qemuCaps,
|
||||
domCaps->virttype,
|
||||
domCaps->machine);
|
||||
if (domCaps->virttype == VIR_DOMAIN_VIRT_KVM) {
|
||||
int hostmaxvcpus;
|
||||
|
@ -604,13 +604,17 @@ bool virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps,
|
||||
virDomainVirtType type,
|
||||
virCPUMode mode);
|
||||
const char *virQEMUCapsGetCanonicalMachine(virQEMUCapsPtr qemuCaps,
|
||||
virDomainVirtType virtType,
|
||||
const char *name);
|
||||
int virQEMUCapsGetMachineMaxCpus(virQEMUCapsPtr qemuCaps,
|
||||
virDomainVirtType virtType,
|
||||
const char *name);
|
||||
bool virQEMUCapsGetMachineHotplugCpus(virQEMUCapsPtr qemuCaps,
|
||||
virDomainVirtType virtType,
|
||||
const char *name);
|
||||
|
||||
void virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps,
|
||||
virDomainVirtType virtType,
|
||||
const char *machineType);
|
||||
|
||||
virFileCachePtr virQEMUCapsCacheNew(const char *libDir,
|
||||
@ -620,6 +624,7 @@ virFileCachePtr virQEMUCapsCacheNew(const char *libDir,
|
||||
virQEMUCapsPtr virQEMUCapsCacheLookup(virFileCachePtr cache,
|
||||
const char *binary);
|
||||
virQEMUCapsPtr virQEMUCapsCacheLookupCopy(virFileCachePtr cache,
|
||||
virDomainVirtType virtType,
|
||||
const char *binary,
|
||||
const char *machineType);
|
||||
virQEMUCapsPtr virQEMUCapsCacheLookupByArch(virFileCachePtr cache,
|
||||
@ -645,7 +650,8 @@ bool virQEMUCapsSupportsGICVersion(virQEMUCapsPtr qemuCaps,
|
||||
virDomainVirtType virtType,
|
||||
virGICVersion version);
|
||||
|
||||
const char *virQEMUCapsGetPreferredMachine(virQEMUCapsPtr qemuCaps);
|
||||
const char *virQEMUCapsGetPreferredMachine(virQEMUCapsPtr qemuCaps,
|
||||
virDomainVirtType virtType);
|
||||
|
||||
int virQEMUCapsInitGuestFromBinary(virCapsPtr caps,
|
||||
const char *binary,
|
||||
|
@ -4306,7 +4306,8 @@ qemuCanonicalizeMachine(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
|
||||
{
|
||||
const char *canon;
|
||||
|
||||
if (!(canon = virQEMUCapsGetCanonicalMachine(qemuCaps, def->os.machine)))
|
||||
if (!(canon = virQEMUCapsGetCanonicalMachine(qemuCaps, def->virtType,
|
||||
def->os.machine)))
|
||||
return 0;
|
||||
|
||||
if (STRNEQ(canon, def->os.machine)) {
|
||||
@ -4841,7 +4842,8 @@ static int
|
||||
qemuDomainValidateCpuCount(const virDomainDef *def,
|
||||
virQEMUCapsPtr qemuCaps)
|
||||
{
|
||||
unsigned int maxCpus = virQEMUCapsGetMachineMaxCpus(qemuCaps, def->os.machine);
|
||||
unsigned int maxCpus = virQEMUCapsGetMachineMaxCpus(qemuCaps, def->virtType,
|
||||
def->os.machine);
|
||||
|
||||
if (virDomainDefGetVcpus(def) == 0) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
@ -8940,6 +8942,7 @@ qemuDomainDefFormatBufInternal(virQEMUDriverPtr driver,
|
||||
qCaps = virObjectRef(qemuCaps);
|
||||
} else {
|
||||
if (!(qCaps = virQEMUCapsCacheLookupCopy(driver->qemuCapsCache,
|
||||
def->virtType,
|
||||
def->emulator,
|
||||
def->os.machine)))
|
||||
goto cleanup;
|
||||
@ -14976,6 +14979,7 @@ qemuDomainUpdateQEMUCaps(virDomainObjPtr vm,
|
||||
|
||||
virObjectUnref(priv->qemuCaps);
|
||||
if (!(priv->qemuCaps = virQEMUCapsCacheLookupCopy(qemuCapsCache,
|
||||
vm->def->virtType,
|
||||
vm->def->emulator,
|
||||
vm->def->os.machine)))
|
||||
return -1;
|
||||
|
@ -83,6 +83,7 @@ fillQemuCaps(virDomainCapsPtr domCaps,
|
||||
virCapsPtr caps = NULL;
|
||||
virQEMUCapsPtr qemuCaps = NULL;
|
||||
virDomainCapsLoaderPtr loader = &domCaps->os.loader;
|
||||
virDomainVirtType virtType;
|
||||
|
||||
if (!(caps = virCapabilitiesNew(domCaps->arch, false, false)) ||
|
||||
fakeHostCPU(caps, domCaps->arch) < 0)
|
||||
@ -92,13 +93,18 @@ fillQemuCaps(virDomainCapsPtr domCaps,
|
||||
if (!(qemuCaps = qemuTestParseCapabilities(caps, path)))
|
||||
goto cleanup;
|
||||
|
||||
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM))
|
||||
virtType = VIR_DOMAIN_VIRT_KVM;
|
||||
else
|
||||
virtType = VIR_DOMAIN_VIRT_QEMU;
|
||||
|
||||
if (machine) {
|
||||
VIR_FREE(domCaps->machine);
|
||||
domCaps->machine = g_strdup(virQEMUCapsGetCanonicalMachine(qemuCaps, machine));
|
||||
domCaps->machine = g_strdup(virQEMUCapsGetCanonicalMachine(qemuCaps, virtType, machine));
|
||||
}
|
||||
|
||||
if (!domCaps->machine)
|
||||
domCaps->machine = g_strdup(virQEMUCapsGetPreferredMachine(qemuCaps));
|
||||
domCaps->machine = g_strdup(virQEMUCapsGetPreferredMachine(qemuCaps, virtType));
|
||||
|
||||
if (virQEMUCapsFillDomainCaps(caps, domCaps, qemuCaps,
|
||||
false,
|
||||
|
Loading…
Reference in New Issue
Block a user