]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: refactor checking for unsupported memory devices
authorPeter Krempa <pkrempa@redhat.com>
Tue, 23 Feb 2016 09:58:10 +0000 (10:58 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 9 Mar 2016 09:09:16 +0000 (10:09 +0100)
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.

16 files changed:
src/bhyve/bhyve_domain.c
src/conf/domain_conf.c
src/conf/domain_conf.h
src/libvirt_private.syms
src/libxl/libxl_domain.c
src/lxc/lxc_domain.c
src/openvz/openvz_driver.c
src/phyp/phyp_driver.c
src/qemu/qemu_domain.c
src/uml/uml_driver.c
src/vbox/vbox_common.c
src/vmware/vmware_driver.c
src/vmx/vmx.c
src/vz/vz_driver.c
src/xen/xen_driver.c
src/xenapi/xenapi_driver.c

index db8fae4ad072a92a56a7aceb5b8a3b042ce6e319..89cb171a9302f36f874ea551200aaf2485963d57 100644 (file)
@@ -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;
 }
 
index 0a6e3e16962ae170f4ec52df9cfde48ca2cd622f..595d8a410d435a1a52aaabc5cb24fd74da1b137c 100644 (file)
@@ -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;
 }
 
index 9e953a0390ffcc782f3b3c4646dbe10af6aa5911..61eb766ae006be8e6799033c2ec69aefc7662b59 100644 (file)
@@ -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);
index 4644203ce93e903bd846df3f34a2f8885634b943..55c3047d3db65f91430a648e5a99ce8969ea11b7 100644 (file)
@@ -204,7 +204,6 @@ virDomainDefAddImplicitControllers;
 virDomainDefAddUSBController;
 virDomainDefCheckABIStability;
 virDomainDefCheckDuplicateDiskInfo;
-virDomainDefCheckUnsupportedMemoryHotplug;
 virDomainDefClearCCWAddresses;
 virDomainDefClearDeviceAliases;
 virDomainDefClearPCIAddresses;
@@ -243,7 +242,6 @@ virDomainDefSetVcpusMax;
 virDomainDeleteConfig;
 virDomainDeviceAddressIsValid;
 virDomainDeviceAddressTypeToString;
-virDomainDeviceDefCheckUnsupportedMemoryDevice;
 virDomainDeviceDefCopy;
 virDomainDeviceDefFree;
 virDomainDeviceDefParse;
index 9d0da6827d30de9342e623d4cde6d4e083b2b2b9..c8d09b182ed67092bb9c052c343849076406023f 100644 (file)
@@ -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;
 }
 
index c3f7a564b36bd090d00f4c70967a21408ecca875..3177a62f87de65c2ee665a7bffa923e9ac7314f1 100644 (file)
@@ -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;
 }
 
index a6834b373f7a35fdbe98c351f526e3a702274e17..c2d54ad530b65e15ef29997faab49babe4dc2288 100644 (file)
@@ -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;
 }
 
index d1c40daaa28022bcfb7bbb4460c4d2ca12cec8f6..55a63e7130fa3a44d30416a0884428396a9b075d 100644 (file)
@@ -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;
 }
 
index 97de6f74cfba0b2a47df3de5851fc2fb7cc79ac1..4fcb85cb599e64d642798b84c6b8e72cf5390caf 100644 (file)
@@ -1620,6 +1620,7 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
 virDomainDefParserConfig virQEMUDriverDomainDefParserConfig = {
     .devicesPostParseCallback = qemuDomainDeviceDefPostParse,
     .domainPostParseCallback = qemuDomainDefPostParse,
+    .features = VIR_DOMAIN_DEF_FEATURE_MEMORY_HOTPLUG,
 };
 
 
index d656704eb82106ad1dee9af9669e6c4f53edbc0a..9fcdc84118d5bfeffe718e7ffdf95ef9e4ce935f 100644 (file)
@@ -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;
 }
 
index 0152b353b04a47b2f3d0813e5eafdb70d895c1f5..c305eb597c320e02e9e206041b1dbb26d8b4a624 100644 (file)
@@ -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;
 }
 
index e4e470a015d8135c0ecf6a71e186820cbcf54391..93f21c9a65c880da61d08181053e8c53710b2651 100644 (file)
@@ -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;
 }
 
index 7263ee57e1560ad83fb6cae589ee5532d0592eb1..b04f549b42d8e9a1d55bdd21f5a1e77b672ff30e 100644 (file)
@@ -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;
 }
 
index eb9b17230aa77063a6c49ec05a241c96d6457b8f..6de7cb9bed68bd901198d5396bea9821bae6bb3f 100644 (file)
@@ -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;
 }
 
index 7628c949b0869cd4e18ed50a307b86d9a15ee9be..3f5d80d9c47ab7ac7441d89fba576cc761979286 100644 (file)
@@ -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;
 }
 
index f75f1389d94654d87359a542096cbbceeddb5da0..a75a4f7a30ccc811963c169f9a6995f0bbeeee03 100644 (file)
@@ -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;
 }