From nobody Wed Feb 11 02:57:57 2026 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; dkim=fail; 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 1516187231815930.3693343822533; Wed, 17 Jan 2018 03:07:11 -0800 (PST) Received: from localhost ([::1]:55390 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eblYh-00062X-72 for importer@patchew.org; Wed, 17 Jan 2018 06:07:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35723) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eblT2-0001Wl-5h for qemu-devel@nongnu.org; Wed, 17 Jan 2018 06:01:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eblSw-0003Ey-Ij for qemu-devel@nongnu.org; Wed, 17 Jan 2018 06:01:16 -0500 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:35513) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eblSw-0003E5-CE; Wed, 17 Jan 2018 06:01:10 -0500 Received: by mail-wm0-x242.google.com with SMTP id r78so14880445wme.0; Wed, 17 Jan 2018 03:01:10 -0800 (PST) Received: from 640k.lan (dynamic-adsl-78-12-229-84.clienti.tiscali.it. [78.12.229.84]) by smtp.gmail.com with ESMTPSA id o12sm3996897wrf.81.2018.01.17.03.01.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jan 2018 03:01:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Snjw5yFk4LpodPvJ+6351EJ2NOr6+utSqeinpdpt5X8=; b=XaZOtYjcbTacsiyLs7XGYPbdqcJtwCrg3jFniNciKUgrSisHlAi++Sx+1BisNJGGRB anpwKVLXJlAfLFPNCSOYjwQKtWZAbX4dXHAxAZt+IluhrowrTlDA3EpPhEYoBtrNrElI jJL4LzT5D+WNMfDGSZbhkD3Hk0kgEi9ZxiFXs4ejBaJkLawbgSFt3/d3Gb1BV4e5WlxN 4EpDR5Rtt66IpCkcHc3WGosbxLR255TI03TBagsmluMiE9W7ZT7p/HRfoX8BSJEQanWJ PoOp3kxDgmhwTfodpZs6TSm1ZBjmxbpj8TJOgCmaqQPPp+zgA2OGuxzu48h5/qxIYZ8g 8GRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Snjw5yFk4LpodPvJ+6351EJ2NOr6+utSqeinpdpt5X8=; b=fgadlhJiZ+OoJzGCQfof0Gs6rx8weeibHJEVZoixlwKD5lgLDcw4doXQIDAxaBZrZX AB/eOnGVIMk+rkePc+8Y9qcj9QELbaJSRf2YpQr0BtVeIFMSt+lg6WmOFZ6VtowoMNVe XNkf6dL/+W3CeVOczUbR64MfIU/qr36bxQ1L8mWSXirFy0dD18J89vP8HhHR5IjTRZQW iGTN+AVAL1JtiY2HgyHVc1aw6+Sz5WCSkOMYuC6lPr/PToKJejdvV8OjaIjk14a8iPmE Q/joCKJprI8DCCb7Px3/EV5plBLtVOtFANbJjVmIbh1u6VBMh+PHzV4ll6TcXN+n+g8s 2IcA== X-Gm-Message-State: AKwxytczfvw/VRvYKX9jZeFsS9bBbcmAAMFMjKb7wcS8MFcZh1Yqi7bV xiy1JPwnJROVeIYzU5enHuP8hI6/ X-Google-Smtp-Source: ACJfBouBQJx0l743+gco4uEihcoyZpV+PqjCrUw7JPOjINcaT1TPhjYk3Y4p4fMLOE7hudF7LXC2kA== X-Received: by 10.28.245.17 with SMTP id t17mr1705582wmh.56.1516186868757; Wed, 17 Jan 2018 03:01:08 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 17 Jan 2018 12:00:47 +0100 Message-Id: <1516186851-23896-4-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1516186851-23896-1-git-send-email-pbonzini@redhat.com> References: <1516186851-23896-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::242 Subject: [Qemu-devel] [PATCH 3/7] 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, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 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 (incoming migration runs in a coroutine), so it's cleaner if metadata is always loaded from a coroutine. Signed-off-by: Paolo Bonzini --- block/qcow2.c | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index fec065b..7c11516 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1087,8 +1087,9 @@ static int qcow2_update_options(BlockDriverState *bs,= QDict *options, return ret; } =20 -static int qcow2_do_open(BlockDriverState *bs, QDict *options, int flags, - Error **errp) +/* Called with s->lock held. */ +static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, + int flags, Error **errp) { BDRVQcow2State *s =3D bs->opaque; unsigned int len, i; @@ -1467,8 +1468,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 */ @@ -1514,16 +1513,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 1.8.3.1