From nobody Wed Nov 5 10:42:42 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1534127190241998.0514790187559; Sun, 12 Aug 2018 19:26:30 -0700 (PDT) Received: from localhost ([::1]:37190 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fp2Yv-0008TT-5W for importer@patchew.org; Sun, 12 Aug 2018 22:26:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53281) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fp2TK-0003de-FP for qemu-devel@nongnu.org; Sun, 12 Aug 2018 22:20:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fp2TJ-0008Gw-GN for qemu-devel@nongnu.org; Sun, 12 Aug 2018 22:20:42 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40352 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 1fp2TE-0008De-RZ; Sun, 12 Aug 2018 22:20:36 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6DD9240241C5; Mon, 13 Aug 2018 02:20:36 +0000 (UTC) Received: from localhost (ovpn-204-21.brq.redhat.com [10.40.204.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0C73010073A7; Mon, 13 Aug 2018 02:20:35 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 13 Aug 2018 04:19:59 +0200 Message-Id: <20180813022006.7216-11-mreitz@redhat.com> In-Reply-To: <20180813022006.7216-1-mreitz@redhat.com> References: <20180813022006.7216-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 13 Aug 2018 02:20:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 13 Aug 2018 02:20:36 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 10/17] mirror: Create mirror_co_alloc_qiov() 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" By pulling this function out of mirror_co_read(), the latter becomes simpler. This is important so the following patches can make it more complicated again. Signed-off-by: Max Reitz --- block/mirror.c | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 6330269156..2a131d8b99 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -293,6 +293,29 @@ static inline void coroutine_fn mirror_co_wait_for_any_operation(s, false); } =20 +/* Allocate a QEMUIOVector from the mirror buffer pool (s->buf_free) */ +static void coroutine_fn mirror_co_alloc_qiov(MirrorBlockJob *s, + QEMUIOVector *qiov, + int64_t offset, uint64_t byt= es) +{ + int nb_chunks =3D DIV_ROUND_UP(bytes, s->granularity); + + while (s->buf_free_count < nb_chunks) { + trace_mirror_yield_in_flight(s, offset, s->in_flight); + mirror_co_wait_for_free_in_flight_slot(s); + } + + qemu_iovec_init(qiov, nb_chunks); + while (nb_chunks-- > 0) { + MirrorBuffer *buf =3D QSIMPLEQ_FIRST(&s->buf_free); + size_t remaining =3D bytes - qiov->size; + + QSIMPLEQ_REMOVE_HEAD(&s->buf_free, next); + s->buf_free_count--; + qemu_iovec_add(qiov, buf, MIN(s->granularity, remaining)); + } +} + /* * Restrict *bytes to how much we can actually handle, and align the * [*offset, *bytes] range to clusters if COW is needed. @@ -327,28 +350,9 @@ static void coroutine_fn mirror_co_read(void *opaque) { MirrorOp *op =3D opaque; MirrorBlockJob *s =3D op->s; - int nb_chunks; uint64_t ret; =20 - nb_chunks =3D DIV_ROUND_UP(op->bytes, s->granularity); - - while (s->buf_free_count < nb_chunks) { - trace_mirror_yield_in_flight(s, op->offset, s->in_flight); - mirror_co_wait_for_free_in_flight_slot(s); - } - - /* Now make a QEMUIOVector taking enough granularity-sized chunks - * from s->buf_free. - */ - qemu_iovec_init(&op->qiov, nb_chunks); - while (nb_chunks-- > 0) { - MirrorBuffer *buf =3D QSIMPLEQ_FIRST(&s->buf_free); - size_t remaining =3D op->bytes - op->qiov.size; - - QSIMPLEQ_REMOVE_HEAD(&s->buf_free, next); - s->buf_free_count--; - qemu_iovec_add(&op->qiov, buf, MIN(s->granularity, remaining)); - } + mirror_co_alloc_qiov(s, &op->qiov, op->offset, op->bytes); =20 /* Copy the dirty cluster. */ s->in_flight++; --=20 2.17.1