From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41066) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X8bMY-0001BU-WA for qemu-devel@nongnu.org; Sat, 19 Jul 2014 16:36:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X8bMS-0001iG-La for qemu-devel@nongnu.org; Sat, 19 Jul 2014 16:36:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20562) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X8bMS-0001iB-Dw for qemu-devel@nongnu.org; Sat, 19 Jul 2014 16:36:04 -0400 From: Max Reitz Date: Sat, 19 Jul 2014 22:35:59 +0200 Message-Id: <1405802159-2355-3-git-send-email-mreitz@redhat.com> In-Reply-To: <1405802159-2355-1-git-send-email-mreitz@redhat.com> References: <1405802159-2355-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH 2/2] qemu-img: Allow cache mode specification for amend List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Peter Lieven , Stefan Hajnoczi , Max Reitz 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 --- 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 5613628..20a21ff 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 845b8c7..df6cb46 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2773,12 +2773,14 @@ static int img_amend(int argc, char **argv) char *options = NULL; QemuOptsList *create_opts = NULL; QemuOpts *opts = 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, "hqf:t:o:"); if (c == -1) { break; } @@ -2805,6 +2807,9 @@ static int img_amend(int argc, char **argv) case 'f': fmt = optarg; break; + case 't': + cache = optarg; + break; case 'q': quiet = true; break; @@ -2827,8 +2832,14 @@ static int img_amend(int argc, char **argv) error_exit("Expecting one image file name"); } - 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 688b28d..cb68948 100644 --- a/qemu-img.texi +++ b/qemu-img.texi @@ -397,7 +397,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. -- 2.0.1