From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57226) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bom1o-0004G3-DP for qemu-devel@nongnu.org; Tue, 27 Sep 2016 02:38:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bom1n-0003Yh-FL for qemu-devel@nongnu.org; Tue, 27 Sep 2016 02:38:08 -0400 From: Fam Zheng Date: Tue, 27 Sep 2016 14:37:52 +0800 Message-Id: <1474958276-7715-2-git-send-email-famz@redhat.com> In-Reply-To: <1474958276-7715-1-git-send-email-famz@redhat.com> References: <1474958276-7715-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH v2 1/5] blockdev-mirror: Sanity check before moving target_bs AioContext List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Kevin Wolf , qemu-stable@nongnu.org, Max Reitz , stefanha@redhat.com, pbonzini@redhat.com Similar to blockdev-backup, if the target was already moved to a different AioContext, bad things can happen. This happens when the target belongs to a data plane device. It's a very unlikely case, but let's check it anyway. Signed-off-by: Fam Zheng --- blockdev.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/blockdev.c b/blockdev.c index 29c6561..a4960b9 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3281,6 +3281,21 @@ BlockDeviceInfoList *qmp_query_named_block_nodes(Error **errp) return bdrv_named_nodes_list(errp); } +static void blockdev_set_aio_context(BlockDriverState *bs, AioContext *ctx, + Error **errp) +{ + if (bdrv_get_aio_context(bs) != ctx) { + if (!bdrv_has_blk(bs)) { + /* The target BDS is not attached, we can safely move it to another + * AioContext. */ + bdrv_set_aio_context(bs, ctx); + } else { + error_setg(errp, "Target is attached to a different thread from " + "source."); + } + } +} + void do_blockdev_backup(BlockdevBackup *backup, BlockJobTxn *txn, Error **errp) { BlockDriverState *bs; @@ -3317,16 +3332,10 @@ void do_blockdev_backup(BlockdevBackup *backup, BlockJobTxn *txn, Error **errp) goto out; } - if (bdrv_get_aio_context(target_bs) != aio_context) { - if (!bdrv_has_blk(target_bs)) { - /* The target BDS is not attached, we can safely move it to another - * AioContext. */ - bdrv_set_aio_context(target_bs, aio_context); - } else { - error_setg(errp, "Target is attached to a different thread from " - "source."); - goto out; - } + blockdev_set_aio_context(target_bs, aio_context, &local_err); + if (local_err) { + error_propagate(errp, local_err); + goto out; } backup_start(backup->job_id, bs, target_bs, backup->speed, backup->sync, NULL, backup->compress, backup->on_source_error, @@ -3538,7 +3547,11 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) goto out; } - bdrv_set_aio_context(target_bs, aio_context); + blockdev_set_aio_context(target_bs, aio_context, &local_err); + if (local_err) { + error_propagate(errp, local_err); + goto out; + } blockdev_mirror_common(arg->has_job_id ? arg->job_id : NULL, bs, target_bs, arg->has_replaces, arg->replaces, arg->sync, -- 2.7.4