From patchwork Thu Jun 16 16:56:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 9181399 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 12D8A60776 for ; Thu, 16 Jun 2016 17:14:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1A5C26785 for ; Thu, 16 Jun 2016 17:14:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E644228360; Thu, 16 Jun 2016 17:14:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 79F6826785 for ; Thu, 16 Jun 2016 17:14:41 +0000 (UTC) Received: from localhost ([::1]:51109 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDasJ-0003Ag-FA for patchwork-qemu-devel@patchwork.kernel.org; Thu, 16 Jun 2016 13:14:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37757) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDabA-0000ly-Gc for qemu-devel@nongnu.org; Thu, 16 Jun 2016 12:56:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bDab6-00034V-8Y for qemu-devel@nongnu.org; Thu, 16 Jun 2016 12:56:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42274) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDab6-00034R-2f for qemu-devel@nongnu.org; Thu, 16 Jun 2016 12:56:52 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9006BC0D61AE; Thu, 16 Jun 2016 16:56:51 +0000 (UTC) Received: from localhost (ovpn-112-23.ams2.redhat.com [10.36.112.23]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5GGuoNY025186; Thu, 16 Jun 2016 12:56:50 -0400 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Date: Thu, 16 Jun 2016 17:56:29 +0100 Message-Id: <1466096189-6477-9-git-send-email-stefanha@redhat.com> In-Reply-To: <1466096189-6477-1-git-send-email-stefanha@redhat.com> References: <1466096189-6477-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 16 Jun 2016 16:56:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 8/8] backup: follow AioContext change gracefully 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 , Fam Zheng , Stefan Hajnoczi , Jeff Cody , mreitz@redhat.com, jjherne@linux.vnet.ibm.com, Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Move s->target to the new AioContext when there is an AioContext change. The backup_run() coroutine does not use asynchronous I/O so there is no need to wait for in-flight requests in a BlockJobDriver->pause() callback. Guest writes are intercepted by the backup job. Treat them as guest activity and do it even while the job is paused. This is necessary since the only alternative would be to fail a job that experienced guest writes during pause once the job is resumed. In practice the guest writes don't interfere with AioContext switching since bdrv_drain() is used by bdrv_set_aio_context(). Loops already contain pause points because of block_job_sleep_ns() calls in the yield_and_check() helper function. It is necessary to convert a raw qemu_coroutine_yield() to block_job_yield() so the MIRROR_SYNC_MODE_NONE case can pause. Signed-off-by: Stefan Hajnoczi --- block/backup.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/block/backup.c b/block/backup.c index feeb9f8..581269b 100644 --- a/block/backup.c +++ b/block/backup.c @@ -246,12 +246,20 @@ static void backup_abort(BlockJob *job) } } +static void backup_attached_aio_context(BlockJob *job, AioContext *aio_context) +{ + BackupBlockJob *s = container_of(job, BackupBlockJob, common); + + blk_set_aio_context(s->target, aio_context); +} + static const BlockJobDriver backup_job_driver = { - .instance_size = sizeof(BackupBlockJob), - .job_type = BLOCK_JOB_TYPE_BACKUP, - .set_speed = backup_set_speed, - .commit = backup_commit, - .abort = backup_abort, + .instance_size = sizeof(BackupBlockJob), + .job_type = BLOCK_JOB_TYPE_BACKUP, + .set_speed = backup_set_speed, + .commit = backup_commit, + .abort = backup_abort, + .attached_aio_context = backup_attached_aio_context, }; static BlockErrorAction backup_error_action(BackupBlockJob *job, @@ -392,9 +400,7 @@ static void coroutine_fn backup_run(void *opaque) while (!block_job_is_cancelled(&job->common)) { /* Yield until the job is cancelled. We just let our before_write * notify callback service CoW requests. */ - job->common.busy = false; - qemu_coroutine_yield(); - job->common.busy = true; + block_job_yield(&job->common); } } else if (job->sync_mode == MIRROR_SYNC_MODE_INCREMENTAL) { ret = backup_run_incremental(job);