Skip to contentSkip to conversation

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

PATCH Applied Thomas Huth 3 participants 5 messages Sep 14 – Oct 30

lore
Share & tools
lore
#0 lore raw

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

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. Thus let's improve this situation by providing a proper list of available drivers when running QEMU with "-blockdev help".

---
v2: Don't re-use the code from "-drive format=help" and print the
help in a better readable way instead

 include/block/block-common.h |  1 +
 block.c                      | 15 +++++++++++++++
 system/vl.c                  |  7 +++++--
 3 files changed, 21 insertions(+), 2 deletions(-)
include/block/block-common.h +1 -0
index 895ea175413..c76a72c1220 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 bdrv_show_help(void);
 
 #endif /* BLOCK_COMMON_H */
block.c +15 -0
index f0a6042e616..895d6db5acf 100644
@@ -524,6 +524,21 @@ bool bdrv_uses_whitelist(void)
     return use_bdrv_whitelist;
 }
 
+static void bdrv_help_format_print(void *opaque, const char *name)
+{
+    if (bdrv_format_is_whitelisted(name, false)) {
+        printf("%s\n", name);
+    } else {
+        printf("%s (read-only)\n", name);
+    }
+}
+
+void bdrv_show_help(void)
+{
+      printf("Available blockdev drivers:\n");
+      bdrv_iterate_format(bdrv_help_format_print, NULL, true);
+}
+
 typedef struct CreateCo {
     BlockDriver *drv;
     char *filename;
system/vl.c +5 -2
index 9bd7664b85c..dc93e8737cb 100644
@@ -2960,7 +2960,10 @@ void qemu_init(int argc, char **argv)
                           HD_OPTS);
                 break;
             case QEMU_OPTION_blockdev:
-                {
+                if (is_help_option(optarg)) {
+                    bdrv_show_help();
+                    exit(EXIT_SUCCESS);
+                } else {
                     Visitor *v;
                     BlockdevOptionsQueueEntry *bdo;
 
@@ -2973,8 +2976,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
#1 lore raw
Quoted 9 lines · Thomas Huth

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. Thus let's improve this situation by providing a proper list of available drivers when running QEMU with "-blockdev help".

Quoted 4 lines

---
v2: Don't re-use the code from "-drive format=help" and print the
help in a better readable way instead

Ping?

Quoted 68 lines
  include/block/block-common.h |  1 +
  block.c                      | 15 +++++++++++++++
  system/vl.c                  |  7 +++++--
  3 files changed, 21 insertions(+), 2 deletions(-)
include/block/block-common.h +1 -0
index 895ea175413..c76a72c1220 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 bdrv_show_help(void);
 
  #endif /* BLOCK_COMMON_H */
block.c +15 -0
index f0a6042e616..895d6db5acf 100644
@@ -524,6 +524,21 @@ bool bdrv_uses_whitelist(void)
      return use_bdrv_whitelist;
  }
 
+static void bdrv_help_format_print(void *opaque, const char *name)
+{
+    if (bdrv_format_is_whitelisted(name, false)) {
+        printf("%s\n", name);
+    } else {
+        printf("%s (read-only)\n", name);
+    }
+}
+
+void bdrv_show_help(void)
+{
+      printf("Available blockdev drivers:\n");
+      bdrv_iterate_format(bdrv_help_format_print, NULL, true);
+}
+
  typedef struct CreateCo {
      BlockDriver *drv;
      char *filename;
system/vl.c +5 -2
index 9bd7664b85c..dc93e8737cb 100644
@@ -2960,7 +2960,10 @@ void qemu_init(int argc, char **argv)
                            HD_OPTS);
                  break;
              case QEMU_OPTION_blockdev:
-                {
+                if (is_help_option(optarg)) {
+                    bdrv_show_help();
+                    exit(EXIT_SUCCESS);
+                } else {
                      Visitor *v;
                      BlockdevOptionsQueueEntry *bdo;
 
@@ -2973,8 +2976,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)) {
Reviewed-by Tested-by on v2 1/1
#2 lore raw
In reply to Thomas Huth
Quoted 9 lines · Thomas Huth

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. Thus let's improve this situation by providing a proper list of available drivers when running QEMU with "-blockdev help".

Quoted 4 lines

---
v2: Don't re-use the code from "-drive format=help" and print the
help in a better readable way instead

One format per line rather than space-separated does seem a bit more machine-parseable, although the output no longer fits in my preferred terminal size without scrolling. I guess "more readable" is subjective ;)

Quoted 5 lines
 include/block/block-common.h |  1 +
 block.c                      | 15 +++++++++++++++
 system/vl.c                  |  7 +++++--
 3 files changed, 21 insertions(+), 2 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org
#3 lore raw
Quoted 15 lines · Eric Blake
Quoted 9 lines · Thomas Huth

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. Thus let's improve this situation by providing a proper list of available drivers when running QEMU with "-blockdev help".

Quoted 4 lines

---
v2: Don't re-use the code from "-drive format=help" and print the
help in a better readable way instead

Quoted 4 lines

One format per line rather than space-separated does seem a bit more machine-parseable, although the output no longer fits in my preferred terminal size without scrolling. I guess "more readable" is subjective ;)

That said, we aren't very consistent; "-chardev help" indents each line by two, while "-netdev help" and this patch for "-blockdev help" does not indent. May be worth a followup patch.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org
Applied
#4 lore raw
In reply to Thomas Huth

Am 14.09.2026 um 11:00 hat Thomas Huth geschrieben:

Quoted 10 lines

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. Thus let's improve this situation by providing a proper list of available drivers when running QEMU with "-blockdev help".

Thanks, applied to the block branch.

Kevin