If pool refresh failed, then the internal table of volumes is
probably left in inconsistent or incomplete state anyways. Clear
it out then. This has an advantage that we can move the
virStoragePoolObjClearVols() from those very few backends that
do call it.

Signed-off-by: Michal Privoznik <mpriv...@redhat.com>
---
 src/storage/storage_backend_gluster.c |  2 --
 src/storage/storage_backend_logical.c | 12 +++---------
 src/storage/storage_backend_rbd.c     |  4 +---
 src/storage/storage_driver.c          |  2 ++
 src/storage/storage_util.c            |  2 --
 5 files changed, 6 insertions(+), 16 deletions(-)

diff --git a/src/storage/storage_backend_gluster.c 
b/src/storage/storage_backend_gluster.c
index 819993439a..5955d834d9 100644
--- a/src/storage/storage_backend_gluster.c
+++ b/src/storage/storage_backend_gluster.c
@@ -402,8 +402,6 @@ virStorageBackendGlusterRefreshPool(virStoragePoolObjPtr 
pool)
     if (dir)
         glfs_closedir(dir);
     virStorageBackendGlusterClose(state);
-    if (ret < 0)
-        virStoragePoolObjClearVols(pool);
     return ret;
 }
 
diff --git a/src/storage/storage_backend_logical.c 
b/src/storage/storage_backend_logical.c
index 77e4dfb8b1..83b5f27151 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -760,14 +760,13 @@ virStorageBackendLogicalRefreshPool(virStoragePoolObjPtr 
pool)
         2
     };
     virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
-    int ret = -1;
     VIR_AUTOPTR(virCommand) cmd = NULL;
 
     virWaitForDevices();
 
     /* Get list of all logical volumes */
     if (virStorageBackendLogicalFindLVs(pool, NULL) < 0)
-        goto cleanup;
+        return -1;
 
     cmd = virCommandNewArgList(VGS,
                                "--separator", ":",
@@ -788,14 +787,9 @@ virStorageBackendLogicalRefreshPool(virStoragePoolObjPtr 
pool)
                            pool,
                            "vgs",
                            NULL) < 0)
-        goto cleanup;
+        return -1;
 
-    ret = 0;
-
- cleanup:
-    if (ret < 0)
-        virStoragePoolObjClearVols(pool);
-    return ret;
+    return 0;
 }
 
 /*
diff --git a/src/storage/storage_backend_rbd.c 
b/src/storage/storage_backend_rbd.c
index 2b7af1db23..3eae780c44 100644
--- a/src/storage/storage_backend_rbd.c
+++ b/src/storage/storage_backend_rbd.c
@@ -648,10 +648,8 @@ virStorageBackendRBDRefreshPool(virStoragePoolObjPtr pool)
             goto cleanup;
         }
 
-        if (virStoragePoolObjAddVol(pool, vol) < 0) {
-            virStoragePoolObjClearVols(pool);
+        if (virStoragePoolObjAddVol(pool, vol) < 0)
             goto cleanup;
-        }
         vol = NULL;
     }
 
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 8cb3c40e51..fee1220b53 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -81,6 +81,8 @@ storagePoolRefreshFailCleanup(virStorageBackendPtr backend,
 {
     virErrorPtr orig_err = virSaveLastError();
 
+    virStoragePoolObjClearVols(obj);
+
     if (stateFile)
         unlink(stateFile);
     if (backend->stopPool)
diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
index 7a879b0f46..62f857f9ea 100644
--- a/src/storage/storage_util.c
+++ b/src/storage/storage_util.c
@@ -3620,8 +3620,6 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr pool)
     ret = 0;
  cleanup:
     VIR_DIR_CLOSE(dir);
-    if (ret < 0)
-        virStoragePoolObjClearVols(pool);
     return ret;
 }
 
-- 
2.19.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to