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