]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Introduce virStoragePoolXMLNamespace
authorJohn Ferlan <jferlan@redhat.com>
Thu, 3 Jan 2019 16:47:48 +0000 (11:47 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Wed, 30 Jan 2019 00:16:13 +0000 (19:16 -0500)
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@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/conf/storage_conf.c
src/conf/storage_conf.h
src/libvirt_private.syms

index bb666af3ecee67171417d6e02bf23bccc97f05e9..7b9f429cba6fd88c2c636e1436fba5df116d90fe 100644 (file)
@@ -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);
 }
 
@@ -834,6 +867,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);
@@ -1010,7 +1050,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);
 
@@ -1063,6 +1106,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");
 
index a6763447a742270ef6a90fb0ba664951beead0a0..24217eb401e29d6a8843697e874eb64a0f7724ad 100644 (file)
 
 # 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;
index e53ae0dbebcf18aa075075f01ee5e713e6cad320..be52eaedb74dd40576fdbf112a1f47efe3c274d5 100644 (file)
@@ -921,6 +921,7 @@ virStoragePoolFormatDiskTypeToString;
 virStoragePoolFormatFileSystemNetTypeToString;
 virStoragePoolFormatFileSystemTypeToString;
 virStoragePoolFormatLogicalTypeToString;
+virStoragePoolOptionsPoolTypeSetXMLNamespace;
 virStoragePoolSaveConfig;
 virStoragePoolSaveState;
 virStoragePoolSourceClear;