Blame SOURCES/kvm-qemu-img-Add-print_amend_option_help.patch

357786
From dfc5e2a61a96cf4f727d2e7b4f41124933746f6d Mon Sep 17 00:00:00 2001
357786
From: Max Reitz <mreitz@redhat.com>
357786
Date: Mon, 18 Jun 2018 14:59:40 +0200
357786
Subject: [PATCH 06/89] qemu-img: Add print_amend_option_help()
357786
357786
RH-Author: Max Reitz <mreitz@redhat.com>
357786
Message-id: <20180618145943.4489-5-mreitz@redhat.com>
357786
Patchwork-id: 80753
357786
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 4/7] qemu-img: Add print_amend_option_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 more generic print_block_option_help() function is not really
357786
suitable for qemu-img amend, for a couple of reasons:
357786
(1) We do not need to append the protocol-level options, as amendment
357786
    happens only on one node and does not descend downwards to its
357786
    children.
357786
(2) print_block_option_help() says those options are "supported".  For
357786
    option amendment, we do not really know that.  So this new function
357786
    explicitly says that those options are the creation options, and not
357786
    all of them may be supported.
357786
(3) If the driver does not support option amendment, we should not print
357786
    anything (except for an error message that amendment is not
357786
    supported).
357786
357786
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1537956
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-5-mreitz@redhat.com
357786
Signed-off-by: Max Reitz <mreitz@redhat.com>
357786
(cherry picked from commit 51641351420e4f9dc6613d0dd03a5f0f214ed5b6)
357786
Signed-off-by: Max Reitz <mreitz@redhat.com>
357786
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
357786
---
357786
 qemu-img.c                 | 30 ++++++++++++++++++++++++++++--
357786
 tests/qemu-iotests/082.out | 44 +++++++++++++++++++++++++++-----------------
357786
 2 files changed, 55 insertions(+), 19 deletions(-)
357786
357786
diff --git a/qemu-img.c b/qemu-img.c
357786
index cdeb01b..d4cbb63 100644
357786
--- a/qemu-img.c
357786
+++ b/qemu-img.c
357786
@@ -3609,6 +3609,32 @@ static void amend_status_cb(BlockDriverState *bs,
357786
     qemu_progress_print(100.f * offset / total_work_size, 0);
357786
 }
357786
 
357786
+static int print_amend_option_help(const char *format)
357786
+{
357786
+    BlockDriver *drv;
357786
+
357786
+    /* Find driver and parse its options */
357786
+    drv = bdrv_find_format(format);
357786
+    if (!drv) {
357786
+        error_report("Unknown file format '%s'", format);
357786
+        return 1;
357786
+    }
357786
+
357786
+    if (!drv->bdrv_amend_options) {
357786
+        error_report("Format driver '%s' does not support option amendment",
357786
+                     format);
357786
+        return 1;
357786
+    }
357786
+
357786
+    /* Every driver supporting amendment must have create_opts */
357786
+    assert(drv->create_opts);
357786
+
357786
+    printf("Creation options for '%s':\n", format);
357786
+    qemu_opts_print_help(drv->create_opts);
357786
+    printf("\nNote that not all of these options may be amendable.\n");
357786
+    return 0;
357786
+}
357786
+
357786
 static int img_amend(int argc, char **argv)
357786
 {
357786
     Error *err = NULL;
357786
@@ -3708,7 +3734,7 @@ static int img_amend(int argc, char **argv)
357786
     if (fmt && has_help_option(options)) {
357786
         /* If a format is explicitly specified (and possibly no filename is
357786
          * given), print option help here */
357786
-        ret = print_block_option_help(filename, fmt);
357786
+        ret = print_amend_option_help(fmt);
357786
         goto out;
357786
     }
357786
 
357786
@@ -3737,7 +3763,7 @@ static int img_amend(int argc, char **argv)
357786
 
357786
     if (has_help_option(options)) {
357786
         /* If the format was auto-detected, print option help here */
357786
-        ret = print_block_option_help(filename, fmt);
357786
+        ret = print_amend_option_help(fmt);
357786
         goto out;
357786
     }
357786
 
357786
diff --git a/tests/qemu-iotests/082.out b/tests/qemu-iotests/082.out
357786
index 1527fbe..4e52dce 100644
357786
--- a/tests/qemu-iotests/082.out
357786
+++ b/tests/qemu-iotests/082.out
357786
@@ -546,7 +546,7 @@ cluster_size: 65536
357786
 === amend: help for -o ===
357786
 
357786
 Testing: amend -f qcow2 -o help TEST_DIR/t.qcow2
357786
-Supported options:
357786
+Creation options for 'qcow2':
357786
 size             Virtual disk size
357786
 compat           Compatibility level (0.10 or 1.1)
357786
 backing_file     File name of a base image
357786
@@ -564,10 +564,11 @@ cluster_size     qcow2 cluster size
357786
 preallocation    Preallocation mode (allowed values: off, metadata, falloc, full)
357786
 lazy_refcounts   Postpone refcount updates
357786
 refcount_bits    Width of a reference count entry in bits
357786
-nocow            Turn off copy-on-write (valid only on btrfs)
357786
+
357786
+Note that not all of these options may be amendable.
357786
 
357786
 Testing: amend -f qcow2 -o ? TEST_DIR/t.qcow2
357786
-Supported options:
357786
+Creation options for 'qcow2':
357786
 size             Virtual disk size
357786
 compat           Compatibility level (0.10 or 1.1)
357786
 backing_file     File name of a base image
357786
@@ -585,10 +586,11 @@ cluster_size     qcow2 cluster size
357786
 preallocation    Preallocation mode (allowed values: off, metadata, falloc, full)
357786
 lazy_refcounts   Postpone refcount updates
357786
 refcount_bits    Width of a reference count entry in bits
357786
-nocow            Turn off copy-on-write (valid only on btrfs)
357786
+
357786
+Note that not all of these options may be amendable.
357786
 
357786
 Testing: amend -f qcow2 -o cluster_size=4k,help TEST_DIR/t.qcow2
357786
-Supported options:
357786
+Creation options for 'qcow2':
357786
 size             Virtual disk size
357786
 compat           Compatibility level (0.10 or 1.1)
357786
 backing_file     File name of a base image
357786
@@ -606,10 +608,11 @@ cluster_size     qcow2 cluster size
357786
 preallocation    Preallocation mode (allowed values: off, metadata, falloc, full)
357786
 lazy_refcounts   Postpone refcount updates
357786
 refcount_bits    Width of a reference count entry in bits
357786
-nocow            Turn off copy-on-write (valid only on btrfs)
357786
+
357786
+Note that not all of these options may be amendable.
357786
 
357786
 Testing: amend -f qcow2 -o cluster_size=4k,? TEST_DIR/t.qcow2
357786
-Supported options:
357786
+Creation options for 'qcow2':
357786
 size             Virtual disk size
357786
 compat           Compatibility level (0.10 or 1.1)
357786
 backing_file     File name of a base image
357786
@@ -627,10 +630,11 @@ cluster_size     qcow2 cluster size
357786
 preallocation    Preallocation mode (allowed values: off, metadata, falloc, full)
357786
 lazy_refcounts   Postpone refcount updates
357786
 refcount_bits    Width of a reference count entry in bits
357786
-nocow            Turn off copy-on-write (valid only on btrfs)
357786
+
357786
+Note that not all of these options may be amendable.
357786
 
357786
 Testing: amend -f qcow2 -o help,cluster_size=4k TEST_DIR/t.qcow2
357786
-Supported options:
357786
+Creation options for 'qcow2':
357786
 size             Virtual disk size
357786
 compat           Compatibility level (0.10 or 1.1)
357786
 backing_file     File name of a base image
357786
@@ -648,10 +652,11 @@ cluster_size     qcow2 cluster size
357786
 preallocation    Preallocation mode (allowed values: off, metadata, falloc, full)
357786
 lazy_refcounts   Postpone refcount updates
357786
 refcount_bits    Width of a reference count entry in bits
357786
-nocow            Turn off copy-on-write (valid only on btrfs)
357786
+
357786
+Note that not all of these options may be amendable.
357786
 
357786
 Testing: amend -f qcow2 -o ?,cluster_size=4k TEST_DIR/t.qcow2
357786
-Supported options:
357786
+Creation options for 'qcow2':
357786
 size             Virtual disk size
357786
 compat           Compatibility level (0.10 or 1.1)
357786
 backing_file     File name of a base image
357786
@@ -669,10 +674,11 @@ cluster_size     qcow2 cluster size
357786
 preallocation    Preallocation mode (allowed values: off, metadata, falloc, full)
357786
 lazy_refcounts   Postpone refcount updates
357786
 refcount_bits    Width of a reference count entry in bits
357786
-nocow            Turn off copy-on-write (valid only on btrfs)
357786
+
357786
+Note that not all of these options may be amendable.
357786
 
357786
 Testing: amend -f qcow2 -o cluster_size=4k -o help TEST_DIR/t.qcow2
357786
-Supported options:
357786
+Creation options for 'qcow2':
357786
 size             Virtual disk size
357786
 compat           Compatibility level (0.10 or 1.1)
357786
 backing_file     File name of a base image
357786
@@ -690,10 +696,11 @@ cluster_size     qcow2 cluster size
357786
 preallocation    Preallocation mode (allowed values: off, metadata, falloc, full)
357786
 lazy_refcounts   Postpone refcount updates
357786
 refcount_bits    Width of a reference count entry in bits
357786
-nocow            Turn off copy-on-write (valid only on btrfs)
357786
+
357786
+Note that not all of these options may be amendable.
357786
 
357786
 Testing: amend -f qcow2 -o cluster_size=4k -o ? TEST_DIR/t.qcow2
357786
-Supported options:
357786
+Creation options for 'qcow2':
357786
 size             Virtual disk size
357786
 compat           Compatibility level (0.10 or 1.1)
357786
 backing_file     File name of a base image
357786
@@ -711,7 +718,8 @@ cluster_size     qcow2 cluster size
357786
 preallocation    Preallocation mode (allowed values: off, metadata, falloc, full)
357786
 lazy_refcounts   Postpone refcount updates
357786
 refcount_bits    Width of a reference count entry in bits
357786
-nocow            Turn off copy-on-write (valid only on btrfs)
357786
+
357786
+Note that not all of these options may be amendable.
357786
 
357786
 Testing: amend -f qcow2 -o backing_file=TEST_DIR/t.qcow2,,help TEST_DIR/t.qcow2
357786
 
357786
@@ -731,7 +739,7 @@ Testing: amend -f qcow2 -o backing_file=TEST_DIR/t.qcow2 -o ,, -o help TEST_DIR/
357786
 qemu-img: Invalid option list: ,,
357786
 
357786
 Testing: amend -f qcow2 -o help
357786
-Supported options:
357786
+Creation options for 'qcow2':
357786
 size             Virtual disk size
357786
 compat           Compatibility level (0.10 or 1.1)
357786
 backing_file     File name of a base image
357786
@@ -750,6 +758,8 @@ preallocation    Preallocation mode (allowed values: off, metadata, falloc, full
357786
 lazy_refcounts   Postpone refcount updates
357786
 refcount_bits    Width of a reference count entry in bits
357786
 
357786
+Note that not all of these options may be amendable.
357786
+
357786
 Testing: convert -o help
357786
 Supported options:
357786
 size             Virtual disk size
357786
-- 
357786
1.8.3.1
357786