From nobody Wed Nov 5 09:04:11 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499706372045237.2093198200265; Mon, 10 Jul 2017 10:06:12 -0700 (PDT) Received: from localhost ([::1]:42141 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUc8N-0001i7-Nx for importer@patchew.org; Mon, 10 Jul 2017 13:06:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58318) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUc17-00043r-It for qemu-devel@nongnu.org; Mon, 10 Jul 2017 12:58:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUc13-0002zG-KI for qemu-devel@nongnu.org; Mon, 10 Jul 2017 12:58:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51288) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUc13-0002yg-Ac for qemu-devel@nongnu.org; Mon, 10 Jul 2017 12:58:33 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3C4997D0F1 for ; Mon, 10 Jul 2017 16:58:32 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-181.ams2.redhat.com [10.36.117.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 411FD5D6A6; Mon, 10 Jul 2017 16:58:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3C4997D0F1 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3C4997D0F1 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 10 Jul 2017 18:58:23 +0200 Message-Id: <20170710165827.4250-2-pbonzini@redhat.com> In-Reply-To: <20170710165827.4250-1-pbonzini@redhat.com> References: <20170710165827.4250-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 10 Jul 2017 16:58:32 +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] [PATCH 1/5] qcow2: make qcow2_do_open a coroutine_fn 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, marcandre.lureau@redhat.com 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" It is called from qcow2_invalidate_cache in coroutine context, so always load metadata from a coroutine. --- block/qcow2.c | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index cb081ea47f..b5de67d113 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -814,8 +814,8 @@ static int qcow2_update_options(BlockDriverState *bs, Q= Dict *options, return ret; } =20 -static int qcow2_do_open(BlockDriverState *bs, QDict *options, int flags, - Error **errp) +static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, + int flags, Error **errp) { BDRVQcow2State *s =3D bs->opaque; unsigned int len, i; @@ -1161,8 +1161,6 @@ static int qcow2_do_open(BlockDriverState *bs, QDict = *options, int flags, } } =20 - /* Initialise locks */ - qemu_co_mutex_init(&s->lock); bs->supported_zero_flags =3D BDRV_REQ_MAY_UNMAP; =20 /* Repair image if dirty */ @@ -1205,16 +1203,53 @@ static int qcow2_do_open(BlockDriverState *bs, QDic= t *options, int flags, return ret; } =20 +typedef struct QCow2OpenCo { + BlockDriverState *bs; + QDict *options; + int flags; + Error **errp; + int ret; +} QCow2OpenCo; + +static void coroutine_fn qcow2_open_entry(void *opaque) +{ + QCow2OpenCo *qoc =3D opaque; + BDRVQcow2State *s =3D qoc->bs->opaque; + + qemu_co_mutex_lock(&s->lock); + qoc->ret =3D qcow2_do_open(qoc->bs, qoc->options, qoc->flags, qoc->err= p); + qemu_co_mutex_unlock(&s->lock); +} + static int qcow2_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { + BDRVQcow2State *s =3D bs->opaque; + QCow2OpenCo qoc =3D { + .bs =3D bs, + .options =3D options, + .flags =3D flags, + .errp =3D errp, + .ret =3D -EINPROGRESS + }; + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, false, errp); if (!bs->file) { return -EINVAL; } =20 - return qcow2_do_open(bs, options, flags, errp); + /* Initialise locks */ + qemu_co_mutex_init(&s->lock); + + if (qemu_in_coroutine()) { + /* From bdrv_co_create. */ + qcow2_open_entry(&qoc); + } else { + qemu_coroutine_enter(qemu_coroutine_create(qcow2_open_entry, &qoc)= ); + BDRV_POLL_WHILE(bs, qoc.ret =3D=3D -EINPROGRESS); + } + return qoc.ret; } =20 static void qcow2_refresh_limits(BlockDriverState *bs, Error **errp) --=20 2.13.0