From ca0ab9cdd2734ad96797c1fd2560693a9e792bdf Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Sun, 19 Aug 2018 08:26:04 +0200 Subject: [PATCH] storage_driver: Release pool object lock for some long running jobs As advertised in previous commit, there are three APIs that might run for quite some time (because they read/write data from/to a volume) and these three are: downloadVol, uploadVol, wipeVol. Release pool object lock and reacquire it later to allow more concurrency. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/storage/storage_backend.h | 12 ++++++++++++ src/storage/storage_backend_iscsi_direct.c | 6 +++++- src/storage/storage_backend_rbd.c | 8 ++++++-- src/storage/storage_driver.c | 6 ++++++ 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/storage/storage_backend.h b/src/storage/storage_backend.h index 5587f84407..6e74f85523 100644 --- a/src/storage/storage_backend.h +++ b/src/storage/storage_backend.h @@ -64,18 +64,30 @@ typedef int (*virStorageBackendVolumeResize)(virStoragePoolObjPtr pool, virStorageVolDefPtr vol, unsigned long long capacity, unsigned int flags); + +/* Upon entering this callback passed @obj is unlocked. However, + * the pool's asyncjobs counter has been incremented and volume's + * in_use has been adjusted to ensure singular usage. */ typedef int (*virStorageBackendVolumeDownload)(virStoragePoolObjPtr obj, virStorageVolDefPtr vol, virStreamPtr stream, unsigned long long offset, unsigned long long length, unsigned int flags); + +/* Upon entering this callback passed @obj is unlocked. However, + * the pool's asyncjobs counter has been incremented and volume's + * in_use has been adjusted to ensure singular usage. */ typedef int (*virStorageBackendVolumeUpload)(virStoragePoolObjPtr obj, virStorageVolDefPtr vol, virStreamPtr stream, unsigned long long offset, unsigned long long len, unsigned int flags); + +/* Upon entering this callback passed @obj is unlocked. However, + * the pool's asyncjobs counter has been incremented and volume's + * in_use has been adjusted to ensure singular usage. */ typedef int (*virStorageBackendVolumeWipe)(virStoragePoolObjPtr pool, virStorageVolDefPtr vol, unsigned int algorithm, diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/storage_backend_iscsi_direct.c index 0d7d6ba9c3..5c1b251a17 100644 --- a/src/storage/storage_backend_iscsi_direct.c +++ b/src/storage/storage_backend_iscsi_direct.c @@ -693,7 +693,11 @@ virStorageBackenISCSIDirectWipeVol(virStoragePoolObjPtr pool, virCheckFlags(0, -1); - if (!(iscsi = virStorageBackendISCSIDirectSetConnection(pool, NULL))) + virObjectLock(pool); + iscsi = virStorageBackendISCSIDirectSetConnection(pool, NULL); + virObjectUnlock(pool); + + if (!iscsi) return -1; switch ((virStorageVolWipeAlgorithm) algorithm) { diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c index c6fb791a81..2cba678b72 100644 --- a/src/storage/storage_backend_rbd.c +++ b/src/storage/storage_backend_rbd.c @@ -1200,7 +1200,7 @@ virStorageBackendRBDVolWipe(virStoragePoolObjPtr pool, unsigned int flags) { virStorageBackendRBDStatePtr ptr = NULL; - virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); + virStoragePoolDefPtr def; rbd_image_t image = NULL; rbd_image_info_t info; uint64_t stripe_count; @@ -1209,9 +1209,13 @@ virStorageBackendRBDVolWipe(virStoragePoolObjPtr pool, virCheckFlags(0, -1); + virObjectLock(pool); + def = virStoragePoolObjGetDef(pool); VIR_DEBUG("Wiping RBD image %s/%s", def->source.name, vol->name); + ptr = virStorageBackendRBDNewState(pool); + virObjectUnlock(pool); - if (!(ptr = virStorageBackendRBDNewState(pool))) + if (!ptr) goto cleanup; if ((r = rbd_open(ptr->ioctx, vol->name, &image, NULL)) < 0) { diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 9edd5df119..8943df1f84 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -2178,9 +2178,11 @@ storageVolDownload(virStorageVolPtr vol, virStoragePoolObjIncrAsyncjobs(obj); voldef->in_use++; + virObjectUnlock(obj); ret = backend->downloadVol(obj, voldef, stream, offset, length, flags); + virObjectLock(obj); voldef->in_use--; virStoragePoolObjDecrAsyncjobs(obj); @@ -2378,9 +2380,11 @@ storageVolUpload(virStorageVolPtr vol, virStoragePoolObjIncrAsyncjobs(obj); voldef->in_use++; + virObjectUnlock(obj); rc = backend->uploadVol(obj, voldef, stream, offset, length, flags); + virObjectLock(obj); voldef->in_use--; virStoragePoolObjDecrAsyncjobs(obj); @@ -2554,9 +2558,11 @@ storageVolWipePattern(virStorageVolPtr vol, virStoragePoolObjIncrAsyncjobs(obj); voldef->in_use++; + virObjectUnlock(obj); rc = backend->wipeVol(obj, voldef, algorithm, flags); + virObjectLock(obj); voldef->in_use--; virStoragePoolObjDecrAsyncjobs(obj); -- GitLab