From nobody Fri Nov 7 10:28:47 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.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 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548189427262657.2414048091623; Tue, 22 Jan 2019 12:37:07 -0800 (PST) Received: from localhost ([127.0.0.1]:49196 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gm2nB-0006yA-KL for importer@patchew.org; Tue, 22 Jan 2019 15:37:05 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45373) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gm1nJ-0007pl-LU for qemu-devel@nongnu.org; Tue, 22 Jan 2019 14:33:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gm1k1-0002YM-1v for qemu-devel@nongnu.org; Tue, 22 Jan 2019 14:29:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56042) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gm1jz-00023k-2a; Tue, 22 Jan 2019 14:29:43 -0500 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 429282DD2B; Tue, 22 Jan 2019 12:19:30 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.118.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4DF265D6A9; Tue, 22 Jan 2019 12:19:29 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 22 Jan 2019 13:19:26 +0100 Message-Id: <20190122121926.25554-1-kwolf@redhat.com> MIME-Version: 1.0 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.38]); Tue, 22 Jan 2019 12:19:30 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] block: Apply auto-read-only for ro-whitelist drivers 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" Content-Type: text/plain; charset="utf-8" If QEMU was configured with a driver in --block-drv-ro-whitelist, trying to use that driver read-write resulted in an error message even if auto-read-only=3Don was set. Consider auto-read-only=3Don for the whitelist checking and use it to automatically degrade to read-only for block drivers on the read-only whitelist. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/block.c b/block.c index 92a3b45a78..0eba8ebe5c 100644 --- a/block.c +++ b/block.c @@ -1438,13 +1438,19 @@ static int bdrv_open_common(BlockDriverState *bs, B= lockBackend *file, bs->read_only =3D !(bs->open_flags & BDRV_O_RDWR); =20 if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv, bs->read_only)) { - error_setg(errp, - !bs->read_only && bdrv_is_whitelisted(drv, true) - ? "Driver '%s' can only be used for read-only devi= ces" - : "Driver '%s' is not whitelisted", - drv->format_name); - ret =3D -ENOTSUP; - goto fail_opts; + if (!bs->read_only && bdrv_is_whitelisted(drv, true)) { + ret =3D bdrv_apply_auto_read_only(bs, NULL, NULL); + } else { + ret =3D -ENOTSUP; + } + if (ret < 0) { + error_setg(errp, + !bs->read_only && bdrv_is_whitelisted(drv, true) + ? "Driver '%s' can only be used for read-only devic= es" + : "Driver '%s' is not whitelisted", + drv->format_name); + goto fail_opts; + } } =20 /* bdrv_new() and bdrv_close() make it so */ --=20 2.20.1