Blame SOURCES/kvm-blockdev-honor-bdrv_try_set_aio_context-context-requ.patch

22c213
From da4ee4c0d56200042cb86f8ccd2777009bd82df3 Mon Sep 17 00:00:00 2001
22c213
From: Sergio Lopez Pascual <slp@redhat.com>
22c213
Date: Fri, 7 Feb 2020 11:27:44 +0000
22c213
Subject: [PATCH 11/18] blockdev: honor bdrv_try_set_aio_context() context
22c213
 requirements
22c213
22c213
RH-Author: Sergio Lopez Pascual <slp@redhat.com>
22c213
Message-id: <20200207112749.25073-5-slp@redhat.com>
22c213
Patchwork-id: 93758
22c213
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH v2 4/9] blockdev: honor bdrv_try_set_aio_context() context requirements
22c213
Bugzilla: 1745606 1746217 1773517 1779036 1782111 1782175 1783965
22c213
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
22c213
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
22c213
RH-Acked-by: Max Reitz <mreitz@redhat.com>
22c213
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
22c213
22c213
bdrv_try_set_aio_context() requires that the old context is held, and
22c213
the new context is not held. Fix all the occurrences where it's not
22c213
done this way.
22c213
22c213
Suggested-by: Max Reitz <mreitz@redhat.com>
22c213
Signed-off-by: Sergio Lopez <slp@redhat.com>
22c213
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
22c213
(cherry picked from commit 3ea67e08832775a28d0bd2795f01bc77e7ea1512)
22c213
Signed-off-by: Sergio Lopez <slp@redhat.com>
22c213
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
22c213
---
22c213
 blockdev.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
22c213
 1 file changed, 60 insertions(+), 8 deletions(-)
22c213
22c213
diff --git a/blockdev.c b/blockdev.c
22c213
index 152a0f7..1dacbc2 100644
22c213
--- a/blockdev.c
22c213
+++ b/blockdev.c
22c213
@@ -1535,6 +1535,7 @@ static void external_snapshot_prepare(BlkActionState *common,
22c213
                              DO_UPCAST(ExternalSnapshotState, common, common);
22c213
     TransactionAction *action = common->action;
22c213
     AioContext *aio_context;
22c213
+    AioContext *old_context;
22c213
     int ret;
22c213
 
22c213
     /* 'blockdev-snapshot' and 'blockdev-snapshot-sync' have similar
22c213
@@ -1675,7 +1676,16 @@ static void external_snapshot_prepare(BlkActionState *common,
22c213
         goto out;
22c213
     }
22c213
 
22c213
+    /* Honor bdrv_try_set_aio_context() context acquisition requirements. */
22c213
+    old_context = bdrv_get_aio_context(state->new_bs);
22c213
+    aio_context_release(aio_context);
22c213
+    aio_context_acquire(old_context);
22c213
+
22c213
     ret = bdrv_try_set_aio_context(state->new_bs, aio_context, errp);
22c213
+
22c213
+    aio_context_release(old_context);
22c213
+    aio_context_acquire(aio_context);
22c213
+
22c213
     if (ret < 0) {
22c213
         goto out;
22c213
     }
22c213
@@ -1775,11 +1785,13 @@ static void drive_backup_prepare(BlkActionState *common, Error **errp)
22c213
     BlockDriverState *target_bs;
22c213
     BlockDriverState *source = NULL;
22c213
     AioContext *aio_context;
22c213
+    AioContext *old_context;
22c213
     QDict *options;
22c213
     Error *local_err = NULL;
22c213
     int flags;
22c213
     int64_t size;
22c213
     bool set_backing_hd = false;
22c213
+    int ret;
22c213
 
22c213
     assert(common->action->type == TRANSACTION_ACTION_KIND_DRIVE_BACKUP);
22c213
     backup = common->action->u.drive_backup.data;
22c213
@@ -1868,6 +1880,21 @@ static void drive_backup_prepare(BlkActionState *common, Error **errp)
22c213
         goto out;
22c213
     }
22c213
 
22c213
+    /* Honor bdrv_try_set_aio_context() context acquisition requirements. */
22c213
+    old_context = bdrv_get_aio_context(target_bs);
22c213
+    aio_context_release(aio_context);
22c213
+    aio_context_acquire(old_context);
22c213
+
22c213
+    ret = bdrv_try_set_aio_context(target_bs, aio_context, errp);
22c213
+    if (ret < 0) {
22c213
+        bdrv_unref(target_bs);
22c213
+        aio_context_release(old_context);
22c213
+        return;
22c213
+    }
22c213
+
22c213
+    aio_context_release(old_context);
22c213
+    aio_context_acquire(aio_context);
22c213
+
22c213
     if (set_backing_hd) {
22c213
         bdrv_set_backing_hd(target_bs, source, &local_err);
22c213
         if (local_err) {
22c213
@@ -1947,6 +1974,8 @@ static void blockdev_backup_prepare(BlkActionState *common, Error **errp)
22c213
     BlockDriverState *bs;
22c213
     BlockDriverState *target_bs;
22c213
     AioContext *aio_context;
22c213
+    AioContext *old_context;
22c213
+    int ret;
22c213
 
22c213
     assert(common->action->type == TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP);
22c213
     backup = common->action->u.blockdev_backup.data;
22c213
@@ -1961,7 +1990,18 @@ static void blockdev_backup_prepare(BlkActionState *common, Error **errp)
22c213
         return;
22c213
     }
22c213
 
22c213
+    /* Honor bdrv_try_set_aio_context() context acquisition requirements. */
22c213
     aio_context = bdrv_get_aio_context(bs);
22c213
+    old_context = bdrv_get_aio_context(target_bs);
22c213
+    aio_context_acquire(old_context);
22c213
+
22c213
+    ret = bdrv_try_set_aio_context(target_bs, aio_context, errp);
22c213
+    if (ret < 0) {
22c213
+        aio_context_release(old_context);
22c213
+        return;
22c213
+    }
22c213
+
22c213
+    aio_context_release(old_context);
22c213
     aio_context_acquire(aio_context);
22c213
     state->bs = bs;
22c213
 
22c213
@@ -3562,7 +3602,6 @@ static BlockJob *do_backup_common(BackupCommon *backup,
22c213
     BlockJob *job = NULL;
22c213
     BdrvDirtyBitmap *bmap = NULL;
22c213
     int job_flags = JOB_DEFAULT;
22c213
-    int ret;
22c213
 
22c213
     if (!backup->has_speed) {
22c213
         backup->speed = 0;
22c213
@@ -3586,11 +3625,6 @@ static BlockJob *do_backup_common(BackupCommon *backup,
22c213
         backup->compress = false;
22c213
     }
22c213
 
22c213
-    ret = bdrv_try_set_aio_context(target_bs, aio_context, errp);
22c213
-    if (ret < 0) {
22c213
-        return NULL;
22c213
-    }
22c213
-
22c213
     if ((backup->sync == MIRROR_SYNC_MODE_BITMAP) ||
22c213
         (backup->sync == MIRROR_SYNC_MODE_INCREMENTAL)) {
22c213
         /* done before desugaring 'incremental' to print the right message */
22c213
@@ -3825,6 +3859,7 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp)
22c213
     BlockDriverState *bs;
22c213
     BlockDriverState *source, *target_bs;
22c213
     AioContext *aio_context;
22c213
+    AioContext *old_context;
22c213
     BlockMirrorBackingMode backing_mode;
22c213
     Error *local_err = NULL;
22c213
     QDict *options = NULL;
22c213
@@ -3937,12 +3972,22 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp)
22c213
                    (arg->mode == NEW_IMAGE_MODE_EXISTING ||
22c213
                     !bdrv_has_zero_init(target_bs)));
22c213
 
22c213
+
22c213
+    /* Honor bdrv_try_set_aio_context() context acquisition requirements. */
22c213
+    old_context = bdrv_get_aio_context(target_bs);
22c213
+    aio_context_release(aio_context);
22c213
+    aio_context_acquire(old_context);
22c213
+
22c213
     ret = bdrv_try_set_aio_context(target_bs, aio_context, errp);
22c213
     if (ret < 0) {
22c213
         bdrv_unref(target_bs);
22c213
-        goto out;
22c213
+        aio_context_release(old_context);
22c213
+        return;
22c213
     }
22c213
 
22c213
+    aio_context_release(old_context);
22c213
+    aio_context_acquire(aio_context);
22c213
+
22c213
     blockdev_mirror_common(arg->has_job_id ? arg->job_id : NULL, bs, target_bs,
22c213
                            arg->has_replaces, arg->replaces, arg->sync,
22c213
                            backing_mode, zero_target,
22c213
@@ -3984,6 +4029,7 @@ void qmp_blockdev_mirror(bool has_job_id, const char *job_id,
22c213
     BlockDriverState *bs;
22c213
     BlockDriverState *target_bs;
22c213
     AioContext *aio_context;
22c213
+    AioContext *old_context;
22c213
     BlockMirrorBackingMode backing_mode = MIRROR_LEAVE_BACKING_CHAIN;
22c213
     Error *local_err = NULL;
22c213
     bool zero_target;
22c213
@@ -4001,10 +4047,16 @@ void qmp_blockdev_mirror(bool has_job_id, const char *job_id,
22c213
 
22c213
     zero_target = (sync == MIRROR_SYNC_MODE_FULL);
22c213
 
22c213
+    /* Honor bdrv_try_set_aio_context() context acquisition requirements. */
22c213
+    old_context = bdrv_get_aio_context(target_bs);
22c213
     aio_context = bdrv_get_aio_context(bs);
22c213
-    aio_context_acquire(aio_context);
22c213
+    aio_context_acquire(old_context);
22c213
 
22c213
     ret = bdrv_try_set_aio_context(target_bs, aio_context, errp);
22c213
+
22c213
+    aio_context_release(old_context);
22c213
+    aio_context_acquire(aio_context);
22c213
+
22c213
     if (ret < 0) {
22c213
         goto out;
22c213
     }
22c213
-- 
22c213
1.8.3.1
22c213