From nobody Tue Apr 15 09:56:12 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 Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1509025277929914.8213374222082; Thu, 26 Oct 2017 06:41:17 -0700 (PDT) Received: from localhost ([::1]:52983 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7iPJ-0002Wp-5A for importer@patchew.org; Thu, 26 Oct 2017 09:41:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59447) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e7i4A-0001KB-CM for qemu-devel@nongnu.org; Thu, 26 Oct 2017 09:19:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e7i46-0002iT-8q for qemu-devel@nongnu.org; Thu, 26 Oct 2017 09:19:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50136) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e7i3x-0002cP-NL; Thu, 26 Oct 2017 09:19:09 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D538281DF3; Thu, 26 Oct 2017 13:19:08 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.118.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 575727F7FD; Thu, 26 Oct 2017 13:19:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D538281DF3 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=kwolf@redhat.com From: Kevin Wolf To: qemu-block@nongnu.org Date: Thu, 26 Oct 2017 15:17:40 +0200 Message-Id: <20171026131741.5059-35-kwolf@redhat.com> In-Reply-To: <20171026131741.5059-1-kwolf@redhat.com> References: <20171026131741.5059-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 26 Oct 2017 13:19:09 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 34/35] qcow2: Always execute preallocate() in a coroutine 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, 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" From: Max Reitz Some qcow2 functions (at least perform_cow()) expect s->lock to be taken. Therefore, if we want to make use of them, we should execute preallocate() (as "preallocate_co") in a coroutine so that we can use the qemu_co_mutex_* functions. Signed-off-by: Max Reitz Message-id: 20171009215533.12530-3-mreitz@redhat.com Cc: qemu-stable@nongnu.org Reviewed-by: Eric Blake Reviewed-by: Jeff Cody Reviewed-by: Stefan Hajnoczi Signed-off-by: Max Reitz --- block/qcow2.c | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 1ea763126d..92cb9f9bfa 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2460,6 +2460,14 @@ static int qcow2_set_up_encryption(BlockDriverState = *bs, const char *encryptfmt, } =20 =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 @@ -2467,9 +2475,12 @@ static int qcow2_set_up_encryption(BlockDriverState = *bs, const char *encryptfmt, * * Returns: 0 on success, -errno on failure. */ -static int preallocate(BlockDriverState *bs, - uint64_t offset, uint64_t new_length) +static void coroutine_fn preallocate_co(void *opaque) { + PreallocCo *params =3D opaque; + BlockDriverState *bs =3D params->bs; + uint64_t offset =3D params->offset; + uint64_t new_length =3D params->new_length; BDRVQcow2State *s =3D bs->opaque; uint64_t bytes; uint64_t host_offset =3D 0; @@ -2477,9 +2488,7 @@ static int preallocate(BlockDriverState *bs, int ret; QCowL2Meta *meta; =20 - if (qemu_in_coroutine()) { - qemu_co_mutex_lock(&s->lock); - } + qemu_co_mutex_lock(&s->lock); =20 assert(offset <=3D new_length); bytes =3D new_length - offset; @@ -2533,10 +2542,28 @@ static int preallocate(BlockDriverState *bs, ret =3D 0; =20 done: + qemu_co_mutex_unlock(&s->lock); + 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()) { - qemu_co_mutex_unlock(&s->lock); + 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 ret; + return params.ret; } =20 /* qcow2_refcount_metadata_size: --=20 2.13.6