From nobody Sun Oct 26 00:02:44 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; 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 1516279579198262.69993596423933; Thu, 18 Jan 2018 04:46:19 -0800 (PST) Received: from localhost ([::1]:56648 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ec9a6-0002nN-R7 for importer@patchew.org; Thu, 18 Jan 2018 07:46:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40041) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ec9Y0-0001Et-Nu for qemu-devel@nongnu.org; Thu, 18 Jan 2018 07:44:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ec9Xz-0004XV-Ac for qemu-devel@nongnu.org; Thu, 18 Jan 2018 07:44:00 -0500 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:40240) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ec9Xz-0004XB-3t; Thu, 18 Jan 2018 07:43:59 -0500 Received: by mail-wm0-x243.google.com with SMTP id v123so22651188wmd.5; Thu, 18 Jan 2018 04:43:58 -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 t51sm13006472wrc.21.2018.01.18.04.43.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Jan 2018 04:43:57 -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=Cidya6VF22F+jwQQ+ltOiiPQVA/Td4uNmy4RAaeMsgnpEeIR/Se+zJyj48OUM13ocC tkQte2ELaa+eCplldJdLwuxY4O9m3WunHN9RqywheFyWnH/R1OOL6KuJBW+EVFZ+nmrT FFKm2EMK5dTHbfsLSR1RHVZ4hdLOai8fIA9vKor9aEP2KRcjC38Ktdo3B+hMDceexrix q2fP6EZuAJoRAa7LsjDwISTMp/cQnQGCFhxHbm96/PgXRLHpDAtQYZdhQ5ywASMomZIn bGdnvdH8vCvdY7NfIynVHE1jUJUn5bqfD+5GraWzhghAygkeuccFvLY+b5ufnz+9Sd2G U+tQ== 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=LC/REByWzoqcnw2sjzhq4CWsIu1esmW5cGNzQJ1A3APOfYXzmRXsxn0PIZQsyv4Vyo Jl7BBExDPhLR/unJlchuukWgn+TFYGkM15Wj2jlIGzp+z/v+535vGZz4VmdGZxN8v9qb rAACEN83tQKY8zWRJ41GrCtGJ/GwDQMxfPe6Vr5nxuBnJb0DLOE6XsmnRQhw+tnDKdZJ zBR5t2x3HOFYpa2jcDmoy1e5Z4dliYL3JqGf66zWyyl+00bKgcIrBd0ndWx/PmZ/PXr3 /B0CEscCPFqyskXLRRt0Q2CujlnBFxurKmbvFL2jGK84O1zREAhpu3UWnIZSQUxF82bR yang== X-Gm-Message-State: AKwxyteRRZuXpeyXIeoXYOw22tyejEUsxhynBlT0oZMzbcnX8gvkHvOs LEmAggrycuFQkt6hJqtwiW8HDsNh X-Google-Smtp-Source: ACJfBotcUzEACeXSmZBE952Z6lD0WYG7zJc0508guWQ4Ixlf4c+KLcmfv5Xg0AvUymaEMQ9+x96C0w== X-Received: by 10.28.238.202 with SMTP id j71mr4904196wmi.34.1516279437666; Thu, 18 Jan 2018 04:43:57 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Jan 2018 13:43:47 +0100 Message-Id: <1516279431-30424-4-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1516279431-30424-1-git-send-email-pbonzini@redhat.com> References: <1516279431-30424-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::243 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