On Thu, Jan 08, 2015 at 15:48:21 +0000, Daniel Berrange wrote:
The virDomainDefineXMLFlags and virDomainCreateXML APIs both
gain new flags allowing them to be told to validate XML.
This updates all the drivers to turn on validation in the
XML parser when the flags are set
...
diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index a40956f..d0a5d0b 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
...
@@ -890,9 +894,13 @@ bhyveDomainCreateXML(virConnectPtr conn,
virObjectEventPtr event = NULL;
virCapsPtr caps = NULL;
unsigned int start_flags = 0;
+ unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
- virCheckFlags(VIR_DOMAIN_START_AUTODESTROY, NULL);
+ virCheckFlags(VIR_DOMAIN_START_AUTODESTROY |
+ VIR_DOMAIN_START_VALIDATE, NULL);
+ if (flags & VIR_DOMAIN_START_VALIDATE
s/$/)/
+ parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE;
if (flags & VIR_DOMAIN_START_AUTODESTROY)
start_flags |= VIR_BHYVE_PROCESS_START_AUTODESTROY;
...
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 4361834..6e06272 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -29,6 +29,7 @@
#include <sys/stat.h>
#include <unistd.h>
+#include "configmake.h"
#include "internal.h"
#include "virerror.h"
#include "datatypes.h"
@@ -12646,6 +12647,11 @@ virDomainDefParseXML(xmlDocPtr xml,
bool usb_master = false;
bool primaryVideo = false;
+ if ((flags & VIR_DOMAIN_DEF_PARSE_VALIDATE) &&
+ virXMLValidateAgainstSchema(PKGDATADIR "/schemas/domain.rng",
+ xml) < 0)
This should be using virFileFindResource() so that it works even for
uninstalled libvirt.
+ return NULL;
+
if (VIR_ALLOC(def) < 0)
return NULL;
...
diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index e35986c..0fc64d9 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
...
@@ -1888,12 +1892,16 @@ xenUnifiedDomainDefineXMLFlags(virConnectPtr
conn, const char *xml, unsigned int
xenUnifiedPrivatePtr priv = conn->privateData;
virDomainDefPtr def = NULL;
virDomainPtr ret = NULL;
+ unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
- virCheckFlags(0, NULL);
+ virCheckFlags(VIR_DOMAIN_DEFINE_VALIDATE, NULL);
+
+ if (flags & VIR_DOMAIN_DEFINE_VALIDATE)
+ parse_flags |= VIR_DOMAIN_DEF_PARSE_INACTIVE;
s/VIR_DOMAIN_DEF_PARSE_INACTIVE/VIR_DOMAIN_DEF_PARSE_VALIDATE/
if (!(def = virDomainDefParseString(xml, priv->caps, priv->xmlopt,
1 << VIR_DOMAIN_VIRT_XEN,
- VIR_DOMAIN_DEF_PARSE_INACTIVE)))
+ parse_flags)))
goto cleanup;
if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0)
...
Jirka