struct _virStoragePoolOptions {
unsigned int flags;
int defaultFormat;
+
+ virStoragePoolXMLNamespace ns;
+
virStoragePoolFormatToString formatToString;
virStoragePoolFormatFromString formatFromString;
};
}
+/* 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)
{
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);
}
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);
_("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);
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");
# 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
virStoragePoolSource source;
virStoragePoolTarget target;
+
+ /* Pool backend specific XML namespace data */
+ void *namespaceData;
+ virStoragePoolXMLNamespace ns;
};
typedef struct _virStoragePoolSourceList virStoragePoolSourceList;