From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33190) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCstv-00017H-T5 for qemu-devel@nongnu.org; Tue, 14 Jun 2016 14:17:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bCstt-0002lW-El for qemu-devel@nongnu.org; Tue, 14 Jun 2016 14:17:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32854) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCstt-0002lR-8q for qemu-devel@nongnu.org; Tue, 14 Jun 2016 14:17:21 -0400 From: Stefan Hajnoczi Date: Tue, 14 Jun 2016 19:17:08 +0100 Message-Id: <1465928228-1184-6-git-send-email-stefanha@redhat.com> In-Reply-To: <1465928228-1184-1-git-send-email-stefanha@redhat.com> References: <1465928228-1184-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PATCH v4 5/5] backup: follow AioContext change gracefully List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , jjherne@linux.vnet.ibm.com, Fam Zheng , Paolo Bonzini , Jeff Cody , mreitz@redhat.com, Stefan Hajnoczi 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); -- 2.5.5