[libvirt] [PATCH 1/4] storage: Fix error reporting when looking up storage pool sources

Peter Krempa pkrempa at redhat.com
Tue Jan 10 18:44:56 UTC 2017


In commit 4090e15399 we went back from reporting no errors if no storage
pools were found on a given host to reporting a bad error. And only in
cases when gluster was not installed.

Report a less bad error in case there are no volumes. Also report the
error when gluster is installed but no volumes were found, since
virStorageBackendFindGlusterPoolSources would return success in that
case.
---
 src/storage/storage_backend.c    | 19 ++++++++++++-------
 src/storage/storage_backend_fs.c | 20 ++++++++++++++------
 2 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 18433e9c7..6c9706897 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -2549,6 +2549,16 @@ virStorageBackendVolWipeLocal(virConnectPtr conn ATTRIBUTE_UNUSED,


 #ifdef GLUSTER_CLI
+/**
+ * virStorageBackendFindGlusterPoolSources:
+ * @host: host to detect volumes on
+ * @pooltype: src->format is set to this value
+ * @list: list of storage pool sources to be filled
+ *
+ * Looks up gluster volumes on @host and fills them to @list.
+ *
+ * Returns number of volumes on the host on success, or -1 on error.
+ */
 int
 virStorageBackendFindGlusterPoolSources(const char *host,
                                         int pooltype,
@@ -2578,8 +2588,6 @@ virStorageBackendFindGlusterPoolSources(const char *host,
         goto cleanup;

     if (rc != 0) {
-        VIR_INFO("failed to query host '%s' for gluster volumes: %s",
-                 host, outbuf);
         ret = 0;
         goto cleanup;
     }
@@ -2588,11 +2596,8 @@ virStorageBackendFindGlusterPoolSources(const char *host,
                                       &ctxt)))
         goto cleanup;

-    if ((nnodes = virXPathNodeSet("//volumes/volume", ctxt, &nodes)) <= 0) {
-        VIR_INFO("no gluster volumes available on '%s'", host);
-        ret = 0;
+    if ((nnodes = virXPathNodeSet("//volumes/volume", ctxt, &nodes)) < 0)
         goto cleanup;
-    }

     for (i = 0; i < nnodes; i++) {
         ctxt->node = nodes[i];
@@ -2616,7 +2621,7 @@ virStorageBackendFindGlusterPoolSources(const char *host,
         src->format = pooltype;
     }

-    ret = 0;
+    ret = nnodes;

  cleanup:
     VIR_FREE(nodes);
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index f4341f32c..b915fd58b 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -281,7 +281,8 @@ virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSE
     virStoragePoolSourcePtr source = NULL;
     char *ret = NULL;
     size_t i;
-    int retNFS = -1, retGluster = -1;
+    int retNFS = -1;
+    int retGluster = 0;

     virCheckFlags(0, NULL);

@@ -306,14 +307,21 @@ virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSE
     retNFS = virStorageBackendFileSystemNetFindNFSPoolSources(&state);

 # ifdef GLUSTER_CLI
-    retGluster =
-        virStorageBackendFindGlusterPoolSources(state.host,
-                                                VIR_STORAGE_POOL_NETFS_GLUSTERFS,
-                                                &state.list);
+    retGluster = virStorageBackendFindGlusterPoolSources(state.host,
+                                                         VIR_STORAGE_POOL_NETFS_GLUSTERFS,
+                                                         &state.list);
+
+    if (retGluster < 0)
+        goto cleanup;
+
 # endif
     /* If both fail, then we won't return an empty list - return an error */
-    if (retNFS < 0 && retGluster < 0)
+    if (retNFS < 0 && retGluster == 0) {
+        virReportError(VIR_ERR_OPERATION_FAILED,
+                       _("no storage pools were found on host '%s'"),
+                       state.host);
         goto cleanup;
+    }

     if (!(ret = virStoragePoolSourceListFormat(&state.list)))
         goto cleanup;
-- 
2.11.0




More information about the libvir-list mailing list