From nobody Mon Feb 9 23:01:42 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490066482967790.6590650710322; Mon, 20 Mar 2017 20:21:22 -0700 (PDT) Received: from localhost ([::1]:36407 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqAML-0003uF-Mc for importer@patchew.org; Mon, 20 Mar 2017 23:21:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40131) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqAJF-0002Dr-NS for qemu-devel@nongnu.org; Mon, 20 Mar 2017 23:18:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cqAJE-0000rQ-NS for qemu-devel@nongnu.org; Mon, 20 Mar 2017 23:18:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58158) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cqAJC-0000p0-Lj; Mon, 20 Mar 2017 23:18:06 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A9CB320264; Tue, 21 Mar 2017 03:18:06 +0000 (UTC) Received: from lemon.redhat.com (ovpn-8-61.pek2.redhat.com [10.72.8.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB7E578DD3; Tue, 21 Mar 2017 03:17:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A9CB320264 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A9CB320264 From: Fam Zheng To: qemu-devel@nongnu.org Date: Tue, 21 Mar 2017 11:16:25 +0800 Message-Id: <20170321031635.22123-7-famz@redhat.com> In-Reply-To: <20170321031635.22123-1-famz@redhat.com> References: <20170321031635.22123-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 21 Mar 2017 03:18:06 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH RFC 06/16] backup: Do initial aio context move of target via BB interface X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Paolo Bonzini , qemu-block@nongnu.org, Stefan Hajnoczi , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The old aio context check is hacky because when it was added we didn't have the permission system to enforce a general rule. It only checks if the target BDS has a BB, which is in fact insufficient because there may be other BBs in the graph that cannot handle the aio context change. Do this through blk_set_aio_context interface, in backup_job_create() as a central place for both drive-backup and blockdev-backup, to take care of the compatibility check. Also the bdrv_set_aio_context in do_drive_backup could have been conditional, to save a recursion when possible. Signed-off-by: Fam Zheng --- block/backup.c | 9 +++++++++ blockdev.c | 14 -------------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/block/backup.c b/block/backup.c index 546c5c5..9136f91 100644 --- a/block/backup.c +++ b/block/backup.c @@ -564,6 +564,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDr= iverState *bs, BlockDriverInfo bdi; BackupBlockJob *job =3D NULL; int ret; + AioContext *aio_context, *target_context; =20 assert(bs); assert(target); @@ -644,6 +645,14 @@ BlockJob *backup_job_create(const char *job_id, BlockD= riverState *bs, goto error; } =20 + aio_context =3D bdrv_get_aio_context(bs); + target_context =3D bdrv_get_aio_context(target); + if (target_context !=3D aio_context) { + aio_context_acquire(target_context); + blk_set_aio_context(job->target, aio_context); + aio_context_release(target_context); + } + job->on_source_error =3D on_source_error; job->on_target_error =3D on_target_error; job->sync_mode =3D sync_mode; diff --git a/blockdev.c b/blockdev.c index c5b2c2c..5d89a9a 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3259,8 +3259,6 @@ static BlockJob *do_drive_backup(DriveBackup *backup,= BlockJobTxn *txn, goto out; } =20 - bdrv_set_aio_context(target_bs, aio_context); - if (backup->has_bitmap) { bmap =3D bdrv_find_dirty_bitmap(bs, backup->bitmap); if (!bmap) { @@ -3337,18 +3335,6 @@ BlockJob *do_blockdev_backup(BlockdevBackup *backup,= BlockJobTxn *txn, if (!target_bs) { goto out; } - - if (bdrv_get_aio_context(target_bs) !=3D aio_context) { - if (!bdrv_has_blk(target_bs)) { - /* The target BDS is not attached, we can safely move it to an= other - * AioContext. */ - bdrv_set_aio_context(target_bs, aio_context); - } else { - error_setg(errp, "Target is attached to a different thread fro= m " - "source."); - goto out; - } - } job =3D backup_job_create(backup->job_id, bs, target_bs, backup->speed, backup->sync, NULL, backup->compress, backup->on_source_error, backup->on_target_err= or, --=20 2.9.3