From patchwork Tue Jan 12 00:36:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 566228 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id F3F1E1402A1 for ; Tue, 12 Jan 2016 11:36:49 +1100 (AEDT) Received: from localhost ([::1]:57411 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aImx5-0002Cb-SA for incoming@patchwork.ozlabs.org; Mon, 11 Jan 2016 19:36:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47150) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aImwh-0001R1-Di for qemu-devel@nongnu.org; Mon, 11 Jan 2016 19:36:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aImwg-0000Bd-AL for qemu-devel@nongnu.org; Mon, 11 Jan 2016 19:36:23 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41113) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aImwd-0000AD-4B; Mon, 11 Jan 2016 19:36:19 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id AB4C73B719; Tue, 12 Jan 2016 00:36:18 +0000 (UTC) Received: from scv.usersys.redhat.com (dhcp-17-163.bos.redhat.com [10.18.17.163]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0C0aEEZ030934; Mon, 11 Jan 2016 19:36:17 -0500 From: John Snow To: qemu-block@nongnu.org Date: Mon, 11 Jan 2016 19:36:11 -0500 Message-Id: <1452558972-20316-5-git-send-email-jsnow@redhat.com> In-Reply-To: <1452558972-20316-1-git-send-email-jsnow@redhat.com> References: <1452558972-20316-1-git-send-email-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, jcody@redhat.com, John Snow , armbru@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 4/5] block/backup: Add subclassed notifier X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Instead of relying on peeking at bs->job, we want to explicitly get a reference to the job that was involved in this notifier callback. Extend the Notifier to include a job pointer, and include a reference to the job registering the callback. This cuts out a few more cases where we have to rely on bs->job. Signed-off-by: John Snow Reviewed-by: Kevin Wolf --- block/backup.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/block/backup.c b/block/backup.c index 325e247..58c76be 100644 --- a/block/backup.c +++ b/block/backup.c @@ -89,11 +89,11 @@ static void cow_request_end(CowRequest *req) } static int coroutine_fn backup_do_cow(BlockDriverState *bs, + BackupBlockJob *job, int64_t sector_num, int nb_sectors, bool *error_is_read, bool is_write_notifier) { - BackupBlockJob *job = (BackupBlockJob *)bs->job; CowRequest cow_request; struct iovec iov; QEMUIOVector bounce_qiov; @@ -187,10 +187,17 @@ out: return ret; } +/* Extend the generic Notifier interface */ +typedef struct BackupNotifier { + NotifierWithReturn common; + BackupBlockJob *job; +} BackupNotifier; + static int coroutine_fn backup_before_write_notify( NotifierWithReturn *notifier, void *opaque) { + BackupNotifier *bnotifier = (BackupNotifier *)notifier; BdrvTrackedRequest *req = opaque; int64_t sector_num = req->offset >> BDRV_SECTOR_BITS; int nb_sectors = req->bytes >> BDRV_SECTOR_BITS; @@ -198,7 +205,8 @@ static int coroutine_fn backup_before_write_notify( assert((req->offset & (BDRV_SECTOR_SIZE - 1)) == 0); assert((req->bytes & (BDRV_SECTOR_SIZE - 1)) == 0); - return backup_do_cow(req->bs, sector_num, nb_sectors, NULL, true); + return backup_do_cow(req->bs, bnotifier->job, sector_num, + nb_sectors, NULL, true); } static void backup_set_speed(BlockJob *job, int64_t speed, Error **errp) @@ -346,7 +354,8 @@ static int coroutine_fn backup_run_incremental(BackupBlockJob *job) if (yield_and_check(job)) { return ret; } - ret = backup_do_cow(bs, cluster * BACKUP_SECTORS_PER_CLUSTER, + ret = backup_do_cow(bs, job, + cluster * BACKUP_SECTORS_PER_CLUSTER, BACKUP_SECTORS_PER_CLUSTER, &error_is_read, false); if ((ret < 0) && @@ -382,8 +391,11 @@ static void coroutine_fn backup_run(void *opaque) BlockDriverState *bs = job->common.bs; BlockDriverState *target = job->target; BlockdevOnError on_target_error = job->on_target_error; - NotifierWithReturn before_write = { - .notify = backup_before_write_notify, + BackupNotifier before_write = { + .common = { + .notify = backup_before_write_notify, + }, + .job = job, }; int64_t start, end; int ret = 0; @@ -402,7 +414,8 @@ static void coroutine_fn backup_run(void *opaque) blk_iostatus_enable(target->blk); } - bdrv_add_before_write_notifier(bs, &before_write); + block_job_ref(&job->common); + bdrv_add_before_write_notifier(bs, (NotifierWithReturn *)&before_write); if (job->sync_mode == MIRROR_SYNC_MODE_NONE) { while (!block_job_is_cancelled(&job->common)) { @@ -454,7 +467,7 @@ static void coroutine_fn backup_run(void *opaque) } } /* FULL sync mode we copy the whole drive. */ - ret = backup_do_cow(bs, start * BACKUP_SECTORS_PER_CLUSTER, + ret = backup_do_cow(bs, job, start * BACKUP_SECTORS_PER_CLUSTER, BACKUP_SECTORS_PER_CLUSTER, &error_is_read, false); if (ret < 0) { /* Depending on error action, fail now or retry cluster */ @@ -470,7 +483,8 @@ static void coroutine_fn backup_run(void *opaque) } } - notifier_with_return_remove(&before_write); + notifier_with_return_remove((NotifierWithReturn *)&before_write); + block_job_unref(&job->common); /* wait until pending backup_do_cow() calls have completed */ qemu_co_rwlock_wrlock(&job->flush_rwlock);