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

[libvirt] [PATCH 03/10] Add namespace callback hooks to domain_conf.



This patch adds namespace XML parsers to be hooked into
the main domain parser.  This allows for individual hypervisor
drivers to add per-namespace XML into the main domain XML.

Signed-off-by: Chris Lalancette <clalance redhat com>
---
 src/conf/capabilities.c |    2 ++
 src/conf/capabilities.h |   17 +++++++++++++++++
 src/conf/domain_conf.c  |   44 +++++++++++++++++++++++++++++++++++++-------
 src/conf/domain_conf.h  |    3 +++
 4 files changed, 59 insertions(+), 7 deletions(-)

diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index dafd821..d4a6070 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -174,6 +174,8 @@ virCapabilitiesFree(virCapsPtr caps) {
     VIR_FREE(caps->host.secModel.doi);
     virCPUDefFree(caps->host.cpu);
 
+    VIR_FREE(caps->ns);
+
     VIR_FREE(caps);
 }
 
diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h
index 0ed0166..95bc65c 100644
--- a/src/conf/capabilities.h
+++ b/src/conf/capabilities.h
@@ -112,6 +112,21 @@ struct _virCapsHost {
     virCPUDefPtr cpu;
 };
 
+typedef int (*virDomainDefNamespaceParse)(xmlDocPtr, xmlNodePtr,
+                                          xmlXPathContextPtr, void **);
+typedef void (*virDomainDefNamespaceFree)(void *);
+typedef int (*virDomainDefNamespaceXMLFormat)(virBufferPtr, void *);
+typedef const char *(*virDomainDefNamespaceHref)(void);
+
+typedef struct _virDomainXMLNamespace virDomainXMLNamespace;
+typedef virDomainXMLNamespace *virDomainXMLNamespacePtr;
+struct _virDomainXMLNamespace {
+    virDomainDefNamespaceParse parse;
+    virDomainDefNamespaceFree free;
+    virDomainDefNamespaceXMLFormat format;
+    virDomainDefNamespaceHref href;
+};
+
 typedef struct _virCaps virCaps;
 typedef virCaps* virCapsPtr;
 struct _virCaps {
@@ -124,6 +139,8 @@ struct _virCaps {
     void (*privateDataFreeFunc)(void *);
     int (*privateDataXMLFormat)(virBufferPtr, void *);
     int (*privateDataXMLParse)(xmlXPathContextPtr, void *);
+
+    virDomainXMLNamespacePtr ns;
 };
 
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index e4a2cac..a374206 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -728,6 +728,9 @@ void virDomainDefFree(virDomainDefPtr def)
 
     virCPUDefFree(def->cpu);
 
+    if (def->namespaceData && def->ns.free)
+        (def->ns.free)(def->namespaceData);
+
     VIR_FREE(def);
 }
 
@@ -3717,7 +3720,10 @@ static char *virDomainDefDefaultEmulator(virDomainDefPtr def,
 }
 
 static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
-                                            xmlXPathContextPtr ctxt, int flags)
+                                            xmlDocPtr xml,
+                                            xmlNodePtr root,
+                                            xmlXPathContextPtr ctxt,
+                                            int flags)
 {
     xmlNodePtr *nodes = NULL, node = NULL;
     char *tmp = NULL;
@@ -4366,6 +4372,22 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
             goto error;
     }
 
+    /* callout to per-namespace parsers (in the individual drivers) */
+    if (caps->ns) {
+        /* we have to make a copy of all of the callback pointers here since
+         * we won't have the virCaps structure available during free
+         */
+        def->ns.parse = caps->ns->parse;
+        def->ns.free = caps->ns->free;
+        def->ns.format = caps->ns->format;
+        def->ns.href = caps->ns->href;
+
+        if (def->ns.parse) {
+            if ((def->ns.parse)(xml, root, ctxt, &def->namespaceData) < 0)
+                goto error;
+        }
+    }
+
     /* Auto-add any implied controllers which aren't present
      */
     if (virDomainDefAddImplicitControllers(def) < 0)
@@ -4386,6 +4408,7 @@ no_memory:
 
 
 static virDomainObjPtr virDomainObjParseXML(virCapsPtr caps,
+                                            xmlDocPtr xml,
                                             xmlXPathContextPtr ctxt)
 {
     char *tmp = NULL;
@@ -4405,7 +4428,7 @@ static virDomainObjPtr virDomainObjParseXML(virCapsPtr caps,
 
     oldnode = ctxt->node;
     ctxt->node = config;
-    obj->def = virDomainDefParseXML(caps, ctxt,
+    obj->def = virDomainDefParseXML(caps, xml, config, ctxt,
                                     VIR_DOMAIN_XML_INTERNAL_STATUS);
     ctxt->node = oldnode;
     if (!obj->def)
@@ -4496,7 +4519,7 @@ virDomainDefPtr virDomainDefParseNode(virCapsPtr caps,
     }
 
     ctxt->node = root;
-    def = virDomainDefParseXML(caps, ctxt, flags);
+    def = virDomainDefParseXML(caps, xml, root, ctxt, flags);
 
 cleanup:
     xmlXPathFreeContext(ctxt);
@@ -4524,7 +4547,7 @@ static virDomainObjPtr virDomainObjParseNode(virCapsPtr caps,
     }
 
     ctxt->node = root;
-    obj = virDomainObjParseXML(caps, ctxt);
+    obj = virDomainObjParseXML(caps, xml, ctxt);
 
 cleanup:
     xmlXPathFreeContext(ctxt);
@@ -5736,10 +5759,12 @@ char *virDomainDefFormat(virDomainDefPtr def,
     if (def->id == -1)
         flags |= VIR_DOMAIN_XML_INACTIVE;
 
+    virBufferVSprintf(&buf, "<domain type='%s'", type);
     if (!(flags & VIR_DOMAIN_XML_INACTIVE))
-        virBufferVSprintf(&buf, "<domain type='%s' id='%d'>\n", type, def->id);
-    else
-        virBufferVSprintf(&buf, "<domain type='%s'>\n", type);
+        virBufferVSprintf(&buf, " id='%d'", def->id);
+    if (def->namespaceData && def->ns.href)
+        virBufferVSprintf(&buf, " %s", (def->ns.href)());
+    virBufferAddLit(&buf, ">\n");
 
     virBufferEscapeString(&buf, "  <name>%s</name>\n", def->name);
 
@@ -5996,6 +6021,11 @@ char *virDomainDefFormat(virDomainDefPtr def,
         }
     }
 
+    if (def->namespaceData && def->ns.format) {
+        if ((def->ns.format)(&buf, def->namespaceData) < 0)
+            goto cleanup;
+    }
+
     virBufferAddLit(&buf, "</domain>\n");
 
     if (virBufferError(&buf))
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index fafa0f5..80f4146 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -863,6 +863,9 @@ struct _virDomainDef {
     virSecurityLabelDef seclabel;
     virDomainWatchdogDefPtr watchdog;
     virCPUDefPtr cpu;
+
+    void *namespaceData;
+    virDomainXMLNamespace ns;
 };
 
 /* Guest VM runtime state */
-- 
1.6.6.1


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