Skip to contentSkip to conversation

block: Print simple help text when calling "-blockdev help"

PATCH Superseded Thomas Huth 3 participants 4 messages Jul 10 – Jul 14

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: Print simple help text when calling "-blockdev help"

From: Thomas Huth <[email protected]>

Other command line options like "-chardev", "-netdev" or "-device" already present the user with a list of available parameters, but when running "-blockdev help", there is currently only an error message. There is already the possibility to run "-drive format=help", but it does not seem to be documented, so this is not very useful for the average user. Let's improve this situation by providing the same list of available drivers when running QEMU with "-blockdev help".

---
 include/block/block-common.h |  1 +
 blockdev.c                   | 15 ++++++++++-----
 system/vl.c                  |  7 +++++--
 3 files changed, 16 insertions(+), 7 deletions(-)
include/block/block-common.h +1 -0
index 895ea175413..010c4425dcf 100644
@@ -583,5 +583,6 @@ char *path_combine(const char *base_path, const char *filename);
 char *bdrv_get_full_backing_filename_from_filename(const char *backed,
                                                    const char *backing,
                                                    Error **errp);
+void blockdev_show_help(void);
 
 #endif /* BLOCK_COMMON_H */
blockdev.c +10 -5
index 6e86c6262f9..3d179939205 100644
@@ -475,6 +475,15 @@ static OnOffAuto account_get_opt(QemuOpts *opts, const char *name)
     return ON_OFF_AUTO_OFF;
 }
 
+void blockdev_show_help(void)
+{
+      qemu_printf("Supported formats:");
+      bdrv_iterate_format(bdrv_format_print, NULL, false);
+      qemu_printf("\nSupported formats (read-only):");
+      bdrv_iterate_format(bdrv_format_print, NULL, true);
+      qemu_printf("\n");
+}
+
 /* Takes the ownership of bs_opts */
 static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
                                    Error **errp)
@@ -541,11 +550,7 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
 
     if ((buf = qemu_opt_get(opts, "format")) != NULL) {
         if (is_help_option(buf)) {
-            qemu_printf("Supported formats:");
-            bdrv_iterate_format(bdrv_format_print, NULL, false);
-            qemu_printf("\nSupported formats (read-only):");
-            bdrv_iterate_format(bdrv_format_print, NULL, true);
-            qemu_printf("\n");
+            blockdev_show_help();
             goto early_err;
         }
 
system/vl.c +5 -2
index 061cbdf860b..40c0593154a 100644
@@ -2961,7 +2961,10 @@ void qemu_init(int argc, char **argv)
                           HD_OPTS);
                 break;
             case QEMU_OPTION_blockdev:
-                {
+                if (is_help_option(optarg)) {
+                    blockdev_show_help();
+                    exit(EXIT_SUCCESS);
+                } else {
                     Visitor *v;
                     BlockdevOptionsQueueEntry *bdo;
 
@@ -2974,8 +2977,8 @@ void qemu_init(int argc, char **argv)
                     visit_free(v);
                     loc_save(&bdo->loc);
                     QSIMPLEQ_INSERT_TAIL(&bdo_queue, bdo, entry);
-                    break;
                 }
+                break;
             case QEMU_OPTION_drive:
                 if (!qemu_opts_parse_noisily(qemu_find_opts("drive"),
                                              optarg, false)) {
Signature · 1 line
2.55.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Thomas Huth

From: Thomas Huth <[email protected]>

Other command line options like "-chardev", "-netdev" or "-device" already present the user with a list of available parameters, but when running "-blockdev help", there is currently only an error message. There is already the possibility to run "-drive format=help", but it does not seem to be documented, so this is not very useful for the average user. Let's improve this situation by providing the same list of available drivers when running QEMU with "-blockdev help".

Quoted 6 lines
---
  include/block/block-common.h |  1 +
  blockdev.c                   | 15 ++++++++++-----
  system/vl.c                  |  7 +++++--
  3 files changed, 16 insertions(+), 7 deletions(-)
#2 lore raw
In reply to Thomas Huth

Am 10.07.2026 um 11:36 hat Thomas Huth geschrieben:

Quoted 11 lines

From: Thomas Huth <[email protected]>

Other command line options like "-chardev", "-netdev" or "-device" already present the user with a list of available parameters, but when running "-blockdev help", there is currently only an error message. There is already the possibility to run "-drive format=help", but it does not seem to be documented, so this is not very useful for the average user. Let's improve this situation by providing the same list of available drivers when running QEMU with "-blockdev help".

Quoted 1 line

Seems like a good idea to print at least some minimal help there. However, I find the list from -drive format=help quite hard to read, and repeating the same list twice for read-write and read-only doesn't help either.

I don't expect we can change -drive because I seem to remember that management tools look at it, but can we make -blockdev help more consistent with the other examples you mention? Something like this:

Available blockdev drivers:
blkdebug
blklogwrites (read-only)
blkreplay
...

Ideally, I'd also love to have a way to show all the options a specific driver offers, but that probably won't happen before Markus QAPIfies the CLI. :-)

Quoted 21 lines
 include/block/block-common.h |  1 +
 blockdev.c                   | 15 ++++++++++-----
 system/vl.c                  |  7 +++++--
 3 files changed, 16 insertions(+), 7 deletions(-)
include/block/block-common.h +1 -0
index 895ea175413..010c4425dcf 100644
@@ -583,5 +583,6 @@ char *path_combine(const char *base_path, const char *filename);
 char *bdrv_get_full_backing_filename_from_filename(const char *backed,
                                                    const char *backing,
                                                    Error **errp);
+void blockdev_show_help(void);
 
 #endif /* BLOCK_COMMON_H */
blockdev.c +0 -0
index 6e86c6262f9..3d179939205 100644

blockdev.c static OnOffAuto account_get_opt(QemuOpts *opts, const char *name) · line 480

Quoted 6 lines
blockdev.c +3 -0
@@ -475,6 +475,15 @@ static OnOffAuto account_get_opt(QemuOpts *opts, const char *name)
     return ON_OFF_AUTO_OFF;
 }
 
+void blockdev_show_help(void)
+{
+      qemu_printf("Supported formats:");

We should definitely talk about "drivers" rather than "formats" with -blockdev. The help in -drive was added in QEMU 0.10 when "formats" was actually still accurate, but it hasn't been for a long time.

Quoted 50 lines
blockdev.c +7 -5
+      bdrv_iterate_format(bdrv_format_print, NULL, false);
+      qemu_printf("\nSupported formats (read-only):");
+      bdrv_iterate_format(bdrv_format_print, NULL, true);
+      qemu_printf("\n");
+}
+
 /* Takes the ownership of bs_opts */
 static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
                                    Error **errp)
@@ -541,11 +550,7 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
 
     if ((buf = qemu_opt_get(opts, "format")) != NULL) {
         if (is_help_option(buf)) {
-            qemu_printf("Supported formats:");
-            bdrv_iterate_format(bdrv_format_print, NULL, false);
-            qemu_printf("\nSupported formats (read-only):");
-            bdrv_iterate_format(bdrv_format_print, NULL, true);
-            qemu_printf("\n");
+            blockdev_show_help();
             goto early_err;
         }
 
system/vl.c +5 -2
index 061cbdf860b..40c0593154a 100644
@@ -2961,7 +2961,10 @@ void qemu_init(int argc, char **argv)
                           HD_OPTS);
                 break;
             case QEMU_OPTION_blockdev:
-                {
+                if (is_help_option(optarg)) {
+                    blockdev_show_help();
+                    exit(EXIT_SUCCESS);
+                } else {
                     Visitor *v;
                     BlockdevOptionsQueueEntry *bdo;
 
@@ -2974,8 +2977,8 @@ void qemu_init(int argc, char **argv)
                     visit_free(v);
                     loc_save(&bdo->loc);
                     QSIMPLEQ_INSERT_TAIL(&bdo_queue, bdo, entry);
-                    break;
                 }
+                break;
             case QEMU_OPTION_drive:
                 if (!qemu_opts_parse_noisily(qemu_find_opts("drive"),
                                              optarg, false)) {
Signature · 1 line
2.55.0

Kevin

#3 lore raw
Quoted 23 lines · Kevin Wolf

Am 10.07.2026 um 11:36 hat Thomas Huth geschrieben:

Quoted 11 lines

From: Thomas Huth <[email protected]>

Other command line options like "-chardev", "-netdev" or "-device" already present the user with a list of available parameters, but when running "-blockdev help", there is currently only an error message. There is already the possibility to run "-drive format=help", but it does not seem to be documented, so this is not very useful for the average user. Let's improve this situation by providing the same list of available drivers when running QEMU with "-blockdev help".

Quoted 1 line

Seems like a good idea to print at least some minimal help there. However, I find the list from -drive format=help quite hard to read, and repeating the same list twice for read-write and read-only doesn't help either.

I don't expect we can change -drive because I seem to remember that management tools look at it, but can we make -blockdev help more consistent with the other examples you mention? Something like this:

Quoted 5 lines

Available blockdev drivers:
blkdebug
blklogwrites (read-only)
blkreplay
...

Yes, that's a good idea. I'll try to have a look at it.

Quoted 3 lines

Ideally, I'd also love to have a way to show all the options a specific driver offers, but that probably won't happen before Markus QAPIfies the CLI. :-)

This would be super helpful, indeed. It's really useful that we've already got this implemented for "-device xyz,help", would be very cool if we can finally also get this for -netdev (where it is also still missing) and -blockdev.

Thomas