From nobody Thu Dec 18 13:19:09 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 1530281771518924.8981579467011; Fri, 29 Jun 2018 07:16:11 -0700 (PDT) Received: from localhost ([::1]:42484 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYuC2-0000Oj-84 for importer@patchew.org; Fri, 29 Jun 2018 10:16:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49565) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYu6R-0003ut-Tq for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYu6M-0003nQ-MB for qemu-devel@nongnu.org; Fri, 29 Jun 2018 10:10:23 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60240 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 1fYu6G-0003d8-Lv; Fri, 29 Jun 2018 10:10:12 -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 4F5057264E; Fri, 29 Jun 2018 14:10:12 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-232.ams2.redhat.com [10.36.116.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E93C1102E29; Fri, 29 Jun 2018 14:10:11 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 29 Jun 2018 16:09:38 +0200 Message-Id: <20180629140959.6690-9-kwolf@redhat.com> In-Reply-To: <20180629140959.6690-1-kwolf@redhat.com> References: <20180629140959.6690-1-kwolf@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.2]); Fri, 29 Jun 2018 14:10:12 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 29 Jun 2018 14:10:12 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 08/29] qcow2: Remove coroutine trampoline for preallocate_co() 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: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" All callers are coroutine_fns now, so we can just directly call preallocate_co(). Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- block/qcow2.c | 51 ++++++++------------------------------------------- 1 file changed, 8 insertions(+), 43 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 9e0ccbbfaf..4a0d92860d 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2521,15 +2521,6 @@ static int qcow2_set_up_encryption(BlockDriverState = *bs, return ret; } =20 - -typedef struct PreallocCo { - BlockDriverState *bs; - uint64_t offset; - uint64_t new_length; - - int ret; -} PreallocCo; - /** * Preallocates metadata structures for data clusters between @offset (in = the * guest disk) and @new_length (which is thus generally the new guest disk @@ -2537,12 +2528,9 @@ typedef struct PreallocCo { * * Returns: 0 on success, -errno on failure. */ -static void coroutine_fn preallocate_co(void *opaque) +static int coroutine_fn preallocate_co(BlockDriverState *bs, uint64_t offs= et, + uint64_t new_length) { - PreallocCo *params =3D opaque; - BlockDriverState *bs =3D params->bs; - uint64_t offset =3D params->offset; - uint64_t new_length =3D params->new_length; uint64_t bytes; uint64_t host_offset =3D 0; unsigned int cur_bytes; @@ -2557,7 +2545,7 @@ static void coroutine_fn preallocate_co(void *opaque) ret =3D qcow2_alloc_cluster_offset(bs, offset, &cur_bytes, &host_offset, &meta); if (ret < 0) { - goto done; + return ret; } =20 while (meta) { @@ -2567,7 +2555,7 @@ static void coroutine_fn preallocate_co(void *opaque) if (ret < 0) { qcow2_free_any_clusters(bs, meta->alloc_offset, meta->nb_clusters, QCOW2_DISCARD_N= EVER); - goto done; + return ret; } =20 /* There are no dependent requests, but we need to remove our @@ -2594,34 +2582,11 @@ static void coroutine_fn preallocate_co(void *opaqu= e) ret =3D bdrv_pwrite(bs->file, (host_offset + cur_bytes) - 1, &data, 1); if (ret < 0) { - goto done; + return ret; } } =20 - ret =3D 0; - -done: - params->ret =3D ret; -} - -static int preallocate(BlockDriverState *bs, - uint64_t offset, uint64_t new_length) -{ - PreallocCo params =3D { - .bs =3D bs, - .offset =3D offset, - .new_length =3D new_length, - .ret =3D -EINPROGRESS, - }; - - if (qemu_in_coroutine()) { - preallocate_co(¶ms); - } else { - Coroutine *co =3D qemu_coroutine_create(preallocate_co, ¶ms); - bdrv_coroutine_enter(bs, co); - BDRV_POLL_WHILE(bs, params.ret =3D=3D -EINPROGRESS); - } - return params.ret; + return 0; } =20 /* qcow2_refcount_metadata_size: @@ -3039,7 +3004,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options= , Error **errp) if (qcow2_opts->preallocation !=3D PREALLOC_MODE_OFF) { BDRVQcow2State *s =3D blk_bs(blk)->opaque; qemu_co_mutex_lock(&s->lock); - ret =3D preallocate(blk_bs(blk), 0, qcow2_opts->size); + ret =3D preallocate_co(blk_bs(blk), 0, qcow2_opts->size); qemu_co_mutex_unlock(&s->lock); =20 if (ret < 0) { @@ -3547,7 +3512,7 @@ static int coroutine_fn qcow2_co_truncate(BlockDriver= State *bs, int64_t offset, break; =20 case PREALLOC_MODE_METADATA: - ret =3D preallocate(bs, old_length, offset); + ret =3D preallocate_co(bs, old_length, offset); if (ret < 0) { error_setg_errno(errp, -ret, "Preallocation failed"); goto fail; --=20 2.13.6