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

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