Blame SOURCES/kvm-block-don-t-keep-AioContext-acquired-after-blockdev_.patch

4a2fec
From 0caba353a8208065904c8a1c80da8f0a8163bc76 Mon Sep 17 00:00:00 2001
4a2fec
From: Stefan Hajnoczi <stefanha@redhat.com>
4a2fec
Date: Fri, 22 Dec 2017 11:08:52 +0100
4a2fec
Subject: [PATCH 34/42] block: don't keep AioContext acquired after
4a2fec
 blockdev_backup_prepare()
4a2fec
4a2fec
RH-Author: Stefan Hajnoczi <stefanha@redhat.com>
4a2fec
Message-id: <20171222110900.24813-13-stefanha@redhat.com>
4a2fec
Patchwork-id: 78497
4a2fec
O-Subject: [RHV7.5 qemu-kvm-rhev PATCH 12/20] block: don't keep AioContext acquired after blockdev_backup_prepare()
4a2fec
Bugzilla: 1519721
4a2fec
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
4a2fec
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
4a2fec
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
4a2fec
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
4a2fec
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
4a2fec
Reviewed-by: Eric Blake <eblake@redhat.com>
4a2fec
Message-id: 20171206144550.22295-5-stefanha@redhat.com
4a2fec
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
4a2fec
(cherry picked from commit edd5adeecddf665e7954bc146ff458bb30f178ae)
4a2fec
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 blockdev.c | 44 ++++++++++++++++++++++++++++++++++----------
4a2fec
 1 file changed, 34 insertions(+), 10 deletions(-)
4a2fec
4a2fec
diff --git a/blockdev.c b/blockdev.c
4a2fec
index c962b8a..6efae53 100644
4a2fec
--- a/blockdev.c
4a2fec
+++ b/blockdev.c
4a2fec
@@ -1979,7 +1979,6 @@ typedef struct BlockdevBackupState {
4a2fec
     BlkActionState common;
4a2fec
     BlockDriverState *bs;
4a2fec
     BlockJob *job;
4a2fec
-    AioContext *aio_context;
4a2fec
 } BlockdevBackupState;
4a2fec
 
4a2fec
 static BlockJob *do_blockdev_backup(BlockdevBackup *backup, BlockJobTxn *txn,
4a2fec
@@ -1990,6 +1989,7 @@ static void blockdev_backup_prepare(BlkActionState *common, Error **errp)
4a2fec
     BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, common);
4a2fec
     BlockdevBackup *backup;
4a2fec
     BlockDriverState *bs, *target;
4a2fec
+    AioContext *aio_context;
4a2fec
     Error *local_err = NULL;
4a2fec
 
4a2fec
     assert(common->action->type == TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP);
4a2fec
@@ -2005,29 +2005,39 @@ static void blockdev_backup_prepare(BlkActionState *common, Error **errp)
4a2fec
         return;
4a2fec
     }
4a2fec
 
4a2fec
-    /* AioContext is released in .clean() */
4a2fec
-    state->aio_context = bdrv_get_aio_context(bs);
4a2fec
-    if (state->aio_context != bdrv_get_aio_context(target)) {
4a2fec
-        state->aio_context = NULL;
4a2fec
+    aio_context = bdrv_get_aio_context(bs);
4a2fec
+    if (aio_context != bdrv_get_aio_context(target)) {
4a2fec
         error_setg(errp, "Backup between two IO threads is not implemented");
4a2fec
         return;
4a2fec
     }
4a2fec
-    aio_context_acquire(state->aio_context);
4a2fec
+    aio_context_acquire(aio_context);
4a2fec
     state->bs = bs;
4a2fec
+
4a2fec
+    /* Paired with .clean() */
4a2fec
     bdrv_drained_begin(state->bs);
4a2fec
 
4a2fec
     state->job = do_blockdev_backup(backup, common->block_job_txn, &local_err);
4a2fec
     if (local_err) {
4a2fec
         error_propagate(errp, local_err);
4a2fec
-        return;
4a2fec
+        goto out;
4a2fec
     }
4a2fec
+
4a2fec
+out:
4a2fec
+    aio_context_release(aio_context);
4a2fec
 }
4a2fec
 
4a2fec
 static void blockdev_backup_commit(BlkActionState *common)
4a2fec
 {
4a2fec
     BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, common);
4a2fec
+    AioContext *aio_context;
4a2fec
+
4a2fec
+    aio_context = bdrv_get_aio_context(state->bs);
4a2fec
+    aio_context_acquire(aio_context);
4a2fec
+
4a2fec
     assert(state->job);
4a2fec
     block_job_start(state->job);
4a2fec
+
4a2fec
+    aio_context_release(aio_context);
4a2fec
 }
4a2fec
 
4a2fec
 static void blockdev_backup_abort(BlkActionState *common)
4a2fec
@@ -2035,18 +2045,32 @@ static void blockdev_backup_abort(BlkActionState *common)
4a2fec
     BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, common);
4a2fec
 
4a2fec
     if (state->job) {
4a2fec
+        AioContext *aio_context;
4a2fec
+
4a2fec
+        aio_context = bdrv_get_aio_context(state->bs);
4a2fec
+        aio_context_acquire(aio_context);
4a2fec
+
4a2fec
         block_job_cancel_sync(state->job);
4a2fec
+
4a2fec
+        aio_context_release(aio_context);
4a2fec
     }
4a2fec
 }
4a2fec
 
4a2fec
 static void blockdev_backup_clean(BlkActionState *common)
4a2fec
 {
4a2fec
     BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, common);
4a2fec
+    AioContext *aio_context;
4a2fec
 
4a2fec
-    if (state->aio_context) {
4a2fec
-        bdrv_drained_end(state->bs);
4a2fec
-        aio_context_release(state->aio_context);
4a2fec
+    if (!state->bs) {
4a2fec
+        return;
4a2fec
     }
4a2fec
+
4a2fec
+    aio_context = bdrv_get_aio_context(state->bs);
4a2fec
+    aio_context_acquire(aio_context);
4a2fec
+
4a2fec
+    bdrv_drained_end(state->bs);
4a2fec
+
4a2fec
+    aio_context_release(aio_context);
4a2fec
 }
4a2fec
 
4a2fec
 typedef struct BlockDirtyBitmapState {
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec