Blame SOURCES/kvm-qemu-img-Recognize-no-creation-support-in-o-help.patch

357786
From 7fafbdbc3b764038e30ec184edb1ec2207c86218 Mon Sep 17 00:00:00 2001
357786
From: Max Reitz <mreitz@redhat.com>
357786
Date: Mon, 18 Jun 2018 14:59:41 +0200
357786
Subject: [PATCH 07/89] qemu-img: Recognize no creation support in -o help
357786
357786
RH-Author: Max Reitz <mreitz@redhat.com>
357786
Message-id: <20180618145943.4489-6-mreitz@redhat.com>
357786
Patchwork-id: 80759
357786
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 5/7] qemu-img: Recognize no creation support in -o help
357786
Bugzilla: 1537956
357786
RH-Acked-by: John Snow <jsnow@redhat.com>
357786
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
357786
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
357786
357786
The only users of print_block_option_help() are qemu-img create and
357786
qemu-img convert for the output image, so this function is always used
357786
for image creation (it used to be used for amendment also, but that is
357786
no longer the case).
357786
357786
So if image creation is not supported by either the format or the
357786
protocol, there is no need to print any option description, because the
357786
user cannot create an image like this anyway.
357786
357786
This also fixes an assertion failure:
357786
357786
    $ qemu-img create -f bochs -o help
357786
    Supported options:
357786
    qemu-img: util/qemu-option.c:219:
357786
    qemu_opts_print_help: Assertion `list' failed.
357786
    [1]    24831 abort (core dumped)  qemu-img create -f bochs -o help
357786
357786
Signed-off-by: Max Reitz <mreitz@redhat.com>
357786
Reviewed-by: John Snow <jsnow@redhat.com>
357786
Reviewed-by: Eric Blake <eblake@redhat.com>
357786
Message-id: 20180509210023.20283-6-mreitz@redhat.com
357786
Signed-off-by: Max Reitz <mreitz@redhat.com>
357786
(cherry picked from commit d402b6a21a825a5c07aac9251990860723d49f5d)
357786
Signed-off-by: Max Reitz <mreitz@redhat.com>
357786
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
357786
---
357786
 qemu-img.c | 10 ++++++++++
357786
 1 file changed, 10 insertions(+)
357786
357786
diff --git a/qemu-img.c b/qemu-img.c
357786
index d4cbb63..4bcf157 100644
357786
--- a/qemu-img.c
357786
+++ b/qemu-img.c
357786
@@ -250,6 +250,11 @@ static int print_block_option_help(const char *filename, const char *fmt)
357786
         return 1;
357786
     }
357786
 
357786
+    if (!drv->create_opts) {
357786
+        error_report("Format driver '%s' does not support image creation", fmt);
357786
+        return 1;
357786
+    }
357786
+
357786
     create_opts = qemu_opts_append(create_opts, drv->create_opts);
357786
     if (filename) {
357786
         proto_drv = bdrv_find_protocol(filename, true, &local_err);
357786
@@ -258,6 +263,11 @@ static int print_block_option_help(const char *filename, const char *fmt)
357786
             qemu_opts_free(create_opts);
357786
             return 1;
357786
         }
357786
+        if (!proto_drv->create_opts) {
357786
+            error_report("Protocal driver '%s' does not support image creation",
357786
+                         proto_drv->format_name);
357786
+            return 1;
357786
+        }
357786
         create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
357786
     }
357786
 
357786
-- 
357786
1.8.3.1
357786