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. --- src/bhyve/bhyve_domain.c | 9 +------ src/conf/domain_conf.c | 58 ++++++++++++++++++++++++++++++++++++++++++++-- src/conf/domain_conf.h | 4 +--- src/libvirt_private.syms | 2 -- src/libxl/libxl_domain.c | 7 ------ src/lxc/lxc_domain.c | 8 ------- src/openvz/openvz_driver.c | 7 ------ src/phyp/phyp_driver.c | 6 +---- src/qemu/qemu_domain.c | 1 + src/uml/uml_driver.c | 9 +------ src/vbox/vbox_common.c | 6 +---- src/vmware/vmware_driver.c | 6 +---- src/vmx/vmx.c | 6 +---- src/vz/vz_driver.c | 6 +---- src/xen/xen_driver.c | 7 ------ src/xenapi/xenapi_driver.c | 7 ------ 16 files changed, 65 insertions(+), 84 deletions(-) diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c index db8fae4..89cb171 100644 --- a/src/bhyve/bhyve_domain.c +++ b/src/bhyve/bhyve_domain.c @@ -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; } diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 705a796..101fae2 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -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 */ @@ -4215,6 +4215,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, @@ -4234,6 +4282,9 @@ virDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, if ((ret = virDomainDeviceDefPostParseInternal(dev, def, caps, flags, xmlopt)) < 0) return ret; + if (virDomainDeviceDefPostParseCheckFeatures(dev, xmlopt) < 0) + return -1; + return 0; } @@ -4291,6 +4342,9 @@ virDomainDefPostParse(virDomainDefPtr def, if ((ret = virDomainDefPostParseInternal(def, caps, parseFlags)) < 0) return ret; + if (virDomainDefPostParseCheckFeatures(def, xmlopt) < 0) + return -1; + return 0; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 223ce2d..c660a02 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2405,6 +2405,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; @@ -2497,9 +2498,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); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 6da9b5c..dc90a6a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -204,7 +204,6 @@ virDomainDefAddImplicitControllers; virDomainDefAddUSBController; virDomainDefCheckABIStability; virDomainDefCheckDuplicateDiskInfo; -virDomainDefCheckUnsupportedMemoryHotplug; virDomainDefClearCCWAddresses; virDomainDefClearDeviceAliases; virDomainDefClearPCIAddresses; @@ -243,7 +242,6 @@ virDomainDefSetVcpusMax; virDomainDeleteConfig; virDomainDeviceAddressIsValid; virDomainDeviceAddressTypeToString; -virDomainDeviceDefCheckUnsupportedMemoryDevice; virDomainDeviceDefCopy; virDomainDeviceDefFree; virDomainDeviceDefParse; diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 50f7eed..5b2b680 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -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; } diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c index c3f7a56..3177a62 100644 --- a/src/lxc/lxc_domain.c +++ b/src/lxc/lxc_domain.c @@ -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; } diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index a6834b3..c2d54ad 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -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; } diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index d1c40da..55a63e7 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -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; } diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index c56f9f1..a0dfa7e 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1515,6 +1515,7 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, virDomainDefParserConfig virQEMUDriverDomainDefParserConfig = { .devicesPostParseCallback = qemuDomainDeviceDefPostParse, .domainPostParseCallback = qemuDomainDefPostParse, + .features = VIR_DOMAIN_DEF_FEATURE_MEMORY_HOTPLUG, }; diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index d656704..9fcdc84 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -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; } diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 8c00a4f..e0d18fc 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -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; } diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index e4e470a..93f21c9 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -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; } diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index cbd6633..6376cca 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -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; } diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index f7a8617..409d777 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -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; } diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index 7628c94..3f5d80d 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -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; } diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index f75f138..a75a4f7 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -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; } -- 2.6.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list