[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH] storage: Don't hold storage pool locked during wipeVol



Currently the way virStorageVolWipe() works is it looks up
pool containing given volume and hold it locked throughout while
API execution. This is suboptimal because wiping a volume means
writing data to it which can take ages. And if the whole pool is
locked during that operation no other API can be issued (nor
pool-list).

Signed-off-by: Michal Privoznik <mprivozn redhat com>
---
 src/storage/storage_backend_iscsi_direct.c | 5 +++++
 src/storage/storage_backend_rbd.c          | 7 ++++++-
 src/storage/storage_util.c                 | 8 +++++++-
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/storage_backend_iscsi_direct.c
index 1624066e9c..58d25557f1 100644
--- a/src/storage/storage_backend_iscsi_direct.c
+++ b/src/storage/storage_backend_iscsi_direct.c
@@ -691,6 +691,9 @@ virStorageBackenISCSIDirectWipeVol(virStoragePoolObjPtr pool,
     if (!(iscsi = virStorageBackendISCSIDirectSetConnection(pool, NULL)))
         return -1;
 
+    vol->in_use++;
+    virObjectUnlock(pool);
+
     switch ((virStorageVolWipeAlgorithm) algorithm) {
     case VIR_STORAGE_VOL_WIPE_ALG_ZERO:
         if (virStorageBackendISCSIDirectVolWipeZero(vol, iscsi) < 0) {
@@ -719,6 +722,8 @@ virStorageBackenISCSIDirectWipeVol(virStoragePoolObjPtr pool,
  cleanup:
     virISCSIDirectDisconnect(iscsi);
     iscsi_destroy_context(iscsi);
+    virObjectLock(pool);
+    vol->in_use--;
     return ret;
 }
 
diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c
index 642cacb673..30c94c109b 100644
--- a/src/storage/storage_backend_rbd.c
+++ b/src/storage/storage_backend_rbd.c
@@ -1212,7 +1212,10 @@ virStorageBackendRBDVolWipe(virStoragePoolObjPtr pool,
     VIR_DEBUG("Wiping RBD image %s/%s", def->source.name, vol->name);
 
     if (!(ptr = virStorageBackendRBDNewState(pool)))
-        goto cleanup;
+        return -1;
+
+    vol->in_use++;
+    virObjectUnlock(pool);
 
     if ((r = rbd_open(ptr->ioctx, vol->name, &image, NULL)) < 0) {
         virReportSystemError(-r, _("failed to open the RBD image %s"),
@@ -1271,6 +1274,8 @@ virStorageBackendRBDVolWipe(virStoragePoolObjPtr pool,
         rbd_close(image);
 
     virStorageBackendRBDFreeState(&ptr);
+    virObjectLock(pool);
+    vol->in_use--;
 
     return ret;
 }
diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
index 42a9b6abf0..5c1fb7b7d3 100644
--- a/src/storage/storage_util.c
+++ b/src/storage/storage_util.c
@@ -2750,7 +2750,7 @@ storageBackendVolWipePloop(virStorageVolDefPtr vol,
 
 
 int
-virStorageBackendVolWipeLocal(virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
+virStorageBackendVolWipeLocal(virStoragePoolObjPtr pool,
                               virStorageVolDefPtr vol,
                               unsigned int algorithm,
                               unsigned int flags)
@@ -2759,6 +2759,9 @@ virStorageBackendVolWipeLocal(virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
 
     virCheckFlags(0, -1);
 
+    vol->in_use++;
+    virObjectUnlock(pool);
+
     VIR_DEBUG("Wiping volume with path '%s' and algorithm %u",
               vol->target.path, algorithm);
 
@@ -2769,6 +2772,9 @@ virStorageBackendVolWipeLocal(virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
                                              vol->target.allocation, false);
     }
 
+    virObjectLock(pool);
+    vol->in_use--;
+
     return ret;
 }
 
-- 
2.16.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]