qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v2 2/2] qemu-img: Allow cache mode specification for


From: Max Reitz
Subject: [Qemu-devel] [PATCH v2 2/2] qemu-img: Allow cache mode specification for amend
Date: Tue, 22 Jul 2014 22:58:43 +0200

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 <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
 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 48df0b8..55aec6b 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
address@hidden amend [-q] [-f @var{fmt}] -o @var{options} @var{filename}
address@hidden 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 9f3909c..ef74ae4 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -2738,12 +2738,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, "ho:f:t:q");
         if (c == -1) {
             break;
         }
@@ -2770,6 +2772,9 @@ static int img_amend(int argc, char **argv)
             case 'f':
                 fmt = optarg;
                 break;
+            case 't':
+                cache = optarg;
+                break;
             case 'q':
                 quiet = true;
                 break;
@@ -2792,8 +2797,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.
 
address@hidden amend [-f @var{fmt}] -o @var{options} @var{filename}
address@hidden 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]