All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 04/33] block: iterate_format with account of whitelisting
Date: Fri,  8 Mar 2019 13:57:54 +0100	[thread overview]
Message-ID: <20190308125823.32535-5-kwolf@redhat.com> (raw)
In-Reply-To: <20190308125823.32535-1-kwolf@redhat.com>

From: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>

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 <rkagan@virtuozzo.com>
Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 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);
 }
 
-int bdrv_is_whitelisted(BlockDriver *drv, bool read_only)
+static int bdrv_format_is_whitelisted(const char *format_name, bool read_only)
 {
     static const char *whitelist_rw[] = {
         CONFIG_BDRV_RW_WHITELIST
@@ -441,13 +441,13 @@ int bdrv_is_whitelisted(BlockDriver *drv, bool read_only)
     }
 
     for (p = whitelist_rw; *p; p++) {
-        if (!strcmp(drv->format_name, *p)) {
+        if (!strcmp(format_name, *p)) {
             return 1;
         }
     }
     if (read_only) {
         for (p = 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_only)
     return 0;
 }
 
+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)
 }
 
 void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
-                         void *opaque)
+                         void *opaque, bool read_only)
 {
     BlockDriver *drv;
     int count = 0;
@@ -4158,6 +4163,11 @@ void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
         if (drv->format_name) {
             bool found = false;
             int i = count;
+
+            if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv, read_only)) {
+                continue;
+            }
+
             while (formats && i && !found) {
                 found = !strcmp(formats[--i], drv->format_name);
             }
@@ -4176,6 +4186,11 @@ void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
             bool found = false;
             int j = count;
 
+            if (use_bdrv_whitelist &&
+                !bdrv_format_is_whitelisted(format_name, read_only)) {
+                continue;
+            }
+
             while (formats && j && !found) {
                 found = !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, QDict *bs_opts,
     if ((buf = qemu_opt_get(opts, "format")) != 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=N' skip N bs-sized blocks at the start of input\n";
 
     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);
 }
-- 
2.20.1

  parent reply	other threads:[~2019-03-08 12:58 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-08 12:57 [Qemu-devel] [PULL 00/33] Block layer patches Kevin Wolf
2019-03-08 12:57 ` [Qemu-devel] [PULL 01/33] iotests: use iotests.VM in 238 Kevin Wolf
2019-03-08 12:57 ` [Qemu-devel] [PULL 02/33] qcow2: Default to 4KB for the qcow2 cache entry size Kevin Wolf
2019-03-08 12:57 ` [Qemu-devel] [PULL 03/33] iotests: open notrun files in text mode Kevin Wolf
2019-03-08 12:57 ` Kevin Wolf [this message]
2019-03-08 12:57 ` [Qemu-devel] [PULL 05/33] iotests: ask QEMU for supported formats Kevin Wolf
2019-03-08 12:57 ` [Qemu-devel] [PULL 06/33] iotests: check whitelisted formats Kevin Wolf
2019-03-08 12:57 ` [Qemu-devel] [PULL 07/33] tests/multiboot: Improve portability by searching bash in the $PATH Kevin Wolf
2019-03-08 12:57 ` [Qemu-devel] [PULL 08/33] tests/bios-tables: " Kevin Wolf
2019-03-08 12:57 ` [Qemu-devel] [PULL 09/33] qemu-iotests: " Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 10/33] qemu-iotests: Ensure GNU sed is used Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 11/33] qemu-iotests: Test qcow2 preallocation modes Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 12/33] qcow2: Simplify preallocation code Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 13/33] qcow2: Extend spec for external data files Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 14/33] qcow2: Basic definitions " Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 15/33] qcow2: Pass bs to qcow2_get_cluster_type() Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 16/33] qcow2: Prepare qcow2_get_cluster_type() for external data file Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 17/33] qcow2: Prepare count_contiguous_clusters() " Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 18/33] qcow2: Don't assume 0 is an invalid cluster offset Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 19/33] qcow2: Return 0/-errno in qcow2_alloc_compressed_cluster_offset() Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 20/33] qcow2: Prepare qcow2_co_block_status() for data file Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 21/33] qcow2: External file I/O Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 22/33] qcow2: Return error for snapshot operation with data file Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 23/33] qcow2: Support external data file in qemu-img check Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 24/33] qcow2: Add basic data-file infrastructure Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 25/33] qcow2: Creating images with external data file Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 26/33] qcow2: Store data file name in the image Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 27/33] qcow2: Implement data-file-raw create option Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 28/33] qemu-iotests: Preallocation with external data file Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 29/33] qemu-iotests: General tests for qcow2 " Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 30/33] qemu-iotests: amend " Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 31/33] ahci-test: Add dependency to qemu-img tool Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 32/33] qemu-iotests: Add dependency to qemu-nbd tool Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 33/33] qcow2 spec: Describe string header extensions Kevin Wolf
2019-03-09 17:35 ` [Qemu-devel] [PULL 00/33] Block layer patches Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190308125823.32535-5-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.