mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-25 01:34:11 +03:00
conf: refactor checking for unsupported memory devices
Introduce a helper to check supported device and domain config and move the memory hotplug checks to it. The advantage of this approach is that by default all new features are considered unsupported by all hypervisors unless specifically changed rather than the previous approach where every hypervisor would need to declare that a given feature is unsupported.
This commit is contained in:
parent
23eb382128
commit
185d13b1b0
@ -68,23 +68,16 @@ bhyveDomainDefPostParse(virDomainDefPtr def,
|
||||
VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT) < 0)
|
||||
return -1;
|
||||
|
||||
/* memory hotplug tunables are not supported by this driver */
|
||||
if (virDomainDefCheckUnsupportedMemoryHotplug(def) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
bhyveDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
|
||||
bhyveDomainDeviceDefPostParse(virDomainDeviceDefPtr dev ATTRIBUTE_UNUSED,
|
||||
const virDomainDef *def ATTRIBUTE_UNUSED,
|
||||
virCapsPtr caps ATTRIBUTE_UNUSED,
|
||||
unsigned int parseFlags ATTRIBUTE_UNUSED,
|
||||
void *opaque ATTRIBUTE_UNUSED)
|
||||
{
|
||||
if (virDomainDeviceDefCheckUnsupportedMemoryDevice(dev) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1138,7 +1138,7 @@ virDomainBlkioDeviceParseXML(xmlNodePtr root,
|
||||
* Returns -1 if the domain definition would enable memory hotplug via the
|
||||
* <maxMemory> tunable and reports an error. Otherwise returns 0.
|
||||
*/
|
||||
int
|
||||
static int
|
||||
virDomainDefCheckUnsupportedMemoryHotplug(virDomainDefPtr def)
|
||||
{
|
||||
/* memory hotplug tunables are not supported by this driver */
|
||||
@ -1160,7 +1160,7 @@ virDomainDefCheckUnsupportedMemoryHotplug(virDomainDefPtr def)
|
||||
* Returns -1 if the device definition describes a memory device and reports an
|
||||
* error. Otherwise returns 0.
|
||||
*/
|
||||
int
|
||||
static int
|
||||
virDomainDeviceDefCheckUnsupportedMemoryDevice(virDomainDeviceDefPtr dev)
|
||||
{
|
||||
/* This driver doesn't yet know how to handle memory devices */
|
||||
@ -4213,6 +4213,54 @@ virDomainDeviceDefPostParseInternal(virDomainDeviceDefPtr dev,
|
||||
}
|
||||
|
||||
|
||||
#define UNSUPPORTED(FEATURE) (!((FEATURE) & xmlopt->config.features))
|
||||
/**
|
||||
* virDomainDefPostParseCheckFeatures:
|
||||
* @def: domain definition
|
||||
* @xmlopt: XML parser option object
|
||||
*
|
||||
* This function checks that the domain configuration is supported according to
|
||||
* the supported features for a given hypervisor. See virDomainDefFeatures and
|
||||
* virDomainDefParserConfig.
|
||||
*
|
||||
* Returns 0 on success and -1 on error with an appropriate libvirt error.
|
||||
*/
|
||||
static int
|
||||
virDomainDefPostParseCheckFeatures(virDomainDefPtr def,
|
||||
virDomainXMLOptionPtr xmlopt)
|
||||
{
|
||||
if (UNSUPPORTED(VIR_DOMAIN_DEF_FEATURE_MEMORY_HOTPLUG) &&
|
||||
virDomainDefCheckUnsupportedMemoryHotplug(def) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virDomainDeviceDefPostParseCheckFeatures:
|
||||
* @dev: device definition
|
||||
* @xmlopt: XML parser option object
|
||||
*
|
||||
* This function checks that the device configuration is supported according to
|
||||
* the supported features for a given hypervisor. See virDomainDefFeatures and
|
||||
* virDomainDefParserConfig.
|
||||
*
|
||||
* Returns 0 on success and -1 on error with an appropriate libvirt error.
|
||||
*/
|
||||
static int
|
||||
virDomainDeviceDefPostParseCheckFeatures(virDomainDeviceDefPtr dev,
|
||||
virDomainXMLOptionPtr xmlopt)
|
||||
{
|
||||
if (UNSUPPORTED(VIR_DOMAIN_DEF_FEATURE_MEMORY_HOTPLUG) &&
|
||||
virDomainDeviceDefCheckUnsupportedMemoryDevice(dev) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#undef UNSUPPORTED
|
||||
|
||||
|
||||
static int
|
||||
virDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
|
||||
const virDomainDef *def,
|
||||
@ -4232,6 +4280,9 @@ virDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
|
||||
if ((ret = virDomainDeviceDefPostParseInternal(dev, def, caps, flags, xmlopt)) < 0)
|
||||
return ret;
|
||||
|
||||
if (virDomainDeviceDefPostParseCheckFeatures(dev, xmlopt) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -4289,6 +4340,9 @@ virDomainDefPostParse(virDomainDefPtr def,
|
||||
if ((ret = virDomainDefPostParseInternal(def, caps, parseFlags)) < 0)
|
||||
return ret;
|
||||
|
||||
if (virDomainDefPostParseCheckFeatures(def, xmlopt) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -2409,6 +2409,7 @@ typedef bool (*virDomainObjListACLFilter)(virConnectPtr conn,
|
||||
|
||||
typedef enum {
|
||||
VIR_DOMAIN_DEF_FEATURE_WIDE_SCSI = (1 << 0),
|
||||
VIR_DOMAIN_DEF_FEATURE_MEMORY_HOTPLUG = (1 << 1),
|
||||
} virDomainDefFeatures;
|
||||
|
||||
|
||||
@ -2501,9 +2502,6 @@ int virDomainObjWait(virDomainObjPtr vm);
|
||||
int virDomainObjWaitUntil(virDomainObjPtr vm,
|
||||
unsigned long long whenms);
|
||||
|
||||
int virDomainDefCheckUnsupportedMemoryHotplug(virDomainDefPtr def);
|
||||
int virDomainDeviceDefCheckUnsupportedMemoryDevice(virDomainDeviceDefPtr dev);
|
||||
|
||||
void virDomainPanicDefFree(virDomainPanicDefPtr panic);
|
||||
void virDomainResourceDefFree(virDomainResourceDefPtr resource);
|
||||
void virDomainGraphicsDefFree(virDomainGraphicsDefPtr def);
|
||||
|
@ -204,7 +204,6 @@ virDomainDefAddImplicitControllers;
|
||||
virDomainDefAddUSBController;
|
||||
virDomainDefCheckABIStability;
|
||||
virDomainDefCheckDuplicateDiskInfo;
|
||||
virDomainDefCheckUnsupportedMemoryHotplug;
|
||||
virDomainDefClearCCWAddresses;
|
||||
virDomainDefClearDeviceAliases;
|
||||
virDomainDefClearPCIAddresses;
|
||||
@ -243,7 +242,6 @@ virDomainDefSetVcpusMax;
|
||||
virDomainDeleteConfig;
|
||||
virDomainDeviceAddressIsValid;
|
||||
virDomainDeviceAddressTypeToString;
|
||||
virDomainDeviceDefCheckUnsupportedMemoryDevice;
|
||||
virDomainDeviceDefCopy;
|
||||
virDomainDeviceDefFree;
|
||||
virDomainDeviceDefParse;
|
||||
|
@ -363,9 +363,6 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
|
||||
}
|
||||
}
|
||||
|
||||
if (virDomainDeviceDefCheckUnsupportedMemoryDevice(dev) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -401,10 +398,6 @@ libxlDomainDefPostParse(virDomainDefPtr def,
|
||||
if (xenDomainDefAddImplicitInputDevice(def) < 0)
|
||||
return -1;
|
||||
|
||||
/* memory hotplug tunables are not supported by this driver */
|
||||
if (virDomainDefCheckUnsupportedMemoryHotplug(def) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -249,10 +249,6 @@ virLXCDomainDefPostParse(virDomainDefPtr def,
|
||||
!(def->emulator = virDomainDefGetDefaultEmulator(def, caps)))
|
||||
return -1;
|
||||
|
||||
/* memory hotplug tunables are not supported by this driver */
|
||||
if (virDomainDefCheckUnsupportedMemoryHotplug(def) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -269,10 +265,6 @@ virLXCDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
|
||||
dev->data.chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE)
|
||||
dev->data.chr->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_LXC;
|
||||
|
||||
|
||||
if (virDomainDeviceDefCheckUnsupportedMemoryDevice(dev) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -98,10 +98,6 @@ openvzDomainDefPostParse(virDomainDefPtr def,
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* memory hotplug tunables are not supported by this driver */
|
||||
if (virDomainDefCheckUnsupportedMemoryHotplug(def) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -128,9 +124,6 @@ openvzDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (virDomainDeviceDefCheckUnsupportedMemoryDevice(dev) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1094,15 +1094,11 @@ openSSHSession(virConnectPtr conn, virConnectAuthPtr auth,
|
||||
|
||||
|
||||
static int
|
||||
phypDomainDefPostParse(virDomainDefPtr def,
|
||||
phypDomainDefPostParse(virDomainDefPtr def ATTRIBUTE_UNUSED,
|
||||
virCapsPtr caps ATTRIBUTE_UNUSED,
|
||||
unsigned int parseFlags ATTRIBUTE_UNUSED,
|
||||
void *opaque ATTRIBUTE_UNUSED)
|
||||
{
|
||||
/* memory hotplug tunables are not supported by this driver */
|
||||
if (virDomainDefCheckUnsupportedMemoryHotplug(def) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1620,6 +1620,7 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
|
||||
virDomainDefParserConfig virQEMUDriverDomainDefParserConfig = {
|
||||
.devicesPostParseCallback = qemuDomainDeviceDefPostParse,
|
||||
.domainPostParseCallback = qemuDomainDefPostParse,
|
||||
.features = VIR_DOMAIN_DEF_FEATURE_MEMORY_HOTPLUG,
|
||||
};
|
||||
|
||||
|
||||
|
@ -427,23 +427,16 @@ umlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (virDomainDeviceDefCheckUnsupportedMemoryDevice(dev) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
umlDomainDefPostParse(virDomainDefPtr def,
|
||||
umlDomainDefPostParse(virDomainDefPtr def ATTRIBUTE_UNUSED,
|
||||
virCapsPtr caps ATTRIBUTE_UNUSED,
|
||||
unsigned int parseFlags ATTRIBUTE_UNUSED,
|
||||
void *opaque ATTRIBUTE_UNUSED)
|
||||
{
|
||||
/* memory hotplug tunables are not supported by this driver */
|
||||
if (virDomainDefCheckUnsupportedMemoryHotplug(def) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -251,15 +251,11 @@ static char *vboxGenerateMediumName(PRUint32 storageBus,
|
||||
}
|
||||
|
||||
static int
|
||||
vboxDomainDefPostParse(virDomainDefPtr def,
|
||||
vboxDomainDefPostParse(virDomainDefPtr def ATTRIBUTE_UNUSED,
|
||||
virCapsPtr caps ATTRIBUTE_UNUSED,
|
||||
unsigned int parseFlags ATTRIBUTE_UNUSED,
|
||||
void *opaque ATTRIBUTE_UNUSED)
|
||||
{
|
||||
/* memory hotplug tunables are not supported by this driver */
|
||||
if (virDomainDefCheckUnsupportedMemoryHotplug(def) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -83,15 +83,11 @@ vmwareDataFreeFunc(void *data)
|
||||
}
|
||||
|
||||
static int
|
||||
vmwareDomainDefPostParse(virDomainDefPtr def,
|
||||
vmwareDomainDefPostParse(virDomainDefPtr def ATTRIBUTE_UNUSED,
|
||||
virCapsPtr caps ATTRIBUTE_UNUSED,
|
||||
unsigned int parseFlags ATTRIBUTE_UNUSED,
|
||||
void *opaque ATTRIBUTE_UNUSED)
|
||||
{
|
||||
/* memory hotplug tunables are not supported by this driver */
|
||||
if (virDomainDefCheckUnsupportedMemoryHotplug(def) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -525,15 +525,11 @@ VIR_ENUM_IMPL(virVMXControllerModelSCSI, VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LAST,
|
||||
*/
|
||||
|
||||
static int
|
||||
virVMXDomainDefPostParse(virDomainDefPtr def,
|
||||
virVMXDomainDefPostParse(virDomainDefPtr def ATTRIBUTE_UNUSED,
|
||||
virCapsPtr caps ATTRIBUTE_UNUSED,
|
||||
unsigned int parseFlags ATTRIBUTE_UNUSED,
|
||||
void *opaque ATTRIBUTE_UNUSED)
|
||||
{
|
||||
/* memory hotplug tunables are not supported by this driver */
|
||||
if (virDomainDefCheckUnsupportedMemoryHotplug(def) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -173,15 +173,11 @@ vzConnectGetCapabilities(virConnectPtr conn)
|
||||
}
|
||||
|
||||
static int
|
||||
vzDomainDefPostParse(virDomainDefPtr def,
|
||||
vzDomainDefPostParse(virDomainDefPtr def ATTRIBUTE_UNUSED,
|
||||
virCapsPtr caps ATTRIBUTE_UNUSED,
|
||||
unsigned int parseFlags ATTRIBUTE_UNUSED,
|
||||
void *opaque ATTRIBUTE_UNUSED)
|
||||
{
|
||||
/* memory hotplug tunables are not supported by this driver */
|
||||
if (virDomainDefCheckUnsupportedMemoryHotplug(def) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -361,9 +361,6 @@ xenDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
|
||||
}
|
||||
}
|
||||
|
||||
if (virDomainDeviceDefCheckUnsupportedMemoryDevice(dev) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -387,10 +384,6 @@ xenDomainDefPostParse(virDomainDefPtr def,
|
||||
if (xenDomainDefAddImplicitInputDevice(def) <0)
|
||||
return -1;
|
||||
|
||||
/* memory hotplug tunables are not supported by this driver */
|
||||
if (virDomainDefCheckUnsupportedMemoryHotplug(def) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -67,9 +67,6 @@ xenapiDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (virDomainDeviceDefCheckUnsupportedMemoryDevice(dev) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -84,10 +81,6 @@ xenapiDomainDefPostParse(virDomainDefPtr def,
|
||||
if (xenDomainDefAddImplicitInputDevice(def) < 0)
|
||||
return -1;
|
||||
|
||||
/* memory hotplug tunables are not supported by this driver */
|
||||
if (virDomainDefCheckUnsupportedMemoryHotplug(def) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user