diff mbox

[RFC,04/12] blockdev: Lock BDS during external snapshot transaction

Message ID 1432896805-23867-5-git-send-email-famz@redhat.com
State New
Headers show

Commit Message

Fam Zheng May 29, 2015, 10:53 a.m. UTC
Lock immediately follows aio_context_acquire, so unlock right before
the corresponding aio_context_release.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 blockdev.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox

Patch

diff --git a/blockdev.c b/blockdev.c
index 46f8d60..1c3946a 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1473,6 +1473,7 @@  static void external_snapshot_prepare(BlkTransactionState *common,
     /* Acquire AioContext now so any threads operating on old_bs stop */
     state->aio_context = bdrv_get_aio_context(state->old_bs);
     aio_context_acquire(state->aio_context);
+    bdrv_lock(state->old_bs);
 
     if (!bdrv_is_inserted(state->old_bs)) {
         error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
@@ -1542,6 +1543,7 @@  static void external_snapshot_commit(BlkTransactionState *common)
     bdrv_reopen(state->new_bs, state->new_bs->open_flags & ~BDRV_O_RDWR,
                 NULL);
 
+    bdrv_unlock(state->old_bs);
     aio_context_release(state->aio_context);
 }
 
@@ -1553,6 +1555,7 @@  static void external_snapshot_abort(BlkTransactionState *common)
         bdrv_unref(state->new_bs);
     }
     if (state->aio_context) {
+        bdrv_unlock(state->old_bs);
         aio_context_release(state->aio_context);
     }
 }