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

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