[libvirt] [PATCH 0/8] Add XML validation to the APIs

This proof of concept patch extends the virDomainDefineXML and virDomainCreateXML APIs so that they can validate the user supplied XML document against the RNG schemas. The virsh command will enable validation by default, it must be turned off with --skip-validation if desired. This series is not complete - The network, interface, storage pool, etc APIs are not wired up to support validation. - Only the QEMU virt driver is wired up to validate - The virsh edit command is not wired up to validate It is enough to demonstrate it working with 'virsh define' and the QEMU driver though. The biggest problem I see is the really awful error messages we get back from libxml2 when validation fails :-( They are essentially useless :-( Daniel P. Berrange (8): Add new virDomainDefineXMLFlags public API Add stub virDomainDefineXMLFlags impls Add virXMLValidateAgainstSchema helper method Fix use of flags when parsing/formatting snapshot domain XML Don't pass VIR_DOMAIN_XML_SECURE to virDomainDefParseString in phyp Fix flags passed to virDomainDefParseString by XenAPI driver Given virDomainDef parser & formatter their own flags Add support for schema validation when passing in XML include/libvirt/libvirt-domain.h | 9 ++ include/libvirt/virterror.h | 1 + src/bhyve/bhyve_driver.c | 21 ++- src/conf/domain_conf.c | 315 +++++++++++++++++++------------------- src/conf/domain_conf.h | 71 ++++++--- src/conf/snapshot_conf.c | 8 +- src/driver-hypervisor.h | 5 + src/esx/esx_driver.c | 23 ++- src/hyperv/hyperv_driver.c | 3 +- src/internal.h | 4 + src/libvirt-domain.c | 48 ++++++ src/libvirt_private.syms | 2 + src/libvirt_public.syms | 5 + src/libxl/libxl_domain.c | 2 +- src/libxl/libxl_driver.c | 35 +++-- src/libxl/libxl_migration.c | 6 +- src/lxc/lxc_driver.c | 25 ++- src/openvz/openvz_driver.c | 23 ++- src/parallels/parallels_driver.c | 11 +- src/phyp/phyp_driver.c | 7 +- src/qemu/qemu_domain.c | 10 +- src/qemu/qemu_driver.c | 48 ++++-- src/qemu/qemu_migration.c | 8 +- src/remote/remote_driver.c | 1 + src/remote/remote_protocol.x | 19 ++- src/remote_protocol-structs | 8 + src/test/test_driver.c | 31 ++-- src/uml/uml_driver.c | 22 ++- src/util/virerror.c | 6 + src/util/virxml.c | 74 +++++++++ src/util/virxml.h | 5 + src/vbox/vbox_common.c | 25 ++- src/vmware/vmware_driver.c | 19 ++- src/xen/xen_driver.c | 21 ++- src/xen/xend_internal.c | 6 +- src/xen/xm_internal.c | 4 +- src/xenapi/xenapi_driver.c | 15 +- tests/domainsnapshotxml2xmltest.c | 2 +- tests/lxcxml2xmltest.c | 4 +- tests/openvzutilstest.c | 2 +- tests/qemuhotplugtest.c | 6 +- tests/qemuxml2argvtest.c | 2 +- tests/qemuxml2xmltest.c | 9 +- tests/qemuxmlnstest.c | 2 +- tests/vmx2xmltest.c | 2 +- tests/xmconfigtest.c | 4 +- tests/xml2sexprtest.c | 2 +- tests/xml2vmxtest.c | 2 +- tools/virsh-domain.c | 19 ++- 49 files changed, 684 insertions(+), 318 deletions(-) -- 2.1.0

The virDomainDefineXML method is one of the few that still lacks a 'unsigned int flags' parameter. This will be needed for adding XML validation to this API. virDomainCreateXML fortunately already has flags. --- include/libvirt/libvirt-domain.h | 4 ++++ src/driver-hypervisor.h | 5 +++++ src/libvirt-domain.c | 48 ++++++++++++++++++++++++++++++++++++++++ src/libvirt_public.syms | 5 +++++ src/qemu/qemu_driver.c | 10 ++++++++- src/remote/remote_driver.c | 1 + src/remote/remote_protocol.x | 19 +++++++++++++++- 7 files changed, 90 insertions(+), 2 deletions(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h index 1fac2a3..864c16c 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -1415,6 +1415,10 @@ int virDomainMemoryPeek (virDomainPtr dom, */ virDomainPtr virDomainDefineXML (virConnectPtr conn, const char *xml); + +virDomainPtr virDomainDefineXMLFlags (virConnectPtr conn, + const char *xml, + unsigned int flags); int virDomainUndefine (virDomainPtr domain); typedef enum { diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index ad66629..f73d40b 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -314,6 +314,10 @@ typedef int typedef virDomainPtr (*virDrvDomainDefineXML)(virConnectPtr conn, const char *xml); +typedef virDomainPtr +(*virDrvDomainDefineXMLFlags)(virConnectPtr conn, + const char *xml, + unsigned int flags); typedef int (*virDrvDomainUndefine)(virDomainPtr dom); @@ -1260,6 +1264,7 @@ struct _virHypervisorDriver { virDrvDomainCreateWithFlags domainCreateWithFlags; virDrvDomainCreateWithFiles domainCreateWithFiles; virDrvDomainDefineXML domainDefineXML; + virDrvDomainDefineXMLFlags domainDefineXMLFlags; virDrvDomainUndefine domainUndefine; virDrvDomainUndefineFlags domainUndefineFlags; virDrvDomainAttachDevice domainAttachDevice; diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 2b0defc..e9d3608 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -6473,6 +6473,54 @@ virDomainDefineXML(virConnectPtr conn, const char *xml) /** + * virDomainDefineXMLFlags: + * @conn: pointer to the hypervisor connection + * @xml: the XML description for the domain, preferably in UTF-8 + * @flags: bitwise OR of virDomainDefineFlags + * + * Define a domain, but does not start it. + * This definition is persistent, until explicitly undefined with + * virDomainUndefine(). A previous definition for this domain would be + * overridden if it already exists. + * + * Some hypervisors may prevent this operation if there is a current + * block copy operation on a transient domain with the same id as the + * domain being defined; in that case, use virDomainBlockJobAbort() to + * stop the block copy first. + * + * virDomainFree should be used to free the resources after the + * domain object is no longer needed. + * + * Returns NULL in case of error, a pointer to the domain otherwise + */ +virDomainPtr +virDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) +{ + VIR_DEBUG("conn=%p, xml=%s flags=%x", conn, xml, flags); + + virResetLastError(); + + virCheckConnectReturn(conn, NULL); + virCheckReadOnlyGoto(conn->flags, error); + virCheckNonNullArgGoto(xml, error); + + if (conn->driver->domainDefineXMLFlags) { + virDomainPtr ret; + ret = conn->driver->domainDefineXMLFlags(conn, xml, flags); + if (!ret) + goto error; + return ret; + } + + virReportUnsupportedError(); + + error: + virDispatchError(conn); + return NULL; +} + + +/** * virDomainUndefine: * @domain: pointer to a defined domain * diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 5f95802..4d9973e 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -684,4 +684,9 @@ LIBVIRT_1.2.9 { virNodeAllocPages; } LIBVIRT_1.2.8; +LIBVIRT_1.2.11 { + global: + virDomainDefineXMLFlags; +} LIBVIRT_1.2.9; + # .... define new API here using predicted next version number .... diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a84fd47..a877b75 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6651,7 +6651,7 @@ qemuDomainCreate(virDomainPtr dom) return qemuDomainCreateWithFlags(dom, 0); } -static virDomainPtr qemuDomainDefineXML(virConnectPtr conn, const char *xml) +static virDomainPtr qemuDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) { virQEMUDriverPtr driver = conn->privateData; virDomainDefPtr def = NULL; @@ -6663,6 +6663,8 @@ static virDomainPtr qemuDomainDefineXML(virConnectPtr conn, const char *xml) virQEMUDriverConfigPtr cfg; virCapsPtr caps = NULL; + virCheckFlags(0, NULL); + cfg = virQEMUDriverGetConfig(driver); if (!(caps = virQEMUDriverGetCapabilities(driver, false))) @@ -6745,6 +6747,11 @@ static virDomainPtr qemuDomainDefineXML(virConnectPtr conn, const char *xml) return dom; } +static virDomainPtr qemuDomainDefineXML(virConnectPtr conn, const char *xml) +{ + return qemuDomainDefineXMLFlags(conn, xml, 0); +} + static int qemuDomainUndefineFlags(virDomainPtr dom, unsigned int flags) @@ -18838,6 +18845,7 @@ static virHypervisorDriver qemuDriver = { .domainCreate = qemuDomainCreate, /* 0.2.0 */ .domainCreateWithFlags = qemuDomainCreateWithFlags, /* 0.8.2 */ .domainDefineXML = qemuDomainDefineXML, /* 0.2.0 */ + .domainDefineXMLFlags = qemuDomainDefineXMLFlags, /* 1.2.11 */ .domainUndefine = qemuDomainUndefine, /* 0.2.0 */ .domainUndefineFlags = qemuDomainUndefineFlags, /* 0.9.4 */ .domainAttachDevice = qemuDomainAttachDevice, /* 0.4.1 */ diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 04e5360..c8e4d06 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -8038,6 +8038,7 @@ static virHypervisorDriver hypervisor_driver = { .domainCreateWithFlags = remoteDomainCreateWithFlags, /* 0.8.2 */ .domainCreateWithFiles = remoteDomainCreateWithFiles, /* 1.1.1 */ .domainDefineXML = remoteDomainDefineXML, /* 0.3.0 */ + .domainDefineXMLFlags = remoteDomainDefineXMLFlags, /* 1.2.11 */ .domainUndefine = remoteDomainUndefine, /* 0.3.0 */ .domainUndefineFlags = remoteDomainUndefineFlags, /* 0.9.4 */ .domainAttachDevice = remoteDomainAttachDevice, /* 0.3.0 */ diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index ebf4530..6a7d3e0 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -1056,6 +1056,15 @@ struct remote_domain_define_xml_ret { remote_nonnull_domain dom; }; +struct remote_domain_define_xml_flags_args { + remote_nonnull_string xml; + unsigned int flags; +}; + +struct remote_domain_define_xml_flags_ret { + remote_nonnull_domain dom; +}; + struct remote_domain_undefine_args { remote_nonnull_domain dom; }; @@ -5506,5 +5515,13 @@ enum remote_procedure { * @generate: none * @acl: connect:write */ - REMOTE_PROC_NODE_ALLOC_PAGES = 347 + REMOTE_PROC_NODE_ALLOC_PAGES = 347, + + /** + * @generate: both + * @priority: high + * @acl: domain:write + * @acl: domain:save + */ + REMOTE_PROC_DOMAIN_DEFINE_XML_FLAGS = 348 }; -- 2.1.0

On Tue, Nov 18, 2014 at 05:59:48PM +0000, Daniel P. Berrange wrote:
The virDomainDefineXML method is one of the few that still lacks a 'unsigned int flags' parameter. This will be needed for adding
s/a/an/?
XML validation to this API. virDomainCreateXML fortunately already has flags. --- include/libvirt/libvirt-domain.h | 4 ++++ src/driver-hypervisor.h | 5 +++++ src/libvirt-domain.c | 48 ++++++++++++++++++++++++++++++++++++++++ src/libvirt_public.syms | 5 +++++ src/qemu/qemu_driver.c | 10 ++++++++- src/remote/remote_driver.c | 1 + src/remote/remote_protocol.x | 19 +++++++++++++++- 7 files changed, 90 insertions(+), 2 deletions(-)
diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h index 1fac2a3..864c16c 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -1415,6 +1415,10 @@ int virDomainMemoryPeek (virDomainPtr dom, */ virDomainPtr virDomainDefineXML (virConnectPtr conn, const char *xml); + +virDomainPtr virDomainDefineXMLFlags (virConnectPtr conn, + const char *xml, + unsigned int flags); int virDomainUndefine (virDomainPtr domain);
typedef enum { diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index ad66629..f73d40b 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -314,6 +314,10 @@ typedef int typedef virDomainPtr (*virDrvDomainDefineXML)(virConnectPtr conn, const char *xml); +typedef virDomainPtr +(*virDrvDomainDefineXMLFlags)(virConnectPtr conn, + const char *xml, + unsigned int flags);
typedef int (*virDrvDomainUndefine)(virDomainPtr dom); @@ -1260,6 +1264,7 @@ struct _virHypervisorDriver { virDrvDomainCreateWithFlags domainCreateWithFlags; virDrvDomainCreateWithFiles domainCreateWithFiles; virDrvDomainDefineXML domainDefineXML; + virDrvDomainDefineXMLFlags domainDefineXMLFlags; virDrvDomainUndefine domainUndefine; virDrvDomainUndefineFlags domainUndefineFlags; virDrvDomainAttachDevice domainAttachDevice; diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 2b0defc..e9d3608 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -6473,6 +6473,54 @@ virDomainDefineXML(virConnectPtr conn, const char *xml)
/** + * virDomainDefineXMLFlags: + * @conn: pointer to the hypervisor connection + * @xml: the XML description for the domain, preferably in UTF-8 + * @flags: bitwise OR of virDomainDefineFlags + * + * Define a domain, but does not start it.
Either "defines" or "do not", I guess.
+ * This definition is persistent, until explicitly undefined with + * virDomainUndefine(). A previous definition for this domain would be + * overridden if it already exists. + * + * Some hypervisors may prevent this operation if there is a current + * block copy operation on a transient domain with the same id as the + * domain being defined; in that case, use virDomainBlockJobAbort() to + * stop the block copy first. + * + * virDomainFree should be used to free the resources after the + * domain object is no longer needed. + * + * Returns NULL in case of error, a pointer to the domain otherwise + */ +virDomainPtr +virDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) +{ + VIR_DEBUG("conn=%p, xml=%s flags=%x", conn, xml, flags); + + virResetLastError(); + + virCheckConnectReturn(conn, NULL); + virCheckReadOnlyGoto(conn->flags, error); + virCheckNonNullArgGoto(xml, error); + + if (conn->driver->domainDefineXMLFlags) { + virDomainPtr ret; + ret = conn->driver->domainDefineXMLFlags(conn, xml, flags); + if (!ret) + goto error; + return ret; + } + + virReportUnsupportedError(); + + error: + virDispatchError(conn); + return NULL; +} + + +/** * virDomainUndefine: * @domain: pointer to a defined domain * diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 5f95802..4d9973e 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -684,4 +684,9 @@ LIBVIRT_1.2.9 { virNodeAllocPages; } LIBVIRT_1.2.8;
+LIBVIRT_1.2.11 { + global: + virDomainDefineXMLFlags; +} LIBVIRT_1.2.9; + # .... define new API here using predicted next version number .... diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a84fd47..a877b75 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6651,7 +6651,7 @@ qemuDomainCreate(virDomainPtr dom) return qemuDomainCreateWithFlags(dom, 0); }
-static virDomainPtr qemuDomainDefineXML(virConnectPtr conn, const char *xml) +static virDomainPtr qemuDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
Pretty long line. Also, this should be joined together with the second patch that updates remote_protocol-structs. Other than that it looks fine. Martin

Make sure every virt driver implements virDomainDefineXMLFlags by adding a trivial passthrough from the existing impl with no flags set. --- src/bhyve/bhyve_driver.c | 12 ++++++++++-- src/esx/esx_driver.c | 10 ++++++++-- src/libxl/libxl_driver.c | 12 ++++++++++-- src/lxc/lxc_driver.c | 13 +++++++++++-- src/openvz/openvz_driver.c | 10 +++++++++- src/parallels/parallels_driver.c | 11 ++++++++++- src/qemu/qemu_driver.c | 2 +- src/remote_protocol-structs | 8 ++++++++ src/test/test_driver.c | 13 +++++++++++-- src/uml/uml_driver.c | 12 ++++++++++-- src/vbox/vbox_common.c | 11 ++++++++++- src/vmware/vmware_driver.c | 10 +++++++++- src/xen/xen_driver.c | 12 ++++++++++-- src/xenapi/xenapi_driver.c | 11 ++++++++++- 14 files changed, 127 insertions(+), 20 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 664e631..f6d5d5e 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -485,7 +485,7 @@ bhyveDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) } static virDomainPtr -bhyveDomainDefineXML(virConnectPtr conn, const char *xml) +bhyveDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) { bhyveConnPtr privconn = conn->privateData; virDomainPtr dom = NULL; @@ -495,6 +495,8 @@ bhyveDomainDefineXML(virConnectPtr conn, const char *xml) virObjectEventPtr event = NULL; virCapsPtr caps = NULL; + virCheckFlags(0, NULL); + caps = bhyveDriverGetCapabilities(privconn); if (!caps) return NULL; @@ -504,7 +506,7 @@ bhyveDomainDefineXML(virConnectPtr conn, const char *xml) VIR_DOMAIN_XML_INACTIVE)) == NULL) goto cleanup; - if (virDomainDefineXMLEnsureACL(conn, def) < 0) + if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) goto cleanup; if (bhyveDomainAssignAddresses(def, NULL) < 0) @@ -546,6 +548,11 @@ bhyveDomainDefineXML(virConnectPtr conn, const char *xml) return dom; } +static virDomainPtr bhyveDomainDefineXML(virConnectPtr conn, const char *xml) +{ + return bhyveDomainDefineXMLFlags(conn, xml, 0); +} + static int bhyveDomainUndefine(virDomainPtr domain) { @@ -1438,6 +1445,7 @@ static virHypervisorDriver bhyveDriver = { .domainLookupByName = bhyveDomainLookupByName, /* 1.2.2 */ .domainLookupByID = bhyveDomainLookupByID, /* 1.2.3 */ .domainDefineXML = bhyveDomainDefineXML, /* 1.2.2 */ + .domainDefineXMLFlags = bhyveDomainDefineXMLFlags, /* 1.2.11 */ .domainUndefine = bhyveDomainUndefine, /* 1.2.2 */ .domainGetXMLDesc = bhyveDomainGetXMLDesc, /* 1.2.2 */ .domainIsActive = bhyveDomainIsActive, /* 1.2.2 */ diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 1cbebb9..248bb92 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -3019,7 +3019,7 @@ esxDomainCreate(virDomainPtr domain) static virDomainPtr -esxDomainDefineXML(virConnectPtr conn, const char *xml) +esxDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) { esxPrivate *priv = conn->privateData; virDomainDefPtr def = NULL; @@ -3045,6 +3045,8 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml) virDomainPtr domain = NULL; const char *src; + virCheckFlags(0, NULL); + memset(&data, 0, sizeof(data)); if (esxVI_EnsureSession(priv->primary) < 0) @@ -3239,7 +3241,10 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml) return domain; } - +static virDomainPtr esxDomainDefineXML(virConnectPtr conn, const char *xml) +{ + return esxDomainDefineXMLFlags(conn, xml, 0); +} static int esxDomainUndefineFlags(virDomainPtr domain, @@ -5183,6 +5188,7 @@ static virHypervisorDriver esxDriver = { .domainCreate = esxDomainCreate, /* 0.7.0 */ .domainCreateWithFlags = esxDomainCreateWithFlags, /* 0.8.2 */ .domainDefineXML = esxDomainDefineXML, /* 0.7.2 */ + .domainDefineXMLFlags = esxDomainDefineXMLFlags, /* 1.2.11 */ .domainUndefine = esxDomainUndefine, /* 0.7.1 */ .domainUndefineFlags = esxDomainUndefineFlags, /* 0.9.4 */ .domainGetAutostart = esxDomainGetAutostart, /* 0.9.0 */ diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 8cbf3c0..9b049db 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -2367,7 +2367,7 @@ libxlDomainCreate(virDomainPtr dom) } static virDomainPtr -libxlDomainDefineXML(virConnectPtr conn, const char *xml) +libxlDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) { libxlDriverPrivatePtr driver = conn->privateData; libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); @@ -2377,12 +2377,14 @@ libxlDomainDefineXML(virConnectPtr conn, const char *xml) virObjectEventPtr event = NULL; virDomainDefPtr oldDef = NULL; + virCheckFlags(0, NULL); + if (!(def = virDomainDefParseString(xml, cfg->caps, driver->xmlopt, 1 << VIR_DOMAIN_VIRT_XEN, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; - if (virDomainDefineXMLEnsureACL(conn, def) < 0) + if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) goto cleanup; if (!(vm = virDomainObjListAdd(driver->domains, def, @@ -2421,6 +2423,11 @@ libxlDomainDefineXML(virConnectPtr conn, const char *xml) return dom; } +static virDomainPtr libxlDomainDefineXML(virConnectPtr conn, const char *xml) +{ + return libxlDomainDefineXMLFlags(conn, xml, 0); +} + static int libxlDomainUndefineFlags(virDomainPtr dom, unsigned int flags) @@ -4778,6 +4785,7 @@ static virHypervisorDriver libxlDriver = { .domainCreate = libxlDomainCreate, /* 0.9.0 */ .domainCreateWithFlags = libxlDomainCreateWithFlags, /* 0.9.0 */ .domainDefineXML = libxlDomainDefineXML, /* 0.9.0 */ + .domainDefineXMLFlags = libxlDomainDefineXMLFlags, /* 1.2.11 */ .domainUndefine = libxlDomainUndefine, /* 0.9.0 */ .domainUndefineFlags = libxlDomainUndefineFlags, /* 0.9.4 */ .domainAttachDevice = libxlDomainAttachDevice, /* 0.9.2 */ diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index cf2a3c8..a9a34b5 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -443,7 +443,8 @@ static int lxcConnectNumOfDefinedDomains(virConnectPtr conn) -static virDomainPtr lxcDomainDefineXML(virConnectPtr conn, const char *xml) +static virDomainPtr +lxcDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) { virLXCDriverPtr driver = conn->privateData; virDomainDefPtr def = NULL; @@ -454,6 +455,8 @@ static virDomainPtr lxcDomainDefineXML(virConnectPtr conn, const char *xml) virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver); virCapsPtr caps = NULL; + virCheckFlags(0, NULL); + if (!(caps = virLXCDriverGetCapabilities(driver, false))) goto cleanup; @@ -462,7 +465,7 @@ static virDomainPtr lxcDomainDefineXML(virConnectPtr conn, const char *xml) VIR_DOMAIN_XML_INACTIVE))) goto cleanup; - if (virDomainDefineXMLEnsureACL(conn, def) < 0) + if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) goto cleanup; if (virSecurityManagerVerify(driver->securityManager, def) < 0) @@ -510,6 +513,11 @@ static virDomainPtr lxcDomainDefineXML(virConnectPtr conn, const char *xml) return dom; } +static virDomainPtr lxcDomainDefineXML(virConnectPtr conn, const char *xml) +{ + return lxcDomainDefineXMLFlags(conn, xml, 0); +} + static int lxcDomainUndefineFlags(virDomainPtr dom, unsigned int flags) { @@ -5761,6 +5769,7 @@ static virHypervisorDriver lxcDriver = { .domainCreateWithFlags = lxcDomainCreateWithFlags, /* 0.8.2 */ .domainCreateWithFiles = lxcDomainCreateWithFiles, /* 1.1.1 */ .domainDefineXML = lxcDomainDefineXML, /* 0.4.2 */ + .domainDefineXMLFlags = lxcDomainDefineXMLFlags, /* 1.2.11 */ .domainUndefine = lxcDomainUndefine, /* 0.4.2 */ .domainUndefineFlags = lxcDomainUndefineFlags, /* 0.9.4 */ .domainAttachDevice = lxcDomainAttachDevice, /* 1.0.1 */ diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index d9e27a1..69bb38c 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -969,13 +969,15 @@ openvzDomainSetNetworkConfig(virConnectPtr conn, static virDomainPtr -openvzDomainDefineXML(virConnectPtr conn, const char *xml) +openvzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) { struct openvz_driver *driver = conn->privateData; virDomainDefPtr vmdef = NULL; virDomainObjPtr vm = NULL; virDomainPtr dom = NULL; + virCheckFlags(0, NULL); + openvzDriverLock(driver); if ((vmdef = virDomainDefParseString(xml, driver->caps, driver->xmlopt, 1 << VIR_DOMAIN_VIRT_OPENVZ, @@ -1051,6 +1053,11 @@ openvzDomainDefineXML(virConnectPtr conn, const char *xml) return dom; } +static virDomainPtr openvzDomainDefineXML(virConnectPtr conn, const char *xml) +{ + return openvzDomainDefineXMLFlags(conn, xml, 0); +} + static virDomainPtr openvzDomainCreateXML(virConnectPtr conn, const char *xml, unsigned int flags) @@ -2588,6 +2595,7 @@ static virHypervisorDriver openvzDriver = { .domainCreate = openvzDomainCreate, /* 0.3.1 */ .domainCreateWithFlags = openvzDomainCreateWithFlags, /* 0.8.2 */ .domainDefineXML = openvzDomainDefineXML, /* 0.3.3 */ + .domainDefineXMLFlags = openvzDomainDefineXMLFlags, /* 1.2.11 */ .domainUndefine = openvzDomainUndefine, /* 0.3.3 */ .domainUndefineFlags = openvzDomainUndefineFlags, /* 0.9.4 */ .domainGetAutostart = openvzDomainGetAutostart, /* 0.4.6 */ diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c index 808dc4a..a7b8cbc 100644 --- a/src/parallels/parallels_driver.c +++ b/src/parallels/parallels_driver.c @@ -2288,13 +2288,15 @@ parallelsCreateCt(virConnectPtr conn ATTRIBUTE_UNUSED, virDomainDefPtr def) } static virDomainPtr -parallelsDomainDefineXML(virConnectPtr conn, const char *xml) +parallelsDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) { parallelsConnPtr privconn = conn->privateData; virDomainPtr ret = NULL; virDomainDefPtr def; virDomainObjPtr olddom = NULL; + virCheckFlags(0, NULL); + parallelsDriverLock(privconn); if ((def = virDomainDefParseString(xml, privconn->caps, privconn->xmlopt, 1 << VIR_DOMAIN_VIRT_PARALLELS, @@ -2345,6 +2347,12 @@ parallelsDomainDefineXML(virConnectPtr conn, const char *xml) return ret; } +static virDomainPtr parallelsDomainDefineXML(virConnectPtr conn, const char *xml) +{ + return parallelsDomainDefineXMLFlags(conn, xml, 0); +} + + static int parallelsNodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED, virNodeInfoPtr nodeinfo) @@ -2494,6 +2502,7 @@ static virHypervisorDriver parallelsDriver = { .domainShutdown = parallelsDomainShutdown, /* 0.10.0 */ .domainCreate = parallelsDomainCreate, /* 0.10.0 */ .domainDefineXML = parallelsDomainDefineXML, /* 0.10.0 */ + .domainDefineXMLFlags = parallelsDomainDefineXMLFlags, /* 1.2.11 */ .nodeGetCPUMap = parallelsNodeGetCPUMap, /* 1.2.8 */ .connectIsEncrypted = parallelsConnectIsEncrypted, /* 1.2.5 */ .connectIsSecure = parallelsConnectIsSecure, /* 1.2.5 */ diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a877b75..654fa2e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6675,7 +6675,7 @@ static virDomainPtr qemuDomainDefineXMLFlags(virConnectPtr conn, const char *xml VIR_DOMAIN_XML_INACTIVE))) goto cleanup; - if (virDomainDefineXMLEnsureACL(conn, def) < 0) + if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) goto cleanup; if (virSecurityManagerVerify(driver->securityManager, def) < 0) diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 362baf9..32bc047 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -686,6 +686,13 @@ struct remote_domain_define_xml_args { struct remote_domain_define_xml_ret { remote_nonnull_domain dom; }; +struct remote_domain_define_xml_flags_args { + remote_nonnull_string xml; + u_int flags; +}; +struct remote_domain_define_xml_flags_ret { + remote_nonnull_domain dom; +}; struct remote_domain_undefine_args { remote_nonnull_domain dom; }; @@ -2927,4 +2934,5 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_BLOCK_COPY = 345, REMOTE_PROC_DOMAIN_EVENT_CALLBACK_TUNABLE = 346, REMOTE_PROC_NODE_ALLOC_PAGES = 347, + REMOTE_PROC_DOMAIN_DEFINE_XML_FLAGS = 348, }; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index d7844bd..4469ad5 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2927,8 +2927,9 @@ static int testConnectListDefinedDomains(virConnectPtr conn, return n; } -static virDomainPtr testDomainDefineXML(virConnectPtr conn, - const char *xml) +static virDomainPtr testDomainDefineXMLFlags(virConnectPtr conn, + const char *xml, + unsigned int flags) { testConnPtr privconn = conn->privateData; virDomainPtr ret = NULL; @@ -2937,6 +2938,8 @@ static virDomainPtr testDomainDefineXML(virConnectPtr conn, virObjectEventPtr event = NULL; virDomainDefPtr oldDef = NULL; + virCheckFlags(0, NULL); + testDriverLock(privconn); if ((def = virDomainDefParseString(xml, privconn->caps, privconn->xmlopt, 1 << VIR_DOMAIN_VIRT_TEST, @@ -2975,6 +2978,11 @@ static virDomainPtr testDomainDefineXML(virConnectPtr conn, return ret; } +static virDomainPtr testDomainDefineXML(virConnectPtr conn, const char *xml) +{ + return testDomainDefineXMLFlags(conn, xml, 0); +} + static char *testDomainGetMetadata(virDomainPtr dom, int type, const char *uri, @@ -7372,6 +7380,7 @@ static virHypervisorDriver testDriver = { .domainCreate = testDomainCreate, /* 0.1.11 */ .domainCreateWithFlags = testDomainCreateWithFlags, /* 0.8.2 */ .domainDefineXML = testDomainDefineXML, /* 0.1.11 */ + .domainDefineXMLFlags = testDomainDefineXMLFlags, /* 1.2.11 */ .domainUndefine = testDomainUndefine, /* 0.1.11 */ .domainUndefineFlags = testDomainUndefineFlags, /* 0.9.4 */ .domainGetAutostart = testDomainGetAutostart, /* 0.3.2 */ diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index b01d631..d15b55a 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -2075,20 +2075,23 @@ static int umlDomainCreate(virDomainPtr dom) return umlDomainCreateWithFlags(dom, 0); } -static virDomainPtr umlDomainDefineXML(virConnectPtr conn, const char *xml) +static virDomainPtr +umlDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) { struct uml_driver *driver = conn->privateData; virDomainDefPtr def; virDomainObjPtr vm = NULL; virDomainPtr dom = NULL; + virCheckFlags(0, NULL); + umlDriverLock(driver); if (!(def = virDomainDefParseString(xml, driver->caps, driver->xmlopt, 1 << VIR_DOMAIN_VIRT_UML, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; - if (virDomainDefineXMLEnsureACL(conn, def) < 0) + if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) goto cleanup; if (!(vm = virDomainObjListAdd(driver->domains, def, @@ -2117,6 +2120,11 @@ static virDomainPtr umlDomainDefineXML(virConnectPtr conn, const char *xml) return dom; } +static virDomainPtr umlDomainDefineXML(virConnectPtr conn, const char *xml) +{ + return umlDomainDefineXMLFlags(conn, xml, 0); +} + static int umlDomainUndefineFlags(virDomainPtr dom, unsigned int flags) { diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index bffec82..322353f 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -1831,7 +1831,8 @@ vboxAttachSharedFolder(virDomainDefPtr def, vboxGlobalData *data, IMachine *mach } } -static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) +static virDomainPtr +vboxDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) { vboxGlobalData *data = conn->privateData; IMachine *machine = NULL; @@ -1842,6 +1843,8 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) char uuidstr[VIR_UUID_STRING_BUFLEN]; virDomainPtr ret = NULL; + virCheckFlags(0, NULL); + if (!data->vboxObj) return ret; @@ -1968,6 +1971,11 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) return NULL; } +static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) +{ + return vboxDomainDefineXMLFlags(conn, xml, 0); +} + static void detachDevices_common(vboxGlobalData *data, vboxIIDUnion *iidu) { @@ -7609,6 +7617,7 @@ virHypervisorDriver vboxCommonDriver = { .domainCreate = vboxDomainCreate, /* 0.6.3 */ .domainCreateWithFlags = vboxDomainCreateWithFlags, /* 0.8.2 */ .domainDefineXML = vboxDomainDefineXML, /* 0.6.3 */ + .domainDefineXMLFlags = vboxDomainDefineXMLFlags, /* 1.2.11*/ .domainUndefine = vboxDomainUndefine, /* 0.6.3 */ .domainUndefineFlags = vboxDomainUndefineFlags, /* 0.9.5 */ .domainAttachDevice = vboxDomainAttachDevice, /* 0.6.3 */ diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 5379876..4ee9526 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -358,7 +358,7 @@ vmwareStartVM(struct vmware_driver *driver, virDomainObjPtr vm) } static virDomainPtr -vmwareDomainDefineXML(virConnectPtr conn, const char *xml) +vmwareDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) { struct vmware_driver *driver = conn->privateData; virDomainDefPtr vmdef = NULL; @@ -371,6 +371,8 @@ vmwareDomainDefineXML(virConnectPtr conn, const char *xml) vmwareDomainPtr pDomain = NULL; virVMXContext ctx; + virCheckFlags(0, NULL); + ctx.formatFileName = vmwareCopyVMXFileName; vmwareDriverLock(driver); @@ -427,6 +429,11 @@ vmwareDomainDefineXML(virConnectPtr conn, const char *xml) return dom; } +static virDomainPtr vmwareDomainDefineXML(virConnectPtr conn, const char *xml) +{ + return vmwareDomainDefineXMLFlags(conn, xml, 0); +} + static int vmwareDomainShutdownFlags(virDomainPtr dom, unsigned int flags) @@ -1211,6 +1218,7 @@ static virHypervisorDriver vmwareDriver = { .domainCreate = vmwareDomainCreate, /* 0.8.7 */ .domainCreateWithFlags = vmwareDomainCreateWithFlags, /* 0.8.7 */ .domainDefineXML = vmwareDomainDefineXML, /* 0.8.7 */ + .domainDefineXMLFlags = vmwareDomainDefineXMLFlags, /* 1.2.11 */ .domainUndefine = vmwareDomainUndefine, /* 0.8.7 */ .domainUndefineFlags = vmwareDomainUndefineFlags, /* 0.9.4 */ .domainIsActive = vmwareDomainIsActive, /* 0.8.7 */ diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index 7334142..1897584 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -1882,18 +1882,20 @@ xenUnifiedDomainCreate(virDomainPtr dom) } static virDomainPtr -xenUnifiedDomainDefineXML(virConnectPtr conn, const char *xml) +xenUnifiedDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) { xenUnifiedPrivatePtr priv = conn->privateData; virDomainDefPtr def = NULL; virDomainPtr ret = NULL; + virCheckFlags(0, NULL); + if (!(def = virDomainDefParseString(xml, priv->caps, priv->xmlopt, 1 << VIR_DOMAIN_VIRT_XEN, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; - if (virDomainDefineXMLEnsureACL(conn, def) < 0) + if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) goto cleanup; if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) { @@ -1915,6 +1917,11 @@ xenUnifiedDomainDefineXML(virConnectPtr conn, const char *xml) return ret; } +static virDomainPtr xenUnifiedDomainDefineXML(virConnectPtr conn, const char *xml) +{ + return xenUnifiedDomainDefineXMLFlags(conn, xml, 0); +} + static int xenUnifiedDomainUndefineFlags(virDomainPtr dom, unsigned int flags) { @@ -2796,6 +2803,7 @@ static virHypervisorDriver xenUnifiedDriver = { .domainCreate = xenUnifiedDomainCreate, /* 0.1.1 */ .domainCreateWithFlags = xenUnifiedDomainCreateWithFlags, /* 0.8.2 */ .domainDefineXML = xenUnifiedDomainDefineXML, /* 0.1.1 */ + .domainDefineXMLFlags = xenUnifiedDomainDefineXMLFlags, /* 1.2.11 */ .domainUndefine = xenUnifiedDomainUndefine, /* 0.1.1 */ .domainUndefineFlags = xenUnifiedDomainUndefineFlags, /* 0.9.4 */ .domainAttachDevice = xenUnifiedDomainAttachDevice, /* 0.1.9 */ diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index 7048556..b659c0a 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -1714,12 +1714,15 @@ xenapiDomainCreate(virDomainPtr dom) * Returns 0 on success or -1 in case of error */ static virDomainPtr -xenapiDomainDefineXML(virConnectPtr conn, const char *xml) +xenapiDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) { struct _xenapiPrivate *priv = conn->privateData; xen_vm_record *record = NULL; xen_vm vm = NULL; virDomainPtr domP = NULL; + + virCheckFlags(0, NULL); + if (!priv->caps) return NULL; virDomainDefPtr defPtr = virDomainDefParseString(xml, @@ -1752,6 +1755,11 @@ xenapiDomainDefineXML(virConnectPtr conn, const char *xml) return domP; } +static virDomainPtr xenapiDomainDefineXML(virConnectPtr conn, const char *xml) +{ + return xenapiDomainDefineXMLFlags(conn, xml, 0); +} + /* * xenapiDomainUndefineFlags * @@ -2002,6 +2010,7 @@ static virHypervisorDriver xenapiDriver = { .domainCreate = xenapiDomainCreate, /* 0.8.0 */ .domainCreateWithFlags = xenapiDomainCreateWithFlags, /* 0.8.2 */ .domainDefineXML = xenapiDomainDefineXML, /* 0.8.0 */ + .domainDefineXMLFlags = xenapiDomainDefineXMLFlags, /* 1.2.11 */ .domainUndefine = xenapiDomainUndefine, /* 0.8.0 */ .domainUndefineFlags = xenapiDomainUndefineFlags, /* 0.9.5 */ .domainGetAutostart = xenapiDomainGetAutostart, /* 0.8.0 */ -- 2.1.0

Add a helper method that can validate an XML document against an RNG schema --- include/libvirt/virterror.h | 1 + src/internal.h | 4 +++ src/libvirt_private.syms | 1 + src/util/virerror.c | 6 ++++ src/util/virxml.c | 74 +++++++++++++++++++++++++++++++++++++++++++++ src/util/virxml.h | 5 +++ 6 files changed, 91 insertions(+) diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h index 85dd74c..3d3d80a 100644 --- a/include/libvirt/virterror.h +++ b/include/libvirt/virterror.h @@ -304,6 +304,7 @@ typedef enum { VIR_ERR_STORAGE_VOL_EXIST = 90, /* the storage vol already exists */ VIR_ERR_CPU_INCOMPATIBLE = 91, /* given CPU is incompatible with host CPU*/ + VIR_ERR_XML_INVALID_SCHEMA = 92, /* XML document doens't validate against schema */ } virErrorNumber; /** diff --git a/src/internal.h b/src/internal.h index f6a88b2..b07421a 100644 --- a/src/internal.h +++ b/src/internal.h @@ -233,11 +233,15 @@ # define VIR_WARNINGS_NO_CAST_ALIGN \ _Pragma ("GCC diagnostic push") \ _Pragma ("GCC diagnostic ignored \"-Wcast-align\"") +# define VIR_WARNINGS_NO_PRINTF \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wsuggest-attribute=format\"") # define VIR_WARNINGS_RESET \ _Pragma ("GCC diagnostic pop") # else # define VIR_WARNINGS_NO_CAST_ALIGN +# define VIR_WARNINGS_NO_PRINTF # define VIR_WARNINGS_RESET # endif diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0864618..b48dde4 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2226,6 +2226,7 @@ virXMLParseHelper; virXMLPickShellSafeComment; virXMLPropString; virXMLSaveFile; +virXMLValidateAgainstSchema; virXPathBoolean; virXPathInt; virXPathLong; diff --git a/src/util/virerror.c b/src/util/virerror.c index 4aa6d04..f5d7f54 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -1285,6 +1285,12 @@ virErrorMsg(virErrorNumber error, const char *info) else errmsg = _("the CPU is incompatible with host CPU: %s"); break; + case VIR_ERR_XML_INVALID_SCHEMA: + if (info == NULL) + errmsg = _("XML document failed to validate against schema"); + else + errmsg = _("XML document failed to validate against schema: %s"); + break; } return errmsg; } diff --git a/src/util/virxml.c b/src/util/virxml.c index 7f591fb..4508e58 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -1076,3 +1076,77 @@ virXMLInjectNamespace(xmlNodePtr node, return 0; } + +static void catchRNGError(void *ctx, + const char *msg, + ...) +{ + virBufferPtr buf = ctx; + va_list args; + + va_start(args, msg); + VIR_WARNINGS_NO_PRINTF; + virBufferVasprintf(buf, msg, args); + VIR_WARNINGS_RESET; + va_end(args); +} + + +static void ignoreRNGError(void *ctx ATTRIBUTE_UNUSED, + const char *msg ATTRIBUTE_UNUSED, + ...) +{} + + +int +virXMLValidateAgainstSchema(const char *schemafile, + xmlDocPtr doc) +{ + xmlRelaxNGParserCtxtPtr rngParser = NULL; + xmlRelaxNGPtr rng = NULL; + xmlRelaxNGValidCtxtPtr rngValid = NULL; + virBuffer buf = VIR_BUFFER_INITIALIZER; + int ret = -1; + + if (!(rngParser = xmlRelaxNGNewParserCtxt(schemafile))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to create RNG parser for %s"), + schemafile); + goto cleanup; + } + + if (!(rng = xmlRelaxNGParse(rngParser))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to parse RNG %s"), + schemafile); + goto cleanup; + } + + if (!(rngValid = xmlRelaxNGNewValidCtxt(rng))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to create RNG validation context %s"), + schemafile); + goto cleanup; + } + + xmlRelaxNGSetValidErrors(rngValid, + catchRNGError, + ignoreRNGError, + &buf); + + if (xmlRelaxNGValidateDoc(rngValid, doc) != 0) { + virReportError(VIR_ERR_XML_INVALID_SCHEMA, + _("Unable to validate doc against %s\n%s"), + schemafile, virBufferCurrentContent(&buf)); + goto cleanup; + } + + ret = 0; + + cleanup: + virBufferFreeAndReset(&buf); + xmlRelaxNGFreeParserCtxt(rngParser); + xmlRelaxNGFreeValidCtxt(rngValid); + xmlRelaxNGFree(rng); + return ret; +} diff --git a/src/util/virxml.h b/src/util/virxml.h index 781b3bf..b94de74 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -28,6 +28,7 @@ # include <libxml/parser.h> # include <libxml/tree.h> # include <libxml/xpath.h> +# include <libxml/relaxng.h> int virXPathBoolean(const char *xpath, xmlXPathContextPtr ctxt); @@ -176,4 +177,8 @@ int virXMLInjectNamespace(xmlNodePtr node, const char *uri, const char *key); +int +virXMLValidateAgainstSchema(const char *schemafile, + xmlDocPtr xml); + #endif /* __VIR_XML_H__ */ -- 2.1.0

The VIR_DOMAIN_XML_SECURE flag only has effect on the formatting of XML so should not be passed to virDomainDefParseNode The VIR_DOMAIN_XML_UPDATE_CPU flag has to be processed by the driver code, so should not be passed to virDomainDefFormatInternal --- src/conf/snapshot_conf.c | 6 ++---- src/qemu/qemu_domain.c | 4 +++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 1f83b2c..a72ded7 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -286,8 +286,7 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, def->dom = virDomainDefParseNode(ctxt->node->doc, domainNode, caps, xmlopt, expectedVirtTypes, - (VIR_DOMAIN_XML_INACTIVE | - VIR_DOMAIN_XML_SECURE)); + VIR_DOMAIN_XML_INACTIVE); if (!def->dom) goto cleanup; } else { @@ -676,8 +675,7 @@ char *virDomainSnapshotDefFormat(const char *domain_uuid, virBuffer buf = VIR_BUFFER_INITIALIZER; size_t i; - virCheckFlags(VIR_DOMAIN_XML_SECURE | - VIR_DOMAIN_XML_UPDATE_CPU, NULL); + virCheckFlags(VIR_DOMAIN_XML_SECURE, NULL); flags |= VIR_DOMAIN_XML_INACTIVE; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 01bf39b..00fbb2f 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1748,6 +1748,8 @@ qemuDomainDefFormatBuf(virQEMUDriverPtr driver, cpuUpdate(cpu, caps->host.cpu) < 0) goto cleanup; def->cpu = cpu; + + flags &= ~VIR_DOMAIN_XML_UPDATE_CPU; } if ((flags & VIR_DOMAIN_XML_MIGRATABLE)) { @@ -2169,7 +2171,7 @@ qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm, virUUIDFormat(vm->def->uuid, uuidstr); newxml = virDomainSnapshotDefFormat(uuidstr, snapshot->def, - QEMU_DOMAIN_FORMAT_LIVE_FLAGS, 1); + VIR_DOMAIN_XML_SECURE, 1); if (newxml == NULL) return -1; -- 2.1.0

The phyp driver is passing the VIR_DOMAIN_XML_SECURE flag to virDomainDefParseString which is wrong, because that flag only has effect when formatting XML. --- src/phyp/phyp_driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 269d030..71db7bd 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -3558,7 +3558,7 @@ phypDomainCreateXML(virConnectPtr conn, if (!(def = virDomainDefParseString(xml, phyp_driver->caps, phyp_driver->xmlopt, 1 << VIR_DOMAIN_VIRT_PHYP, - VIR_DOMAIN_XML_SECURE))) + 0))) goto err; /* checking if this name already exists on this system */ -- 2.1.0

The XenAPI driver was passing the flags for virDomainCreateXML straight into the virDomainDefParseString method, even though they expect totally different sets of flags. It should have been using VIR_DOMAIN_XML_INACTIVE --- src/xenapi/xenapi_driver.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index b659c0a..656f923 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -554,7 +554,7 @@ xenapiDomainCreateXML(virConnectPtr conn, virDomainDefPtr defPtr = virDomainDefParseString(xmlDesc, priv->caps, priv->xmlopt, 1 << VIR_DOMAIN_VIRT_XEN, - flags); + VIR_DOMAIN_XML_INACTIVE); createVMRecordFromXml(conn, defPtr, &record, &vm); virDomainDefFree(defPtr); if (record) { @@ -1728,7 +1728,7 @@ xenapiDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int fla virDomainDefPtr defPtr = virDomainDefParseString(xml, priv->caps, priv->xmlopt, 1 << VIR_DOMAIN_VIRT_XEN, - 0); + VIR_DOMAIN_XML_INACTIVE); if (!defPtr) return NULL; -- 2.1.0

The virDomainDefParse* and virDomainDefFormat* methods both accept the VIR_DOMAIN_XML_* flags defined in the public API, along with a set of other VIR_DOMAIN_XML_INTERNAL_* flags defined in domain_conf.c. This is seriously confusing & error prone for a number of reasons: - VIR_DOMAIN_XML_SECURE, VIR_DOMAIN_XML_MIGRATABLE and VIR_DOMAIN_XML_UPDATE_CPU are only relevant for the formatting operation - VIR_DOMAIN_XML_UPDATE_CPU is not in fact handled by the domain_conf.c code at all - it must be dealt with by the driver code - Some of the VIR_DOMAIN_XML_INTERNAL_* flags only apply to parse or to format, but not both. This patch cleanly separates out the flags. There are two distint VIR_DOMAIN_DEF_PARSE_* and VIR_DOMAIN_DEF_FORMAT_* flags that are used by the corresponding methods. The VIR_DOMAIN_XML_* flags received via public API calls must be converted to the VIR_DOMAIN_DEF_FORMAT_* flags where needed. The various calls to virDomainDefParse which hardcoded the use of the VIR_DOMAIN_XML_INACTIVE flag change to use the VIR_DOMAIN_DEF_PARSE_INACTIVE flag. --- src/bhyve/bhyve_driver.c | 9 +- src/conf/domain_conf.c | 309 ++++++++++++++++++-------------------- src/conf/domain_conf.h | 70 ++++++--- src/conf/snapshot_conf.c | 6 +- src/esx/esx_driver.c | 13 +- src/hyperv/hyperv_driver.c | 3 +- src/libvirt_private.syms | 1 + src/libxl/libxl_domain.c | 2 +- src/libxl/libxl_driver.c | 23 +-- src/libxl/libxl_migration.c | 6 +- src/lxc/lxc_driver.c | 12 +- src/openvz/openvz_driver.c | 13 +- src/phyp/phyp_driver.c | 5 +- src/qemu/qemu_domain.c | 8 +- src/qemu/qemu_driver.c | 26 ++-- src/qemu/qemu_migration.c | 8 +- src/test/test_driver.c | 18 ++- src/uml/uml_driver.c | 10 +- src/vbox/vbox_common.c | 14 +- src/vmware/vmware_driver.c | 9 +- src/xen/xen_driver.c | 9 +- src/xen/xend_internal.c | 6 +- src/xen/xm_internal.c | 4 +- src/xenapi/xenapi_driver.c | 4 +- tests/domainsnapshotxml2xmltest.c | 2 +- tests/lxcxml2xmltest.c | 4 +- tests/openvzutilstest.c | 2 +- tests/qemuhotplugtest.c | 6 +- tests/qemuxml2argvtest.c | 2 +- tests/qemuxml2xmltest.c | 9 +- tests/qemuxmlnstest.c | 2 +- tests/vmx2xmltest.c | 2 +- tests/xmconfigtest.c | 4 +- tests/xml2sexprtest.c | 2 +- tests/xml2vmxtest.c | 2 +- 35 files changed, 334 insertions(+), 291 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index f6d5d5e..a7312d0 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -476,7 +476,8 @@ bhyveDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) if (virDomainGetXMLDescEnsureACL(domain->conn, vm->def, flags) < 0) goto cleanup; - ret = virDomainDefFormat(vm->def, flags); + ret = virDomainDefFormat(vm->def, + virDomainDefFormatConvertXMLFlags(flags)); cleanup: if (vm) @@ -503,7 +504,7 @@ bhyveDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flag if ((def = virDomainDefParseString(xml, caps, privconn->xmlopt, 1 << VIR_DOMAIN_VIRT_BHYVE, - VIR_DOMAIN_XML_INACTIVE)) == NULL) + VIR_DOMAIN_DEF_PARSE_INACTIVE)) == NULL) goto cleanup; if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) @@ -690,7 +691,7 @@ bhyveConnectDomainXMLToNative(virConnectPtr conn, if (!(def = virDomainDefParseString(xmlData, caps, privconn->xmlopt, 1 << VIR_DOMAIN_VIRT_BHYVE, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; if (bhyveDomainAssignAddresses(def, NULL) < 0) @@ -901,7 +902,7 @@ bhyveDomainCreateXML(virConnectPtr conn, if ((def = virDomainDefParseString(xml, caps, privconn->xmlopt, 1 << VIR_DOMAIN_VIRT_BHYVE, - VIR_DOMAIN_XML_INACTIVE)) == NULL) + VIR_DOMAIN_DEF_PARSE_INACTIVE)) == NULL) goto cleanup; if (virDomainCreateXMLEnsureACL(conn, def) < 0) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5f4b9f6..2dace76 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -85,39 +85,12 @@ struct _virDomainXMLOption { /* XML namespace callbacks */ virDomainXMLNamespace ns; - }; - - -/* Private flags used internally by virDomainSaveStatus and - * virDomainLoadStatus, in addition to the public virDomainXMLFlags. */ -typedef enum { - /* dump internal domain status information */ - VIR_DOMAIN_XML_INTERNAL_STATUS = 1 << 16, - /* dump/parse <actual> element */ - VIR_DOMAIN_XML_INTERNAL_ACTUAL_NET = 1 << 17, - /* dump/parse original states of host PCI device */ - VIR_DOMAIN_XML_INTERNAL_PCI_ORIG_STATES = 1 << 18, - VIR_DOMAIN_XML_INTERNAL_ALLOW_ROM = 1 << 19, - VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT = 1 << 20, - VIR_DOMAIN_XML_INTERNAL_CLOCK_ADJUST = 1 << 21, - /* parse only source half of <disk> */ - VIR_DOMAIN_XML_INTERNAL_DISK_SOURCE = 1 << 22, -} virDomainXMLInternalFlags; - -#define DUMPXML_FLAGS \ - (VIR_DOMAIN_XML_SECURE | \ - VIR_DOMAIN_XML_INACTIVE | \ - VIR_DOMAIN_XML_UPDATE_CPU | \ - VIR_DOMAIN_XML_MIGRATABLE) - -verify(((VIR_DOMAIN_XML_INTERNAL_STATUS | - VIR_DOMAIN_XML_INTERNAL_ACTUAL_NET | - VIR_DOMAIN_XML_INTERNAL_PCI_ORIG_STATES | - VIR_DOMAIN_XML_INTERNAL_ALLOW_ROM | - VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT | - VIR_DOMAIN_XML_INTERNAL_CLOCK_ADJUST | - VIR_DOMAIN_XML_INTERNAL_DISK_SOURCE) - & DUMPXML_FLAGS) == 0); +}; + +#define VIR_DOMAIN_DEF_FORMAT_COMMON_FLAGS \ + (VIR_DOMAIN_DEF_FORMAT_SECURE | \ + VIR_DOMAIN_DEF_FORMAT_INACTIVE | \ + VIR_DOMAIN_DEF_FORMAT_MIGRATABLE) VIR_ENUM_IMPL(virDomainTaint, VIR_DOMAIN_TAINT_LAST, "custom-argv", @@ -792,9 +765,6 @@ VIR_ENUM_DECL(virDomainBlockJob) VIR_ENUM_IMPL(virDomainBlockJob, VIR_DOMAIN_BLOCK_JOB_TYPE_LAST, "", "", "copy", "", "active-commit") -#define VIR_DOMAIN_XML_WRITE_FLAGS VIR_DOMAIN_XML_SECURE -#define VIR_DOMAIN_XML_READ_FLAGS VIR_DOMAIN_XML_INACTIVE - static virClassPtr virDomainObjClass; static virClassPtr virDomainObjListClass; static virClassPtr virDomainXMLOptionClass; @@ -2650,11 +2620,11 @@ virDomainDeviceGetInfo(virDomainDeviceDefPtr device) } static bool -virDomainDeviceInfoIsSet(virDomainDeviceInfoPtr info, unsigned int flags) +virDomainDeviceInfoNeedsFormat(virDomainDeviceInfoPtr info, unsigned int flags) { if (info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) return true; - if (info->alias && !(flags & VIR_DOMAIN_XML_INACTIVE)) + if (info->alias && !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)) return true; if (info->mastertype != VIR_DOMAIN_CONTROLLER_MASTER_NONE) return true; @@ -3263,11 +3233,11 @@ virDomainDeviceInfoFormat(virBufferPtr buf, virDomainDeviceInfoPtr info, unsigned int flags) { - if ((flags & VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT) && info->bootIndex) + if ((flags & VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT) && info->bootIndex) virBufferAsprintf(buf, "<boot order='%d'/>\n", info->bootIndex); if (info->alias && - !(flags & VIR_DOMAIN_XML_INACTIVE)) { + !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)) { virBufferAsprintf(buf, "<alias name='%s'/>\n", info->alias); } @@ -3276,7 +3246,7 @@ virDomainDeviceInfoFormat(virBufferPtr buf, info->master.usb.startport); } - if ((flags & VIR_DOMAIN_XML_INTERNAL_ALLOW_ROM) && + if ((flags & VIR_DOMAIN_DEF_FORMAT_ALLOW_ROM) && (info->rombar || info->romfile)) { virBufferAddLit(buf, "<rom"); @@ -3760,7 +3730,7 @@ virDomainDeviceInfoParseXML(xmlNodePtr node, while (cur != NULL) { if (cur->type == XML_ELEMENT_NODE) { if (alias == NULL && - !(flags & VIR_DOMAIN_XML_INACTIVE) && + !(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) && xmlStrEqual(cur->name, BAD_CAST "alias")) { alias = cur; } else if (address == NULL && @@ -3770,11 +3740,11 @@ virDomainDeviceInfoParseXML(xmlNodePtr node, xmlStrEqual(cur->name, BAD_CAST "master")) { master = cur; } else if (boot == NULL && - (flags & VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT) && + (flags & VIR_DOMAIN_DEF_PARSE_ALLOW_BOOT) && xmlStrEqual(cur->name, BAD_CAST "boot")) { boot = cur; } else if (rom == NULL && - (flags & VIR_DOMAIN_XML_INTERNAL_ALLOW_ROM) && + (flags & VIR_DOMAIN_DEF_PARSE_ALLOW_ROM) && xmlStrEqual(cur->name, BAD_CAST "rom")) { rom = cur; } @@ -4102,7 +4072,7 @@ virDomainHostdevSubsysPCIDefParseXML(xmlNodePtr node, if (virDevicePCIAddressParseXML(cur, addr) < 0) goto out; - } else if ((flags & VIR_DOMAIN_XML_INTERNAL_STATUS) && + } else if ((flags & VIR_DOMAIN_DEF_PARSE_STATUS) && xmlStrEqual(cur->name, BAD_CAST "state")) { /* Legacy back-compat. Don't add any more attributes here */ char *devaddr = virXMLPropString(cur, "devaddr"); @@ -4116,7 +4086,7 @@ virDomainHostdevSubsysPCIDefParseXML(xmlNodePtr node, goto out; } def->info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; - } else if ((flags & VIR_DOMAIN_XML_INTERNAL_PCI_ORIG_STATES) && + } else if ((flags & VIR_DOMAIN_DEF_PARSE_PCI_ORIG_STATES) && xmlStrEqual(cur->name, BAD_CAST "origstates")) { virDomainHostdevOrigStatesPtr states = &def->origstates; if (virDomainHostdevSubsysPCIOrigStatesDefParseXML(cur, states) < 0) @@ -4914,7 +4884,7 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, * present. Hence, return now. */ if (STREQ_NULLABLE(seclabel->model, "none")) { - if (flags & VIR_DOMAIN_XML_INACTIVE) { + if (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) { /* Fix older configurations */ seclabel->type = VIR_DOMAIN_SECLABEL_NONE; seclabel->relabel = false; @@ -4935,7 +4905,7 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, * if the 'live' VM XML is requested */ if (seclabel->type == VIR_DOMAIN_SECLABEL_STATIC || - (!(flags & VIR_DOMAIN_XML_INACTIVE) && + (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) && seclabel->type != VIR_DOMAIN_SECLABEL_NONE)) { p = virXPathStringLimit("string(./label[1])", VIR_SECURITY_LABEL_BUFLEN-1, ctxt); @@ -4951,7 +4921,7 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, /* Only parse imagelabel, if requested live XML with relabeling */ if (seclabel->relabel && - (!(flags & VIR_DOMAIN_XML_INACTIVE) && + (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) && seclabel->type != VIR_DOMAIN_SECLABEL_NONE)) { p = virXPathStringLimit("string(./imagelabel[1])", VIR_SECURITY_LABEL_BUFLEN-1, ctxt); @@ -5042,7 +5012,7 @@ virSecurityLabelDefsParseXML(virDomainDefPtr def, if (def->seclabels[0]->type == VIR_DOMAIN_SECLABEL_NONE || (def->seclabels[0]->type == VIR_DOMAIN_SECLABEL_DYNAMIC && !def->seclabels[0]->baselabel && - (flags & VIR_DOMAIN_XML_INACTIVE))) { + (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE))) { /* Copy model from host. */ VIR_DEBUG("Found seclabel without a model, using '%s'", host->secModels[0].model); @@ -5050,7 +5020,7 @@ virSecurityLabelDefsParseXML(virDomainDefPtr def, goto error; if (STREQ(def->seclabels[0]->model, "none") && - flags & VIR_DOMAIN_XML_INACTIVE) { + flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) { /* Fix older configurations */ def->seclabels[0]->type = VIR_DOMAIN_SECLABEL_NONE; def->seclabels[0]->relabel = false; @@ -5158,7 +5128,7 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLabelDefPtr **seclabels_rtn, /* labelskip is only parsed on live images */ labelskip = virXMLPropString(list[i], "labelskip"); seclabels[i]->labelskip = false; - if (labelskip && !(flags & VIR_DOMAIN_XML_INACTIVE)) + if (labelskip && !(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) seclabels[i]->labelskip = STREQ(labelskip, "yes"); VIR_FREE(labelskip); @@ -5653,7 +5623,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, driverIOThread = virXMLPropString(cur, "iothread"); } else if (!def->mirror && xmlStrEqual(cur->name, BAD_CAST "mirror") && - !(flags & VIR_DOMAIN_XML_INACTIVE)) { + !(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) { char *ready; char *blockJob; @@ -5905,7 +5875,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, def->src->shared = true; } else if (xmlStrEqual(cur->name, BAD_CAST "transient")) { def->transient = true; - } else if ((flags & VIR_DOMAIN_XML_INTERNAL_STATUS) && + } else if ((flags & VIR_DOMAIN_DEF_PARSE_STATUS) && xmlStrEqual(cur->name, BAD_CAST "state")) { /* Legacy back-compat. Don't add any more attributes here */ devaddr = virXMLPropString(cur, "devaddr"); @@ -5984,7 +5954,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, * that are not attached to a physical device presently */ if (source == NULL && def->src->hosts == NULL && !def->src->srcpool && (def->device == VIR_DOMAIN_DISK_DEVICE_DISK || - (flags & VIR_DOMAIN_XML_INTERNAL_DISK_SOURCE))) { + (flags & VIR_DOMAIN_DEF_PARSE_DISK_SOURCE))) { virReportError(VIR_ERR_NO_SOURCE, target ? "%s" : NULL, target); goto error; @@ -6004,7 +5974,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, ctxt->node = saved_node; } - if (!target && !(flags & VIR_DOMAIN_XML_INTERNAL_DISK_SOURCE)) { + if (!target && !(flags & VIR_DOMAIN_DEF_PARSE_DISK_SOURCE)) { if (def->src->srcpool) { char *tmp; if (virAsprintf(&tmp, "pool = '%s', volume = '%s'", @@ -6019,7 +5989,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, goto error; } - if (!(flags & VIR_DOMAIN_XML_INTERNAL_DISK_SOURCE)) { + if (!(flags & VIR_DOMAIN_DEF_PARSE_DISK_SOURCE)) { if (def->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY && !STRPREFIX(target, "fd")) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -6090,7 +6060,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, } else { if (def->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) { def->bus = VIR_DOMAIN_DISK_BUS_FDC; - } else if (!(flags & VIR_DOMAIN_XML_INTERNAL_DISK_SOURCE)) { + } else if (!(flags & VIR_DOMAIN_DEF_PARSE_DISK_SOURCE)) { if (STRPREFIX(target, "hd")) def->bus = VIR_DOMAIN_DISK_BUS_IDE; else if (STRPREFIX(target, "sd")) @@ -6264,7 +6234,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, def->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; } else { if (virDomainDeviceInfoParseXML(node, bootHash, &def->info, - flags | VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT) < 0) + flags | VIR_DOMAIN_DEF_PARSE_ALLOW_BOOT) < 0) goto error; } @@ -6324,7 +6294,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, } } - if (!(flags & VIR_DOMAIN_XML_INTERNAL_DISK_SOURCE)) { + if (!(flags & VIR_DOMAIN_DEF_PARSE_DISK_SOURCE)) { if (def->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE && virDomainDiskDefAssignAddress(xmlopt, def) < 0) goto error; @@ -7215,7 +7185,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, xmlStrEqual(cur->name, BAD_CAST "target")) { ifname = virXMLPropString(cur, "dev"); if (ifname && - (flags & VIR_DOMAIN_XML_INACTIVE) && + (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) && STRPREFIX(ifname, VIR_NET_GENERATED_PREFIX)) { /* An auto-generated target name, blank it out */ VIR_FREE(ifname); @@ -7248,14 +7218,14 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, filter = virXMLPropString(cur, "filter"); virNWFilterHashTableFree(filterparams); filterparams = virNWFilterParseParamAttributes(cur); - } else if ((flags & VIR_DOMAIN_XML_INTERNAL_STATUS) && + } else if ((flags & VIR_DOMAIN_DEF_PARSE_STATUS) && xmlStrEqual(cur->name, BAD_CAST "state")) { /* Legacy back-compat. Don't add any more attributes here */ devaddr = virXMLPropString(cur, "devaddr"); } else if (xmlStrEqual(cur->name, BAD_CAST "boot")) { /* boot is parsed as part of virDomainDeviceInfoParseXML */ } else if (!actual && - (flags & VIR_DOMAIN_XML_INTERNAL_ACTUAL_NET) && + (flags & VIR_DOMAIN_DEF_PARSE_ACTUAL_NET) && def->type == VIR_DOMAIN_NET_TYPE_NETWORK && xmlStrEqual(cur->name, BAD_CAST "actual")) { if (virDomainActualNetDefParseXML(cur, ctxt, def, @@ -7312,8 +7282,8 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, def->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; } else { if (virDomainDeviceInfoParseXML(node, bootHash, &def->info, - flags | VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT - | VIR_DOMAIN_XML_INTERNAL_ALLOW_ROM) < 0) + flags | VIR_DOMAIN_DEF_PARSE_ALLOW_BOOT + | VIR_DOMAIN_DEF_PARSE_ALLOW_ROM) < 0) goto error; } @@ -7494,7 +7464,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt, def->data.direct.linkdev = dev; dev = NULL; - if (flags & VIR_DOMAIN_XML_INACTIVE) + if (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) VIR_FREE(ifname); break; @@ -7995,7 +7965,7 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def, /* PTY path is only parsed from live xml. */ if (!path && (def->type != VIR_DOMAIN_CHR_TYPE_PTY || - !(flags & VIR_DOMAIN_XML_INACTIVE))) + !(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE))) path = virXMLPropString(cur, "path"); break; @@ -8973,7 +8943,7 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def, if (address && address[0] && (def->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS || (def->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK && - !(flags & VIR_DOMAIN_XML_INACTIVE)))) { + !(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)))) { def->address = address; address = NULL; } @@ -8991,7 +8961,7 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def, } if (fromConfig && - flags & VIR_DOMAIN_XML_INTERNAL_STATUS) { + flags & VIR_DOMAIN_DEF_PARSE_STATUS) { if (virStrToLong_i(fromConfig, NULL, 10, &tmp) < 0) { virReportError(VIR_ERR_XML_ERROR, _("Invalid fromConfig value: %s"), @@ -9130,7 +9100,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, VIR_FREE(port); /* Legacy compat syntax, used -1 for auto-port */ if (def->data.vnc.port == -1) { - if (flags & VIR_DOMAIN_XML_INACTIVE) + if (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) def->data.vnc.port = 0; def->data.vnc.autoport = true; } @@ -9141,7 +9111,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, if ((autoport = virXMLPropString(node, "autoport")) != NULL) { if (STREQ(autoport, "yes")) { - if (flags & VIR_DOMAIN_XML_INACTIVE) + if (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) def->data.vnc.port = 0; def->data.vnc.autoport = true; } @@ -9231,7 +9201,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, VIR_FREE(autoport); } - if (def->data.rdp.autoport && (flags & VIR_DOMAIN_XML_INACTIVE)) + if (def->data.rdp.autoport && (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) def->data.rdp.port = 0; if ((replaceUser = virXMLPropString(node, "replaceUser")) != NULL) { @@ -9324,7 +9294,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, def->data.spice.autoport = true; } - if (def->data.spice.autoport && (flags & VIR_DOMAIN_XML_INACTIVE)) { + if (def->data.spice.autoport && (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) { def->data.spice.port = 0; def->data.spice.tlsPort = 0; } @@ -10351,8 +10321,8 @@ virDomainHostdevDefParseXML(virDomainXMLOptionPtr xmlopt, if (def->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) { if (virDomainDeviceInfoParseXML(node, bootHash, def->info, - flags | VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT - | VIR_DOMAIN_XML_INTERNAL_ALLOW_ROM) < 0) + flags | VIR_DOMAIN_DEF_PARSE_ALLOW_BOOT + | VIR_DOMAIN_DEF_PARSE_ALLOW_ROM) < 0) goto error; } @@ -10446,7 +10416,7 @@ virDomainRedirdevDefParseXML(xmlNodePtr node, def->source.chr.data.spicevmc = VIR_DOMAIN_CHR_SPICEVMC_USBREDIR; if (virDomainDeviceInfoParseXML(node, bootHash, &def->info, - flags | VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT) < 0) + flags | VIR_DOMAIN_DEF_PARSE_ALLOW_BOOT) < 0) goto error; if (def->bus == VIR_DOMAIN_REDIRDEV_BUS_USB && @@ -10877,7 +10847,7 @@ virDomainDiskDefSourceParse(const char *xmlStr, goto cleanup; } - flags |= VIR_DOMAIN_XML_INTERNAL_DISK_SOURCE; + flags |= VIR_DOMAIN_DEF_PARSE_DISK_SOURCE; if (!(disk = virDomainDiskDefParseXML(xmlopt, node, ctxt, NULL, def->seclabels, def->nseclabels, @@ -12177,6 +12147,7 @@ virDomainLoaderDefParseXML(xmlNodePtr node, return ret; } + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr root, @@ -12203,7 +12174,7 @@ virDomainDefParseXML(xmlDocPtr xml, if (VIR_ALLOC(def) < 0) return NULL; - if (!(flags & VIR_DOMAIN_XML_INACTIVE)) + if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) if (virXPathLong("string(./@id)", ctxt, &id) < 0) id = -1; def->id = (int)id; @@ -15939,7 +15910,7 @@ virSecurityDeviceLabelDefFormat(virBufferPtr buf, { /* For offline output, skip elements that allow labels but have no * label specified (possible if labelskip was ignored on input). */ - if ((flags & VIR_DOMAIN_XML_INACTIVE) && !def->label && def->relabel) + if ((flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE) && !def->label && def->relabel) return; virBufferAddLit(buf, "<seclabel"); @@ -16346,7 +16317,7 @@ virDomainDiskDefFormat(virBufferPtr buf, /* Don't format backingStore to inactive XMLs until the code for * persistent storage of backing chains is ready. */ - if (!(flags & VIR_DOMAIN_XML_INACTIVE) && + if (!(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE) && virDomainDiskBackingStoreFormat(buf, def->src->backingStore, def->src->backingStoreRaw, 1) < 0) return -1; @@ -16360,7 +16331,7 @@ virDomainDiskDefFormat(virBufferPtr buf, * the new style similar to backingStore, but for back-compat on * blockcopy files we also have to output old style attributes. * The parser accepts either style across libvirtd upgrades. */ - if (def->mirror && !(flags & VIR_DOMAIN_XML_INACTIVE)) { + if (def->mirror && !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)) { const char *formatStr = NULL; if (def->mirror->format) @@ -16503,7 +16474,7 @@ virDomainDiskDefFormat(virBufferPtr buf, virStorageEncryptionFormat(buf, def->src->encryption) < 0) return -1; if (virDomainDeviceInfoFormat(buf, &def->info, - flags | VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT) < 0) + flags | VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT) < 0) return -1; virBufferAdjustIndent(buf, -2); @@ -16579,7 +16550,7 @@ virDomainControllerDefFormat(virBufferPtr buf, } if (def->queues || def->cmd_per_lun || def->max_sectors || - virDomainDeviceInfoIsSet(&def->info, flags) || pcihole64) { + virDomainDeviceInfoNeedsFormat(&def->info, flags) || pcihole64) { virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); if (def->queues) @@ -16591,7 +16562,7 @@ virDomainControllerDefFormat(virBufferPtr buf, if (def->max_sectors) virBufferAsprintf(buf, "<driver max_sectors='%u'/>\n", def->max_sectors); - if (virDomainDeviceInfoIsSet(&def->info, flags) && + if (virDomainDeviceInfoNeedsFormat(&def->info, flags) && virDomainDeviceInfoFormat(buf, &def->info, flags) < 0) return -1; @@ -16749,10 +16720,10 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf, policy = virDomainStartupPolicyTypeToString(def->startupPolicy); virBufferAsprintf(buf, " startupPolicy='%s'", policy); } - if (usbsrc->autoAddress && (flags & VIR_DOMAIN_XML_MIGRATABLE)) + if (usbsrc->autoAddress && (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE)) virBufferAddLit(buf, " autoAddress='yes'"); - if (def->missing && !(flags & VIR_DOMAIN_XML_INACTIVE)) + if (def->missing && !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)) virBufferAddLit(buf, " missing='yes'"); } @@ -16786,7 +16757,7 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("PCI address Formatting failed")); - if ((flags & VIR_DOMAIN_XML_INTERNAL_PCI_ORIG_STATES) && + if ((flags & VIR_DOMAIN_DEF_FORMAT_PCI_ORIG_STATES) && (def->origstates.states.pci.unbind_from_stub || def->origstates.states.pci.remove_slot || def->origstates.states.pci.reprobe)) { @@ -17107,7 +17078,7 @@ virDomainNetDefFormat(virBufferPtr buf, unsigned int actualType = virDomainNetGetActualType(def); bool publicActual = (def->type == VIR_DOMAIN_NET_TYPE_NETWORK && def->data.network.actual && - !(flags & (VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_INTERNAL_ACTUAL_NET))); + !(flags & (VIR_DOMAIN_DEF_FORMAT_INACTIVE | VIR_DOMAIN_DEF_FORMAT_ACTUAL_NET))); const char *typeStr; virDomainHostdevDefPtr hostdef = NULL; char macstr[VIR_MAC_STRING_BUFLEN]; @@ -17172,7 +17143,7 @@ virDomainNetDefFormat(virBufferPtr buf, * as a subelement of <interface> so that no persistent config * data is overwritten. */ - if ((flags & VIR_DOMAIN_XML_INTERNAL_ACTUAL_NET) && + if ((flags & VIR_DOMAIN_DEF_FORMAT_ACTUAL_NET) && (virDomainActualNetDefFormat(buf, def, flags) < 0)) return -1; break; @@ -17254,7 +17225,7 @@ virDomainNetDefFormat(virBufferPtr buf, virBufferEscapeString(buf, "<script path='%s'/>\n", def->script); if (def->ifname && - !((flags & VIR_DOMAIN_XML_INACTIVE) && + !((flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE) && (STRPREFIX(def->ifname, VIR_NET_GENERATED_PREFIX)))) { /* Skip auto-generated target names for inactive config. */ virBufferEscapeString(buf, "<target dev='%s'/>\n", def->ifname); @@ -17331,8 +17302,8 @@ virDomainNetDefFormat(virBufferPtr buf, virDomainNetInterfaceLinkStateTypeToString(def->linkstate)); } if (virDomainDeviceInfoFormat(buf, &def->info, - flags | VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT - | VIR_DOMAIN_XML_INTERNAL_ALLOW_ROM) < 0) + flags | VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT + | VIR_DOMAIN_DEF_FORMAT_ALLOW_ROM) < 0) return -1; virBufferAdjustIndent(buf, -2); @@ -17388,7 +17359,7 @@ virDomainChrSourceDefFormat(virBufferPtr buf, case VIR_DOMAIN_CHR_TYPE_PIPE: if (def->type != VIR_DOMAIN_CHR_TYPE_PTY || (def->data.file.path && - !(flags & VIR_DOMAIN_XML_INACTIVE))) { + !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE))) { virBufferEscapeString(buf, "<source path='%s'", def->data.file.path); virDomainSourceDefFormatSeclabel(buf, nseclabels, seclabels, flags); @@ -17486,7 +17457,7 @@ virDomainChrDefFormat(virBufferPtr buf, tty_compat = (def->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE && def->target.port == 0 && def->source.type == VIR_DOMAIN_CHR_TYPE_PTY && - !(flags & VIR_DOMAIN_XML_INACTIVE) && + !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE) && def->source.data.file.path); if (virDomainChrSourceDefFormat(buf, def, &def->source, tty_compat, flags) < 0) return -1; @@ -17554,7 +17525,7 @@ virDomainChrDefFormat(virBufferPtr buf, break; } - if (virDomainDeviceInfoIsSet(&def->info, flags)) { + if (virDomainDeviceInfoNeedsFormat(&def->info, flags)) { if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0) return -1; } @@ -17583,7 +17554,7 @@ virDomainSmartcardDefFormat(virBufferPtr buf, virBufferAdjustIndent(buf, 2); switch (def->type) { case VIR_DOMAIN_SMARTCARD_TYPE_HOST: - if (!virDomainDeviceInfoIsSet(&def->info, flags)) { + if (!virDomainDeviceInfoNeedsFormat(&def->info, flags)) { virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "/>\n"); return 0; @@ -17659,7 +17630,7 @@ virDomainTPMDefFormat(virBufferPtr buf, virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "</backend>\n"); - if (virDomainDeviceInfoIsSet(&def->info, flags)) { + if (virDomainDeviceInfoNeedsFormat(&def->info, flags)) { if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0) return -1; } @@ -17697,7 +17668,7 @@ virDomainSoundDefFormat(virBufferPtr buf, virDomainSoundCodecDefFormat(buf, def->codecs[i]); } - if (virDomainDeviceInfoIsSet(&def->info, flags)) { + if (virDomainDeviceInfoNeedsFormat(&def->info, flags)) { if (!children) { virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); @@ -17735,7 +17706,7 @@ virDomainMemballoonDefFormat(virBufferPtr buf, virBufferAsprintf(buf, "<memballoon model='%s'", model); virBufferAdjustIndent(buf, 2); - if (virDomainDeviceInfoIsSet(&def->info, flags)) { + if (virDomainDeviceInfoNeedsFormat(&def->info, flags)) { virBufferAddLit(buf, ">\n"); if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0) return -1; @@ -17765,7 +17736,7 @@ virDomainNVRAMDefFormat(virBufferPtr buf, { virBufferAddLit(buf, "<nvram>\n"); virBufferAdjustIndent(buf, 2); - if (virDomainDeviceInfoIsSet(&def->info, flags) && + if (virDomainDeviceInfoNeedsFormat(&def->info, flags) && virDomainDeviceInfoFormat(buf, &def->info, flags) < 0) return -1; @@ -17799,7 +17770,7 @@ virDomainWatchdogDefFormat(virBufferPtr buf, virBufferAsprintf(buf, "<watchdog model='%s' action='%s'", model, action); - if (virDomainDeviceInfoIsSet(&def->info, flags)) { + if (virDomainDeviceInfoNeedsFormat(&def->info, flags)) { virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0) @@ -17836,7 +17807,7 @@ virDomainShmemDefFormat(virBufferPtr buf, if (!def->size && !def->server.enabled && !def->msi.enabled && - !virDomainDeviceInfoIsSet(&def->info, flags)) { + !virDomainDeviceInfoNeedsFormat(&def->info, flags)) { virBufferAddLit(buf, "/>\n"); return 0; } else { @@ -17908,7 +17879,7 @@ virDomainRNGDefFormat(virBufferPtr buf, break; } - if (virDomainDeviceInfoIsSet(&def->info, flags)) { + if (virDomainDeviceInfoNeedsFormat(&def->info, flags)) { if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0) return -1; } @@ -18016,7 +17987,7 @@ virDomainInputDefFormat(virBufferPtr buf, virBufferAsprintf(buf, "<input type='%s' bus='%s'", type, bus); - if (virDomainDeviceInfoIsSet(&def->info, flags)) { + if (virDomainDeviceInfoNeedsFormat(&def->info, flags)) { virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0) @@ -18123,7 +18094,7 @@ virDomainGraphicsAuthDefFormatAttr(virBufferPtr buf, if (!def->passwd) return; - if (flags & VIR_DOMAIN_XML_SECURE) + if (flags & VIR_DOMAIN_DEF_FORMAT_SECURE) virBufferEscapeString(buf, " passwd='%s'", def->passwd); @@ -18148,7 +18119,7 @@ virDomainGraphicsListenDefFormat(virBufferPtr buf, { /* If generating migratable XML, skip listen address * dragged in from config file */ - if ((flags & VIR_DOMAIN_XML_MIGRATABLE) && def->fromConfig) + if ((flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE) && def->fromConfig) return; virBufferAddLit(buf, "<listen"); @@ -18160,7 +18131,7 @@ virDomainGraphicsListenDefFormat(virBufferPtr buf, if (def->address && (def->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS || (def->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK && - !(flags & VIR_DOMAIN_XML_INACTIVE)))) { + !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)))) { /* address may also be set to show current status when type='network', * but we don't want to print that if INACTIVE data is requested. */ virBufferAsprintf(buf, " address='%s'", def->address); @@ -18171,7 +18142,7 @@ virDomainGraphicsListenDefFormat(virBufferPtr buf, virBufferEscapeString(buf, " network='%s'", def->network); } - if (flags & VIR_DOMAIN_XML_INTERNAL_STATUS) + if (flags & VIR_DOMAIN_DEF_FORMAT_STATUS) virBufferAsprintf(buf, " fromConfig='%d'", def->fromConfig); virBufferAddLit(buf, "/>\n"); @@ -18200,7 +18171,7 @@ virDomainGraphicsDefFormat(virBufferPtr buf, for (i = 0; i < def->nListens; i++) { if (virDomainGraphicsListenGetType(def, i) == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS) { - if (flags & VIR_DOMAIN_XML_MIGRATABLE && + if (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE && def->listens[i].fromConfig) continue; listenAddr = virDomainGraphicsListenGetAddress(def, i); @@ -18218,7 +18189,7 @@ virDomainGraphicsDefFormat(virBufferPtr buf, def->data.vnc.socket); } else { if (def->data.vnc.port && - (!def->data.vnc.autoport || !(flags & VIR_DOMAIN_XML_INACTIVE))) + (!def->data.vnc.autoport || !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE))) virBufferAsprintf(buf, " port='%d'", def->data.vnc.port); else if (def->data.vnc.autoport) @@ -18322,7 +18293,7 @@ virDomainGraphicsDefFormat(virBufferPtr buf, if (virDomainGraphicsListenGetType(def, i) == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE) continue; - if (flags & VIR_DOMAIN_XML_MIGRATABLE && + if (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE && def->listens[i].fromConfig) continue; if (!children) { @@ -18471,8 +18442,8 @@ virDomainHostdevDefFormat(virBufferPtr buf, virBufferAddLit(buf, "<shareable/>\n"); if (virDomainDeviceInfoFormat(buf, def->info, - flags | VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT - | VIR_DOMAIN_XML_INTERNAL_ALLOW_ROM) < 0) + flags | VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT + | VIR_DOMAIN_DEF_FORMAT_ALLOW_ROM) < 0) return -1; virBufferAdjustIndent(buf, -2); @@ -18495,7 +18466,7 @@ virDomainRedirdevDefFormat(virBufferPtr buf, if (virDomainChrSourceDefFormat(buf, NULL, &def->source.chr, false, flags) < 0) return -1; if (virDomainDeviceInfoFormat(buf, &def->info, - flags | VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT) < 0) + flags | VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT) < 0) return -1; virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "</redirdev>\n"); @@ -18552,7 +18523,7 @@ virDomainHubDefFormat(virBufferPtr buf, virBufferAsprintf(buf, "<hub type='%s'", type); - if (virDomainDeviceInfoIsSet(&def->info, flags)) { + if (virDomainDeviceInfoNeedsFormat(&def->info, flags)) { virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0) @@ -18690,8 +18661,7 @@ virDomainDefHasCapabilitiesFeatures(virDomainDefPtr def) return false; } -/* This internal version can accept VIR_DOMAIN_XML_INTERNAL_*, - * whereas the public version cannot. Also, it appends to an existing +/* This internal version appends to an existing * buffer (possibly with auto-indent), rather than flattening to string. * Return -1 on failure. */ int @@ -18707,11 +18677,11 @@ virDomainDefFormatInternal(virDomainDefPtr def, bool blkio = false; bool cputune = false; - virCheckFlags(DUMPXML_FLAGS | - VIR_DOMAIN_XML_INTERNAL_STATUS | - VIR_DOMAIN_XML_INTERNAL_ACTUAL_NET | - VIR_DOMAIN_XML_INTERNAL_PCI_ORIG_STATES | - VIR_DOMAIN_XML_INTERNAL_CLOCK_ADJUST, + virCheckFlags(VIR_DOMAIN_DEF_FORMAT_COMMON_FLAGS | + VIR_DOMAIN_DEF_FORMAT_STATUS | + VIR_DOMAIN_DEF_FORMAT_ACTUAL_NET | + VIR_DOMAIN_DEF_FORMAT_PCI_ORIG_STATES | + VIR_DOMAIN_DEF_FORMAT_CLOCK_ADJUST, -1); if (!(type = virDomainVirtTypeToString(def->virtType))) { @@ -18721,10 +18691,10 @@ virDomainDefFormatInternal(virDomainDefPtr def, } if (def->id == -1) - flags |= VIR_DOMAIN_XML_INACTIVE; + flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE; virBufferAsprintf(buf, "<domain type='%s'", type); - if (!(flags & VIR_DOMAIN_XML_INACTIVE)) + if (!(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)) virBufferAsprintf(buf, " id='%d'", def->id); if (def->namespaceData && def->ns.href) virBufferAsprintf(buf, " %s", (def->ns.href)()); @@ -19279,7 +19249,7 @@ virDomainDefFormatInternal(virDomainDefPtr def, virBufferAsprintf(buf, " adjustment='%lld' basis='%s'", def->clock.data.variable.adjustment, virDomainClockBasisTypeToString(def->clock.data.variable.basis)); - if (flags & VIR_DOMAIN_XML_INTERNAL_CLOCK_ADJUST) { + if (flags & VIR_DOMAIN_DEF_FORMAT_CLOCK_ADJUST) { if (def->clock.data.variable.adjustment0) virBufferAsprintf(buf, " adjustment0='%lld'", def->clock.data.variable.adjustment0); @@ -19429,7 +19399,7 @@ virDomainDefFormatInternal(virDomainDefPtr def, if (virDomainInputDefFormat(buf, &autoInput, flags) < 0) goto error; - if (!(flags & VIR_DOMAIN_XML_MIGRATABLE)) { + if (!(flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE)) { autoInput.type = VIR_DOMAIN_INPUT_TYPE_KBD; if (virDomainInputDefFormat(buf, &autoInput, flags) < 0) goto error; @@ -19517,12 +19487,31 @@ virDomainDefFormatInternal(virDomainDefPtr def, return -1; } +int virDomainDefFormatConvertXMLFlags(unsigned int flags) +{ + int formatFlags = 0; + + if (flags & VIR_DOMAIN_XML_SECURE) + formatFlags |= VIR_DOMAIN_DEF_FORMAT_SECURE; + if (flags & VIR_DOMAIN_XML_INACTIVE) + formatFlags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE; + if (flags & VIR_DOMAIN_XML_MIGRATABLE) + formatFlags |= VIR_DOMAIN_DEF_FORMAT_MIGRATABLE; + + /* VIR_DOMAIN_XML_UPDATE_CPU is not handled at the + XML formatting level. The driver code must take + care of it, so we don't include it here */ + + return formatFlags; +} + + char * virDomainDefFormat(virDomainDefPtr def, unsigned int flags) { virBuffer buf = VIR_BUFFER_INITIALIZER; - virCheckFlags(DUMPXML_FLAGS, NULL); + virCheckFlags(VIR_DOMAIN_DEF_FORMAT_COMMON_FLAGS, NULL); if (virDomainDefFormatInternal(def, flags, &buf) < 0) return NULL; @@ -19699,7 +19688,7 @@ virDomainSaveConfig(const char *configDir, int ret = -1; char *xml; - if (!(xml = virDomainDefFormat(def, VIR_DOMAIN_XML_WRITE_FLAGS))) + if (!(xml = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_SECURE))) goto cleanup; if (virDomainSaveXML(configDir, def, xml)) @@ -19716,11 +19705,11 @@ virDomainSaveStatus(virDomainXMLOptionPtr xmlopt, const char *statusDir, virDomainObjPtr obj) { - unsigned int flags = (VIR_DOMAIN_XML_SECURE | - VIR_DOMAIN_XML_INTERNAL_STATUS | - VIR_DOMAIN_XML_INTERNAL_ACTUAL_NET | - VIR_DOMAIN_XML_INTERNAL_PCI_ORIG_STATES | - VIR_DOMAIN_XML_INTERNAL_CLOCK_ADJUST); + unsigned int flags = (VIR_DOMAIN_DEF_FORMAT_SECURE | + VIR_DOMAIN_DEF_FORMAT_STATUS | + VIR_DOMAIN_DEF_FORMAT_ACTUAL_NET | + VIR_DOMAIN_DEF_FORMAT_PCI_ORIG_STATES | + VIR_DOMAIN_DEF_FORMAT_CLOCK_ADJUST); int ret = -1; char *xml; @@ -19759,7 +19748,7 @@ virDomainObjListLoadConfig(virDomainObjListPtr doms, goto error; if (!(def = virDomainDefParseFile(configFile, caps, xmlopt, expectedVirtTypes, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto error; if ((autostartLink = virDomainConfigFile(autostartDir, name)) == NULL) @@ -19806,10 +19795,10 @@ virDomainObjListLoadStatus(virDomainObjListPtr doms, goto error; if (!(obj = virDomainObjParseFile(statusFile, caps, xmlopt, expectedVirtTypes, - VIR_DOMAIN_XML_INTERNAL_STATUS | - VIR_DOMAIN_XML_INTERNAL_ACTUAL_NET | - VIR_DOMAIN_XML_INTERNAL_PCI_ORIG_STATES | - VIR_DOMAIN_XML_INTERNAL_CLOCK_ADJUST))) + VIR_DOMAIN_DEF_PARSE_STATUS | + VIR_DOMAIN_DEF_PARSE_ACTUAL_NET | + VIR_DOMAIN_DEF_PARSE_PCI_ORIG_STATES | + VIR_DOMAIN_DEF_PARSE_CLOCK_ADJUST))) goto error; virUUIDFormat(obj->def->uuid, uuidstr); @@ -20332,17 +20321,17 @@ virDomainDefCopy(virDomainDefPtr src, { char *xml; virDomainDefPtr ret; - unsigned int write_flags = VIR_DOMAIN_XML_WRITE_FLAGS; - unsigned int read_flags = VIR_DOMAIN_XML_READ_FLAGS; + unsigned int format_flags = VIR_DOMAIN_DEF_FORMAT_SECURE; + unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE; if (migratable) - write_flags |= VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_MIGRATABLE; + format_flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE | VIR_DOMAIN_DEF_FORMAT_MIGRATABLE; /* Easiest to clone via a round-trip through XML. */ - if (!(xml = virDomainDefFormat(src, write_flags))) + if (!(xml = virDomainDefFormat(src, format_flags))) return NULL; - ret = virDomainDefParseString(xml, caps, xmlopt, -1, read_flags); + ret = virDomainDefParseString(xml, caps, xmlopt, -1, parse_flags); VIR_FREE(xml); return ret; @@ -20796,7 +20785,7 @@ virDomainNetFind(virDomainDefPtr def, const char *device) * @src: source to be copied * * virDomainDeviceDefCopy does a deep copy of only the parts of a - * DeviceDef that are valid when just the flag VIR_DOMAIN_XML_INACTIVE is + * DeviceDef that are valid when just the flag VIR_DOMAIN_DEF_PARSE_INACTIVE is * set. This means that any part of the device xml that is conditionally * parsed/formatted based on some other flag being set (or on the INACTIVE * flag being reset) *will not* be copied to the destination. Caveat emptor. @@ -20811,55 +20800,54 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src, { virDomainDeviceDefPtr ret = NULL; virBuffer buf = VIR_BUFFER_INITIALIZER; - int flags = VIR_DOMAIN_XML_INACTIVE; char *xmlStr = NULL; int rc = -1; switch ((virDomainDeviceType) src->type) { case VIR_DOMAIN_DEVICE_DISK: - rc = virDomainDiskDefFormat(&buf, src->data.disk, flags); + rc = virDomainDiskDefFormat(&buf, src->data.disk, VIR_DOMAIN_DEF_FORMAT_INACTIVE); break; case VIR_DOMAIN_DEVICE_LEASE: rc = virDomainLeaseDefFormat(&buf, src->data.lease); break; case VIR_DOMAIN_DEVICE_FS: - rc = virDomainFSDefFormat(&buf, src->data.fs, flags); + rc = virDomainFSDefFormat(&buf, src->data.fs, VIR_DOMAIN_DEF_FORMAT_INACTIVE); break; case VIR_DOMAIN_DEVICE_NET: - rc = virDomainNetDefFormat(&buf, src->data.net, flags); + rc = virDomainNetDefFormat(&buf, src->data.net, VIR_DOMAIN_DEF_FORMAT_INACTIVE); break; case VIR_DOMAIN_DEVICE_INPUT: - rc = virDomainInputDefFormat(&buf, src->data.input, flags); + rc = virDomainInputDefFormat(&buf, src->data.input, VIR_DOMAIN_DEF_FORMAT_INACTIVE); break; case VIR_DOMAIN_DEVICE_SOUND: - rc = virDomainSoundDefFormat(&buf, src->data.sound, flags); + rc = virDomainSoundDefFormat(&buf, src->data.sound, VIR_DOMAIN_DEF_FORMAT_INACTIVE); break; case VIR_DOMAIN_DEVICE_VIDEO: - rc = virDomainVideoDefFormat(&buf, src->data.video, flags); + rc = virDomainVideoDefFormat(&buf, src->data.video, VIR_DOMAIN_DEF_FORMAT_INACTIVE); break; case VIR_DOMAIN_DEVICE_HOSTDEV: - rc = virDomainHostdevDefFormat(&buf, src->data.hostdev, flags); + rc = virDomainHostdevDefFormat(&buf, src->data.hostdev, VIR_DOMAIN_DEF_FORMAT_INACTIVE); break; case VIR_DOMAIN_DEVICE_WATCHDOG: - rc = virDomainWatchdogDefFormat(&buf, src->data.watchdog, flags); + rc = virDomainWatchdogDefFormat(&buf, src->data.watchdog, VIR_DOMAIN_DEF_FORMAT_INACTIVE); break; case VIR_DOMAIN_DEVICE_CONTROLLER: - rc = virDomainControllerDefFormat(&buf, src->data.controller, flags); + rc = virDomainControllerDefFormat(&buf, src->data.controller, VIR_DOMAIN_DEF_FORMAT_INACTIVE); break; case VIR_DOMAIN_DEVICE_GRAPHICS: - rc = virDomainGraphicsDefFormat(&buf, src->data.graphics, flags); + rc = virDomainGraphicsDefFormat(&buf, src->data.graphics, VIR_DOMAIN_DEF_FORMAT_INACTIVE); break; case VIR_DOMAIN_DEVICE_HUB: - rc = virDomainHubDefFormat(&buf, src->data.hub, flags); + rc = virDomainHubDefFormat(&buf, src->data.hub, VIR_DOMAIN_DEF_FORMAT_INACTIVE); break; case VIR_DOMAIN_DEVICE_REDIRDEV: - rc = virDomainRedirdevDefFormat(&buf, src->data.redirdev, flags); + rc = virDomainRedirdevDefFormat(&buf, src->data.redirdev, VIR_DOMAIN_DEF_FORMAT_INACTIVE); break; case VIR_DOMAIN_DEVICE_RNG: - rc = virDomainRNGDefFormat(&buf, src->data.rng, flags); + rc = virDomainRNGDefFormat(&buf, src->data.rng, VIR_DOMAIN_DEF_FORMAT_INACTIVE); break; case VIR_DOMAIN_DEVICE_CHR: - rc = virDomainChrDefFormat(&buf, src->data.chr, flags); + rc = virDomainChrDefFormat(&buf, src->data.chr, VIR_DOMAIN_DEF_FORMAT_INACTIVE); break; case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_SMARTCARD: @@ -20878,7 +20866,8 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src, goto cleanup; xmlStr = virBufferContentAndReset(&buf); - ret = virDomainDeviceDefParse(xmlStr, def, caps, xmlopt, flags); + ret = virDomainDeviceDefParse(xmlStr, def, caps, xmlopt, + VIR_DOMAIN_DEF_PARSE_INACTIVE); cleanup: VIR_FREE(xmlStr); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 530a3ca..98497d6 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2389,42 +2389,74 @@ void virDomainObjListRemove(virDomainObjListPtr doms, void virDomainObjListRemoveLocked(virDomainObjListPtr doms, virDomainObjPtr dom); +typedef enum { + /* parse internal domain status information */ + VIR_DOMAIN_DEF_PARSE_STATUS = 1 << 0, + VIR_DOMAIN_DEF_PARSE_INACTIVE = 1 << 2, + /* parse <actual> element */ + VIR_DOMAIN_DEF_PARSE_ACTUAL_NET = 1 << 3, + /* parse original states of host PCI device */ + VIR_DOMAIN_DEF_PARSE_PCI_ORIG_STATES = 1 << 4, + VIR_DOMAIN_DEF_PARSE_ALLOW_ROM = 1 << 5, + VIR_DOMAIN_DEF_PARSE_ALLOW_BOOT = 1 << 6, + VIR_DOMAIN_DEF_PARSE_CLOCK_ADJUST = 1 << 7, + /* parse only source half of <disk> */ + VIR_DOMAIN_DEF_PARSE_DISK_SOURCE = 1 << 8, +} virDomainDefParseFlags; + +typedef enum { + VIR_DOMAIN_DEF_FORMAT_SECURE = 1 << 0, + VIR_DOMAIN_DEF_FORMAT_INACTIVE = 1 << 1, + VIR_DOMAIN_DEF_FORMAT_MIGRATABLE = 1 << 2, + /* format internal domain status information */ + VIR_DOMAIN_DEF_FORMAT_STATUS = 1 << 3, + /* format <actual> element */ + VIR_DOMAIN_DEF_FORMAT_ACTUAL_NET = 1 << 4, + /* format original states of host PCI device */ + VIR_DOMAIN_DEF_FORMAT_PCI_ORIG_STATES = 1 << 5, + VIR_DOMAIN_DEF_FORMAT_ALLOW_ROM = 1 << 6, + VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT = 1 << 7, + VIR_DOMAIN_DEF_FORMAT_CLOCK_ADJUST = 1 << 8, +} virDomainDefFormatFlags; + virDomainDeviceDefPtr virDomainDeviceDefParse(const char *xmlStr, const virDomainDef *def, virCapsPtr caps, virDomainXMLOptionPtr xmlopt, unsigned int flags); virStorageSourcePtr virDomainDiskDefSourceParse(const char *xmlStr, - const virDomainDef *def, - virDomainXMLOptionPtr xmlopt, - unsigned int flags); + const virDomainDef *def, + virDomainXMLOptionPtr xmlopt, + unsigned int flags); virDomainDefPtr virDomainDefParseString(const char *xmlStr, - virCapsPtr caps, - virDomainXMLOptionPtr xmlopt, - unsigned int expectedVirtTypes, - unsigned int flags); + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int expectedVirtTypes, + unsigned int flags); virDomainDefPtr virDomainDefParseFile(const char *filename, - virCapsPtr caps, - virDomainXMLOptionPtr xmlopt, - unsigned int expectedVirtTypes, - unsigned int flags); + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int expectedVirtTypes, + unsigned int flags); virDomainDefPtr virDomainDefParseNode(xmlDocPtr doc, - xmlNodePtr root, - virCapsPtr caps, - virDomainXMLOptionPtr xmlopt, - unsigned int expectedVirtTypes, - unsigned int flags); + xmlNodePtr root, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int expectedVirtTypes, + unsigned int flags); bool virDomainDefCheckABIStability(virDomainDefPtr src, virDomainDefPtr dst); int virDomainDefAddImplicitControllers(virDomainDefPtr def); +int virDomainDefFormatConvertXMLFlags(unsigned int flags); + char *virDomainDefFormat(virDomainDefPtr def, - unsigned int flags); + unsigned int flags); int virDomainDefFormatInternal(virDomainDefPtr def, - unsigned int flags, - virBufferPtr buf); + unsigned int flags, + virBufferPtr buf); int virDomainDiskSourceFormat(virBufferPtr buf, virStorageSourcePtr src, diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index a72ded7..602db3e 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -286,7 +286,7 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, def->dom = virDomainDefParseNode(ctxt->node->doc, domainNode, caps, xmlopt, expectedVirtTypes, - VIR_DOMAIN_XML_INACTIVE); + VIR_DOMAIN_DEF_PARSE_INACTIVE); if (!def->dom) goto cleanup; } else { @@ -675,9 +675,9 @@ char *virDomainSnapshotDefFormat(const char *domain_uuid, virBuffer buf = VIR_BUFFER_INITIALIZER; size_t i; - virCheckFlags(VIR_DOMAIN_XML_SECURE, NULL); + virCheckFlags(VIR_DOMAIN_DEF_FORMAT_SECURE, NULL); - flags |= VIR_DOMAIN_XML_INACTIVE; + flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE; virBufferAddLit(&buf, "<domainsnapshot>\n"); virBufferAdjustIndent(&buf, 2); diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 248bb92..aa3ae5c 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -2751,7 +2751,8 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) def->id = id; - xml = virDomainDefFormat(def, flags); + xml = virDomainDefFormat(def, + virDomainDefFormatConvertXMLFlags(flags)); } cleanup: @@ -2805,7 +2806,7 @@ esxConnectDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat, def = virVMXParseConfig(&ctx, priv->xmlopt, nativeConfig); if (def) - xml = virDomainDefFormat(def, VIR_DOMAIN_XML_INACTIVE); + xml = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_INACTIVE); virDomainDefFree(def); @@ -2844,7 +2845,7 @@ esxConnectDomainXMLToNative(virConnectPtr conn, const char *nativeFormat, def = virDomainDefParseString(domainXml, priv->caps, priv->xmlopt, 1 << VIR_DOMAIN_VIRT_VMWARE, - VIR_DOMAIN_XML_INACTIVE); + VIR_DOMAIN_DEF_PARSE_INACTIVE); if (!def) return NULL; @@ -3055,7 +3056,7 @@ esxDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) /* Parse domain XML */ def = virDomainDefParseString(xml, priv->caps, priv->xmlopt, 1 << VIR_DOMAIN_VIRT_VMWARE, - VIR_DOMAIN_XML_INACTIVE); + VIR_DOMAIN_DEF_PARSE_INACTIVE); if (!def) return NULL; @@ -4301,7 +4302,9 @@ esxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, virUUIDFormat(snapshot->domain->uuid, uuid_string); - xml = virDomainSnapshotDefFormat(uuid_string, &def, flags, 0); + xml = virDomainSnapshotDefFormat(uuid_string, &def, + virDomainDefFormatConvertXMLFlags(flags), + 0); cleanup: esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList); diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index ece943e..ca214f2 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -887,7 +887,8 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) /* FIXME: devices section is totally missing */ - xml = virDomainDefFormat(def, flags); + xml = virDomainDefFormat(def, + virDomainDefFormatConvertXMLFlags(flags)); cleanup: virDomainDefFree(def); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b48dde4..8165bfd 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -192,6 +192,7 @@ virDomainDefCompatibleDevice; virDomainDefCopy; virDomainDefFindDevice; virDomainDefFormat; +virDomainDefFormatConvertXMLFlags; virDomainDefFormatInternal; virDomainDefFree; virDomainDefGetDefaultEmulator; diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 9c62291..9185117 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -880,7 +880,7 @@ libxlDomainSaveImageOpen(libxlDriverPrivatePtr driver, if (!(def = virDomainDefParseString(xml, cfg->caps, driver->xmlopt, 1 << VIR_DOMAIN_VIRT_XEN, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto error; VIR_FREE(xml); diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 9b049db..8a1a11f 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -643,7 +643,7 @@ libxlDomainCreateXML(virConnectPtr conn, const char *xml, if (!(def = virDomainDefParseString(xml, cfg->caps, driver->xmlopt, 1 << VIR_DOMAIN_VIRT_XEN, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; if (virDomainCreateXMLEnsureACL(conn, def) < 0) @@ -2189,7 +2189,8 @@ libxlDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) if (virDomainGetXMLDescEnsureACL(dom->conn, vm->def, flags) < 0) goto cleanup; - ret = virDomainDefFormat(vm->def, flags); + ret = virDomainDefFormat(vm->def, + virDomainDefFormatConvertXMLFlags(flags)); cleanup: if (vm) @@ -2241,7 +2242,7 @@ libxlConnectDomainXMLFromNative(virConnectPtr conn, goto cleanup; } - xml = virDomainDefFormat(def, VIR_DOMAIN_XML_INACTIVE); + xml = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_INACTIVE); cleanup: virDomainDefFree(def); @@ -2278,7 +2279,7 @@ libxlConnectDomainXMLToNative(virConnectPtr conn, const char * nativeFormat, if (!(def = virDomainDefParseString(domainXml, cfg->caps, driver->xmlopt, 1 << VIR_DOMAIN_VIRT_XEN, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; if (!(conf = xenFormatXM(conn, def, cfg->verInfo->xen_version_major))) @@ -2381,7 +2382,7 @@ libxlDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flag if (!(def = virDomainDefParseString(xml, cfg->caps, driver->xmlopt, 1 << VIR_DOMAIN_VIRT_XEN, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) @@ -3273,7 +3274,7 @@ libxlDomainAttachDeviceFlags(virDomainPtr dom, const char *xml, if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) { if (!(dev = virDomainDeviceDefParse(xml, vm->def, cfg->caps, driver->xmlopt, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto endjob; /* Make a copy for updated domain. */ @@ -3290,7 +3291,7 @@ libxlDomainAttachDeviceFlags(virDomainPtr dom, const char *xml, virDomainDeviceDefFree(dev); if (!(dev = virDomainDeviceDefParse(xml, vm->def, cfg->caps, driver->xmlopt, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto endjob; if (libxlDomainAttachDeviceLive(driver, priv, vm, dev) < 0) @@ -3384,7 +3385,7 @@ libxlDomainDetachDeviceFlags(virDomainPtr dom, const char *xml, if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) { if (!(dev = virDomainDeviceDefParse(xml, vm->def, cfg->caps, driver->xmlopt, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto endjob; /* Make a copy for updated domain. */ @@ -3401,7 +3402,7 @@ libxlDomainDetachDeviceFlags(virDomainPtr dom, const char *xml, virDomainDeviceDefFree(dev); if (!(dev = virDomainDeviceDefParse(xml, vm->def, cfg->caps, driver->xmlopt, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto endjob; if (libxlDomainDetachDeviceLive(driver, priv, vm, dev) < 0) @@ -3492,7 +3493,7 @@ libxlDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml, if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) { if (!(dev = virDomainDeviceDefParse(xml, vm->def, cfg->caps, driver->xmlopt, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; /* Make a copy for updated domain. */ @@ -3511,7 +3512,7 @@ libxlDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml, virDomainDeviceDefFree(dev); if (!(dev = virDomainDeviceDefParse(xml, vm->def, cfg->caps, driver->xmlopt, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; if ((ret = libxlDomainUpdateDeviceLive(priv, vm, dev)) < 0) diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c index 0b562f7..ac42a70 100644 --- a/src/libxl/libxl_migration.c +++ b/src/libxl/libxl_migration.c @@ -199,7 +199,7 @@ libxlDomainMigrationBegin(virConnectPtr conn, if (!(tmpdef = virDomainDefParseString(xmlin, cfg->caps, driver->xmlopt, 1 << VIR_DOMAIN_VIRT_XEN, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto endjob; if (!libxlDomainDefCheckABIStability(driver, vm->def, tmpdef)) @@ -213,7 +213,7 @@ libxlDomainMigrationBegin(virConnectPtr conn, if (!libxlDomainMigrationIsAllowed(def)) goto endjob; - xml = virDomainDefFormat(def, VIR_DOMAIN_XML_SECURE); + xml = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_SECURE); endjob: if (!libxlDomainObjEndJob(driver, vm)) @@ -245,7 +245,7 @@ libxlDomainMigrationPrepareDef(libxlDriverPrivatePtr driver, if (!(def = virDomainDefParseString(dom_xml, cfg->caps, driver->xmlopt, 1 << VIR_DOMAIN_VIRT_XEN, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; if (dname) { diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index a9a34b5..54e9fef 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -462,7 +462,7 @@ lxcDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) if (!(def = virDomainDefParseString(xml, caps, driver->xmlopt, 1 << VIR_DOMAIN_VIRT_LXC, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) @@ -1038,7 +1038,7 @@ static char *lxcDomainGetXMLDesc(virDomainPtr dom, ret = virDomainDefFormat((flags & VIR_DOMAIN_XML_INACTIVE) && vm->newDef ? vm->newDef : vm->def, - flags); + virDomainDefFormatConvertXMLFlags(flags)); cleanup: if (vm) @@ -1204,7 +1204,7 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn, if (!(def = virDomainDefParseString(xml, caps, driver->xmlopt, 1 << VIR_DOMAIN_VIRT_LXC, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; if (virDomainCreateXMLWithFilesEnsureACL(conn, def) < 0) @@ -5004,7 +5004,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom, dev = dev_copy = virDomainDeviceDefParse(xml, vm->def, caps, driver->xmlopt, - VIR_DOMAIN_XML_INACTIVE); + VIR_DOMAIN_DEF_PARSE_INACTIVE); if (dev == NULL) goto cleanup; @@ -5133,7 +5133,7 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom, dev = dev_copy = virDomainDeviceDefParse(xml, vm->def, caps, driver->xmlopt, - VIR_DOMAIN_XML_INACTIVE); + VIR_DOMAIN_DEF_PARSE_INACTIVE); if (dev == NULL) goto cleanup; @@ -5246,7 +5246,7 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom, dev = dev_copy = virDomainDeviceDefParse(xml, vm->def, caps, driver->xmlopt, - VIR_DOMAIN_XML_INACTIVE); + VIR_DOMAIN_DEF_PARSE_INACTIVE); if (dev == NULL) goto cleanup; diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 69bb38c..e2a6b9e 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -566,7 +566,8 @@ static char *openvzDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { goto cleanup; } - ret = virDomainDefFormat(vm->def, flags); + ret = virDomainDefFormat(vm->def, + virDomainDefFormatConvertXMLFlags(flags)); cleanup: if (vm) @@ -981,7 +982,7 @@ openvzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int fla openvzDriverLock(driver); if ((vmdef = virDomainDefParseString(xml, driver->caps, driver->xmlopt, 1 << VIR_DOMAIN_VIRT_OPENVZ, - VIR_DOMAIN_XML_INACTIVE)) == NULL) + VIR_DOMAIN_DEF_PARSE_INACTIVE)) == NULL) goto cleanup; vm = virDomainObjListFindByName(driver->domains, vmdef->name); @@ -1073,7 +1074,7 @@ openvzDomainCreateXML(virConnectPtr conn, const char *xml, openvzDriverLock(driver); if ((vmdef = virDomainDefParseString(xml, driver->caps, driver->xmlopt, 1 << VIR_DOMAIN_VIRT_OPENVZ, - VIR_DOMAIN_XML_INACTIVE)) == NULL) + VIR_DOMAIN_DEF_PARSE_INACTIVE)) == NULL) goto cleanup; vm = virDomainObjListFindByName(driver->domains, vmdef->name); @@ -2105,7 +2106,7 @@ openvzDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml, goto cleanup; dev = virDomainDeviceDefParse(xml, vmdef, driver->caps, driver->xmlopt, - VIR_DOMAIN_XML_INACTIVE); + VIR_DOMAIN_DEF_PARSE_INACTIVE); if (!dev) goto cleanup; @@ -2260,7 +2261,7 @@ openvzDomainMigrateBegin3Params(virDomainPtr domain, goto cleanup; } - xml = virDomainDefFormat(vm->def, VIR_DOMAIN_XML_SECURE); + xml = virDomainDefFormat(vm->def, VIR_DOMAIN_DEF_FORMAT_SECURE); cleanup: if (vm) @@ -2308,7 +2309,7 @@ openvzDomainMigratePrepare3Params(virConnectPtr dconn, if (!(def = virDomainDefParseString(dom_xml, driver->caps, driver->xmlopt, 1 << VIR_DOMAIN_VIRT_OPENVZ, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto error; if (!(vm = virDomainObjListAdd(driver->domains, def, diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 71db7bd..7d2c849 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -1720,7 +1720,7 @@ phypDomainAttachDevice(virDomainPtr domain, const char *xml) goto cleanup; dev = virDomainDeviceDefParse(xml, def, phyp_driver->caps, NULL, - VIR_DOMAIN_XML_INACTIVE); + VIR_DOMAIN_DEF_PARSE_INACTIVE); if (!dev) goto cleanup; @@ -3291,7 +3291,8 @@ phypDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) goto err; } - return virDomainDefFormat(&def, flags); + return virDomainDefFormat(&def, + virDomainDefFormatConvertXMLFlags(flags)); err: return NULL; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 00fbb2f..98386f3 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1708,7 +1708,7 @@ qemuDomainDefCopy(virQEMUDriverPtr driver, if (!(ret = virDomainDefParseString(xml, caps, driver->xmlopt, QEMU_EXPECTED_VIRT_TYPES, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; cleanup: @@ -1818,7 +1818,9 @@ qemuDomainDefFormatBuf(virQEMUDriverPtr driver, } - ret = virDomainDefFormatInternal(def, flags, buf); + ret = virDomainDefFormatInternal(def, + virDomainDefFormatConvertXMLFlags(flags), + buf); cleanup: def->cpu = def_cpu; @@ -2171,7 +2173,7 @@ qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm, virUUIDFormat(vm->def->uuid, uuidstr); newxml = virDomainSnapshotDefFormat(uuidstr, snapshot->def, - VIR_DOMAIN_XML_SECURE, 1); + VIR_DOMAIN_DEF_FORMAT_SECURE, 1); if (newxml == NULL) return -1; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 654fa2e..6ccf940 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1705,7 +1705,7 @@ static virDomainPtr qemuDomainCreateXML(virConnectPtr conn, if (!(def = virDomainDefParseString(xml, caps, driver->xmlopt, QEMU_EXPECTED_VIRT_TYPES, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; if (virDomainCreateXMLEnsureACL(conn, def) < 0) @@ -3220,7 +3220,7 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver, virDomainPtr dom, if (!(def = virDomainDefParseString(xmlin, caps, driver->xmlopt, QEMU_EXPECTED_VIRT_TYPES, - VIR_DOMAIN_XML_INACTIVE))) { + VIR_DOMAIN_DEF_PARSE_INACTIVE))) { goto endjob; } if (!qemuDomainDefCheckABIStability(driver, vm->def, def)) { @@ -5577,7 +5577,7 @@ qemuDomainSaveImageUpdateDef(virQEMUDriverPtr driver, if (!(newdef = virDomainDefParseString(newxml, caps, driver->xmlopt, QEMU_EXPECTED_VIRT_TYPES, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; if (!(newdef_migr = qemuDomainDefCopy(driver, @@ -5733,7 +5733,7 @@ qemuDomainSaveImageOpen(virQEMUDriverPtr driver, /* Create a domain from this XML */ if (!(def = virDomainDefParseString(xml, caps, driver->xmlopt, QEMU_EXPECTED_VIRT_TYPES, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto error; if (xmlout) @@ -6319,7 +6319,7 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn, def = virDomainDefParseString(xmlData, caps, driver->xmlopt, QEMU_EXPECTED_VIRT_TYPES, - VIR_DOMAIN_XML_INACTIVE); + VIR_DOMAIN_DEF_PARSE_INACTIVE); if (!def) goto cleanup; @@ -6672,7 +6672,7 @@ static virDomainPtr qemuDomainDefineXMLFlags(virConnectPtr conn, const char *xml if (!(def = virDomainDefParseString(xml, caps, driver->xmlopt, QEMU_EXPECTED_VIRT_TYPES, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) @@ -7493,7 +7493,7 @@ static int qemuDomainAttachDeviceFlags(virDomainPtr dom, const char *xml, virDomainDefPtr vmdef = NULL; virDomainDeviceDefPtr dev = NULL, dev_copy = NULL; int ret = -1; - unsigned int affect, parse_flags = VIR_DOMAIN_XML_INACTIVE; + unsigned int affect, parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE; virQEMUCapsPtr qemuCaps = NULL; qemuDomainObjPrivatePtr priv; virQEMUDriverConfigPtr cfg = NULL; @@ -7694,7 +7694,7 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom, dev = dev_copy = virDomainDeviceDefParse(xml, vm->def, caps, driver->xmlopt, - VIR_DOMAIN_XML_INACTIVE); + VIR_DOMAIN_DEF_PARSE_INACTIVE); if (dev == NULL) goto endjob; @@ -7832,7 +7832,7 @@ static int qemuDomainDetachDeviceFlags(virDomainPtr dom, const char *xml, if ((flags & VIR_DOMAIN_AFFECT_CONFIG) && !(flags & VIR_DOMAIN_AFFECT_LIVE)) - parse_flags |= VIR_DOMAIN_XML_INACTIVE; + parse_flags |= VIR_DOMAIN_DEF_PARSE_INACTIVE; dev = dev_copy = virDomainDeviceDefParse(xml, vm->def, caps, driver->xmlopt, @@ -13954,7 +13954,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain, if (!(xml = qemuDomainDefFormatLive(driver, vm->def, true, true)) || !(def->dom = virDomainDefParseString(xml, caps, driver->xmlopt, QEMU_EXPECTED_VIRT_TYPES, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto endjob; if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY) { @@ -14393,7 +14393,9 @@ qemuDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, virUUIDFormat(snapshot->domain->uuid, uuidstr); - xml = virDomainSnapshotDefFormat(uuidstr, snap->def, flags, 0); + xml = virDomainSnapshotDefFormat(uuidstr, snap->def, + virDomainDefFormatConvertXMLFlags(flags), + 0); cleanup: virObjectUnlock(vm); @@ -16181,7 +16183,7 @@ qemuDomainBlockCopy(virDomainPtr dom, const char *disk, const char *destxml, } if (!(dest = virDomainDiskDefSourceParse(destxml, vm->def, driver->xmlopt, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; ret = qemuDomainBlockCopyCommon(vm, dom->conn, disk, dest, diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 100600e..9d53987 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -1108,7 +1108,7 @@ qemuMigrationCookieXMLParse(qemuMigrationCookiePtr mig, } mig->persistent = virDomainDefParseNode(doc, nodes[0], caps, driver->xmlopt, - -1, VIR_DOMAIN_XML_INACTIVE); + -1, VIR_DOMAIN_DEF_PARSE_INACTIVE); if (!mig->persistent) { /* virDomainDefParseNode already reported * an error for us */ @@ -2386,7 +2386,7 @@ static char if (xmlin) { if (!(def = virDomainDefParseString(xmlin, caps, driver->xmlopt, QEMU_EXPECTED_VIRT_TYPES, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; if (!qemuDomainDefCheckABIStability(driver, vm->def, def)) @@ -2598,7 +2598,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver, VIR_DEBUG("Using hook-filtered domain XML: %s", xmlout); newdef = virDomainDefParseString(xmlout, caps, driver->xmlopt, QEMU_EXPECTED_VIRT_TYPES, - VIR_DOMAIN_XML_INACTIVE); + VIR_DOMAIN_DEF_PARSE_INACTIVE); if (!newdef) goto cleanup; @@ -3078,7 +3078,7 @@ qemuMigrationPrepareDef(virQEMUDriverPtr driver, if (!(def = virDomainDefParseString(dom_xml, caps, driver->xmlopt, QEMU_EXPECTED_VIRT_TYPES, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; if (dname) { diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 4469ad5..a71ed7b 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -758,7 +758,7 @@ testOpenDefault(virConnectPtr conn) privconn->caps, privconn->xmlopt, 1 << VIR_DOMAIN_VIRT_TEST, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto error; if (testDomainGenerateIfnames(domdef) < 0) @@ -1082,7 +1082,7 @@ testParseDomains(testConnPtr privconn, def = virDomainDefParseNode(ctxt->doc, node, privconn->caps, privconn->xmlopt, 1 << VIR_DOMAIN_VIRT_TEST, - VIR_DOMAIN_XML_INACTIVE); + VIR_DOMAIN_DEF_PARSE_INACTIVE); if (!def) goto error; @@ -1749,7 +1749,7 @@ testDomainCreateXML(virConnectPtr conn, const char *xml, testDriverLock(privconn); if ((def = virDomainDefParseString(xml, privconn->caps, privconn->xmlopt, 1 << VIR_DOMAIN_VIRT_TEST, - VIR_DOMAIN_XML_INACTIVE)) == NULL) + VIR_DOMAIN_DEF_PARSE_INACTIVE)) == NULL) goto cleanup; if (testDomainGenerateIfnames(def) < 0) @@ -2218,7 +2218,7 @@ testDomainSaveFlags(virDomainPtr domain, const char *path, } xml = virDomainDefFormat(privdom->def, - VIR_DOMAIN_XML_SECURE); + VIR_DOMAIN_DEF_FORMAT_SECURE); if (xml == NULL) { virReportSystemError(errno, @@ -2362,7 +2362,7 @@ testDomainRestoreFlags(virConnectPtr conn, def = virDomainDefParseString(xml, privconn->caps, privconn->xmlopt, 1 << VIR_DOMAIN_VIRT_TEST, - VIR_DOMAIN_XML_INACTIVE); + VIR_DOMAIN_DEF_PARSE_INACTIVE); if (!def) goto cleanup; @@ -2890,7 +2890,7 @@ static char *testDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) privdom->newDef ? privdom->newDef : privdom->def; ret = virDomainDefFormat(def, - flags); + virDomainDefFormatConvertXMLFlags(flags)); cleanup: if (privdom) @@ -2943,7 +2943,7 @@ static virDomainPtr testDomainDefineXMLFlags(virConnectPtr conn, testDriverLock(privconn); if ((def = virDomainDefParseString(xml, privconn->caps, privconn->xmlopt, 1 << VIR_DOMAIN_VIRT_TEST, - VIR_DOMAIN_XML_INACTIVE)) == NULL) + VIR_DOMAIN_DEF_PARSE_INACTIVE)) == NULL) goto cleanup; if (testDomainGenerateIfnames(def) < 0) @@ -6784,7 +6784,9 @@ testDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, virUUIDFormat(snapshot->domain->uuid, uuidstr); - xml = virDomainSnapshotDefFormat(uuidstr, snap->def, flags, 0); + xml = virDomainSnapshotDefFormat(uuidstr, snap->def, + virDomainDefFormatConvertXMLFlags(flags), + 0); cleanup: if (vm) diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index d15b55a..5684df0 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -1612,7 +1612,7 @@ static virDomainPtr umlDomainCreateXML(virConnectPtr conn, const char *xml, umlDriverLock(driver); if (!(def = virDomainDefParseString(xml, driver->caps, driver->xmlopt, 1 << VIR_DOMAIN_VIRT_UML, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; if (virDomainCreateXMLEnsureACL(conn, def) < 0) @@ -1988,7 +1988,7 @@ static char *umlDomainGetXMLDesc(virDomainPtr dom, ret = virDomainDefFormat((flags & VIR_DOMAIN_XML_INACTIVE) && vm->newDef ? vm->newDef : vm->def, - flags); + virDomainDefFormatConvertXMLFlags(flags)); cleanup: if (vm) @@ -2088,7 +2088,7 @@ umlDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) umlDriverLock(driver); if (!(def = virDomainDefParseString(xml, driver->caps, driver->xmlopt, 1 << VIR_DOMAIN_VIRT_UML, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) @@ -2252,7 +2252,7 @@ static int umlDomainAttachDevice(virDomainPtr dom, const char *xml) } dev = virDomainDeviceDefParse(xml, vm->def, driver->caps, driver->xmlopt, - VIR_DOMAIN_XML_INACTIVE); + VIR_DOMAIN_DEF_PARSE_INACTIVE); if (dev == NULL) goto cleanup; @@ -2372,7 +2372,7 @@ static int umlDomainDetachDevice(virDomainPtr dom, const char *xml) } dev = virDomainDeviceDefParse(xml, vm->def, driver->caps, driver->xmlopt, - VIR_DOMAIN_XML_INACTIVE); + VIR_DOMAIN_DEF_PARSE_INACTIVE); if (dev == NULL) goto cleanup; diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 322353f..18d05c5 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -1851,7 +1851,7 @@ vboxDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags VBOX_IID_INITIALIZE(&mchiid); if (!(def = virDomainDefParseString(xml, data->caps, data->xmlopt, 1 << VIR_DOMAIN_VIRT_VBOX, - VIR_DOMAIN_XML_INACTIVE))) { + VIR_DOMAIN_DEF_PARSE_INACTIVE))) { goto cleanup; } @@ -3967,7 +3967,7 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) /* dump USB devices/filters if active */ vboxHostDeviceGetXMLDesc(data, def, machine); - ret = virDomainDefFormat(def, flags); + ret = virDomainDefFormat(def, virDomainDefFormatConvertXMLFlags(flags)); cleanup: VBOX_RELEASE(machine); @@ -4106,7 +4106,7 @@ static int vboxDomainAttachDeviceImpl(virDomainPtr dom, goto cleanup; dev = virDomainDeviceDefParse(xml, def, data->caps, data->xmlopt, - VIR_DOMAIN_XML_INACTIVE); + VIR_DOMAIN_DEF_PARSE_INACTIVE); if (dev == NULL) goto cleanup; @@ -4238,7 +4238,7 @@ static int vboxDomainDetachDevice(virDomainPtr dom, const char *xml) goto cleanup; dev = virDomainDeviceDefParse(xml, def, data->caps, data->xmlopt, - VIR_DOMAIN_XML_INACTIVE); + VIR_DOMAIN_DEF_PARSE_INACTIVE); if (dev == NULL) goto cleanup; @@ -5198,7 +5198,7 @@ vboxSnapshotRedefine(virDomainPtr dom, VIR_FREE(currentSnapshotXmlFilePath); if (virAsprintf(¤tSnapshotXmlFilePath, "%s%s.xml", machineLocationPath, snapshotMachineDesc->currentSnapshot) < 0) goto cleanup; - char *snapshotContent = virDomainSnapshotDefFormat(NULL, def, VIR_DOMAIN_XML_SECURE, 0); + char *snapshotContent = virDomainSnapshotDefFormat(NULL, def, VIR_DOMAIN_DEF_FORMAT_SECURE, 0); if (snapshotContent == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to get snapshot content")); @@ -6118,7 +6118,9 @@ static char *vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, virUUIDFormat(dom->uuid, uuidstr); memcpy(def->dom->uuid, dom->uuid, VIR_UUID_BUFLEN); - ret = virDomainSnapshotDefFormat(uuidstr, def, flags, 0); + ret = virDomainSnapshotDefFormat(uuidstr, def, + virDomainDefFormatConvertXMLFlags(flags), + 0); cleanup: virDomainSnapshotDefFree(def); diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 4ee9526..8c87a1b 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -378,7 +378,7 @@ vmwareDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int fla vmwareDriverLock(driver); if ((vmdef = virDomainDefParseString(xml, driver->caps, driver->xmlopt, 1 << VIR_DOMAIN_VIRT_VMWARE, - VIR_DOMAIN_XML_INACTIVE)) == NULL) + VIR_DOMAIN_DEF_PARSE_INACTIVE)) == NULL) goto cleanup; /* generate vmx file */ @@ -665,7 +665,7 @@ vmwareDomainCreateXML(virConnectPtr conn, const char *xml, if ((vmdef = virDomainDefParseString(xml, driver->caps, driver->xmlopt, 1 << VIR_DOMAIN_VIRT_VMWARE, - VIR_DOMAIN_XML_INACTIVE)) == NULL) + VIR_DOMAIN_DEF_PARSE_INACTIVE)) == NULL) goto cleanup; /* generate vmx file */ @@ -983,7 +983,8 @@ vmwareDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) goto cleanup; } - ret = virDomainDefFormat(vm->def, flags); + ret = virDomainDefFormat(vm->def, + virDomainDefFormatConvertXMLFlags(flags)); cleanup: if (vm) @@ -1014,7 +1015,7 @@ vmwareConnectDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat, def = virVMXParseConfig(&ctx, driver->xmlopt, nativeConfig); if (def != NULL) - xml = virDomainDefFormat(def, VIR_DOMAIN_XML_INACTIVE); + xml = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_INACTIVE); virDomainDefFree(def); diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index 1897584..6a2e535 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -775,7 +775,7 @@ xenUnifiedDomainCreateXML(virConnectPtr conn, if (!(def = virDomainDefParseString(xml, priv->caps, priv->xmlopt, 1 << VIR_DOMAIN_VIRT_XEN, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; if (virDomainCreateXMLEnsureACL(conn, def) < 0) @@ -1596,7 +1596,8 @@ xenUnifiedDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) } if (def) - ret = virDomainDefFormat(def, flags); + ret = virDomainDefFormat(def, + virDomainDefFormatConvertXMLFlags(flags)); cleanup: virDomainDefFree(def); @@ -1686,7 +1687,7 @@ xenUnifiedConnectDomainXMLToNative(virConnectPtr conn, if (!(def = virDomainDefParseString(xmlData, priv->caps, priv->xmlopt, 1 << VIR_DOMAIN_VIRT_XEN, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; if (STREQ(format, XEN_CONFIG_FORMAT_XM)) { @@ -1892,7 +1893,7 @@ xenUnifiedDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int if (!(def = virDomainDefParseString(xml, priv->caps, priv->xmlopt, 1 << VIR_DOMAIN_VIRT_XEN, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c index b233b6b..a51cb20 100644 --- a/src/xen/xend_internal.c +++ b/src/xen/xend_internal.c @@ -2256,7 +2256,7 @@ xenDaemonAttachDeviceFlags(virConnectPtr conn, goto cleanup; if (!(dev = virDomainDeviceDefParse(xml, def, priv->caps, priv->xmlopt, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; @@ -2404,7 +2404,7 @@ xenDaemonUpdateDeviceFlags(virConnectPtr conn, goto cleanup; if (!(dev = virDomainDeviceDefParse(xml, def, priv->caps, priv->xmlopt, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; @@ -2506,7 +2506,7 @@ xenDaemonDetachDeviceFlags(virConnectPtr conn, goto cleanup; if (!(dev = virDomainDeviceDefParse(xml, def, priv->caps, priv->xmlopt, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; if (virDomainXMLDevID(conn, minidef, dev, class, ref, sizeof(ref))) diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c index 293b2ab..dc6f88a 100644 --- a/src/xen/xm_internal.c +++ b/src/xen/xm_internal.c @@ -1251,7 +1251,7 @@ xenXMDomainAttachDeviceFlags(virConnectPtr conn, if (!(dev = virDomainDeviceDefParse(xml, entry->def, priv->caps, priv->xmlopt, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; switch (dev->type) { @@ -1338,7 +1338,7 @@ xenXMDomainDetachDeviceFlags(virConnectPtr conn, if (!(dev = virDomainDeviceDefParse(xml, entry->def, priv->caps, priv->xmlopt, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; switch (dev->type) { diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index 656f923..405c129 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -554,7 +554,7 @@ xenapiDomainCreateXML(virConnectPtr conn, virDomainDefPtr defPtr = virDomainDefParseString(xmlDesc, priv->caps, priv->xmlopt, 1 << VIR_DOMAIN_VIRT_XEN, - VIR_DOMAIN_XML_INACTIVE); + VIR_DOMAIN_DEF_PARSE_INACTIVE); createVMRecordFromXml(conn, defPtr, &record, &vm); virDomainDefFree(defPtr); if (record) { @@ -1728,7 +1728,7 @@ xenapiDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int fla virDomainDefPtr defPtr = virDomainDefParseString(xml, priv->caps, priv->xmlopt, 1 << VIR_DOMAIN_VIRT_XEN, - VIR_DOMAIN_XML_INACTIVE); + VIR_DOMAIN_DEF_PARSE_INACTIVE); if (!defPtr) return NULL; diff --git a/tests/domainsnapshotxml2xmltest.c b/tests/domainsnapshotxml2xmltest.c index 1b3a28f..845d52f 100644 --- a/tests/domainsnapshotxml2xmltest.c +++ b/tests/domainsnapshotxml2xmltest.c @@ -102,7 +102,7 @@ testCompareXMLToXMLFiles(const char *inxml, goto cleanup; if (!(actual = virDomainSnapshotDefFormat(uuid, def, - VIR_DOMAIN_XML_SECURE, + VIR_DOMAIN_DEF_FORMAT_SECURE, internal))) goto cleanup; diff --git a/tests/lxcxml2xmltest.c b/tests/lxcxml2xmltest.c index 6dce070..e372dcd 100644 --- a/tests/lxcxml2xmltest.c +++ b/tests/lxcxml2xmltest.c @@ -38,7 +38,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool live) if (!(def = virDomainDefParseString(inXmlData, caps, xmlopt, 1 << VIR_DOMAIN_VIRT_LXC, - live ? 0 : VIR_DOMAIN_XML_INACTIVE))) + live ? 0 : VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto fail; if (!virDomainDefCheckABIStability(def, def)) { @@ -46,7 +46,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool live) goto fail; } - if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_XML_SECURE))) + if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_SECURE))) goto fail; if (STRNEQ(outXmlData, actual)) { diff --git a/tests/openvzutilstest.c b/tests/openvzutilstest.c index f5a8d12..c57543f 100644 --- a/tests/openvzutilstest.c +++ b/tests/openvzutilstest.c @@ -115,7 +115,7 @@ testReadNetworkConf(const void *data ATTRIBUTE_UNUSED) goto cleanup; } - actual = virDomainDefFormat(def, VIR_DOMAIN_XML_INACTIVE); + actual = virDomainDefFormat(def, VIR_DOMAIN_DEF_PARSE_INACTIVE); if (actual == NULL) { err = virGetLastError(); diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index 9d39968..8bdd37f 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -67,7 +67,7 @@ qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt, driver.caps, driver.xmlopt, QEMU_EXPECTED_VIRT_TYPES, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto cleanup; priv = (*vm)->privateData; @@ -177,7 +177,7 @@ testQemuHotplugCheckResult(virDomainObjPtr vm, char *actual; int ret; - actual = virDomainDefFormat(vm->def, VIR_DOMAIN_XML_SECURE); + actual = virDomainDefFormat(vm->def, VIR_DOMAIN_DEF_FORMAT_SECURE); if (!actual) return -1; @@ -246,7 +246,7 @@ testQemuHotplug(const void *data) } if (test->action == ATTACH) - device_parse_flags = VIR_DOMAIN_XML_INACTIVE; + device_parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE; if (!(dev = virDomainDeviceDefParse(device_xml, vm->def, caps, driver.xmlopt, diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index b2e60e8..6357d28 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -287,7 +287,7 @@ static int testCompareXMLToArgvFiles(const char *xml, if (!(vmdef = virDomainDefParseFile(xml, driver.caps, driver.xmlopt, QEMU_EXPECTED_VIRT_TYPES, - VIR_DOMAIN_XML_INACTIVE))) { + VIR_DOMAIN_DEF_PARSE_INACTIVE))) { if (!virtTestOOMActive() && (flags & FLAG_EXPECT_PARSE_ERROR)) goto ok; diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index ca11e90..0cf7c99 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -30,7 +30,10 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool live) char *actual = NULL; int ret = -1; virDomainDefPtr def = NULL; - unsigned int flags = live ? 0 : VIR_DOMAIN_XML_INACTIVE; + unsigned int parse_flags = live ? 0 : VIR_DOMAIN_DEF_PARSE_INACTIVE; + unsigned int format_flags = VIR_DOMAIN_XML_SECURE; + if (live) + format_flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE; if (virtTestLoadFile(inxml, &inXmlData) < 0) goto fail; @@ -38,7 +41,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool live) goto fail; if (!(def = virDomainDefParseString(inXmlData, driver.caps, driver.xmlopt, - QEMU_EXPECTED_VIRT_TYPES, flags))) + QEMU_EXPECTED_VIRT_TYPES, parse_flags))) goto fail; if (!virDomainDefCheckABIStability(def, def)) { @@ -46,7 +49,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool live) goto fail; } - if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_XML_SECURE | flags))) + if (!(actual = virDomainDefFormat(def, format_flags))) goto fail; if (STRNEQ(outXmlData, actual)) { diff --git a/tests/qemuxmlnstest.c b/tests/qemuxmlnstest.c index 2f37a26..947aa9c 100644 --- a/tests/qemuxmlnstest.c +++ b/tests/qemuxmlnstest.c @@ -56,7 +56,7 @@ static int testCompareXMLToArgvFiles(const char *xml, if (!(vmdef = virDomainDefParseFile(xml, driver.caps, driver.xmlopt, QEMU_EXPECTED_VIRT_TYPES, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto fail; if (!virDomainDefCheckABIStability(vmdef, vmdef)) { diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index 6b1e724..412be88 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -90,7 +90,7 @@ testCompareFiles(const char *vmx, const char *xml) goto cleanup; } - if (!(formatted = virDomainDefFormat(def, VIR_DOMAIN_XML_SECURE))) + if (!(formatted = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_SECURE))) goto cleanup; if (STRNEQ(xmlData, formatted)) { diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c index 0c6f803..b3dfd97 100644 --- a/tests/xmconfigtest.c +++ b/tests/xmconfigtest.c @@ -74,7 +74,7 @@ testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion) if (!(def = virDomainDefParseString(xmlData, caps, xmlopt, 1 << VIR_DOMAIN_VIRT_XEN, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto fail; if (!virDomainDefCheckABIStability(def, def)) { @@ -140,7 +140,7 @@ testCompareFormatXML(const char *xmcfg, const char *xml, int xendConfigVersion) if (!(def = xenParseXM(conf, priv.xendConfigVersion, priv.caps))) goto fail; - if (!(gotxml = virDomainDefFormat(def, VIR_DOMAIN_XML_SECURE))) + if (!(gotxml = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_SECURE))) goto fail; if (STRNEQ(xmlData, gotxml)) { diff --git a/tests/xml2sexprtest.c b/tests/xml2sexprtest.c index 7d9e780..f65eaef 100644 --- a/tests/xml2sexprtest.c +++ b/tests/xml2sexprtest.c @@ -37,7 +37,7 @@ testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion) if (!(def = virDomainDefParseString(xmlData, caps, xmlopt, 1 << VIR_DOMAIN_VIRT_XEN, - VIR_DOMAIN_XML_INACTIVE))) + VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto fail; if (!virDomainDefCheckABIStability(def, def)) { diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c index ca9445d..2d72407 100644 --- a/tests/xml2vmxtest.c +++ b/tests/xml2vmxtest.c @@ -86,7 +86,7 @@ testCompareFiles(const char *xml, const char *vmx, int virtualHW_version) def = virDomainDefParseString(xmlData, caps, xmlopt, 1 << VIR_DOMAIN_VIRT_VMWARE, - VIR_DOMAIN_XML_INACTIVE); + VIR_DOMAIN_DEF_PARSE_INACTIVE); if (def == NULL) goto failure; -- 2.1.0

On Tue, Nov 18, 2014 at 05:59:54PM +0000, Daniel P. Berrange wrote:
The virDomainDefParse* and virDomainDefFormat* methods both accept the VIR_DOMAIN_XML_* flags defined in the public API, along with a set of other VIR_DOMAIN_XML_INTERNAL_* flags defined in domain_conf.c.
This is seriously confusing & error prone for a number of reasons:
- VIR_DOMAIN_XML_SECURE, VIR_DOMAIN_XML_MIGRATABLE and VIR_DOMAIN_XML_UPDATE_CPU are only relevant for the formatting operation - VIR_DOMAIN_XML_UPDATE_CPU is not in fact handled by the domain_conf.c code at all - it must be dealt with by the driver code - Some of the VIR_DOMAIN_XML_INTERNAL_* flags only apply to parse or to format, but not both.
This patch cleanly separates out the flags. There are two distint VIR_DOMAIN_DEF_PARSE_* and VIR_DOMAIN_DEF_FORMAT_* flags that are used by the corresponding methods. The VIR_DOMAIN_XML_* flags received via public API calls must be converted to the VIR_DOMAIN_DEF_FORMAT_* flags where needed.
The various calls to virDomainDefParse which hardcoded the use of the VIR_DOMAIN_XML_INACTIVE flag change to use the VIR_DOMAIN_DEF_PARSE_INACTIVE flag. --- [...] diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5f4b9f6..2dace76 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18690,8 +18661,7 @@ virDomainDefHasCapabilitiesFeatures(virDomainDefPtr def) return false; }
-/* This internal version can accept VIR_DOMAIN_XML_INTERNAL_*, - * whereas the public version cannot. Also, it appends to an existing +/* This internal version appends to an existing Biggest nit-pick ever ^^ two spaces here.
/me hides under the rock
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 530a3ca..98497d6 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2389,42 +2389,74 @@ void virDomainObjListRemove(virDomainObjListPtr doms, void virDomainObjListRemoveLocked(virDomainObjListPtr doms, virDomainObjPtr dom);
+typedef enum { + /* parse internal domain status information */ + VIR_DOMAIN_DEF_PARSE_STATUS = 1 << 0, + VIR_DOMAIN_DEF_PARSE_INACTIVE = 1 << 2, + /* parse <actual> element */ + VIR_DOMAIN_DEF_PARSE_ACTUAL_NET = 1 << 3, + /* parse original states of host PCI device */ + VIR_DOMAIN_DEF_PARSE_PCI_ORIG_STATES = 1 << 4, + VIR_DOMAIN_DEF_PARSE_ALLOW_ROM = 1 << 5, + VIR_DOMAIN_DEF_PARSE_ALLOW_BOOT = 1 << 6, + VIR_DOMAIN_DEF_PARSE_CLOCK_ADJUST = 1 << 7, + /* parse only source half of <disk> */ + VIR_DOMAIN_DEF_PARSE_DISK_SOURCE = 1 << 8, +} virDomainDefParseFlags; + +typedef enum { + VIR_DOMAIN_DEF_FORMAT_SECURE = 1 << 0, + VIR_DOMAIN_DEF_FORMAT_INACTIVE = 1 << 1, + VIR_DOMAIN_DEF_FORMAT_MIGRATABLE = 1 << 2, + /* format internal domain status information */ + VIR_DOMAIN_DEF_FORMAT_STATUS = 1 << 3, + /* format <actual> element */ + VIR_DOMAIN_DEF_FORMAT_ACTUAL_NET = 1 << 4, + /* format original states of host PCI device */ + VIR_DOMAIN_DEF_FORMAT_PCI_ORIG_STATES = 1 << 5, + VIR_DOMAIN_DEF_FORMAT_ALLOW_ROM = 1 << 6, + VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT = 1 << 7, + VIR_DOMAIN_DEF_FORMAT_CLOCK_ADJUST = 1 << 8, +} virDomainDefFormatFlags; + virDomainDeviceDefPtr virDomainDeviceDefParse(const char *xmlStr, const virDomainDef *def, virCapsPtr caps, virDomainXMLOptionPtr xmlopt, unsigned int flags); virStorageSourcePtr virDomainDiskDefSourceParse(const char *xmlStr, - const virDomainDef *def, - virDomainXMLOptionPtr xmlopt, - unsigned int flags); + const virDomainDef *def, + virDomainXMLOptionPtr xmlopt, + unsigned int flags); virDomainDefPtr virDomainDefParseString(const char *xmlStr, - virCapsPtr caps, - virDomainXMLOptionPtr xmlopt, - unsigned int expectedVirtTypes, - unsigned int flags); + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int expectedVirtTypes, + unsigned int flags); virDomainDefPtr virDomainDefParseFile(const char *filename, - virCapsPtr caps, - virDomainXMLOptionPtr xmlopt, - unsigned int expectedVirtTypes, - unsigned int flags); + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int expectedVirtTypes, + unsigned int flags); virDomainDefPtr virDomainDefParseNode(xmlDocPtr doc, - xmlNodePtr root, - virCapsPtr caps, - virDomainXMLOptionPtr xmlopt, - unsigned int expectedVirtTypes, - unsigned int flags); + xmlNodePtr root, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int expectedVirtTypes, + unsigned int flags);
It looks like this part of this hunk just screws up indentation. If this is not a mistake, then somewhere along the way the mail itself got screwed. Martin

The virDomainDefineXMLFlags and virDomainCreateXML APIs both gain new flags allowing them to be told to validate XML. The main limitation with this is that libxml2's errors for failing schema validation are really awful and not likely to be any help for the user eg, I added an element <foo>bar</foo> immediately below the <domain> element and got this: $ virsh define --validate ppcdemo.xml error: Failed to define domain from ppcdemo.xml error: XML document failed to validate against schema: Unable to validate doc against /usr/share/libvirt/schemas/domain.rng Expecting an element os, got nothing Invalid sequence in interleave Invalid sequence in interleave Element domain failed to validate content Either libxml2 would have to dramatically improve its error reporting, or we'd have to look at a different library for schema validation. --- include/libvirt/libvirt-domain.h | 5 +++++ src/conf/domain_conf.c | 6 ++++++ src/conf/domain_conf.h | 1 + src/qemu/qemu_driver.c | 16 ++++++++++++---- tools/virsh-domain.c | 19 ++++++++++++++++++- 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h index 864c16c..8ce2f68 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -273,6 +273,7 @@ typedef enum { VIR_DOMAIN_START_AUTODESTROY = 1 << 1, /* Automatically kill guest when virConnectPtr is closed */ VIR_DOMAIN_START_BYPASS_CACHE = 1 << 2, /* Avoid file system cache pollution */ VIR_DOMAIN_START_FORCE_BOOT = 1 << 3, /* Boot, discarding any managed save */ + VIR_DOMAIN_START_VALIDATE = 1 << 4, /* Validate the XML document against schema */ } virDomainCreateFlags; @@ -1410,6 +1411,10 @@ int virDomainMemoryPeek (virDomainPtr dom, void *buffer, unsigned int flags); +typedef enum { + VIR_DOMAIN_DEFINE_VALIDATE = (1 << 0), /* Validate the XML document against schema */ +} virDomainDefineFlags; + /* * defined but not running domains */ diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 2dace76..9218df8 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" @@ -12171,6 +12172,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) + return NULL; + if (VIR_ALLOC(def) < 0) return NULL; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 98497d6..df9789a 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2402,6 +2402,7 @@ typedef enum { VIR_DOMAIN_DEF_PARSE_CLOCK_ADJUST = 1 << 7, /* parse only source half of <disk> */ VIR_DOMAIN_DEF_PARSE_DISK_SOURCE = 1 << 8, + VIR_DOMAIN_DEF_PARSE_VALIDATE = 1 << 9, } virDomainDefParseFlags; typedef enum { diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 6ccf940..48e7e75 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1689,10 +1689,14 @@ static virDomainPtr qemuDomainCreateXML(virConnectPtr conn, unsigned int start_flags = VIR_QEMU_PROCESS_START_COLD; virQEMUCapsPtr qemuCaps = NULL; virCapsPtr caps = NULL; + unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE; virCheckFlags(VIR_DOMAIN_START_PAUSED | - VIR_DOMAIN_START_AUTODESTROY, NULL); + VIR_DOMAIN_START_AUTODESTROY | + VIR_DOMAIN_START_VALIDATE, NULL); + if (flags & VIR_DOMAIN_START_VALIDATE) + parse_flags |= VIR_DOMAIN_DEF_PARSE_VALIDATE; if (flags & VIR_DOMAIN_START_PAUSED) start_flags |= VIR_QEMU_PROCESS_START_PAUSED; if (flags & VIR_DOMAIN_START_AUTODESTROY) @@ -1705,7 +1709,7 @@ static virDomainPtr qemuDomainCreateXML(virConnectPtr conn, if (!(def = virDomainDefParseString(xml, caps, driver->xmlopt, QEMU_EXPECTED_VIRT_TYPES, - VIR_DOMAIN_DEF_PARSE_INACTIVE))) + parse_flags))) goto cleanup; if (virDomainCreateXMLEnsureACL(conn, def) < 0) @@ -6662,8 +6666,12 @@ static virDomainPtr qemuDomainDefineXMLFlags(virConnectPtr conn, const char *xml virQEMUCapsPtr qemuCaps = NULL; virQEMUDriverConfigPtr cfg; virCapsPtr caps = 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_VALIDATE; cfg = virQEMUDriverGetConfig(driver); @@ -6672,7 +6680,7 @@ static virDomainPtr qemuDomainDefineXMLFlags(virConnectPtr conn, const char *xml if (!(def = virDomainDefParseString(xml, caps, driver->xmlopt, QEMU_EXPECTED_VIRT_TYPES, - VIR_DOMAIN_DEF_PARSE_INACTIVE))) + parse_flags))) goto cleanup; if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index a7e9151..876fd4b 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -7163,6 +7163,10 @@ static const vshCmdOptDef opts_define[] = { .flags = VSH_OFLAG_REQ, .help = N_("file containing an XML domain description") }, + {.name = "skip-validate", + .type = VSH_OT_BOOL, + .help = N_("skip validation of the XML against the schema") + }, {.name = NULL} }; @@ -7173,14 +7177,27 @@ cmdDefine(vshControl *ctl, const vshCmd *cmd) const char *from = NULL; bool ret = true; char *buffer; + unsigned int flags = VIR_DOMAIN_DEFINE_VALIDATE; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) return false; + if (vshCommandOptBool(cmd, "skip-validate")) + flags &= ~VIR_DOMAIN_DEFINE_VALIDATE; + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) return false; - dom = virDomainDefineXML(ctl->conn, buffer); + if (flags) { + dom = virDomainDefineXMLFlags(ctl->conn, buffer, flags); + if (!dom) { + virErrorPtr err = virGetLastError(); + if (err && err->code == VIR_ERR_NO_SUPPORT) + dom = virDomainDefineXML(ctl->conn, buffer); + } + } else { + dom = virDomainDefineXML(ctl->conn, buffer); + } VIR_FREE(buffer); if (dom != NULL) { -- 2.1.0

On Tue, Nov 18, 2014 at 05:59:47PM +0000, Daniel P. Berrange wrote:
This proof of concept patch extends the virDomainDefineXML and virDomainCreateXML APIs so that they can validate the user supplied XML document against the RNG schemas.
The virsh command will enable validation by default, it must be turned off with --skip-validation if desired.
This series is not complete
- The network, interface, storage pool, etc APIs are not wired up to support validation. - Only the QEMU virt driver is wired up to validate - The virsh edit command is not wired up to validate
It is enough to demonstrate it working with 'virsh define' and the QEMU driver though.
The biggest problem I see is the really awful error messages we get back from libxml2 when validation fails :-( They are essentially useless :-(
This is one of the things why I'm not convinced this work is worth it. It may be nice if we tell the user their XML is invalid instead of silently losing information. But error message similar to "invalid element in interleave" doesn't help much when you are adding 100-line XML. There are some better validators, but requiring those would be too cumbersome. That said, I'm not _against_ this idea, I'm just thinking out loud. Maybe we could create some descriptive mapping schema between XML <-> internal structures and then simplify our parsing to error out on unknown data if a flag is present. However, that's something the code is not prepared to do now. Other than that, with this series applied, I get some errors with make check, particularly these: qemuxml2xmltest openvzutilstest cpuset define-dev-segfault read-non-seekable read-bufsiz Most of those are due to the test driver not supporting the new flag: error: unsupported flags (0x1) in function testDomainDefineXMLFlags Martin

On Wed, Nov 19, 2014 at 08:23:22AM +0100, Martin Kletzander wrote:
On Tue, Nov 18, 2014 at 05:59:47PM +0000, Daniel P. Berrange wrote:
This proof of concept patch extends the virDomainDefineXML and virDomainCreateXML APIs so that they can validate the user supplied XML document against the RNG schemas.
The virsh command will enable validation by default, it must be turned off with --skip-validation if desired.
This series is not complete
- The network, interface, storage pool, etc APIs are not wired up to support validation. - Only the QEMU virt driver is wired up to validate - The virsh edit command is not wired up to validate
It is enough to demonstrate it working with 'virsh define' and the QEMU driver though.
The biggest problem I see is the really awful error messages we get back from libxml2 when validation fails :-( They are essentially useless :-(
This is one of the things why I'm not convinced this work is worth it. It may be nice if we tell the user their XML is invalid instead of silently losing information. But error message similar to "invalid element in interleave" doesn't help much when you are adding 100-line XML. There are some better validators, but requiring those would be too cumbersome.
At least when using 'virsh edit' you would know what element you just changed / added. So if you got get a generic 'validation failed' error you have a pretty good idea of where in teh document you made the mistake. So I think it'd be useful in that scenario. The error reporting is more of a problem for the apps where they're passing in a big XML document to define the guest and basically anything could be wrong.
Other than that, with this series applied, I get some errors with make check, particularly these:
qemuxml2xmltest openvzutilstest cpuset define-dev-segfault read-non-seekable read-bufsiz
Most of those are due to the test driver not supporting the new flag:
error: unsupported flags (0x1) in function testDomainDefineXMLFlags
Opps, yes, I should have said this proof of concept also hasn't fixed the tests yet :-) Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Wed, Nov 19, 2014 at 09:45:39AM +0000, Daniel P. Berrange wrote:
On Wed, Nov 19, 2014 at 08:23:22AM +0100, Martin Kletzander wrote:
On Tue, Nov 18, 2014 at 05:59:47PM +0000, Daniel P. Berrange wrote:
This proof of concept patch extends the virDomainDefineXML and virDomainCreateXML APIs so that they can validate the user supplied XML document against the RNG schemas.
The virsh command will enable validation by default, it must be turned off with --skip-validation if desired.
This series is not complete
- The network, interface, storage pool, etc APIs are not wired up to support validation. - Only the QEMU virt driver is wired up to validate - The virsh edit command is not wired up to validate
It is enough to demonstrate it working with 'virsh define' and the QEMU driver though.
The biggest problem I see is the really awful error messages we get back from libxml2 when validation fails :-( They are essentially useless :-(
This is one of the things why I'm not convinced this work is worth it. It may be nice if we tell the user their XML is invalid instead of silently losing information. But error message similar to "invalid element in interleave" doesn't help much when you are adding 100-line XML. There are some better validators, but requiring those would be too cumbersome.
At least when using 'virsh edit' you would know what element you just changed / added. So if you got get a generic 'validation failed' error you have a pretty good idea of where in teh document you made the mistake. So I think it'd be useful in that scenario. The error reporting is more of a problem for the apps where they're passing in a big XML document to define the guest and basically anything could be wrong.
So, it seems not all of the error messages are so awful. It does a bad job of reporting unknown elements, but if you have an unknown attribute it does better: "Invalid attribute foo for element name" If you give an invalid value for an attribute which is an enum it is semi-usefull "Element domain failed to validate attributes" So this does seem somewhat more useful to have in libvirt Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Wed, Nov 19, 2014 at 12:51:22PM +0000, Daniel P. Berrange wrote:
On Wed, Nov 19, 2014 at 09:45:39AM +0000, Daniel P. Berrange wrote:
On Wed, Nov 19, 2014 at 08:23:22AM +0100, Martin Kletzander wrote:
On Tue, Nov 18, 2014 at 05:59:47PM +0000, Daniel P. Berrange wrote:
This proof of concept patch extends the virDomainDefineXML and virDomainCreateXML APIs so that they can validate the user supplied XML document against the RNG schemas.
The virsh command will enable validation by default, it must be turned off with --skip-validation if desired.
This series is not complete
- The network, interface, storage pool, etc APIs are not wired up to support validation. - Only the QEMU virt driver is wired up to validate - The virsh edit command is not wired up to validate
It is enough to demonstrate it working with 'virsh define' and the QEMU driver though.
The biggest problem I see is the really awful error messages we get back from libxml2 when validation fails :-( They are essentially useless :-(
This is one of the things why I'm not convinced this work is worth it. It may be nice if we tell the user their XML is invalid instead of silently losing information. But error message similar to "invalid element in interleave" doesn't help much when you are adding 100-line XML. There are some better validators, but requiring those would be too cumbersome.
At least when using 'virsh edit' you would know what element you just changed / added. So if you got get a generic 'validation failed' error you have a pretty good idea of where in teh document you made the mistake. So I think it'd be useful in that scenario. The error reporting is more of a problem for the apps where they're passing in a big XML document to define the guest and basically anything could be wrong.
So, it seems not all of the error messages are so awful. It does a bad job of reporting unknown elements, but if you have an unknown attribute it does better:
"Invalid attribute foo for element name"
If you give an invalid value for an attribute which is an enum it is semi-usefull
"Element domain failed to validate attributes"
So this does seem somewhat more useful to have in libvirt
As I said, I'm not against this, I agree that it will still be useful. If you meant this as an RFC, then I misunderstood that and I should've just wrote that as an initial PoC it's fine with me :) Do you want me to finish the review? Martin

On Thu, Nov 20, 2014 at 12:02:12PM +0100, Martin Kletzander wrote:
On Wed, Nov 19, 2014 at 12:51:22PM +0000, Daniel P. Berrange wrote:
On Wed, Nov 19, 2014 at 09:45:39AM +0000, Daniel P. Berrange wrote:
On Wed, Nov 19, 2014 at 08:23:22AM +0100, Martin Kletzander wrote:
On Tue, Nov 18, 2014 at 05:59:47PM +0000, Daniel P. Berrange wrote:
This proof of concept patch extends the virDomainDefineXML and virDomainCreateXML APIs so that they can validate the user supplied XML document against the RNG schemas.
The virsh command will enable validation by default, it must be turned off with --skip-validation if desired.
This series is not complete
- The network, interface, storage pool, etc APIs are not wired up to support validation. - Only the QEMU virt driver is wired up to validate - The virsh edit command is not wired up to validate
It is enough to demonstrate it working with 'virsh define' and the QEMU driver though.
The biggest problem I see is the really awful error messages we get back from libxml2 when validation fails :-( They are essentially useless :-(
This is one of the things why I'm not convinced this work is worth it. It may be nice if we tell the user their XML is invalid instead of silently losing information. But error message similar to "invalid element in interleave" doesn't help much when you are adding 100-line XML. There are some better validators, but requiring those would be too cumbersome.
At least when using 'virsh edit' you would know what element you just changed / added. So if you got get a generic 'validation failed' error you have a pretty good idea of where in teh document you made the mistake. So I think it'd be useful in that scenario. The error reporting is more of a problem for the apps where they're passing in a big XML document to define the guest and basically anything could be wrong.
So, it seems not all of the error messages are so awful. It does a bad job of reporting unknown elements, but if you have an unknown attribute it does better:
"Invalid attribute foo for element name"
If you give an invalid value for an attribute which is an enum it is semi-usefull
"Element domain failed to validate attributes"
So this does seem somewhat more useful to have in libvirt
As I said, I'm not against this, I agree that it will still be useful.
If you meant this as an RFC, then I misunderstood that and I should've just wrote that as an initial PoC it's fine with me :)
Do you want me to finish the review?
No, I should probably finish doing the rest of the work first if people agree using this API flag is the right way forward. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Thu, Nov 20, 2014 at 12:02:12PM +0100, Martin Kletzander wrote:
On Wed, Nov 19, 2014 at 12:51:22PM +0000, Daniel P. Berrange wrote:
On Wed, Nov 19, 2014 at 09:45:39AM +0000, Daniel P. Berrange wrote:
On Wed, Nov 19, 2014 at 08:23:22AM +0100, Martin Kletzander wrote:
On Tue, Nov 18, 2014 at 05:59:47PM +0000, Daniel P. Berrange wrote:
This proof of concept patch extends the virDomainDefineXML and virDomainCreateXML APIs so that they can validate the user supplied XML document against the RNG schemas.
The virsh command will enable validation by default, it must be turned off with --skip-validation if desired.
This series is not complete
- The network, interface, storage pool, etc APIs are not wired up to support validation. - Only the QEMU virt driver is wired up to validate - The virsh edit command is not wired up to validate
It is enough to demonstrate it working with 'virsh define' and the QEMU driver though.
The biggest problem I see is the really awful error messages we get back from libxml2 when validation fails :-( They are essentially useless :-(
This is one of the things why I'm not convinced this work is worth it. It may be nice if we tell the user their XML is invalid instead of silently losing information. But error message similar to "invalid element in interleave" doesn't help much when you are adding 100-line XML. There are some better validators, but requiring those would be too cumbersome.
At least when using 'virsh edit' you would know what element you just changed / added. So if you got get a generic 'validation failed' error you have a pretty good idea of where in teh document you made the mistake. So I think it'd be useful in that scenario. The error reporting is more of a problem for the apps where they're passing in a big XML document to define the guest and basically anything could be wrong.
So, it seems not all of the error messages are so awful. It does a bad job of reporting unknown elements, but if you have an unknown attribute it does better:
"Invalid attribute foo for element name"
If you give an invalid value for an attribute which is an enum it is semi-usefull
"Element domain failed to validate attributes"
So this does seem somewhat more useful to have in libvirt
As I said, I'm not against this, I agree that it will still be useful.
If you meant this as an RFC, then I misunderstood that and I should've just wrote that as an initial PoC it's fine with me :)
Do you want me to finish the review?
Actually if you want to review patches 4, 5, 6, 7 that would be useful. Those are general refactoring of the way we handle flags with the XML parsers/formatters. The 7th patch was awful to create and will be a rebase nightmare if we leave it too long. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Thu, Nov 20, 2014 at 01:43:29PM +0000, Daniel P. Berrange wrote:
On Thu, Nov 20, 2014 at 12:02:12PM +0100, Martin Kletzander wrote:
On Wed, Nov 19, 2014 at 12:51:22PM +0000, Daniel P. Berrange wrote:
On Wed, Nov 19, 2014 at 09:45:39AM +0000, Daniel P. Berrange wrote:
On Wed, Nov 19, 2014 at 08:23:22AM +0100, Martin Kletzander wrote:
On Tue, Nov 18, 2014 at 05:59:47PM +0000, Daniel P. Berrange wrote:
This proof of concept patch extends the virDomainDefineXML and virDomainCreateXML APIs so that they can validate the user supplied XML document against the RNG schemas.
The virsh command will enable validation by default, it must be turned off with --skip-validation if desired.
This series is not complete
- The network, interface, storage pool, etc APIs are not wired up to support validation. - Only the QEMU virt driver is wired up to validate - The virsh edit command is not wired up to validate
It is enough to demonstrate it working with 'virsh define' and the QEMU driver though.
The biggest problem I see is the really awful error messages we get back from libxml2 when validation fails :-( They are essentially useless :-(
This is one of the things why I'm not convinced this work is worth it. It may be nice if we tell the user their XML is invalid instead of silently losing information. But error message similar to "invalid element in interleave" doesn't help much when you are adding 100-line XML. There are some better validators, but requiring those would be too cumbersome.
At least when using 'virsh edit' you would know what element you just changed / added. So if you got get a generic 'validation failed' error you have a pretty good idea of where in teh document you made the mistake. So I think it'd be useful in that scenario. The error reporting is more of a problem for the apps where they're passing in a big XML document to define the guest and basically anything could be wrong.
So, it seems not all of the error messages are so awful. It does a bad job of reporting unknown elements, but if you have an unknown attribute it does better:
"Invalid attribute foo for element name"
If you give an invalid value for an attribute which is an enum it is semi-usefull
"Element domain failed to validate attributes"
So this does seem somewhat more useful to have in libvirt
As I said, I'm not against this, I agree that it will still be useful.
If you meant this as an RFC, then I misunderstood that and I should've just wrote that as an initial PoC it's fine with me :)
Do you want me to finish the review?
Actually if you want to review patches 4, 5, 6, 7 that would be useful. Those are general refactoring of the way we handle flags with the XML parsers/formatters. The 7th patch was awful to create and will be a rebase nightmare if we leave it too long.
ACK to 4-7, just read that 7/8 before pushing. Unfortunately it will need a bigger rebase, still :( Martin
participants (2)
-
Daniel P. Berrange
-
Martin Kletzander