提交 e238bfa6 编写于 作者: P Peter Krempa

storage: util: Split out the gluster volume extraction code into new function

To allow testing of the algorithm, split out the extractor into a
separate helper.
上级 a92160db
......@@ -2836,6 +2836,60 @@ virStorageBackendDeleteLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
}
int
virStorageUtilGlusterExtractPoolSources(const char *host,
const char *xml,
virStoragePoolSourceListPtr list,
virStoragePoolType pooltype)
{
xmlDocPtr doc = NULL;
xmlXPathContextPtr ctxt = NULL;
xmlNodePtr *nodes = NULL;
virStoragePoolSource *src = NULL;
size_t i;
int nnodes;
int ret = -1;
if (!(doc = virXMLParseStringCtxt(xml, _("(gluster_cli_output)"), &ctxt)))
goto cleanup;
if ((nnodes = virXPathNodeSet("//volumes/volume", ctxt, &nodes)) < 0)
goto cleanup;
for (i = 0; i < nnodes; i++) {
ctxt->node = nodes[i];
if (!(src = virStoragePoolSourceListNewSource(list)))
goto cleanup;
if (!(src->dir = virXPathString("string(//name)", ctxt))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("failed to extract gluster volume name"));
goto cleanup;
}
if (pooltype == VIR_STORAGE_POOL_NETFS)
src->format = VIR_STORAGE_POOL_NETFS_GLUSTERFS;
if (VIR_ALLOC_N(src->hosts, 1) < 0)
goto cleanup;
src->nhost = 1;
if (VIR_STRDUP(src->hosts[0].name, host) < 0)
goto cleanup;
}
ret = nnodes;
cleanup:
VIR_FREE(nodes);
xmlXPathFreeContext(ctxt);
xmlFreeDoc(doc);
return ret;
}
/**
* virStorageBackendFindGlusterPoolSources:
* @host: host to detect volumes on
......@@ -2860,12 +2914,6 @@ virStorageBackendFindGlusterPoolSources(const char *host,
char *glusterpath = NULL;
char *outbuf = NULL;
virCommandPtr cmd = NULL;
xmlDocPtr doc = NULL;
xmlXPathContextPtr ctxt = NULL;
xmlNodePtr *nodes = NULL;
virStoragePoolSource *src = NULL;
size_t i;
int nnodes;
int rc;
int ret = -1;
......@@ -2896,42 +2944,9 @@ virStorageBackendFindGlusterPoolSources(const char *host,
goto cleanup;
}
if (!(doc = virXMLParseStringCtxt(outbuf, _("(gluster_cli_output)"),
&ctxt)))
goto cleanup;
if ((nnodes = virXPathNodeSet("//volumes/volume", ctxt, &nodes)) < 0)
goto cleanup;
for (i = 0; i < nnodes; i++) {
ctxt->node = nodes[i];
if (!(src = virStoragePoolSourceListNewSource(list)))
goto cleanup;
if (!(src->dir = virXPathString("string(//name)", ctxt))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("failed to extract gluster volume name"));
goto cleanup;
}
if (pooltype == VIR_STORAGE_POOL_NETFS)
src->format = VIR_STORAGE_POOL_NETFS_GLUSTERFS;
if (VIR_ALLOC_N(src->hosts, 1) < 0)
goto cleanup;
src->nhost = 1;
if (VIR_STRDUP(src->hosts[0].name, host) < 0)
goto cleanup;
}
ret = nnodes;
ret = virStorageUtilGlusterExtractPoolSources(host, outbuf, list, pooltype);
cleanup:
VIR_FREE(nodes);
xmlXPathFreeContext(ctxt);
xmlFreeDoc(doc);
VIR_FREE(outbuf);
virCommandFree(cmd);
VIR_FREE(glusterpath);
......
......@@ -93,6 +93,10 @@ int virStorageBackendDeleteLocal(virConnectPtr conn,
int virStorageBackendRefreshLocal(virConnectPtr conn,
virStoragePoolObjPtr pool);
int virStorageUtilGlusterExtractPoolSources(const char *host,
const char *xml,
virStoragePoolSourceListPtr list,
virStoragePoolType pooltype);
int virStorageBackendFindGlusterPoolSources(const char *host,
virStoragePoolType pooltype,
virStoragePoolSourceListPtr list,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册