mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-30 09:53:10 +00:00
conf: Introduce virStoragePoolXMLNamespace
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>
This commit is contained in:
parent
a3dbaa3647
commit
fa7a66d079
@ -124,6 +124,9 @@ typedef virStoragePoolOptions *virStoragePoolOptionsPtr;
|
|||||||
struct _virStoragePoolOptions {
|
struct _virStoragePoolOptions {
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
int defaultFormat;
|
int defaultFormat;
|
||||||
|
|
||||||
|
virStoragePoolXMLNamespace ns;
|
||||||
|
|
||||||
virStoragePoolFormatToString formatToString;
|
virStoragePoolFormatToString formatToString;
|
||||||
virStoragePoolFormatFromString formatFromString;
|
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
|
static virStorageVolOptionsPtr
|
||||||
virStorageVolOptionsForPoolType(int type)
|
virStorageVolOptionsForPoolType(int type)
|
||||||
{
|
{
|
||||||
@ -401,6 +432,8 @@ virStoragePoolDefFree(virStoragePoolDefPtr def)
|
|||||||
|
|
||||||
VIR_FREE(def->target.path);
|
VIR_FREE(def->target.path);
|
||||||
VIR_FREE(def->target.perms.label);
|
VIR_FREE(def->target.perms.label);
|
||||||
|
if (def->namespaceData && def->ns.free)
|
||||||
|
(def->ns.free)(def->namespaceData);
|
||||||
VIR_FREE(def);
|
VIR_FREE(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -834,6 +867,13 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt)
|
|||||||
goto error;
|
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:
|
cleanup:
|
||||||
VIR_FREE(uuid);
|
VIR_FREE(uuid);
|
||||||
VIR_FREE(type);
|
VIR_FREE(type);
|
||||||
@ -1010,7 +1050,10 @@ virStoragePoolDefFormatBuf(virBufferPtr buf,
|
|||||||
_("unexpected pool type"));
|
_("unexpected pool type"));
|
||||||
return -1;
|
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);
|
virBufferAdjustIndent(buf, 2);
|
||||||
virBufferEscapeString(buf, "<name>%s</name>\n", def->name);
|
virBufferEscapeString(buf, "<name>%s</name>\n", def->name);
|
||||||
|
|
||||||
@ -1063,6 +1106,12 @@ virStoragePoolDefFormatBuf(virBufferPtr buf,
|
|||||||
virBufferAdjustIndent(buf, -2);
|
virBufferAdjustIndent(buf, -2);
|
||||||
virBufferAddLit(buf, "</target>\n");
|
virBufferAddLit(buf, "</target>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (def->namespaceData && def->ns.format) {
|
||||||
|
if ((def->ns.format)(buf, def->namespaceData) < 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
virBufferAdjustIndent(buf, -2);
|
virBufferAdjustIndent(buf, -2);
|
||||||
virBufferAddLit(buf, "</pool>\n");
|
virBufferAddLit(buf, "</pool>\n");
|
||||||
|
|
||||||
|
@ -33,6 +33,26 @@
|
|||||||
|
|
||||||
# include <libxml/tree.h>
|
# 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
|
* How the volume's data is stored on underlying
|
||||||
* physical devices - can potentially span many
|
* physical devices - can potentially span many
|
||||||
@ -222,6 +242,10 @@ struct _virStoragePoolDef {
|
|||||||
|
|
||||||
virStoragePoolSource source;
|
virStoragePoolSource source;
|
||||||
virStoragePoolTarget target;
|
virStoragePoolTarget target;
|
||||||
|
|
||||||
|
/* Pool backend specific XML namespace data */
|
||||||
|
void *namespaceData;
|
||||||
|
virStoragePoolXMLNamespace ns;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _virStoragePoolSourceList virStoragePoolSourceList;
|
typedef struct _virStoragePoolSourceList virStoragePoolSourceList;
|
||||||
|
@ -921,6 +921,7 @@ virStoragePoolFormatDiskTypeToString;
|
|||||||
virStoragePoolFormatFileSystemNetTypeToString;
|
virStoragePoolFormatFileSystemNetTypeToString;
|
||||||
virStoragePoolFormatFileSystemTypeToString;
|
virStoragePoolFormatFileSystemTypeToString;
|
||||||
virStoragePoolFormatLogicalTypeToString;
|
virStoragePoolFormatLogicalTypeToString;
|
||||||
|
virStoragePoolOptionsPoolTypeSetXMLNamespace;
|
||||||
virStoragePoolSaveConfig;
|
virStoragePoolSaveConfig;
|
||||||
virStoragePoolSaveState;
|
virStoragePoolSaveState;
|
||||||
virStoragePoolSourceClear;
|
virStoragePoolSourceClear;
|
||||||
|
Loading…
Reference in New Issue
Block a user