[PATCH 3/5] conf: Add virNetworkXMLNamespace

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

 



Just the plumbing, no real implementation yet

Signed-off-by: Cole Robinson <crobinso@xxxxxxxxxx>
---
 src/conf/network_conf.c     | 22 ++++++++++++++++++++--
 src/conf/network_conf.h     | 21 ++++++++++++++++++++-
 src/network/bridge_driver.c |  2 +-
 3 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 067adf7936..c5a243684a 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -93,7 +93,7 @@ virNetworkXMLOnceInit(void)
 VIR_ONCE_GLOBAL_INIT(virNetworkXML);
 
 virNetworkXMLOptionPtr
-virNetworkXMLOptionNew(void)
+virNetworkXMLOptionNew(virNetworkXMLNamespacePtr xmlns)
 {
     virNetworkXMLOptionPtr xmlopt;
 
@@ -103,6 +103,9 @@ virNetworkXMLOptionNew(void)
     if (!(xmlopt = virObjectNew(virNetworkXMLOptionClass)))
         return NULL;
 
+    if (xmlns)
+        xmlopt->ns = *xmlns;
+
     return xmlopt;
 }
 
@@ -268,6 +271,8 @@ virNetworkDefFree(virNetworkDefPtr def)
 
     xmlFreeNode(def->metadata);
 
+    if (def->namespaceData && def->ns.free)
+        (def->ns.free)(def->namespaceData);
     VIR_FREE(def);
 }
 
@@ -1622,7 +1627,7 @@ virNetworkForwardDefParseXML(const char *networkName,
 
 virNetworkDefPtr
 virNetworkDefParseXML(xmlXPathContextPtr ctxt,
-                      virNetworkXMLOptionPtr xmlopt ATTRIBUTE_UNUSED)
+                      virNetworkXMLOptionPtr xmlopt)
 {
     virNetworkDefPtr def;
     char *tmp = NULL;
@@ -2043,6 +2048,12 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
         virXMLNodeSanitizeNamespaces(def->metadata);
     }
 
+    if (xmlopt)
+        def->ns = xmlopt->ns;
+    if (def->ns.parse &&
+        (def->ns.parse)(ctxt, &def->namespaceData) < 0)
+        goto error;
+
     ctxt->node = save;
     return def;
 
@@ -2422,6 +2433,8 @@ virNetworkDefFormatBuf(virBufferPtr buf,
     bool hasbridge = false;
 
     virBufferAddLit(buf, "<network");
+    if (def->namespaceData && def->ns.href)
+        virBufferAsprintf(buf, " %s", (def->ns.href)());
     if (!(flags & VIR_NETWORK_XML_INACTIVE) && (def->connections > 0))
         virBufferAsprintf(buf, " connections='%d'", def->connections);
     if (def->ipv6nogw)
@@ -2627,6 +2640,11 @@ virNetworkDefFormatBuf(virBufferPtr buf,
         if (virPortGroupDefFormat(buf, &def->portGroups[i]) < 0)
             goto error;
 
+    if (def->namespaceData && def->ns.format) {
+        if ((def->ns.format)(buf, def->namespaceData) < 0)
+            return -1;
+    }
+
     virBufferAdjustIndent(buf, -2);
     virBufferAddLit(buf, "</network>\n");
 
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index b7ce569d4a..b167b57e85 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -41,9 +41,24 @@
 #include "virmacmap.h"
 #include "virenum.h"
 
+typedef int (*virNetworkDefNamespaceParse)(xmlXPathContextPtr, void **);
+typedef void (*virNetworkDefNamespaceFree)(void *);
+typedef int (*virNetworkDefNamespaceXMLFormat)(virBufferPtr, void *);
+typedef const char *(*virNetworkDefNamespaceHref)(void);
+
+typedef struct _virNetworkXMLNamespace virNetworkXMLNamespace;
+typedef virNetworkXMLNamespace *virNetworkXMLNamespacePtr;
+struct _virNetworkXMLNamespace {
+    virNetworkDefNamespaceParse parse;
+    virNetworkDefNamespaceFree free;
+    virNetworkDefNamespaceXMLFormat format;
+    virNetworkDefNamespaceHref href;
+};
 
 struct _virNetworkXMLOption {
     virObject parent;
+
+    virNetworkXMLNamespace ns;
 };
 typedef struct _virNetworkXMLOption virNetworkXMLOption;
 typedef virNetworkXMLOption *virNetworkXMLOptionPtr;
@@ -277,6 +292,10 @@ struct _virNetworkDef {
 
     /* Application-specific custom metadata */
     xmlNodePtr metadata;
+
+    /* Network specific XML namespace data */
+    void *namespaceData;
+    virNetworkXMLNamespace ns;
 };
 
 typedef enum {
@@ -298,7 +317,7 @@ enum {
 };
 
 virNetworkXMLOptionPtr
-virNetworkXMLOptionNew(void);
+virNetworkXMLOptionNew(virNetworkXMLNamespacePtr xmlns);
 
 virNetworkDefPtr
 virNetworkDefCopy(virNetworkDefPtr def,
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 3353754eb5..1a4d6e7f7b 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -139,7 +139,7 @@ networkDnsmasqCapsRefresh(virNetworkDriverStatePtr driver)
 static virNetworkXMLOptionPtr
 networkDnsmasqCreateXMLConf(void)
 {
-    return virNetworkXMLOptionNew();
+    return virNetworkXMLOptionNew(NULL);
 }
 
 
-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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