From patchwork Mon Aug 13 02:19:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 10563843 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 76E831515 for ; Mon, 13 Aug 2018 02:28:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5AD9E28DF2 for ; Mon, 13 Aug 2018 02:28:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E3FB28E3A; Mon, 13 Aug 2018 02:28:18 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 DFF8B28DF2 for ; Mon, 13 Aug 2018 02:28:17 +0000 (UTC) Received: from localhost ([::1]:37203 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fp2ae-0001qD-SN for patchwork-qemu-devel@patchwork.kernel.org; Sun, 12 Aug 2018 22:28:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53094) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fp2T3-0003Qf-Sc 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-0007vY-QE for qemu-devel@nongnu.org; Sun, 12 Aug 2018 22:20:25 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41538 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 1fp2T0-0007nx-72; Sun, 12 Aug 2018 22:20:22 -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 C95D58780F; Mon, 13 Aug 2018 02:20:21 +0000 (UTC) Received: from localhost (ovpn-204-21.brq.redhat.com [10.40.204.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6775C1C67F; Mon, 13 Aug 2018 02:20:21 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 13 Aug 2018 04:19:53 +0200 Message-Id: <20180813022006.7216-5-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.1]); Mon, 13 Aug 2018 02:20:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 13 Aug 2018 02:20:21 +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 04/17] mirror: Remove bytes_handled, part 1 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP By moving the mirror_align_for_copy() call from mirror_co_read() to mirror_perform(), we can drop bytes_handled from MirrorOp. mirror_align_for_copy() takes a uint64_t * for @bytes, so this commit changes mirror_perform()'s @bytes parameter to uint64_t, too; but it still asserts that its value does not exceed UINT_MAX (necessary because it may be assigned to bytes_handled, which is returned and may thus not exceed UINT_MAX). This assertion is removed in a later patch. Signed-off-by: Max Reitz --- block/mirror.c | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 34cb8293b2..3234b8b687 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -91,10 +91,6 @@ struct MirrorOp { int64_t offset; uint64_t bytes; - /* The pointee is set by mirror_co_read(), mirror_co_zero(), and - * mirror_co_discard() before yielding for the first time */ - int64_t *bytes_handled; - bool is_pseudo_op; bool is_active_write; CoQueue waiting_requests; @@ -343,14 +339,7 @@ static void mirror_align_for_copy(MirrorBlockJob *s, 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. - */ +/* Perform a mirror copy operation. */ static void coroutine_fn mirror_co_read(void *opaque) { MirrorOp *op = opaque; @@ -358,7 +347,6 @@ static void coroutine_fn mirror_co_read(void *opaque) 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) { @@ -396,7 +384,6 @@ static void coroutine_fn mirror_co_zero(void *opaque) op->s->in_flight++; op->s->bytes_in_flight += op->bytes; - *op->bytes_handled = op->bytes; ret = blk_co_pwrite_zeroes(op->s->target, op->offset, op->bytes, op->s->unmap ? BDRV_REQ_MAY_UNMAP : 0); @@ -410,25 +397,33 @@ static void coroutine_fn mirror_co_discard(void *opaque) op->s->in_flight++; op->s->bytes_in_flight += op->bytes; - *op->bytes_handled = op->bytes; ret = blk_co_pdiscard(op->s->target, op->offset, op->bytes); mirror_write_complete(op, ret); } static unsigned mirror_perform(MirrorBlockJob *s, int64_t offset, - unsigned bytes, MirrorMethod mirror_method) + uint64_t bytes, MirrorMethod mirror_method) { MirrorOp *op; Coroutine *co; - int64_t bytes_handled = -1; + int64_t bytes_handled; + + /* FIXME: Drop this assertion */ + assert(bytes <= UINT_MAX); + + if (mirror_method == MIRROR_METHOD_COPY) { + mirror_align_for_copy(s, &offset, &bytes, &bytes_handled); + assert(bytes_handled <= UINT_MAX); + } else { + bytes_handled = bytes; + } op = g_new(MirrorOp, 1); *op = (MirrorOp){ .s = s, .offset = offset, .bytes = bytes, - .bytes_handled = &bytes_handled, }; qemu_co_queue_init(&op->waiting_requests); @@ -448,16 +443,7 @@ static unsigned mirror_perform(MirrorBlockJob *s, int64_t offset, QTAILQ_INSERT_TAIL(&s->ops_in_flight, op, next); qemu_coroutine_enter(co); - /* At this point, ownership of op has been moved to the coroutine - * and the object may already be freed */ - - /* Assert that this value has been set */ - assert(bytes_handled >= 0); - /* Same assertion as in mirror_co_read() (and for mirror_co_read() - * and mirror_co_discard(), bytes_handled == op->bytes, which - * is the @bytes parameter given to this function) */ - assert(bytes_handled <= UINT_MAX); return bytes_handled; }