mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
Refactor storage XML parsing to be consistent with domain/network conf.
The storage driver arranges its parsing routines in a way that make them difficult to use in the test driver for non-default file parsing. This refactoring moves things to be consistent with the way domain_conf and network_conf do things.
This commit is contained in:
parent
5de555cae2
commit
3f305eb1e9
@ -1,3 +1,9 @@
|
|||||||
|
Mon Jun 22 12:40:11 EDT 2009 Cole Robinson <crobinso@redhat.com>
|
||||||
|
|
||||||
|
* src/libvirt_private.syms src/storage_conf.c src/storage_conf.h
|
||||||
|
src/storage_driver.c src/test.c:
|
||||||
|
Refactor storage XML parsing to be consistent with domain/network conf.
|
||||||
|
|
||||||
Mon Jun 22 12:38:19 EDT 2009 Cole Robinson <crobinso@redhat.com>
|
Mon Jun 22 12:38:19 EDT 2009 Cole Robinson <crobinso@redhat.com>
|
||||||
|
|
||||||
* src/test.c: Activate virtual networks initialized in custom test driver.
|
* src/test.c: Activate virtual networks initialized in custom test driver.
|
||||||
|
@ -267,7 +267,9 @@ virSecurityDriverGetModel;
|
|||||||
# storage_conf.h
|
# storage_conf.h
|
||||||
virStoragePoolDefFormat;
|
virStoragePoolDefFormat;
|
||||||
virStoragePoolDefFree;
|
virStoragePoolDefFree;
|
||||||
virStoragePoolDefParse;
|
virStoragePoolDefParseString;
|
||||||
|
virStoragePoolDefParseFile;
|
||||||
|
virStoragePoolDefParseNode;
|
||||||
virStoragePoolLoadAllConfigs;
|
virStoragePoolLoadAllConfigs;
|
||||||
virStoragePoolObjAssignDef;
|
virStoragePoolObjAssignDef;
|
||||||
virStoragePoolObjClearVols;
|
virStoragePoolObjClearVols;
|
||||||
@ -284,7 +286,9 @@ virStorageVolDefFindByName;
|
|||||||
virStorageVolDefFindByPath;
|
virStorageVolDefFindByPath;
|
||||||
virStorageVolDefFormat;
|
virStorageVolDefFormat;
|
||||||
virStorageVolDefFree;
|
virStorageVolDefFree;
|
||||||
virStorageVolDefParse;
|
virStorageVolDefParseFile;
|
||||||
|
virStorageVolDefParseString;
|
||||||
|
virStorageVolDefParseNode;
|
||||||
virStoragePoolFormatDiskTypeToString;
|
virStoragePoolFormatDiskTypeToString;
|
||||||
virStoragePoolFormatFileSystemTypeToString;
|
virStoragePoolFormatFileSystemTypeToString;
|
||||||
virStoragePoolFormatFileSystemNetTypeToString;
|
virStoragePoolFormatFileSystemNetTypeToString;
|
||||||
|
@ -363,14 +363,14 @@ static int
|
|||||||
virStoragePoolDefParseAuthChap(virConnectPtr conn,
|
virStoragePoolDefParseAuthChap(virConnectPtr conn,
|
||||||
xmlXPathContextPtr ctxt,
|
xmlXPathContextPtr ctxt,
|
||||||
virStoragePoolAuthChapPtr auth) {
|
virStoragePoolAuthChapPtr auth) {
|
||||||
auth->login = virXPathString(conn, "string(/pool/source/auth/@login)", ctxt);
|
auth->login = virXPathString(conn, "string(./source/auth/@login)", ctxt);
|
||||||
if (auth->login == NULL) {
|
if (auth->login == NULL) {
|
||||||
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
||||||
"%s", _("missing auth host attribute"));
|
"%s", _("missing auth host attribute"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
auth->passwd = virXPathString(conn, "string(/pool/source/auth/@passwd)", ctxt);
|
auth->passwd = virXPathString(conn, "string(./source/auth/@passwd)", ctxt);
|
||||||
if (auth->passwd == NULL) {
|
if (auth->passwd == NULL) {
|
||||||
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
||||||
"%s", _("missing auth passwd attribute"));
|
"%s", _("missing auth passwd attribute"));
|
||||||
@ -452,14 +452,12 @@ error:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static virStoragePoolDefPtr
|
static virStoragePoolDefPtr
|
||||||
virStoragePoolDefParseDoc(virConnectPtr conn,
|
virStoragePoolDefParseXML(virConnectPtr conn,
|
||||||
xmlXPathContextPtr ctxt,
|
xmlXPathContextPtr ctxt) {
|
||||||
xmlNodePtr root) {
|
|
||||||
virStoragePoolOptionsPtr options;
|
virStoragePoolOptionsPtr options;
|
||||||
virStoragePoolDefPtr ret;
|
virStoragePoolDefPtr ret;
|
||||||
xmlChar *type = NULL;
|
char *type = NULL;
|
||||||
char *uuid = NULL;
|
char *uuid = NULL;
|
||||||
char *authType = NULL;
|
char *authType = NULL;
|
||||||
|
|
||||||
@ -468,13 +466,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STRNEQ((const char *)root->name, "pool")) {
|
type = virXPathString(conn, "string(./@type)", ctxt);
|
||||||
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
|
||||||
"%s", _("unknown root element for storage pool"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
type = xmlGetProp(root, BAD_CAST "type");
|
|
||||||
if ((ret->type = virStoragePoolTypeFromString((const char *)type)) < 0) {
|
if ((ret->type = virStoragePoolTypeFromString((const char *)type)) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("unknown storage pool type %s"), (const char*)type);
|
_("unknown storage pool type %s"), (const char*)type);
|
||||||
@ -488,17 +480,17 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret->name = virXPathString(conn, "string(/pool/name)", ctxt);
|
ret->name = virXPathString(conn, "string(./name)", ctxt);
|
||||||
if (ret->name == NULL &&
|
if (ret->name == NULL &&
|
||||||
options->flags & VIR_STORAGE_POOL_SOURCE_NAME)
|
options->flags & VIR_STORAGE_POOL_SOURCE_NAME)
|
||||||
ret->name = virXPathString(conn, "string(/pool/source/name)", ctxt);
|
ret->name = virXPathString(conn, "string(./source/name)", ctxt);
|
||||||
if (ret->name == NULL) {
|
if (ret->name == NULL) {
|
||||||
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
||||||
"%s", _("missing pool source name element"));
|
"%s", _("missing pool source name element"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
uuid = virXPathString(conn, "string(/pool/uuid)", ctxt);
|
uuid = virXPathString(conn, "string(./uuid)", ctxt);
|
||||||
if (uuid == NULL) {
|
if (uuid == NULL) {
|
||||||
if (virUUIDGenerate(ret->uuid) < 0) {
|
if (virUUIDGenerate(ret->uuid) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
@ -515,7 +507,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (options->formatFromString) {
|
if (options->formatFromString) {
|
||||||
char *format = virXPathString(conn, "string(/pool/source/format/@type)", ctxt);
|
char *format = virXPathString(conn, "string(./source/format/@type)", ctxt);
|
||||||
if (format == NULL)
|
if (format == NULL)
|
||||||
ret->source.format = options->defaultFormat;
|
ret->source.format = options->defaultFormat;
|
||||||
else
|
else
|
||||||
@ -531,7 +523,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (options->flags & VIR_STORAGE_POOL_SOURCE_HOST) {
|
if (options->flags & VIR_STORAGE_POOL_SOURCE_HOST) {
|
||||||
if ((ret->source.host.name = virXPathString(conn, "string(/pool/source/host/@name)", ctxt)) == NULL) {
|
if ((ret->source.host.name = virXPathString(conn, "string(./source/host/@name)", ctxt)) == NULL) {
|
||||||
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
||||||
"%s", _("missing storage pool source host name"));
|
"%s", _("missing storage pool source host name"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -541,7 +533,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
|
|||||||
xmlNodePtr *nodeset = NULL;
|
xmlNodePtr *nodeset = NULL;
|
||||||
int nsource, i;
|
int nsource, i;
|
||||||
|
|
||||||
if ((nsource = virXPathNodeSet(conn, "/pool/source/device", ctxt, &nodeset)) < 0) {
|
if ((nsource = virXPathNodeSet(conn, "./source/device", ctxt, &nodeset)) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
||||||
"%s", _("cannot extract storage pool source devices"));
|
"%s", _("cannot extract storage pool source devices"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -565,14 +557,14 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
|
|||||||
ret->source.ndevice = nsource;
|
ret->source.ndevice = nsource;
|
||||||
}
|
}
|
||||||
if (options->flags & VIR_STORAGE_POOL_SOURCE_DIR) {
|
if (options->flags & VIR_STORAGE_POOL_SOURCE_DIR) {
|
||||||
if ((ret->source.dir = virXPathString(conn, "string(/pool/source/dir/@path)", ctxt)) == NULL) {
|
if ((ret->source.dir = virXPathString(conn, "string(./source/dir/@path)", ctxt)) == NULL) {
|
||||||
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
||||||
"%s", _("missing storage pool source path"));
|
"%s", _("missing storage pool source path"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (options->flags & VIR_STORAGE_POOL_SOURCE_NAME) {
|
if (options->flags & VIR_STORAGE_POOL_SOURCE_NAME) {
|
||||||
ret->source.name = virXPathString(conn, "string(/pool/source/name)",
|
ret->source.name = virXPathString(conn, "string(./source/name)",
|
||||||
ctxt);
|
ctxt);
|
||||||
if (ret->source.name == NULL) {
|
if (ret->source.name == NULL) {
|
||||||
/* source name defaults to pool name */
|
/* source name defaults to pool name */
|
||||||
@ -586,7 +578,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
|
|||||||
|
|
||||||
if (options->flags & VIR_STORAGE_POOL_SOURCE_ADAPTER) {
|
if (options->flags & VIR_STORAGE_POOL_SOURCE_ADAPTER) {
|
||||||
if ((ret->source.adapter = virXPathString(conn,
|
if ((ret->source.adapter = virXPathString(conn,
|
||||||
"string(/pool/source/adapter/@name)",
|
"string(./source/adapter/@name)",
|
||||||
ctxt)) == NULL) {
|
ctxt)) == NULL) {
|
||||||
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
||||||
"%s", _("missing storage pool source adapter name"));
|
"%s", _("missing storage pool source adapter name"));
|
||||||
@ -594,7 +586,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
authType = virXPathString(conn, "string(/pool/source/auth/@type)", ctxt);
|
authType = virXPathString(conn, "string(./source/auth/@type)", ctxt);
|
||||||
if (authType == NULL) {
|
if (authType == NULL) {
|
||||||
ret->source.authType = VIR_STORAGE_POOL_AUTH_NONE;
|
ret->source.authType = VIR_STORAGE_POOL_AUTH_NONE;
|
||||||
} else {
|
} else {
|
||||||
@ -615,14 +607,14 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ret->target.path = virXPathString(conn, "string(/pool/target/path)", ctxt)) == NULL) {
|
if ((ret->target.path = virXPathString(conn, "string(./target/path)", ctxt)) == NULL) {
|
||||||
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
||||||
"%s", _("missing storage pool target path"));
|
"%s", _("missing storage pool target path"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virStorageDefParsePerms(conn, ctxt, &ret->target.perms,
|
if (virStorageDefParsePerms(conn, ctxt, &ret->target.perms,
|
||||||
"/pool/target/permissions", 0700) < 0)
|
"./target/permissions", 0700) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -656,6 +648,32 @@ catchXMLError (void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
virStoragePoolDefPtr
|
virStoragePoolDefPtr
|
||||||
|
virStoragePoolDefParseNode(virConnectPtr conn,
|
||||||
|
xmlDocPtr xml,
|
||||||
|
xmlNodePtr root) {
|
||||||
|
xmlXPathContextPtr ctxt = NULL;
|
||||||
|
virStoragePoolDefPtr def = NULL;
|
||||||
|
|
||||||
|
if (STRNEQ((const char *)root->name, "pool")) {
|
||||||
|
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
||||||
|
"%s", _("unknown root element for storage pool"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctxt = xmlXPathNewContext(xml);
|
||||||
|
if (ctxt == NULL) {
|
||||||
|
virReportOOMError(conn);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctxt->node = root;
|
||||||
|
def = virStoragePoolDefParseXML(conn, ctxt);
|
||||||
|
cleanup:
|
||||||
|
xmlXPathFreeContext(ctxt);
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
|
||||||
|
static virStoragePoolDefPtr
|
||||||
virStoragePoolDefParse(virConnectPtr conn,
|
virStoragePoolDefParse(virConnectPtr conn,
|
||||||
const char *xmlStr,
|
const char *xmlStr,
|
||||||
const char *filename) {
|
const char *filename) {
|
||||||
@ -663,7 +681,6 @@ virStoragePoolDefParse(virConnectPtr conn,
|
|||||||
xmlParserCtxtPtr pctxt;
|
xmlParserCtxtPtr pctxt;
|
||||||
xmlDocPtr xml = NULL;
|
xmlDocPtr xml = NULL;
|
||||||
xmlNodePtr node = NULL;
|
xmlNodePtr node = NULL;
|
||||||
xmlXPathContextPtr ctxt = NULL;
|
|
||||||
|
|
||||||
/* Set up a parser context so we can catch the details of XML errors. */
|
/* Set up a parser context so we can catch the details of XML errors. */
|
||||||
pctxt = xmlNewParserCtxt ();
|
pctxt = xmlNewParserCtxt ();
|
||||||
@ -673,10 +690,17 @@ virStoragePoolDefParse(virConnectPtr conn,
|
|||||||
pctxt->_private = conn;
|
pctxt->_private = conn;
|
||||||
|
|
||||||
if (conn) virResetError (&conn->err);
|
if (conn) virResetError (&conn->err);
|
||||||
xml = xmlCtxtReadDoc (pctxt, BAD_CAST xmlStr,
|
if (filename) {
|
||||||
filename ? filename : "storage.xml", NULL,
|
xml = xmlCtxtReadFile (pctxt, filename, NULL,
|
||||||
XML_PARSE_NOENT | XML_PARSE_NONET |
|
XML_PARSE_NOENT | XML_PARSE_NONET |
|
||||||
XML_PARSE_NOWARNING);
|
XML_PARSE_NOWARNING);
|
||||||
|
} else {
|
||||||
|
xml = xmlCtxtReadDoc (pctxt, BAD_CAST xmlStr,
|
||||||
|
"storage.xml", NULL,
|
||||||
|
XML_PARSE_NOENT | XML_PARSE_NONET |
|
||||||
|
XML_PARSE_NOWARNING);
|
||||||
|
}
|
||||||
|
|
||||||
if (!xml) {
|
if (!xml) {
|
||||||
if (conn && conn->err.code == VIR_ERR_NONE)
|
if (conn && conn->err.code == VIR_ERR_NONE)
|
||||||
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
||||||
@ -684,12 +708,6 @@ virStoragePoolDefParse(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctxt = xmlXPathNewContext(xml);
|
|
||||||
if (ctxt == NULL) {
|
|
||||||
virReportOOMError(conn);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
node = xmlDocGetRootElement(xml);
|
node = xmlDocGetRootElement(xml);
|
||||||
if (node == NULL) {
|
if (node == NULL) {
|
||||||
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
||||||
@ -697,21 +715,33 @@ virStoragePoolDefParse(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = virStoragePoolDefParseDoc(conn, ctxt, node);
|
ret = virStoragePoolDefParseNode(conn, xml, node);
|
||||||
|
|
||||||
xmlFreeParserCtxt (pctxt);
|
xmlFreeParserCtxt (pctxt);
|
||||||
xmlXPathFreeContext(ctxt);
|
|
||||||
xmlFreeDoc(xml);
|
xmlFreeDoc(xml);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
xmlFreeParserCtxt (pctxt);
|
xmlFreeParserCtxt (pctxt);
|
||||||
xmlXPathFreeContext(ctxt);
|
|
||||||
xmlFreeDoc(xml);
|
xmlFreeDoc(xml);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virStoragePoolDefPtr
|
||||||
|
virStoragePoolDefParseString(virConnectPtr conn,
|
||||||
|
const char *xmlStr)
|
||||||
|
{
|
||||||
|
return virStoragePoolDefParse(conn, xmlStr, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
virStoragePoolDefPtr
|
||||||
|
virStoragePoolDefParseFile(virConnectPtr conn,
|
||||||
|
const char *filename)
|
||||||
|
{
|
||||||
|
return virStoragePoolDefParse(conn, NULL, filename);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virStoragePoolSourceFormat(virConnectPtr conn,
|
virStoragePoolSourceFormat(virConnectPtr conn,
|
||||||
virBufferPtr buf,
|
virBufferPtr buf,
|
||||||
@ -916,10 +946,9 @@ virStorageSize(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static virStorageVolDefPtr
|
static virStorageVolDefPtr
|
||||||
virStorageVolDefParseDoc(virConnectPtr conn,
|
virStorageVolDefParseXML(virConnectPtr conn,
|
||||||
virStoragePoolDefPtr pool,
|
virStoragePoolDefPtr pool,
|
||||||
xmlXPathContextPtr ctxt,
|
xmlXPathContextPtr ctxt) {
|
||||||
xmlNodePtr root) {
|
|
||||||
virStorageVolDefPtr ret;
|
virStorageVolDefPtr ret;
|
||||||
virStorageVolOptionsPtr options;
|
virStorageVolOptionsPtr options;
|
||||||
char *allocation = NULL;
|
char *allocation = NULL;
|
||||||
@ -935,13 +964,7 @@ virStorageVolDefParseDoc(virConnectPtr conn,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STRNEQ((const char *)root->name, "volume")) {
|
ret->name = virXPathString(conn, "string(./name)", ctxt);
|
||||||
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
|
||||||
"%s", _("unknown root element"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret->name = virXPathString(conn, "string(/volume/name)", ctxt);
|
|
||||||
if (ret->name == NULL) {
|
if (ret->name == NULL) {
|
||||||
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
||||||
"%s", _("missing volume name element"));
|
"%s", _("missing volume name element"));
|
||||||
@ -949,10 +972,10 @@ virStorageVolDefParseDoc(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Auto-generated so deliberately ignore */
|
/* Auto-generated so deliberately ignore */
|
||||||
/*ret->key = virXPathString(conn, "string(/volume/key)", ctxt);*/
|
/*ret->key = virXPathString(conn, "string(./key)", ctxt);*/
|
||||||
|
|
||||||
capacity = virXPathString(conn, "string(/volume/capacity)", ctxt);
|
capacity = virXPathString(conn, "string(./capacity)", ctxt);
|
||||||
unit = virXPathString(conn, "string(/volume/capacity/@unit)", ctxt);
|
unit = virXPathString(conn, "string(./capacity/@unit)", ctxt);
|
||||||
if (capacity == NULL) {
|
if (capacity == NULL) {
|
||||||
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
||||||
"%s", _("missing capacity element"));
|
"%s", _("missing capacity element"));
|
||||||
@ -963,9 +986,9 @@ virStorageVolDefParseDoc(virConnectPtr conn,
|
|||||||
VIR_FREE(capacity);
|
VIR_FREE(capacity);
|
||||||
VIR_FREE(unit);
|
VIR_FREE(unit);
|
||||||
|
|
||||||
allocation = virXPathString(conn, "string(/volume/allocation)", ctxt);
|
allocation = virXPathString(conn, "string(./allocation)", ctxt);
|
||||||
if (allocation) {
|
if (allocation) {
|
||||||
unit = virXPathString(conn, "string(/volume/allocation/@unit)", ctxt);
|
unit = virXPathString(conn, "string(./allocation/@unit)", ctxt);
|
||||||
if (virStorageSize(conn, unit, allocation, &ret->allocation) < 0)
|
if (virStorageSize(conn, unit, allocation, &ret->allocation) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
VIR_FREE(allocation);
|
VIR_FREE(allocation);
|
||||||
@ -974,9 +997,9 @@ virStorageVolDefParseDoc(virConnectPtr conn,
|
|||||||
ret->allocation = ret->capacity;
|
ret->allocation = ret->capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret->target.path = virXPathString(conn, "string(/volume/target/path)", ctxt);
|
ret->target.path = virXPathString(conn, "string(./target/path)", ctxt);
|
||||||
if (options->formatFromString) {
|
if (options->formatFromString) {
|
||||||
char *format = virXPathString(conn, "string(/volume/target/format/@type)", ctxt);
|
char *format = virXPathString(conn, "string(./target/format/@type)", ctxt);
|
||||||
if (format == NULL)
|
if (format == NULL)
|
||||||
ret->target.format = options->defaultFormat;
|
ret->target.format = options->defaultFormat;
|
||||||
else
|
else
|
||||||
@ -992,14 +1015,14 @@ virStorageVolDefParseDoc(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (virStorageDefParsePerms(conn, ctxt, &ret->target.perms,
|
if (virStorageDefParsePerms(conn, ctxt, &ret->target.perms,
|
||||||
"/volume/target/permissions", 0600) < 0)
|
"./target/permissions", 0600) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ret->backingStore.path = virXPathString(conn, "string(/volume/backingStore/path)", ctxt);
|
ret->backingStore.path = virXPathString(conn, "string(./backingStore/path)", ctxt);
|
||||||
if (options->formatFromString) {
|
if (options->formatFromString) {
|
||||||
char *format = virXPathString(conn, "string(/volume/backingStore/format/@type)", ctxt);
|
char *format = virXPathString(conn, "string(./backingStore/format/@type)", ctxt);
|
||||||
if (format == NULL)
|
if (format == NULL)
|
||||||
ret->backingStore.format = options->defaultFormat;
|
ret->backingStore.format = options->defaultFormat;
|
||||||
else
|
else
|
||||||
@ -1015,7 +1038,7 @@ virStorageVolDefParseDoc(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (virStorageDefParsePerms(conn, ctxt, &ret->backingStore.perms,
|
if (virStorageDefParsePerms(conn, ctxt, &ret->backingStore.perms,
|
||||||
"/volume/backingStore/permissions", 0600) < 0)
|
"./backingStore/permissions", 0600) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -1028,8 +1051,34 @@ virStorageVolDefParseDoc(virConnectPtr conn,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virStorageVolDefPtr
|
virStorageVolDefPtr
|
||||||
|
virStorageVolDefParseNode(virConnectPtr conn,
|
||||||
|
virStoragePoolDefPtr pool,
|
||||||
|
xmlDocPtr xml,
|
||||||
|
xmlNodePtr root) {
|
||||||
|
xmlXPathContextPtr ctxt = NULL;
|
||||||
|
virStorageVolDefPtr def = NULL;
|
||||||
|
|
||||||
|
if (STRNEQ((const char *)root->name, "volume")) {
|
||||||
|
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
||||||
|
"%s", _("unknown root element for storage vol"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctxt = xmlXPathNewContext(xml);
|
||||||
|
if (ctxt == NULL) {
|
||||||
|
virReportOOMError(conn);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctxt->node = root;
|
||||||
|
def = virStorageVolDefParseXML(conn, pool, ctxt);
|
||||||
|
cleanup:
|
||||||
|
xmlXPathFreeContext(ctxt);
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
|
||||||
|
static virStorageVolDefPtr
|
||||||
virStorageVolDefParse(virConnectPtr conn,
|
virStorageVolDefParse(virConnectPtr conn,
|
||||||
virStoragePoolDefPtr pool,
|
virStoragePoolDefPtr pool,
|
||||||
const char *xmlStr,
|
const char *xmlStr,
|
||||||
@ -1038,7 +1087,6 @@ virStorageVolDefParse(virConnectPtr conn,
|
|||||||
xmlParserCtxtPtr pctxt;
|
xmlParserCtxtPtr pctxt;
|
||||||
xmlDocPtr xml = NULL;
|
xmlDocPtr xml = NULL;
|
||||||
xmlNodePtr node = NULL;
|
xmlNodePtr node = NULL;
|
||||||
xmlXPathContextPtr ctxt = NULL;
|
|
||||||
|
|
||||||
/* Set up a parser context so we can catch the details of XML errors. */
|
/* Set up a parser context so we can catch the details of XML errors. */
|
||||||
pctxt = xmlNewParserCtxt ();
|
pctxt = xmlNewParserCtxt ();
|
||||||
@ -1048,10 +1096,18 @@ virStorageVolDefParse(virConnectPtr conn,
|
|||||||
pctxt->_private = conn;
|
pctxt->_private = conn;
|
||||||
|
|
||||||
if (conn) virResetError (&conn->err);
|
if (conn) virResetError (&conn->err);
|
||||||
xml = xmlCtxtReadDoc (pctxt, BAD_CAST xmlStr,
|
|
||||||
filename ? filename : "storage.xml", NULL,
|
if (filename) {
|
||||||
XML_PARSE_NOENT | XML_PARSE_NONET |
|
xml = xmlCtxtReadFile (pctxt, filename, NULL,
|
||||||
XML_PARSE_NOWARNING);
|
XML_PARSE_NOENT | XML_PARSE_NONET |
|
||||||
|
XML_PARSE_NOWARNING);
|
||||||
|
} else {
|
||||||
|
xml = xmlCtxtReadDoc (pctxt, BAD_CAST xmlStr,
|
||||||
|
"storage.xml", NULL,
|
||||||
|
XML_PARSE_NOENT | XML_PARSE_NONET |
|
||||||
|
XML_PARSE_NOWARNING);
|
||||||
|
}
|
||||||
|
|
||||||
if (!xml) {
|
if (!xml) {
|
||||||
if (conn && conn->err.code == VIR_ERR_NONE)
|
if (conn && conn->err.code == VIR_ERR_NONE)
|
||||||
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
||||||
@ -1059,12 +1115,6 @@ virStorageVolDefParse(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctxt = xmlXPathNewContext(xml);
|
|
||||||
if (ctxt == NULL) {
|
|
||||||
virReportOOMError(conn);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
node = xmlDocGetRootElement(xml);
|
node = xmlDocGetRootElement(xml);
|
||||||
if (node == NULL) {
|
if (node == NULL) {
|
||||||
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
||||||
@ -1072,21 +1122,34 @@ virStorageVolDefParse(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = virStorageVolDefParseDoc(conn, pool, ctxt, node);
|
ret = virStorageVolDefParseNode(conn, pool, xml, node);
|
||||||
|
|
||||||
xmlFreeParserCtxt (pctxt);
|
xmlFreeParserCtxt (pctxt);
|
||||||
xmlXPathFreeContext(ctxt);
|
|
||||||
xmlFreeDoc(xml);
|
xmlFreeDoc(xml);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
xmlFreeParserCtxt (pctxt);
|
xmlFreeParserCtxt (pctxt);
|
||||||
xmlXPathFreeContext(ctxt);
|
|
||||||
xmlFreeDoc(xml);
|
xmlFreeDoc(xml);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virStorageVolDefPtr
|
||||||
|
virStorageVolDefParseString(virConnectPtr conn,
|
||||||
|
virStoragePoolDefPtr pool,
|
||||||
|
const char *xmlStr)
|
||||||
|
{
|
||||||
|
return virStorageVolDefParse(conn, pool, xmlStr, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
virStorageVolDefPtr
|
||||||
|
virStorageVolDefParseFile(virConnectPtr conn,
|
||||||
|
virStoragePoolDefPtr pool,
|
||||||
|
const char *filename)
|
||||||
|
{
|
||||||
|
return virStorageVolDefParse(conn, pool, NULL, filename);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virStorageVolTargetDefFormat(virConnectPtr conn,
|
virStorageVolTargetDefFormat(virConnectPtr conn,
|
||||||
|
@ -28,6 +28,8 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "threads.h"
|
#include "threads.h"
|
||||||
|
|
||||||
|
#include <libxml/tree.h>
|
||||||
|
|
||||||
/* Shared structs */
|
/* Shared structs */
|
||||||
|
|
||||||
|
|
||||||
@ -306,16 +308,26 @@ virStorageVolDefPtr virStorageVolDefFindByName(virStoragePoolObjPtr pool,
|
|||||||
|
|
||||||
void virStoragePoolObjClearVols(virStoragePoolObjPtr pool);
|
void virStoragePoolObjClearVols(virStoragePoolObjPtr pool);
|
||||||
|
|
||||||
virStoragePoolDefPtr virStoragePoolDefParse(virConnectPtr conn,
|
virStoragePoolDefPtr virStoragePoolDefParseString(virConnectPtr conn,
|
||||||
const char *xml,
|
const char *xml);
|
||||||
const char *filename);
|
virStoragePoolDefPtr virStoragePoolDefParseFile(virConnectPtr conn,
|
||||||
|
const char *filename);
|
||||||
|
virStoragePoolDefPtr virStoragePoolDefParseNode(virConnectPtr conn,
|
||||||
|
xmlDocPtr xml,
|
||||||
|
xmlNodePtr root);
|
||||||
char *virStoragePoolDefFormat(virConnectPtr conn,
|
char *virStoragePoolDefFormat(virConnectPtr conn,
|
||||||
virStoragePoolDefPtr def);
|
virStoragePoolDefPtr def);
|
||||||
|
|
||||||
virStorageVolDefPtr virStorageVolDefParse(virConnectPtr conn,
|
virStorageVolDefPtr virStorageVolDefParseString(virConnectPtr conn,
|
||||||
virStoragePoolDefPtr pool,
|
virStoragePoolDefPtr pool,
|
||||||
const char *xml,
|
const char *xml);
|
||||||
const char *filename);
|
virStorageVolDefPtr virStorageVolDefParseFile(virConnectPtr conn,
|
||||||
|
virStoragePoolDefPtr pool,
|
||||||
|
const char *filename);
|
||||||
|
virStorageVolDefPtr virStorageVolDefParseNode(virConnectPtr conn,
|
||||||
|
virStoragePoolDefPtr pool,
|
||||||
|
xmlDocPtr xml,
|
||||||
|
xmlNodePtr root);
|
||||||
char *virStorageVolDefFormat(virConnectPtr conn,
|
char *virStorageVolDefFormat(virConnectPtr conn,
|
||||||
virStoragePoolDefPtr pool,
|
virStoragePoolDefPtr pool,
|
||||||
virStorageVolDefPtr def);
|
virStorageVolDefPtr def);
|
||||||
|
@ -466,7 +466,7 @@ storagePoolCreate(virConnectPtr conn,
|
|||||||
virStorageBackendPtr backend;
|
virStorageBackendPtr backend;
|
||||||
|
|
||||||
storageDriverLock(driver);
|
storageDriverLock(driver);
|
||||||
if (!(def = virStoragePoolDefParse(conn, xml, NULL)))
|
if (!(def = virStoragePoolDefParseString(conn, xml)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
pool = virStoragePoolObjFindByUUID(&driver->pools, def->uuid);
|
pool = virStoragePoolObjFindByUUID(&driver->pools, def->uuid);
|
||||||
@ -520,7 +520,7 @@ storagePoolDefine(virConnectPtr conn,
|
|||||||
virStorageBackendPtr backend;
|
virStorageBackendPtr backend;
|
||||||
|
|
||||||
storageDriverLock(driver);
|
storageDriverLock(driver);
|
||||||
if (!(def = virStoragePoolDefParse(conn, xml, NULL)))
|
if (!(def = virStoragePoolDefParseString(conn, xml)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((backend = virStorageBackendForType(def->type)) == NULL)
|
if ((backend = virStorageBackendForType(def->type)) == NULL)
|
||||||
@ -1222,7 +1222,7 @@ storageVolumeCreateXML(virStoragePoolPtr obj,
|
|||||||
if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
|
if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
voldef = virStorageVolDefParse(obj->conn, pool->def, xmldesc, NULL);
|
voldef = virStorageVolDefParseString(obj->conn, pool->def, xmldesc);
|
||||||
if (voldef == NULL)
|
if (voldef == NULL)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
@ -1364,7 +1364,7 @@ storageVolumeCreateXMLFrom(virStoragePoolPtr obj,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
newvol = virStorageVolDefParse(obj->conn, pool->def, xmldesc, NULL);
|
newvol = virStorageVolDefParseString(obj->conn, pool->def, xmldesc);
|
||||||
if (newvol == NULL)
|
if (newvol == NULL)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
25
src/test.c
25
src/test.c
@ -286,7 +286,7 @@ static int testOpenDefault(virConnectPtr conn) {
|
|||||||
netobj->persistent = 1;
|
netobj->persistent = 1;
|
||||||
virNetworkObjUnlock(netobj);
|
virNetworkObjUnlock(netobj);
|
||||||
|
|
||||||
if (!(pooldef = virStoragePoolDefParse(conn, defaultPoolXML, NULL)))
|
if (!(pooldef = virStoragePoolDefParseString(conn, defaultPoolXML)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!(poolobj = virStoragePoolObjAssignDef(conn, &privconn->pools,
|
if (!(poolobj = virStoragePoolObjAssignDef(conn, &privconn->pools,
|
||||||
@ -567,22 +567,13 @@ static int testOpenFromFile(virConnectPtr conn,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
def = virStoragePoolDefParse(conn, NULL, absFile);
|
def = virStoragePoolDefParseFile(conn, absFile);
|
||||||
VIR_FREE(absFile);
|
VIR_FREE(absFile);
|
||||||
if (!def)
|
if (!def)
|
||||||
goto error;
|
goto error;
|
||||||
} else {
|
} else {
|
||||||
xmlBufferPtr buf;
|
if ((def = virStoragePoolDefParseNode(conn, xml,
|
||||||
xmlSaveCtxtPtr sctxt;
|
pools[i])) == NULL) {
|
||||||
|
|
||||||
buf = xmlBufferCreate();
|
|
||||||
sctxt = xmlSaveToBuffer(buf, NULL, 0);
|
|
||||||
xmlSaveTree(sctxt, pools[i]);
|
|
||||||
xmlSaveClose(sctxt);
|
|
||||||
if ((def = virStoragePoolDefParse(conn,
|
|
||||||
(const char *) buf->content,
|
|
||||||
NULL)) == NULL) {
|
|
||||||
xmlBufferFree(buf);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2517,7 +2508,7 @@ testStoragePoolCreate(virConnectPtr conn,
|
|||||||
virStoragePoolPtr ret = NULL;
|
virStoragePoolPtr ret = NULL;
|
||||||
|
|
||||||
testDriverLock(privconn);
|
testDriverLock(privconn);
|
||||||
if (!(def = virStoragePoolDefParse(conn, xml, NULL)))
|
if (!(def = virStoragePoolDefParseString(conn, xml)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
pool = virStoragePoolObjFindByUUID(&privconn->pools, def->uuid);
|
pool = virStoragePoolObjFindByUUID(&privconn->pools, def->uuid);
|
||||||
@ -2560,7 +2551,7 @@ testStoragePoolDefine(virConnectPtr conn,
|
|||||||
virStoragePoolPtr ret = NULL;
|
virStoragePoolPtr ret = NULL;
|
||||||
|
|
||||||
testDriverLock(privconn);
|
testDriverLock(privconn);
|
||||||
if (!(def = virStoragePoolDefParse(conn, xml, NULL)))
|
if (!(def = virStoragePoolDefParseString(conn, xml)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
def->capacity = defaultPoolCap;
|
def->capacity = defaultPoolCap;
|
||||||
@ -3085,7 +3076,7 @@ testStorageVolumeCreateXML(virStoragePoolPtr pool,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
privvol = virStorageVolDefParse(pool->conn, privpool->def, xmldesc, NULL);
|
privvol = virStorageVolDefParseString(pool->conn, privpool->def, xmldesc);
|
||||||
if (privvol == NULL)
|
if (privvol == NULL)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
@ -3166,7 +3157,7 @@ testStorageVolumeCreateXMLFrom(virStoragePoolPtr pool,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
privvol = virStorageVolDefParse(pool->conn, privpool->def, xmldesc, NULL);
|
privvol = virStorageVolDefParseString(pool->conn, privpool->def, xmldesc);
|
||||||
if (privvol == NULL)
|
if (privvol == NULL)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user