thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

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

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