[libvirt] [PATCH v4 06/10] conf: Introduce virStoragePoolXMLNamespace

John Ferlan jferlan at redhat.com
Thu Jan 17 21:22:12 UTC 2019


Introduce the infrastructure necessary to manage a Storage Pool XML
Namespace. The general concept is similar to virDomainXMLNamespace,
except that for Storage Pools the storage backend specific details
can be stored within the _virStoragePoolOptions unlike the domain
processing code which manages its xmlopt's via the virDomainXMLOption
which is allocated/passed around for each domain.

This patch defines the add the parse, format, free, and href methods
required to process the XML and callout from the Storage Pool Def
parse, format, and free API's to perform the action on the XML data
for/from the backend.

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 src/conf/storage_conf.c  | 51 +++++++++++++++++++++++++++++++++++++++-
 src/conf/storage_conf.h  | 24 +++++++++++++++++++
 src/libvirt_private.syms |  1 +
 3 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 76e0bb987b..a7298381ef 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -124,6 +124,9 @@ typedef virStoragePoolOptions *virStoragePoolOptionsPtr;
 struct _virStoragePoolOptions {
     unsigned int flags;
     int defaultFormat;
+
+    virStoragePoolXMLNamespace ns;
+
     virStoragePoolFormatToString formatToString;
     virStoragePoolFormatFromString formatFromString;
 };
@@ -318,6 +321,34 @@ virStoragePoolOptionsForPoolType(int type)
 }
 
 
+/* virStoragePoolOptionsPoolTypeSetXMLNamespace:
+ * @type: virStoragePoolType
+ * @ns: xmlopt namespace pointer
+ *
+ * Store the @ns in the pool options for the particular backend.
+ * This allows the parse/format code to then directly call the Namespace
+ * method space (parse, format, href, free) as needed during processing.
+ *
+ * Returns: 0 on success, -1 on failure.
+ */
+int
+virStoragePoolOptionsPoolTypeSetXMLNamespace(int type,
+                                             virStoragePoolXMLNamespacePtr ns)
+{
+    int ret = -1;
+    virStoragePoolTypeInfoPtr backend = virStoragePoolTypeInfoLookup(type);
+
+    if (!backend)
+        goto cleanup;
+
+    backend->poolOptions.ns = *ns;
+    ret = 0;
+
+ cleanup:
+    return ret;
+}
+
+
 static virStorageVolOptionsPtr
 virStorageVolOptionsForPoolType(int type)
 {
@@ -401,6 +432,8 @@ virStoragePoolDefFree(virStoragePoolDefPtr def)
 
     VIR_FREE(def->target.path);
     VIR_FREE(def->target.perms.label);
+    if (def->namespaceData && def->ns.free)
+        (def->ns.free)(def->namespaceData);
     VIR_FREE(def);
 }
 
@@ -835,6 +868,13 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt)
         goto error;
     }
 
+    /* Make a copy of all the callback pointers here for easier use,
+     * especially during the virStoragePoolSourceClear method */
+    ret->ns = options->ns;
+    if (ret->ns.parse &&
+        (ret->ns.parse)(ctxt, &ret->namespaceData) < 0)
+        goto error;
+
  cleanup:
     VIR_FREE(uuid);
     VIR_FREE(type);
@@ -1011,7 +1051,10 @@ virStoragePoolDefFormatBuf(virBufferPtr buf,
                        _("unexpected pool type"));
         return -1;
     }
-    virBufferAsprintf(buf, "<pool type='%s'>\n", type);
+    virBufferAsprintf(buf, "<pool type='%s'", type);
+    if (def->namespaceData && def->ns.href)
+        virBufferAsprintf(buf, " %s", (def->ns.href)());
+    virBufferAddLit(buf, ">\n");
     virBufferAdjustIndent(buf, 2);
     virBufferEscapeString(buf, "<name>%s</name>\n", def->name);
 
@@ -1064,6 +1107,12 @@ virStoragePoolDefFormatBuf(virBufferPtr buf,
         virBufferAdjustIndent(buf, -2);
         virBufferAddLit(buf, "</target>\n");
     }
+
+    if (def->namespaceData && def->ns.format) {
+        if ((def->ns.format)(buf, def->namespaceData) < 0)
+            return -1;
+    }
+
     virBufferAdjustIndent(buf, -2);
     virBufferAddLit(buf, "</pool>\n");
 
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index a6763447a7..24217eb401 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -33,6 +33,26 @@
 
 # include <libxml/tree.h>
 
+/* Various callbacks needed to parse/create Storage Pool XML's using
+ * a private namespace */
+typedef int (*virStoragePoolDefNamespaceParse)(xmlXPathContextPtr, void **);
+typedef void (*virStoragePoolDefNamespaceFree)(void *);
+typedef int (*virStoragePoolDefNamespaceXMLFormat)(virBufferPtr, void *);
+typedef const char *(*virStoragePoolDefNamespaceHref)(void);
+
+typedef struct _virStoragePoolXMLNamespace virStoragePoolXMLNamespace;
+typedef virStoragePoolXMLNamespace *virStoragePoolXMLNamespacePtr;
+struct _virStoragePoolXMLNamespace {
+    virStoragePoolDefNamespaceParse parse;
+    virStoragePoolDefNamespaceFree free;
+    virStoragePoolDefNamespaceXMLFormat format;
+    virStoragePoolDefNamespaceHref href;
+};
+
+int
+virStoragePoolOptionsPoolTypeSetXMLNamespace(int type,
+                                             virStoragePoolXMLNamespacePtr ns);
+
 /*
  * How the volume's data is stored on underlying
  * physical devices - can potentially span many
@@ -222,6 +242,10 @@ struct _virStoragePoolDef {
 
     virStoragePoolSource source;
     virStoragePoolTarget target;
+
+    /* Pool backend specific XML namespace data */
+    void *namespaceData;
+    virStoragePoolXMLNamespace ns;
 };
 
 typedef struct _virStoragePoolSourceList virStoragePoolSourceList;
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index c3d6306809..4d82797ee1 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -919,6 +919,7 @@ virStoragePoolFormatDiskTypeToString;
 virStoragePoolFormatFileSystemNetTypeToString;
 virStoragePoolFormatFileSystemTypeToString;
 virStoragePoolFormatLogicalTypeToString;
+virStoragePoolOptionsPoolTypeSetXMLNamespace;
 virStoragePoolSaveConfig;
 virStoragePoolSaveState;
 virStoragePoolSourceClear;
-- 
2.20.1




More information about the libvir-list mailing list