From nobody Wed Nov 5 10:43:14 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 1534127567005104.86208052601114; Sun, 12 Aug 2018 19:32:47 -0700 (PDT) Received: from localhost ([::1]:37227 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fp2ez-0005Zw-G3 for importer@patchew.org; Sun, 12 Aug 2018 22:32:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53377) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fp2TS-0003mk-U6 for qemu-devel@nongnu.org; Sun, 12 Aug 2018 22:20:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fp2TR-0008KT-Lj for qemu-devel@nongnu.org; Sun, 12 Aug 2018 22:20:50 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53892 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 1fp2TM-0008Ic-VS; Sun, 12 Aug 2018 22:20:45 -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 93E7D40216FC; Mon, 13 Aug 2018 02:20:44 +0000 (UTC) Received: from localhost (ovpn-204-21.brq.redhat.com [10.40.204.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0B1011C67F; Mon, 13 Aug 2018 02:20:43 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 13 Aug 2018 04:20:02 +0200 Message-Id: <20180813022006.7216-14-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.5]); Mon, 13 Aug 2018 02:20:44 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 13 Aug 2018 02:20:44 +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 13/17] mirror: Linearize mirror_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+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" This function inlines mirror_read_complete() and mirror_write_complete() into mirror_co_read() (which is thus renamed to mirror_co_copy()). In addition, freeing of the I/O vector is removed from mirror_iteration_done() and put into an own function mirror_free_qiov() (which is called by mirror_co_copy()). Signed-off-by: Max Reitz --- block/mirror.c | 118 ++++++++++++++++++++----------------------------- 1 file changed, 48 insertions(+), 70 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index f3df7dd984..62fd499799 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -154,26 +154,16 @@ static void coroutine_fn mirror_wait_on_conflicts(Mir= rorOp *self, } } =20 -static void coroutine_fn mirror_iteration_done(MirrorOp *op, int ret, - QEMUIOVector *qiov) +static void coroutine_fn mirror_iteration_done(MirrorOp *op, int ret) { MirrorBlockJob *s =3D op->s; - struct iovec *iov; int64_t chunk_num; - int i, nb_chunks; + int nb_chunks; =20 trace_mirror_iteration_done(s, op->offset, op->bytes, ret); =20 s->in_flight--; s->bytes_in_flight -=3D op->bytes; - if (qiov) { - iov =3D qiov->iov; - for (i =3D 0; i < qiov->niov; i++) { - MirrorBuffer *buf =3D (MirrorBuffer *) iov[i].iov_base; - QSIMPLEQ_INSERT_TAIL(&s->buf_free, buf, next); - s->buf_free_count++; - } - } =20 chunk_num =3D op->offset / s->granularity; nb_chunks =3D DIV_ROUND_UP(op->bytes, s->granularity); @@ -188,53 +178,11 @@ static void coroutine_fn mirror_iteration_done(Mirror= Op *op, int ret, job_progress_update(&s->common.job, op->bytes); } } - if (qiov) { - qemu_iovec_destroy(qiov); - } =20 qemu_co_queue_restart_all(&op->waiting_requests); g_free(op); } =20 -static void coroutine_fn mirror_write_complete(MirrorOp *op, int ret, - QEMUIOVector *qiov) -{ - MirrorBlockJob *s =3D op->s; - - if (ret < 0) { - BlockErrorAction action; - - bdrv_set_dirty_bitmap(s->dirty_bitmap, op->offset, op->bytes); - action =3D mirror_error_action(s, false, -ret); - if (action =3D=3D BLOCK_ERROR_ACTION_REPORT && s->ret >=3D 0) { - s->ret =3D ret; - } - } - mirror_iteration_done(op, ret, qiov); -} - -static void coroutine_fn mirror_read_complete(MirrorOp *op, int ret, - QEMUIOVector *qiov) -{ - MirrorBlockJob *s =3D op->s; - - if (ret < 0) { - BlockErrorAction action; - - bdrv_set_dirty_bitmap(s->dirty_bitmap, op->offset, op->bytes); - action =3D mirror_error_action(s, true, -ret); - if (action =3D=3D BLOCK_ERROR_ACTION_REPORT && s->ret >=3D 0) { - s->ret =3D ret; - } - - mirror_iteration_done(op, ret, qiov); - } else { - ret =3D blk_co_pwritev(s->target, op->offset, - qiov->size, qiov, 0); - mirror_write_complete(op, ret, qiov); - } -} - /* Clip bytes relative to offset to not exceed end-of-file */ static inline int64_t mirror_clip_bytes(MirrorBlockJob *s, int64_t offset, @@ -322,6 +270,19 @@ static void coroutine_fn mirror_co_alloc_qiov(MirrorBl= ockJob *s, } } =20 +static void mirror_free_qiov(MirrorBlockJob *s, QEMUIOVector *qiov) +{ + struct iovec *iov =3D qiov->iov; + int i; + + for (i =3D 0; i < qiov->niov; i++) { + MirrorBuffer *buf =3D (MirrorBuffer *) iov[i].iov_base; + QSIMPLEQ_INSERT_TAIL(&s->buf_free, buf, next); + s->buf_free_count++; + } + qemu_iovec_destroy(qiov); +} + /* * Restrict *bytes to how much we can actually handle, and align the * [*offset, *bytes] range to clusters if COW is needed. @@ -351,24 +312,41 @@ static void mirror_align_for_copy(MirrorBlockJob *s, assert(QEMU_IS_ALIGNED(*bytes, BDRV_SECTOR_SIZE)); } =20 -/* Perform a mirror copy operation. */ -static void coroutine_fn mirror_co_read(void *opaque) +/* + * Perform a mirror copy operation. + * + * On error, -errno is returned and *failed_on_read is set to the + * appropriate value. + */ +static int coroutine_fn mirror_co_copy(MirrorBlockJob *s, + int64_t offset, int64_t bytes, + bool *failed_on_read) { - MirrorOp *op =3D opaque; - MirrorBlockJob *s =3D op->s; QEMUIOVector qiov; - uint64_t ret; + int ret; =20 - mirror_co_alloc_qiov(s, &qiov, op->offset, op->bytes); + mirror_co_alloc_qiov(s, &qiov, offset, bytes); =20 /* Copy the dirty cluster. */ s->in_flight++; - s->bytes_in_flight +=3D op->bytes; - trace_mirror_one_iteration(s, op->offset, op->bytes); + s->bytes_in_flight +=3D bytes; + trace_mirror_one_iteration(s, offset, bytes); + + ret =3D bdrv_co_preadv(s->mirror_top_bs->backing, offset, bytes, &qiov= , 0); + if (ret < 0) { + *failed_on_read =3D true; + goto fail; + } =20 - ret =3D bdrv_co_preadv(s->mirror_top_bs->backing, op->offset, op->byte= s, - &qiov, 0); - mirror_read_complete(op, ret, &qiov); + ret =3D blk_co_pwritev(s->target, offset, bytes, &qiov, 0); + if (ret < 0) { + *failed_on_read =3D false; + goto fail; + } + +fail: + mirror_free_qiov(s, &qiov); + return ret; } =20 static int coroutine_fn mirror_co_zero(MirrorBlockJob *s, @@ -395,6 +373,7 @@ static void coroutine_fn mirror_co_perform(void *opaque) MirrorOp *op =3D opaque; MirrorBlockJob *s =3D op->s; AioContext *aio_context; + bool failed_on_read =3D false; int ret; =20 aio_context =3D blk_get_aio_context(s->common.blk); @@ -402,8 +381,8 @@ static void coroutine_fn mirror_co_perform(void *opaque) =20 switch (op->mirror_method) { case MIRROR_METHOD_COPY: - mirror_co_read(opaque); - goto done; + ret =3D mirror_co_copy(s, op->offset, op->bytes, &failed_on_read); + break; case MIRROR_METHOD_ZERO: ret =3D mirror_co_zero(s, op->offset, op->bytes); break; @@ -418,15 +397,14 @@ static void coroutine_fn mirror_co_perform(void *opaq= ue) BlockErrorAction action; =20 bdrv_set_dirty_bitmap(s->dirty_bitmap, op->offset, op->bytes); - action =3D mirror_error_action(s, false, -ret); + action =3D mirror_error_action(s, failed_on_read, -ret); if (action =3D=3D BLOCK_ERROR_ACTION_REPORT && s->ret >=3D 0) { s->ret =3D ret; } } =20 - mirror_iteration_done(op, ret, NULL); + mirror_iteration_done(op, ret); =20 -done: aio_context_release(aio_context); } =20 --=20 2.17.1