From patchwork Tue Jan 26 23:54:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 8128331 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7E09CBEEE5 for ; Tue, 26 Jan 2016 23:56:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D0AFA201FA for ; Tue, 26 Jan 2016 23:56:34 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 10FAE201BC for ; Tue, 26 Jan 2016 23:56:34 +0000 (UTC) Received: from localhost ([::1]:47436 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aODTN-00068I-HA for patchwork-qemu-devel@patchwork.kernel.org; Tue, 26 Jan 2016 18:56:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45377) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aODS1-0003Us-IO for qemu-devel@nongnu.org; Tue, 26 Jan 2016 18:55:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aODS0-0001cc-4x for qemu-devel@nongnu.org; Tue, 26 Jan 2016 18:55:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54046) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aODRx-0001bj-Mf; Tue, 26 Jan 2016 18:55:05 -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 4570C8F4E9; Tue, 26 Jan 2016 23:55:05 +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 u0QNt0ns005461; Tue, 26 Jan 2016 18:55:04 -0500 From: John Snow To: qemu-block@nongnu.org Date: Tue, 26 Jan 2016 18:54:58 -0500 Message-Id: <1453852499-25800-5-git-send-email-jsnow@redhat.com> In-Reply-To: <1453852499-25800-1-git-send-email-jsnow@redhat.com> References: <1453852499-25800-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 v2 4/5] block/backup: Pack Notifier within BackupBlockJob 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Pack the Notifier inside of the BackupBlockJob so we can use container_of to get a reference back to the BackupBlockJob object. This cuts out one more case where we rely unnecessarily on bs->job. Suggested-by: Paolo Bonzini Signed-off-by: John Snow Reviewed-by: Fam Zheng --- block/backup.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/block/backup.c b/block/backup.c index ce96b45..735cbe6 100644 --- a/block/backup.c +++ b/block/backup.c @@ -46,6 +46,7 @@ typedef struct BackupBlockJob { CoRwlock flush_rwlock; uint64_t sectors_read; HBitmap *bitmap; + NotifierWithReturn before_write; QLIST_HEAD(, CowRequest) inflight_reqs; } BackupBlockJob; @@ -87,11 +88,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; @@ -189,6 +190,7 @@ static int coroutine_fn backup_before_write_notify( NotifierWithReturn *notifier, void *opaque) { + BackupBlockJob *job = container_of(notifier, BackupBlockJob, before_write); BdrvTrackedRequest *req = opaque; int64_t sector_num = req->offset >> BDRV_SECTOR_BITS; int nb_sectors = req->bytes >> BDRV_SECTOR_BITS; @@ -196,7 +198,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, job, sector_num, + nb_sectors, NULL, true); } static void backup_set_speed(BlockJob *job, int64_t speed, Error **errp) @@ -344,7 +347,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) && @@ -380,9 +384,6 @@ 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, - }; int64_t start, end; int ret = 0; @@ -400,7 +401,8 @@ static void coroutine_fn backup_run(void *opaque) blk_iostatus_enable(target->blk); } - bdrv_add_before_write_notifier(bs, &before_write); + job->before_write.notify = backup_before_write_notify; + bdrv_add_before_write_notifier(bs, &job->before_write); if (job->sync_mode == MIRROR_SYNC_MODE_NONE) { while (!block_job_is_cancelled(&job->common)) { @@ -452,7 +454,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 */ @@ -468,7 +470,7 @@ static void coroutine_fn backup_run(void *opaque) } } - notifier_with_return_remove(&before_write); + notifier_with_return_remove(&job->before_write); /* wait until pending backup_do_cow() calls have completed */ qemu_co_rwlock_wrlock(&job->flush_rwlock);