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

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