From patchwork Tue Jan 22 12:19:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 1029518 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43kgD32R7Mz9s4s for ; Wed, 23 Jan 2019 07:35:47 +1100 (AEDT) Received: from localhost ([127.0.0.1]:49160 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gm2lt-0005lv-36 for incoming@patchwork.ozlabs.org; Tue, 22 Jan 2019 15:35:45 -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) 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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=on was set. Consider auto-read-only=on 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, BlockBackend *file, bs->read_only = !(bs->open_flags & BDRV_O_RDWR); 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 devices" - : "Driver '%s' is not whitelisted", - drv->format_name); - ret = -ENOTSUP; - goto fail_opts; + if (!bs->read_only && bdrv_is_whitelisted(drv, true)) { + ret = bdrv_apply_auto_read_only(bs, NULL, NULL); + } else { + ret = -ENOTSUP; + } + if (ret < 0) { + error_setg(errp, + !bs->read_only && bdrv_is_whitelisted(drv, true) + ? "Driver '%s' can only be used for read-only devices" + : "Driver '%s' is not whitelisted", + drv->format_name); + goto fail_opts; + } } /* bdrv_new() and bdrv_close() make it so */