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.
This commit is contained in:
parent
a92160dbd5
commit
e238bfa6d4
@ -2836,68 +2836,21 @@ virStorageBackendDeleteLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* virStorageBackendFindGlusterPoolSources:
|
|
||||||
* @host: host to detect volumes on
|
|
||||||
* @pooltype: type of the pool
|
|
||||||
* @list: list of storage pool sources to be filled
|
|
||||||
* @report: report error if the 'gluster' cli tool is missing
|
|
||||||
*
|
|
||||||
* Looks up gluster volumes on @host and fills them to @list.
|
|
||||||
*
|
|
||||||
* @pooltype allows to influence the specific differences between netfs and
|
|
||||||
* native gluster pools. Users should pass only VIR_STORAGE_POOL_NETFS or
|
|
||||||
* VIR_STORAGE_POOL_GLUSTER.
|
|
||||||
*
|
|
||||||
* Returns number of volumes on the host on success, or -1 on error.
|
|
||||||
*/
|
|
||||||
int
|
int
|
||||||
virStorageBackendFindGlusterPoolSources(const char *host,
|
virStorageUtilGlusterExtractPoolSources(const char *host,
|
||||||
virStoragePoolType pooltype,
|
const char *xml,
|
||||||
virStoragePoolSourceListPtr list,
|
virStoragePoolSourceListPtr list,
|
||||||
bool report)
|
virStoragePoolType pooltype)
|
||||||
{
|
{
|
||||||
char *glusterpath = NULL;
|
|
||||||
char *outbuf = NULL;
|
|
||||||
virCommandPtr cmd = NULL;
|
|
||||||
xmlDocPtr doc = NULL;
|
xmlDocPtr doc = NULL;
|
||||||
xmlXPathContextPtr ctxt = NULL;
|
xmlXPathContextPtr ctxt = NULL;
|
||||||
xmlNodePtr *nodes = NULL;
|
xmlNodePtr *nodes = NULL;
|
||||||
virStoragePoolSource *src = NULL;
|
virStoragePoolSource *src = NULL;
|
||||||
size_t i;
|
size_t i;
|
||||||
int nnodes;
|
int nnodes;
|
||||||
int rc;
|
|
||||||
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (!(glusterpath = virFindFileInPath("gluster"))) {
|
if (!(doc = virXMLParseStringCtxt(xml, _("(gluster_cli_output)"), &ctxt)))
|
||||||
if (report) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("'gluster' command line tool not found"));
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd = virCommandNewArgList(glusterpath,
|
|
||||||
"--xml",
|
|
||||||
"--log-file=/dev/null",
|
|
||||||
"volume", "info", "all", NULL);
|
|
||||||
|
|
||||||
virCommandAddArgFormat(cmd, "--remote-host=%s", host);
|
|
||||||
virCommandSetOutputBuffer(cmd, &outbuf);
|
|
||||||
|
|
||||||
if (virCommandRun(cmd, &rc) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (rc != 0) {
|
|
||||||
ret = 0;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(doc = virXMLParseStringCtxt(outbuf, _("(gluster_cli_output)"),
|
|
||||||
&ctxt)))
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((nnodes = virXPathNodeSet("//volumes/volume", ctxt, &nodes)) < 0)
|
if ((nnodes = virXPathNodeSet("//volumes/volume", ctxt, &nodes)) < 0)
|
||||||
@ -2932,6 +2885,68 @@ virStorageBackendFindGlusterPoolSources(const char *host,
|
|||||||
VIR_FREE(nodes);
|
VIR_FREE(nodes);
|
||||||
xmlXPathFreeContext(ctxt);
|
xmlXPathFreeContext(ctxt);
|
||||||
xmlFreeDoc(doc);
|
xmlFreeDoc(doc);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virStorageBackendFindGlusterPoolSources:
|
||||||
|
* @host: host to detect volumes on
|
||||||
|
* @pooltype: type of the pool
|
||||||
|
* @list: list of storage pool sources to be filled
|
||||||
|
* @report: report error if the 'gluster' cli tool is missing
|
||||||
|
*
|
||||||
|
* Looks up gluster volumes on @host and fills them to @list.
|
||||||
|
*
|
||||||
|
* @pooltype allows to influence the specific differences between netfs and
|
||||||
|
* native gluster pools. Users should pass only VIR_STORAGE_POOL_NETFS or
|
||||||
|
* VIR_STORAGE_POOL_GLUSTER.
|
||||||
|
*
|
||||||
|
* Returns number of volumes on the host on success, or -1 on error.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
virStorageBackendFindGlusterPoolSources(const char *host,
|
||||||
|
virStoragePoolType pooltype,
|
||||||
|
virStoragePoolSourceListPtr list,
|
||||||
|
bool report)
|
||||||
|
{
|
||||||
|
char *glusterpath = NULL;
|
||||||
|
char *outbuf = NULL;
|
||||||
|
virCommandPtr cmd = NULL;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (!(glusterpath = virFindFileInPath("gluster"))) {
|
||||||
|
if (report) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("'gluster' command line tool not found"));
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd = virCommandNewArgList(glusterpath,
|
||||||
|
"--xml",
|
||||||
|
"--log-file=/dev/null",
|
||||||
|
"volume", "info", "all", NULL);
|
||||||
|
|
||||||
|
virCommandAddArgFormat(cmd, "--remote-host=%s", host);
|
||||||
|
virCommandSetOutputBuffer(cmd, &outbuf);
|
||||||
|
|
||||||
|
if (virCommandRun(cmd, &rc) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (rc != 0) {
|
||||||
|
ret = 0;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = virStorageUtilGlusterExtractPoolSources(host, outbuf, list, pooltype);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
VIR_FREE(outbuf);
|
VIR_FREE(outbuf);
|
||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
VIR_FREE(glusterpath);
|
VIR_FREE(glusterpath);
|
||||||
|
@ -93,6 +93,10 @@ int virStorageBackendDeleteLocal(virConnectPtr conn,
|
|||||||
int virStorageBackendRefreshLocal(virConnectPtr conn,
|
int virStorageBackendRefreshLocal(virConnectPtr conn,
|
||||||
virStoragePoolObjPtr pool);
|
virStoragePoolObjPtr pool);
|
||||||
|
|
||||||
|
int virStorageUtilGlusterExtractPoolSources(const char *host,
|
||||||
|
const char *xml,
|
||||||
|
virStoragePoolSourceListPtr list,
|
||||||
|
virStoragePoolType pooltype);
|
||||||
int virStorageBackendFindGlusterPoolSources(const char *host,
|
int virStorageBackendFindGlusterPoolSources(const char *host,
|
||||||
virStoragePoolType pooltype,
|
virStoragePoolType pooltype,
|
||||||
virStoragePoolSourceListPtr list,
|
virStoragePoolSourceListPtr list,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user