To allow testing of the algorithm, split out the extractor into a
separate helper.
---
src/storage/storage_util.c | 95 +++++++++++++++++++++++++++-------------------
src/storage/storage_util.h | 4 ++
2 files changed, 59 insertions(+), 40 deletions(-)
diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
index 715361923..b7c594da2 100644
--- a/src/storage/storage_util.c
+++ b/src/storage/storage_util.c
@@ -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);
diff --git a/src/storage/storage_util.h b/src/storage/storage_util.h
index 1ba259c1e..602d3a069 100644
--- a/src/storage/storage_util.h
+++ b/src/storage/storage_util.h
@@ -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,
--
2.12.2