mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-09-13 19:25:13 +00:00
domain_conf.c: move virDomainDeviceDefValidate() to domain_validate.c
Move virDomainDeviceDefValidate() and all its helper functions to domain_validate.c. Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
parent
45d9466f75
commit
9432693e2b
@ -5643,13 +5643,6 @@ virDomainDeviceDefPostParseOne(virDomainDeviceDefPtr dev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct virDomainDefPostParseDeviceIteratorData {
|
|
||||||
virDomainXMLOptionPtr xmlopt;
|
|
||||||
void *parseOpaque;
|
|
||||||
unsigned int parseFlags;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virDomainDefPostParseDeviceIterator(virDomainDefPtr def,
|
virDomainDefPostParseDeviceIterator(virDomainDefPtr def,
|
||||||
virDomainDeviceDefPtr dev,
|
virDomainDeviceDefPtr dev,
|
||||||
@ -6398,7 +6391,7 @@ virDomainDeviceDefValidateInternal(const virDomainDeviceDef *dev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
int
|
||||||
virDomainDeviceDefValidate(const virDomainDeviceDef *dev,
|
virDomainDeviceDefValidate(const virDomainDeviceDef *dev,
|
||||||
const virDomainDef *def,
|
const virDomainDef *def,
|
||||||
unsigned int parseFlags,
|
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
|
bool
|
||||||
virDomainDefLifecycleActionAllowed(virDomainLifecycle type,
|
virDomainDefLifecycleActionAllowed(virDomainLifecycle type,
|
||||||
virDomainLifecycleAction action)
|
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
|
int
|
||||||
virDomainObjCheckActive(virDomainObjPtr dom)
|
virDomainObjCheckActive(virDomainObjPtr dom)
|
||||||
{
|
{
|
||||||
|
@ -3006,6 +3006,12 @@ struct _virDomainXMLOption {
|
|||||||
virDomainMomentPostParseCallback momentPostParse;
|
virDomainMomentPostParseCallback momentPostParse;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct virDomainDefPostParseDeviceIteratorData {
|
||||||
|
virDomainXMLOptionPtr xmlopt;
|
||||||
|
void *parseOpaque;
|
||||||
|
unsigned int parseFlags;
|
||||||
|
};
|
||||||
|
|
||||||
bool
|
bool
|
||||||
virDomainSCSIDriveAddressIsUsed(const virDomainDef *def,
|
virDomainSCSIDriveAddressIsUsed(const virDomainDef *def,
|
||||||
const virDomainDeviceDriveAddress *addr);
|
const virDomainDeviceDriveAddress *addr);
|
||||||
@ -3018,11 +3024,6 @@ bool virDomainDefHasUSB(const virDomainDef *def);
|
|||||||
|
|
||||||
bool virDomainDeviceAliasIsUserAlias(const char *aliasStr);
|
bool virDomainDeviceAliasIsUserAlias(const char *aliasStr);
|
||||||
|
|
||||||
int virDomainDefValidate(virDomainDefPtr def,
|
|
||||||
unsigned int parseFlags,
|
|
||||||
virDomainXMLOptionPtr xmlopt,
|
|
||||||
void *parseOpaque);
|
|
||||||
|
|
||||||
int
|
int
|
||||||
virDomainActualNetDefValidate(const virDomainNetDef *net);
|
virDomainActualNetDefValidate(const virDomainNetDef *net);
|
||||||
|
|
||||||
@ -3124,6 +3125,11 @@ void virDomainRedirdevDefFree(virDomainRedirdevDefPtr def);
|
|||||||
void virDomainRedirFilterDefFree(virDomainRedirFilterDefPtr def);
|
void virDomainRedirFilterDefFree(virDomainRedirFilterDefPtr def);
|
||||||
void virDomainShmemDefFree(virDomainShmemDefPtr def);
|
void virDomainShmemDefFree(virDomainShmemDefPtr def);
|
||||||
void virDomainDeviceDefFree(virDomainDeviceDefPtr 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);
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainDeviceDef, virDomainDeviceDefFree);
|
||||||
virDomainDeviceDefPtr virDomainDeviceDefCopy(virDomainDeviceDefPtr src,
|
virDomainDeviceDefPtr virDomainDeviceDefCopy(virDomainDeviceDefPtr src,
|
||||||
const virDomainDef *def,
|
const virDomainDef *def,
|
||||||
|
@ -1040,3 +1040,132 @@ virDomainDefCputuneValidate(const virDomainDef *def)
|
|||||||
}
|
}
|
||||||
#undef CPUTUNE_VALIDATE_PERIOD
|
#undef CPUTUNE_VALIDATE_PERIOD
|
||||||
#undef CPUTUNE_VALIDATE_QUOTA
|
#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;
|
||||||
|
}
|
||||||
|
@ -58,3 +58,7 @@ int virDomainDefMemtuneValidate(const virDomainDef *def);
|
|||||||
int virDomainDefOSValidate(const virDomainDef *def,
|
int virDomainDefOSValidate(const virDomainDef *def,
|
||||||
virDomainXMLOptionPtr xmlopt);
|
virDomainXMLOptionPtr xmlopt);
|
||||||
int virDomainDefCputuneValidate(const virDomainDef *def);
|
int virDomainDefCputuneValidate(const virDomainDef *def);
|
||||||
|
int virDomainDefValidate(virDomainDefPtr def,
|
||||||
|
unsigned int parseFlags,
|
||||||
|
virDomainXMLOptionPtr xmlopt,
|
||||||
|
void *parseOpaque);
|
||||||
|
@ -342,7 +342,6 @@ virDomainDefSave;
|
|||||||
virDomainDefSetMemoryTotal;
|
virDomainDefSetMemoryTotal;
|
||||||
virDomainDefSetVcpus;
|
virDomainDefSetVcpus;
|
||||||
virDomainDefSetVcpusMax;
|
virDomainDefSetVcpusMax;
|
||||||
virDomainDefValidate;
|
|
||||||
virDomainDefVcpuOrderClear;
|
virDomainDefVcpuOrderClear;
|
||||||
virDomainDeleteConfig;
|
virDomainDeleteConfig;
|
||||||
virDomainDeviceAliasIsUserAlias;
|
virDomainDeviceAliasIsUserAlias;
|
||||||
@ -744,6 +743,7 @@ virDomainConfVMNWFilterTeardown;
|
|||||||
|
|
||||||
|
|
||||||
# conf/domain_validate.h
|
# conf/domain_validate.h
|
||||||
|
virDomainDefValidate;
|
||||||
virDomainDeviceValidateAliasForHotplug;
|
virDomainDeviceValidateAliasForHotplug;
|
||||||
|
|
||||||
|
|
||||||
|
@ -74,6 +74,7 @@
|
|||||||
#include "virhostcpu.h"
|
#include "virhostcpu.h"
|
||||||
#include "domain_audit.h"
|
#include "domain_audit.h"
|
||||||
#include "domain_nwfilter.h"
|
#include "domain_nwfilter.h"
|
||||||
|
#include "domain_validate.h"
|
||||||
#include "locking/domain_lock.h"
|
#include "locking/domain_lock.h"
|
||||||
#include "viruuid.h"
|
#include "viruuid.h"
|
||||||
#include "virprocess.h"
|
#include "virprocess.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user