From patchwork Mon Aug 13 02:19:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 956768 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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 41pfcD1xFRz9ryt for ; Mon, 13 Aug 2018 12:21:32 +1000 (AEST) Received: from localhost ([::1]:37160 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fp2U5-0003cn-Qv for incoming@patchwork.ozlabs.org; Sun, 12 Aug 2018 22:21:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53092) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fp2T3-0003QN-L0 for qemu-devel@nongnu.org; Sun, 12 Aug 2018 22:20:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fp2T2-0007uO-DK for qemu-devel@nongnu.org; Sun, 12 Aug 2018 22:20:25 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57578 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fp2Sy-0007kD-3n; Sun, 12 Aug 2018 22:20:20 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B21A97C6A9; Mon, 13 Aug 2018 02:20:19 +0000 (UTC) Received: from localhost (ovpn-204-21.brq.redhat.com [10.40.204.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8EDE51C67F; Mon, 13 Aug 2018 02:20:17 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 13 Aug 2018 04:19:52 +0200 Message-Id: <20180813022006.7216-4-mreitz@redhat.com> In-Reply-To: <20180813022006.7216-1-mreitz@redhat.com> References: <20180813022006.7216-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 13 Aug 2018 02:20:19 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 13 Aug 2018 02:20:19 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 03/17] mirror: Pull *_align_for_copy() from *_co_read() 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 , Jeff Cody , Fam Zheng , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Max Reitz Reviewed-by: Jeff Cody --- block/mirror.c | 54 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index c28b6159d5..34cb8293b2 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -305,42 +305,60 @@ static inline void coroutine_fn mirror_co_wait_for_any_operation(s, false); } -/* Perform a mirror copy operation. +/* + * Restrict *bytes to how much we can actually handle, and align the + * [*offset, *bytes] range to clusters if COW is needed. * - * *op->bytes_handled is set to the number of bytes copied after and + * *bytes_handled is set to the number of bytes copied after and * including offset, excluding any bytes copied prior to offset due - * to alignment. This will be op->bytes if no alignment is necessary, - * or (new_end - op->offset) if the tail is rounded up or down due to + * to alignment. This will be *bytes if no alignment is necessary, or + * (new_end - *offset) if the tail is rounded up or down due to * alignment or buffer limit. */ -static void coroutine_fn mirror_co_read(void *opaque) +static void mirror_align_for_copy(MirrorBlockJob *s, + int64_t *offset, uint64_t *bytes, + int64_t *bytes_handled) { - MirrorOp *op = opaque; - MirrorBlockJob *s = op->s; - int nb_chunks; - uint64_t ret; uint64_t max_bytes; max_bytes = s->granularity * s->max_iov; /* We can only handle as much as buf_size at a time. */ - op->bytes = MIN(s->buf_size, MIN(max_bytes, op->bytes)); - assert(op->bytes); - assert(op->bytes < BDRV_REQUEST_MAX_BYTES); - *op->bytes_handled = op->bytes; + *bytes = MIN(s->buf_size, MIN(max_bytes, *bytes)); + assert(*bytes); + assert(*bytes < BDRV_REQUEST_MAX_BYTES); + *bytes_handled = *bytes; if (s->cow_bitmap) { - *op->bytes_handled += mirror_cow_align(s, &op->offset, &op->bytes); + *bytes_handled += mirror_cow_align(s, offset, bytes); } /* Cannot exceed BDRV_REQUEST_MAX_BYTES + INT_MAX */ - assert(*op->bytes_handled <= UINT_MAX); - assert(op->bytes <= s->buf_size); + assert(*bytes_handled <= UINT_MAX); + assert(*bytes <= s->buf_size); /* The offset is granularity-aligned because: * 1) Caller passes in aligned values; * 2) mirror_cow_align is used only when target cluster is larger. */ - assert(QEMU_IS_ALIGNED(op->offset, s->granularity)); + assert(QEMU_IS_ALIGNED(*offset, s->granularity)); /* The range is sector-aligned, since bdrv_getlength() rounds up. */ - assert(QEMU_IS_ALIGNED(op->bytes, BDRV_SECTOR_SIZE)); + assert(QEMU_IS_ALIGNED(*bytes, BDRV_SECTOR_SIZE)); +} + +/* Perform a mirror copy operation. + * + * *op->bytes_handled is set to the number of bytes copied after and + * including offset, excluding any bytes copied prior to offset due + * to alignment. This will be op->bytes if no alignment is necessary, + * or (new_end - op->offset) if the tail is rounded up or down due to + * alignment or buffer limit. + */ +static void coroutine_fn mirror_co_read(void *opaque) +{ + MirrorOp *op = opaque; + MirrorBlockJob *s = op->s; + int nb_chunks; + uint64_t ret; + + mirror_align_for_copy(s, &op->offset, &op->bytes, op->bytes_handled); nb_chunks = DIV_ROUND_UP(op->bytes, s->granularity); while (s->buf_free_count < nb_chunks) {