All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roman Kagan <rkagan@virtuozzo.com>
To: Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	qemu-block@nongnu.org, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 01/17] block: iterate_format with account of whitelisting
Date: Thu, 26 Apr 2018 19:19:42 +0300	[thread overview]
Message-ID: <20180426161958.2872-2-rkagan@virtuozzo.com> (raw)
In-Reply-To: <20180426161958.2872-1-rkagan@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.

As a result, QEMU lies when asked for the list of block drivers it
supports with "-drive format=?": some of the formats there may be
recognized by qemu-* tools but unusable in qemu proper.

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 as 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>
---
 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 cdec3639a3..e60983248f 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -429,7 +429,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 a2caadf0a0..eaa73edc79 100644
--- a/block.c
+++ b/block.c
@@ -371,7 +371,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
@@ -386,13 +386,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;
             }
         }
@@ -400,6 +400,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;
@@ -3886,7 +3891,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;
@@ -3897,6 +3902,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);
             }
@@ -3915,6 +3925,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 c31bf3d98d..f43c6bcf27 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -530,7 +530,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 855fa52514..a938cb253e 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -201,7 +201,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.14.3

  reply	other threads:[~2018-04-26 16:20 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-26 16:19 [Qemu-devel] [PATCH 00/17] iotests: don't choke on disabled drivers Roman Kagan
2018-04-26 16:19 ` Roman Kagan [this message]
2018-04-26 18:15   ` [Qemu-devel] [PATCH 01/17] block: iterate_format with account of whitelisting Eric Blake
2018-05-30 12:03   ` Max Reitz
2018-04-26 16:19 ` [Qemu-devel] [PATCH 02/17] iotests: iotests.py: prevent deadlock in subprocess Roman Kagan
2018-05-30 12:07   ` Max Reitz
2018-04-26 16:19 ` [Qemu-devel] [PATCH 03/17] iotests: ask qemu for supported formats Roman Kagan
2018-05-30 12:17   ` Max Reitz
2018-05-30 13:07     ` Roman Kagan
2018-06-04  7:18   ` Markus Armbruster
2018-06-04 10:34     ` Thomas Huth
2018-06-04 22:40       ` Eric Blake
2018-06-05  4:02         ` Thomas Huth
2018-06-07  6:57           ` Markus Armbruster
2018-06-07  7:50             ` Thomas Huth
2018-06-07 11:07               ` Paolo Bonzini
2018-06-07 11:10                 ` Thomas Huth
2018-06-07 11:18                   ` Paolo Bonzini
2018-06-07 11:27                     ` [Qemu-devel] -enable-kvm and friens (was: Re: [PATCH 03/17] iotests: ask qemu for supported formats) Thomas Huth
2018-06-07 11:42                       ` Paolo Bonzini
2018-06-07 11:51                         ` [Qemu-devel] -enable-kvm and friens Thomas Huth
2018-06-07 11:29               ` [Qemu-devel] [PATCH 03/17] iotests: ask qemu for supported formats Markus Armbruster
2018-06-07 12:42               ` Daniel P. Berrangé
2018-04-26 16:19 ` [Qemu-devel] [PATCH 04/17] iotest 030: skip quorum test setup/teardown too Roman Kagan
2018-05-30 12:19   ` Max Reitz
2018-04-26 16:19 ` [Qemu-devel] [PATCH 05/17] iotest 030: require blkdebug Roman Kagan
2018-05-30 12:19   ` Max Reitz
2018-04-26 16:19 ` [Qemu-devel] [PATCH 06/17] iotest 055: skip unsupported backup target formats Roman Kagan
2018-05-30 12:22   ` Max Reitz
2018-04-26 16:19 ` [Qemu-devel] [PATCH 07/17] iotest 055: require blkdebug Roman Kagan
2018-05-30 12:22   ` Max Reitz
2018-04-26 16:19 ` [Qemu-devel] [PATCH 08/17] iotest 056: skip testcases using blkdebug if disabled Roman Kagan
2018-05-30 12:26   ` Max Reitz
2018-04-26 16:19 ` [Qemu-devel] [PATCH 09/17] iotest 071: notrun if blkdebug or blkverify is disabled Roman Kagan
2018-04-26 16:19 ` [Qemu-devel] [PATCH 10/17] iotest 081: notrun if quorum " Roman Kagan
2018-04-26 16:19 ` [Qemu-devel] [PATCH 11/17] iotest 087: notrun if null-co " Roman Kagan
2018-04-26 16:19 ` [Qemu-devel] [PATCH 12/17] iotest 093: notrun if null-co or null-aio " Roman Kagan
2018-04-26 16:19 ` [Qemu-devel] [PATCH 13/17] iotest 099: notrun if blkdebug or blkverify " Roman Kagan
2018-04-26 16:19 ` [Qemu-devel] [PATCH 14/17] iotest 124: skip testcases using blkdebug if disabled Roman Kagan
2018-04-26 16:19 ` [Qemu-devel] [PATCH 15/17] iotest 139: skip testcases using disabled drivers Roman Kagan
2018-04-26 16:19 ` [Qemu-devel] [PATCH 16/17] iotest 147: notrun if nbd is disabled Roman Kagan
2018-04-26 16:19 ` [Qemu-devel] [PATCH 17/17] iotest 184: notrun if null-co or throttle " Roman Kagan
2018-04-26 16:47 ` [Qemu-devel] [PATCH 00/17] iotests: don't choke on disabled drivers no-reply
2018-05-17 16:11 ` [Qemu-devel] [Qemu-block] " Roman Kagan
2018-05-30 12:35 ` [Qemu-devel] " Max Reitz
2018-05-30 13:47   ` Roman Kagan
2018-05-30 13:53     ` Max Reitz
2018-05-30 14:16       ` Roman Kagan

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=20180426161958.2872-2-rkagan@virtuozzo.com \
    --to=rkagan@virtuozzo.com \
    --cc=armbru@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --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.