From nobody Tue Apr 15 11:31:24 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 1552050308280221.88155491445877; Fri, 8 Mar 2019 05:05:08 -0800 (PST) Received: from localhost ([127.0.0.1]:42686 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h2FBP-00048B-9m for importer@patchew.org; Fri, 08 Mar 2019 08:05:03 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59343) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h2F5V-0008BV-GX for qemu-devel@nongnu.org; Fri, 08 Mar 2019 07:58:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h2F5S-0005ju-GC for qemu-devel@nongnu.org; Fri, 08 Mar 2019 07:58:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60346) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h2F5H-0004NB-Qe; Fri, 08 Mar 2019 07:58:44 -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 107C8309E979; Fri, 8 Mar 2019 12:58:38 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-27.ams2.redhat.com [10.36.117.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id F3CF55D786; Fri, 8 Mar 2019 12:58:36 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 8 Mar 2019 13:57:54 +0100 Message-Id: <20190308125823.32535-5-kwolf@redhat.com> In-Reply-To: <20190308125823.32535-1-kwolf@redhat.com> References: <20190308125823.32535-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.49]); Fri, 08 Mar 2019 12:58:38 +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] [PULL 04/33] block: iterate_format with account of whitelisting 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Andrey Shinkevich bdrv_iterate_format (which is currently only used for printing out the formats supported by the block layer) doesn't take format whitelisting into account. This creates a problem for tests: they enumerate supported formats to decide which tests to enable, but then discover that QEMU doesn't let them actually use some of those formats. To avoid that, exclude formats that are not whitelisted from enumeration, if whitelisting is in use. Since we have separate whitelists for r/w and r/o, take this a parameter to bdrv_iterate_format, and print two lists of supported formats (r/w and r/o) in main qemu. Signed-off-by: Roman Kagan Signed-off-by: Andrey Shinkevich Signed-off-by: Kevin Wolf --- include/block/block.h | 2 +- block.c | 23 +++++++++++++++++++---- blockdev.c | 4 +++- qemu-img.c | 2 +- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 5b5cf868df..6a758a76f8 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -472,7 +472,7 @@ void bdrv_next_cleanup(BdrvNextIterator *it); BlockDriverState *bdrv_next_monitor_owned(BlockDriverState *bs); bool bdrv_is_encrypted(BlockDriverState *bs); void bdrv_iterate_format(void (*it)(void *opaque, const char *name), - void *opaque); + void *opaque, bool read_only); const char *bdrv_get_node_name(const BlockDriverState *bs); const char *bdrv_get_device_name(const BlockDriverState *bs); const char *bdrv_get_device_or_node_name(const BlockDriverState *bs); diff --git a/block.c b/block.c index 35e78e2172..ccf008c177 100644 --- a/block.c +++ b/block.c @@ -426,7 +426,7 @@ BlockDriver *bdrv_find_format(const char *format_name) return bdrv_do_find_format(format_name); } =20 -int bdrv_is_whitelisted(BlockDriver *drv, bool read_only) +static int bdrv_format_is_whitelisted(const char *format_name, bool read_o= nly) { static const char *whitelist_rw[] =3D { CONFIG_BDRV_RW_WHITELIST @@ -441,13 +441,13 @@ int bdrv_is_whitelisted(BlockDriver *drv, bool read_o= nly) } =20 for (p =3D whitelist_rw; *p; p++) { - if (!strcmp(drv->format_name, *p)) { + if (!strcmp(format_name, *p)) { return 1; } } if (read_only) { for (p =3D whitelist_ro; *p; p++) { - if (!strcmp(drv->format_name, *p)) { + if (!strcmp(format_name, *p)) { return 1; } } @@ -455,6 +455,11 @@ int bdrv_is_whitelisted(BlockDriver *drv, bool read_on= ly) return 0; } =20 +int bdrv_is_whitelisted(BlockDriver *drv, bool read_only) +{ + return bdrv_format_is_whitelisted(drv->format_name, read_only); +} + bool bdrv_uses_whitelist(void) { return use_bdrv_whitelist; @@ -4147,7 +4152,7 @@ static int qsort_strcmp(const void *a, const void *b) } =20 void bdrv_iterate_format(void (*it)(void *opaque, const char *name), - void *opaque) + void *opaque, bool read_only) { BlockDriver *drv; int count =3D 0; @@ -4158,6 +4163,11 @@ void bdrv_iterate_format(void (*it)(void *opaque, co= nst char *name), if (drv->format_name) { bool found =3D false; int i =3D count; + + if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv, read_only)= ) { + continue; + } + while (formats && i && !found) { found =3D !strcmp(formats[--i], drv->format_name); } @@ -4176,6 +4186,11 @@ void bdrv_iterate_format(void (*it)(void *opaque, co= nst char *name), bool found =3D false; int j =3D count; =20 + if (use_bdrv_whitelist && + !bdrv_format_is_whitelisted(format_name, read_only)) { + continue; + } + while (formats && j && !found) { found =3D !strcmp(formats[--j], format_name); } diff --git a/blockdev.c b/blockdev.c index 7e6bf9955c..871966ca13 100644 --- a/blockdev.c +++ b/blockdev.c @@ -531,7 +531,9 @@ static BlockBackend *blockdev_init(const char *file, QD= ict *bs_opts, if ((buf =3D qemu_opt_get(opts, "format")) !=3D NULL) { if (is_help_option(buf)) { error_printf("Supported formats:"); - bdrv_iterate_format(bdrv_format_print, NULL); + bdrv_iterate_format(bdrv_format_print, NULL, false); + error_printf("\nSupported formats (read-only):"); + bdrv_iterate_format(bdrv_format_print, NULL, true); error_printf("\n"); goto early_err; } diff --git a/qemu-img.c b/qemu-img.c index 660c01898e..5fac840742 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -198,7 +198,7 @@ static void QEMU_NORETURN help(void) " 'skip=3DN' skip N bs-sized blocks at the start of input\n"; =20 printf("%s\nSupported formats:", help_msg); - bdrv_iterate_format(format_print, NULL); + bdrv_iterate_format(format_print, NULL, false); printf("\n\n" QEMU_HELP_BOTTOM "\n"); exit(EXIT_SUCCESS); } --=20 2.20.1