[PATCH 2/4] conf: virnetworkportdef: add validation against schema in network port create

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We need to validate the XML against schema if option '--validate'
was passed to the virsh command. This patch also includes
propagation of flags into the virNetworkPortDefParse().

Signed-off-by: Kristina Hanicova <khanicov@xxxxxxxxxx>
---
 src/conf/domain_conf.c       |  2 +-
 src/conf/virnetworkportdef.c | 14 +++++++++-----
 src/conf/virnetworkportdef.h |  3 ++-
 src/network/bridge_driver.c  |  2 +-
 4 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 6127513117..dbefc98ee8 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -30330,7 +30330,7 @@ virDomainNetCreatePort(virConnectPtr conn,
     VIR_FREE(portxml);
 
     if (!(portxml = virNetworkPortGetXMLDesc(port, 0)) ||
-        !(portdef = virNetworkPortDefParseString(portxml)) ||
+        !(portdef = virNetworkPortDefParseString(portxml, 0)) ||
         virDomainNetDefActualFromNetworkPort(iface, portdef) < 0) {
         virErrorPreserveLast(&save_err);
         virNetworkPortDelete(port, 0);
diff --git a/src/conf/virnetworkportdef.c b/src/conf/virnetworkportdef.c
index c1749eebe0..1ca1eddb5a 100644
--- a/src/conf/virnetworkportdef.c
+++ b/src/conf/virnetworkportdef.c
@@ -287,12 +287,15 @@ virNetworkPortDefParseNode(xmlDocPtr xml,
 
 static virNetworkPortDef *
 virNetworkPortDefParse(const char *xmlStr,
-                       const char *filename)
+                       const char *filename,
+                       unsigned int flags)
 {
     virNetworkPortDef *def = NULL;
     g_autoptr(xmlDoc) xml = NULL;
 
-    if ((xml = virXMLParse(filename, xmlStr, _("(networkport_definition)"), NULL, false))) {
+    if ((xml = virXMLParse(filename, xmlStr, _("(networkport_definition)"),
+                           "networkport.rng",
+                           flags & VIR_NETWORK_PORT_CREATE_VALIDATE))) {
         def = virNetworkPortDefParseNode(xml, xmlDocGetRootElement(xml));
     }
 
@@ -301,16 +304,17 @@ virNetworkPortDefParse(const char *xmlStr,
 
 
 virNetworkPortDef *
-virNetworkPortDefParseString(const char *xmlStr)
+virNetworkPortDefParseString(const char *xmlStr,
+                             unsigned int flags)
 {
-    return virNetworkPortDefParse(xmlStr, NULL);
+    return virNetworkPortDefParse(xmlStr, NULL, flags);
 }
 
 
 virNetworkPortDef *
 virNetworkPortDefParseFile(const char *filename)
 {
-    return virNetworkPortDefParse(NULL, filename);
+    return virNetworkPortDefParse(NULL, filename, 0);
 }
 
 
diff --git a/src/conf/virnetworkportdef.h b/src/conf/virnetworkportdef.h
index 0ac232d16a..5c7cd2953e 100644
--- a/src/conf/virnetworkportdef.h
+++ b/src/conf/virnetworkportdef.h
@@ -86,7 +86,8 @@ virNetworkPortDefParseNode(xmlDocPtr xml,
                            xmlNodePtr root);
 
 virNetworkPortDef *
-virNetworkPortDefParseString(const char *xml);
+virNetworkPortDefParseString(const char *xml,
+                             unsigned int flags);
 
 virNetworkPortDef *
 virNetworkPortDefParseFile(const char *filename);
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index e8b9ffa1fc..7513ddad48 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -5287,7 +5287,7 @@ networkPortCreateXML(virNetworkPtr net,
 
     def = virNetworkObjGetDef(obj);
 
-    if (!(portdef = virNetworkPortDefParseString(xmldesc)))
+    if (!(portdef = virNetworkPortDefParseString(xmldesc, 0)))
         goto cleanup;
 
     if (virNetworkPortCreateXMLEnsureACL(net->conn, def, portdef) < 0)
-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux