Move virDomainDeviceDefValidate() and all its helper functions to domain_validate.c. Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx> --- src/conf/domain_conf.c | 137 +------------------------------------ src/conf/domain_conf.h | 16 +++-- src/conf/domain_validate.c | 129 ++++++++++++++++++++++++++++++++++ src/conf/domain_validate.h | 4 ++ src/libvirt_private.syms | 2 +- src/qemu/qemu_process.c | 1 + 6 files changed, 147 insertions(+), 142 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1cd7733652..bf9d00094c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5643,13 +5643,6 @@ virDomainDeviceDefPostParseOne(virDomainDeviceDefPtr dev, } -struct virDomainDefPostParseDeviceIteratorData { - virDomainXMLOptionPtr xmlopt; - void *parseOpaque; - unsigned int parseFlags; -}; - - static int virDomainDefPostParseDeviceIterator(virDomainDefPtr def, virDomainDeviceDefPtr dev, @@ -6398,7 +6391,7 @@ virDomainDeviceDefValidateInternal(const virDomainDeviceDef *dev, } -static int +int virDomainDeviceDefValidate(const virDomainDeviceDef *dev, const virDomainDef *def, unsigned int parseFlags, @@ -6420,19 +6413,6 @@ virDomainDeviceDefValidate(const virDomainDeviceDef *dev, } -static int -virDomainDefValidateDeviceIterator(virDomainDefPtr def, - virDomainDeviceDefPtr dev, - virDomainDeviceInfoPtr info G_GNUC_UNUSED, - void *opaque) -{ - struct virDomainDefPostParseDeviceIteratorData *data = opaque; - return virDomainDeviceDefValidate(dev, def, - data->parseFlags, data->xmlopt, - data->parseOpaque); -} - - bool virDomainDefLifecycleActionAllowed(virDomainLifecycle type, virDomainLifecycleAction action) @@ -6465,121 +6445,6 @@ virDomainDefLifecycleActionAllowed(virDomainLifecycle type, } -static int -virDomainDefValidateInternal(const virDomainDef *def, - virDomainXMLOptionPtr xmlopt) -{ - if (virDomainDefDuplicateDiskInfoValidate(def) < 0) - return -1; - - if (virDomainDefDuplicateDriveAddressesValidate(def) < 0) - return -1; - - if (virDomainDefGetVcpusTopology(def, NULL) < 0) - return -1; - - if (virDomainDefValidateAliases(def, NULL) < 0) - return -1; - - if (def->iommu && - def->iommu->intremap == VIR_TRISTATE_SWITCH_ON && - def->features[VIR_DOMAIN_FEATURE_IOAPIC] != VIR_DOMAIN_IOAPIC_QEMU) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("IOMMU interrupt remapping requires split I/O APIC " - "(ioapic driver='qemu')")); - return -1; - } - - if (def->iommu && - def->iommu->eim == VIR_TRISTATE_SWITCH_ON && - def->iommu->intremap != VIR_TRISTATE_SWITCH_ON) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("IOMMU eim requires interrupt remapping to be enabled")); - return -1; - } - - if (virDomainDefLifecycleActionValidate(def) < 0) - return -1; - - if (virDomainDefMemtuneValidate(def) < 0) - return -1; - - if (virDomainDefOSValidate(def, xmlopt) < 0) - return -1; - - if (virDomainDefCputuneValidate(def) < 0) - return -1; - - if (virDomainDefBootValidate(def) < 0) - return -1; - - if (virDomainDefVideoValidate(def) < 0) - return -1; - - if (virDomainDefTunablesValidate(def) < 0) - return -1; - - if (virDomainDefIdMapValidate(def) < 0) - return -1; - - if (virDomainNumaDefValidate(def->numa) < 0) - return -1; - - return 0; -} - - -/** - * virDomainDefValidate: - * @def: domain definition - * @caps: driver capabilities object - * @parseFlags: virDomainDefParseFlags - * @xmlopt: XML parser option object - * @parseOpaque: hypervisor driver specific data for this validation run - * - * This validation function is designed to take checks of globally invalid - * configurations that the parser needs to accept so that VMs don't vanish upon - * daemon restart. Such definition can be rejected upon startup or define, where - * this function shall be called. - * - * Returns 0 if domain definition is valid, -1 on error and reports an - * appropriate message. - */ -int -virDomainDefValidate(virDomainDefPtr def, - unsigned int parseFlags, - virDomainXMLOptionPtr xmlopt, - void *parseOpaque) -{ - struct virDomainDefPostParseDeviceIteratorData data = { - .xmlopt = xmlopt, - .parseFlags = parseFlags, - .parseOpaque = parseOpaque, - }; - - /* validate configuration only in certain places */ - if (parseFlags & VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE) - return 0; - - /* call the domain config callback */ - if (xmlopt->config.domainValidateCallback && - xmlopt->config.domainValidateCallback(def, xmlopt->config.priv, parseOpaque) < 0) - return -1; - - /* iterate the devices */ - if (virDomainDeviceInfoIterateFlags(def, - virDomainDefValidateDeviceIterator, - (DOMAIN_DEVICE_ITERATE_ALL_CONSOLES | - DOMAIN_DEVICE_ITERATE_MISSING_INFO), - &data) < 0) - return -1; - - if (virDomainDefValidateInternal(def, xmlopt) < 0) - return -1; - - return 0; -} - int virDomainObjCheckActive(virDomainObjPtr dom) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 5f8ec16b7d..1c1533ed2f 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3006,6 +3006,12 @@ struct _virDomainXMLOption { virDomainMomentPostParseCallback momentPostParse; }; +struct virDomainDefPostParseDeviceIteratorData { + virDomainXMLOptionPtr xmlopt; + void *parseOpaque; + unsigned int parseFlags; +}; + bool virDomainSCSIDriveAddressIsUsed(const virDomainDef *def, const virDomainDeviceDriveAddress *addr); @@ -3018,11 +3024,6 @@ bool virDomainDefHasUSB(const virDomainDef *def); bool virDomainDeviceAliasIsUserAlias(const char *aliasStr); -int virDomainDefValidate(virDomainDefPtr def, - unsigned int parseFlags, - virDomainXMLOptionPtr xmlopt, - void *parseOpaque); - int virDomainActualNetDefValidate(const virDomainNetDef *net); @@ -3124,6 +3125,11 @@ void virDomainRedirdevDefFree(virDomainRedirdevDefPtr def); void virDomainRedirFilterDefFree(virDomainRedirFilterDefPtr def); void virDomainShmemDefFree(virDomainShmemDefPtr def); void virDomainDeviceDefFree(virDomainDeviceDefPtr def); +int virDomainDeviceDefValidate(const virDomainDeviceDef *dev, + const virDomainDef *def, + unsigned int parseFlags, + virDomainXMLOptionPtr xmlopt, + void *parseOpaque); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainDeviceDef, virDomainDeviceDefFree); virDomainDeviceDefPtr virDomainDeviceDefCopy(virDomainDeviceDefPtr src, const virDomainDef *def, diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index 02cd761ee2..47aa3e4375 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -1040,3 +1040,132 @@ virDomainDefCputuneValidate(const virDomainDef *def) } #undef CPUTUNE_VALIDATE_PERIOD #undef CPUTUNE_VALIDATE_QUOTA + + +static int +virDomainDefValidateInternal(const virDomainDef *def, + virDomainXMLOptionPtr xmlopt) +{ + if (virDomainDefDuplicateDiskInfoValidate(def) < 0) + return -1; + + if (virDomainDefDuplicateDriveAddressesValidate(def) < 0) + return -1; + + if (virDomainDefGetVcpusTopology(def, NULL) < 0) + return -1; + + if (virDomainDefValidateAliases(def, NULL) < 0) + return -1; + + if (def->iommu && + def->iommu->intremap == VIR_TRISTATE_SWITCH_ON && + def->features[VIR_DOMAIN_FEATURE_IOAPIC] != VIR_DOMAIN_IOAPIC_QEMU) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("IOMMU interrupt remapping requires split I/O APIC " + "(ioapic driver='qemu')")); + return -1; + } + + if (def->iommu && + def->iommu->eim == VIR_TRISTATE_SWITCH_ON && + def->iommu->intremap != VIR_TRISTATE_SWITCH_ON) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("IOMMU eim requires interrupt remapping to be enabled")); + return -1; + } + + if (virDomainDefLifecycleActionValidate(def) < 0) + return -1; + + if (virDomainDefMemtuneValidate(def) < 0) + return -1; + + if (virDomainDefOSValidate(def, xmlopt) < 0) + return -1; + + if (virDomainDefCputuneValidate(def) < 0) + return -1; + + if (virDomainDefBootValidate(def) < 0) + return -1; + + if (virDomainDefVideoValidate(def) < 0) + return -1; + + if (virDomainDefTunablesValidate(def) < 0) + return -1; + + if (virDomainDefIdMapValidate(def) < 0) + return -1; + + if (virDomainNumaDefValidate(def->numa) < 0) + return -1; + + return 0; +} + + +static int +virDomainDefValidateDeviceIterator(virDomainDefPtr def, + virDomainDeviceDefPtr dev, + virDomainDeviceInfoPtr info G_GNUC_UNUSED, + void *opaque) +{ + struct virDomainDefPostParseDeviceIteratorData *data = opaque; + return virDomainDeviceDefValidate(dev, def, + data->parseFlags, data->xmlopt, + data->parseOpaque); +} + + +/** + * virDomainDefValidate: + * @def: domain definition + * @caps: driver capabilities object + * @parseFlags: virDomainDefParseFlags + * @xmlopt: XML parser option object + * @parseOpaque: hypervisor driver specific data for this validation run + * + * This validation function is designed to take checks of globally invalid + * configurations that the parser needs to accept so that VMs don't vanish upon + * daemon restart. Such definition can be rejected upon startup or define, where + * this function shall be called. + * + * Returns 0 if domain definition is valid, -1 on error and reports an + * appropriate message. + */ +int +virDomainDefValidate(virDomainDefPtr def, + unsigned int parseFlags, + virDomainXMLOptionPtr xmlopt, + void *parseOpaque) +{ + struct virDomainDefPostParseDeviceIteratorData data = { + .xmlopt = xmlopt, + .parseFlags = parseFlags, + .parseOpaque = parseOpaque, + }; + + /* validate configuration only in certain places */ + if (parseFlags & VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE) + return 0; + + /* call the domain config callback */ + if (xmlopt->config.domainValidateCallback && + xmlopt->config.domainValidateCallback(def, xmlopt->config.priv, parseOpaque) < 0) + return -1; + + /* iterate the devices */ + if (virDomainDeviceInfoIterateFlags(def, + virDomainDefValidateDeviceIterator, + (DOMAIN_DEVICE_ITERATE_ALL_CONSOLES | + DOMAIN_DEVICE_ITERATE_MISSING_INFO), + &data) < 0) + return -1; + + if (virDomainDefValidateInternal(def, xmlopt) < 0) + return -1; + + return 0; +} diff --git a/src/conf/domain_validate.h b/src/conf/domain_validate.h index 4247dfd758..309ae5f950 100644 --- a/src/conf/domain_validate.h +++ b/src/conf/domain_validate.h @@ -58,3 +58,7 @@ int virDomainDefMemtuneValidate(const virDomainDef *def); int virDomainDefOSValidate(const virDomainDef *def, virDomainXMLOptionPtr xmlopt); int virDomainDefCputuneValidate(const virDomainDef *def); +int virDomainDefValidate(virDomainDefPtr def, + unsigned int parseFlags, + virDomainXMLOptionPtr xmlopt, + void *parseOpaque); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c3056232db..3cbc336bad 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -342,7 +342,6 @@ virDomainDefSave; virDomainDefSetMemoryTotal; virDomainDefSetVcpus; virDomainDefSetVcpusMax; -virDomainDefValidate; virDomainDefVcpuOrderClear; virDomainDeleteConfig; virDomainDeviceAliasIsUserAlias; @@ -744,6 +743,7 @@ virDomainConfVMNWFilterTeardown; # conf/domain_validate.h +virDomainDefValidate; virDomainDeviceValidateAliasForHotplug; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 3b64caa619..bb78967ca3 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -74,6 +74,7 @@ #include "virhostcpu.h" #include "domain_audit.h" #include "domain_nwfilter.h" +#include "domain_validate.h" #include "locking/domain_lock.h" #include "viruuid.h" #include "virprocess.h" -- 2.26.2