]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: netfs: Support lookup of glusterfs pool sources
authorPeter Krempa <pkrempa@redhat.com>
Wed, 26 Mar 2014 18:17:55 +0000 (19:17 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 1 Apr 2014 09:06:05 +0000 (11:06 +0200)
https://bugzilla.redhat.com/show_bug.cgi?id=1072714

Use the "gluster" command line tool to retrieve information about remote
volumes on a gluster server to allow storage pool source lookup.

Unfortunately gluster doesn't provide a management library so that we
could use that directly, instead the RPC calls are hardcoded in the
command line tool.

configure.ac
src/storage/storage_backend.c
src/storage/storage_backend.h
src/storage/storage_backend_fs.c

index 7b9e38ae198affa88e842cc9719be3cf2c7093ce..e68f5f63ae7d85a8f2f04e7ec814c77fd2d33b0b 100644 (file)
@@ -1936,6 +1936,12 @@ if test "$with_storage_gluster" = "yes"; then
 fi
 AM_CONDITIONAL([WITH_STORAGE_GLUSTER], [test "$with_storage_gluster" = "yes"])
 
+if test "$with_storage_fs" = "yes" ||
+   test "$with_storage_gluster" = "yes"; then
+  AC_PATH_PROG([GLUSTER_CLI], [gluster], [], [$PATH:/sbin:/usr/sbin])
+  AC_DEFINE_UNQUOTED([GLUSTER_CLI], ["$GLUSTER_CLI"],
+    [Location or name of the gluster command line tool])
+fi
 
 LIBPARTED_CFLAGS=
 LIBPARTED_LIBS=
index adf0311166bb34cabd9cd7c7b35722e6b53aa82b..1c299d6303c3479dde1ceeb036b5f983b22c9bdd 100644 (file)
@@ -1636,3 +1636,92 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool,
 
     return stablepath;
 }
+
+#ifdef GLUSTER_CLI
+int
+virStorageBackendFindGlusterPoolSources(const char *host,
+                                        int pooltype,
+                                        virStoragePoolSourceListPtr list)
+{
+    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;
+
+    cmd = virCommandNewArgList(GLUSTER_CLI,
+                               "--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) {
+        VIR_INFO("failed to query host '%s' for gluster volumes: %s",
+                 host, outbuf);
+        ret = 0;
+        goto cleanup;
+    }
+
+    if (!(doc = virXMLParseStringCtxt(outbuf, _("(gluster_cli_output)"),
+                                      &ctxt)))
+        goto cleanup;
+
+    if ((nnodes = virXPathNodeSet("//volumes/volume", ctxt, &nodes)) <= 0) {
+        VIR_INFO("no gluster volumes available on '%s'", host);
+        ret = 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 (VIR_ALLOC_N(src->hosts, 1) < 0)
+            goto cleanup;
+        src->nhost = 1;
+
+        if (VIR_STRDUP(src->hosts[0].name, host) < 0)
+            goto cleanup;
+
+        src->format = pooltype;
+    }
+
+    ret = 0;
+
+ cleanup:
+    VIR_FREE(nodes);
+    xmlXPathFreeContext(ctxt);
+    xmlFreeDoc(doc);
+    VIR_FREE(outbuf);
+    virCommandFree(cmd);
+    return ret;
+}
+#else /* #ifdef GLUSTER_CLI */
+int
+virStorageBackendFindGlusterPoolSources(const char *host ATTRIBUTE_UNUSED,
+                                        int pooltype ATTRIBUTE_UNUSED,
+                                        virStoragePoolSourceListPtr list ATTRIBUTE_UNUSED)
+{
+    VIR_INFO("gluster cli tool not installed");
+    return 0;
+}
+#endif /* #ifdef GLUSTER_CLI */
index 9b8ef7fa356db269fbccb2eb26c427996c313441..c0d16685a6be28e578f370fdca37d2fbcbf59acd 100644 (file)
@@ -87,6 +87,10 @@ int virStorageBackendFindFSImageTool(char **tool);
 virStorageBackendBuildVolFrom
 virStorageBackendFSImageToolTypeToFunc(int tool_type);
 
+int virStorageBackendFindGlusterPoolSources(const char *host,
+                                            int pooltype,
+                                            virStoragePoolSourceListPtr list);
+
 
 typedef struct _virStorageBackend virStorageBackend;
 typedef virStorageBackend *virStorageBackendPtr;
index 561581ea68838dad59cd12f876955dd2304be646..1c3665dcdd32bd993f68a7ca495900fd17e64136 100644 (file)
@@ -316,6 +316,11 @@ virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSE
 
     virStorageBackendFileSystemNetFindNFSPoolSources(&state);
 
+    if (virStorageBackendFindGlusterPoolSources(state.host,
+                                                VIR_STORAGE_POOL_NETFS_GLUSTERFS,
+                                                &state.list) < 0)
+        goto cleanup;
+
     if (!(ret = virStoragePoolSourceListFormat(&state.list)))
         goto cleanup;