Blame SOURCES/kvm-qemu-img-Allow-cache-mode-specification-for-amend.patch

958e1b
From bb18c8167f4b3a912e57ca4185e9e58d4d3a149b Mon Sep 17 00:00:00 2001
958e1b
From: Max Reitz <mreitz@redhat.com>
958e1b
Date: Fri, 24 Oct 2014 08:17:58 +0200
958e1b
Subject: [PATCH 10/19] qemu-img: Allow cache mode specification for amend
958e1b
958e1b
Message-id: <1414138680-19600-3-git-send-email-mreitz@redhat.com>
958e1b
Patchwork-id: 61863
958e1b
O-Subject: [RHEL-7.1 qemu-kvm PATCH v2 2/4] qemu-img: Allow cache mode specification for amend
958e1b
Bugzilla: 1138691
958e1b
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
958e1b
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
958e1b
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
958e1b
958e1b
qemu-img amend may extensively modify the target image, depending on the
958e1b
options to be amended (e.g. conversion to qcow2 compat level 0.10 from
958e1b
1.1 for an image with many unallocated zero clusters). Therefore it
958e1b
makes sense to allow the user to specify the cache mode to be used.
958e1b
958e1b
Signed-off-by: Max Reitz <mreitz@redhat.com>
958e1b
Reviewed-by: Eric Blake <eblake@redhat.com>
958e1b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
958e1b
(cherry picked from commit bd39e6ed0b88a1473c652c97e731a156cccf16e2)
958e1b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
958e1b
958e1b
Conflicts:
958e1b
	qemu-img.c
958e1b
958e1b
QemuOpts are not used throughout the downstream block layer.
958e1b
958e1b
Signed-off-by: Max Reitz <mreitz@redhat.com>
958e1b
---
958e1b
 qemu-img-cmds.hx |  4 ++--
958e1b
 qemu-img.c       | 19 +++++++++++++++----
958e1b
 qemu-img.texi    |  2 +-
958e1b
 3 files changed, 18 insertions(+), 7 deletions(-)
958e1b
958e1b
diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
958e1b
index e590d46..5efdfe9 100644
958e1b
--- a/qemu-img-cmds.hx
958e1b
+++ b/qemu-img-cmds.hx
958e1b
@@ -70,8 +70,8 @@ STEXI
958e1b
 ETEXI
958e1b
 
958e1b
 DEF("amend", img_amend,
958e1b
-    "amend [-q] [-f fmt] -o options filename")
958e1b
+    "amend [-q] [-f fmt] [-t cache] -o options filename")
958e1b
 STEXI
958e1b
-@item amend [-q] [-f @var{fmt}] -o @var{options} @var{filename}
958e1b
+@item amend [-q] [-f @var{fmt}] [-t @var{cache}] -o @var{options} @var{filename}
958e1b
 @end table
958e1b
 ETEXI
958e1b
diff --git a/qemu-img.c b/qemu-img.c
958e1b
index 25fdc37..1f28729 100644
958e1b
--- a/qemu-img.c
958e1b
+++ b/qemu-img.c
958e1b
@@ -2659,12 +2659,14 @@ static int img_amend(int argc, char **argv)
958e1b
     int c, ret = 0;
958e1b
     char *options = NULL;
958e1b
     QEMUOptionParameter *create_options = NULL, *options_param = NULL;
958e1b
-    const char *fmt = NULL, *filename;
958e1b
+    const char *fmt = NULL, *filename, *cache;
958e1b
+    int flags;
958e1b
     bool quiet = false;
958e1b
     BlockDriverState *bs = NULL;
958e1b
 
958e1b
+    cache = BDRV_DEFAULT_CACHE;
958e1b
     for (;;) {
958e1b
-        c = getopt(argc, argv, "hqf:o:");
958e1b
+        c = getopt(argc, argv, "ho:f:t:q");
958e1b
         if (c == -1) {
958e1b
             break;
958e1b
         }
958e1b
@@ -2691,6 +2693,9 @@ static int img_amend(int argc, char **argv)
958e1b
             case 'f':
958e1b
                 fmt = optarg;
958e1b
                 break;
958e1b
+            case 't':
958e1b
+                cache = optarg;
958e1b
+                break;
958e1b
             case 'q':
958e1b
                 quiet = true;
958e1b
                 break;
958e1b
@@ -2713,8 +2718,14 @@ static int img_amend(int argc, char **argv)
958e1b
         help();
958e1b
     }
958e1b
 
958e1b
-    bs = bdrv_new_open("image", filename, fmt,
958e1b
-                       BDRV_O_FLAGS | BDRV_O_RDWR, true, quiet);
958e1b
+    flags = BDRV_O_FLAGS | BDRV_O_RDWR;
958e1b
+    ret = bdrv_parse_cache_flags(cache, &flags);
958e1b
+    if (ret < 0) {
958e1b
+        error_report("Invalid cache option: %s", cache);
958e1b
+        goto out;
958e1b
+    }
958e1b
+
958e1b
+    bs = bdrv_new_open("image", filename, fmt, flags, true, quiet);
958e1b
     if (!bs) {
958e1b
         error_report("Could not open image '%s'", filename);
958e1b
         ret = -1;
958e1b
diff --git a/qemu-img.texi b/qemu-img.texi
958e1b
index 3d06e91..078fe81 100644
958e1b
--- a/qemu-img.texi
958e1b
+++ b/qemu-img.texi
958e1b
@@ -370,7 +370,7 @@ After using this command to grow a disk image, you must use file system and
958e1b
 partitioning tools inside the VM to actually begin using the new space on the
958e1b
 device.
958e1b
 
958e1b
-@item amend [-f @var{fmt}] -o @var{options} @var{filename}
958e1b
+@item amend [-f @var{fmt}] [-t @var{cache}] -o @var{options} @var{filename}
958e1b
 
958e1b
 Amends the image format specific @var{options} for the image file
958e1b
 @var{filename}. Not all file formats support this operation.
958e1b
-- 
958e1b
1.8.3.1
958e1b