Currently, qemu-img 'amend' subcommand would fail to adjust image's backing file
which was moved into different path.
For example, parent.qcow2, the backing file of leaf.qcow2, first is at /home/a/,
then moved into /home/b/. Originally this command,
 "qemu-img amend -f qcow2 -o 
backing_fmt=qcow2,backing_file=/home/b/parent.qcow2 leaf.qcow2",
 would fail because qemu-img failed to open the old backing file of leaf.qcow2.
Give the 'amend' subcommand a '-u' option to not open the old backing file
 while openning leaf.qcow2.

Signed-off-by: Li Ping<li.ping...@zte.com.cn>
---
 qemu-img.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index b220cf7..a32e9d6 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -145,9 +145,10 @@ static void QEMU_NORETURN help(void)
            "  'snapshot_id_or_name' is deprecated, use 'snapshot_param'\n"
            "    instead\n"
            "  '-c' indicates that target image must be compressed (qcow format 
only)\n"
-           "  '-u' enables unsafe rebasing. It is assumed that old and new 
backing file\n"
-           "       match exactly. The image doesn't need a working backing 
file before\n"
-           "       rebasing in this case (useful for renaming the backing 
file)\n"
+           "  '-u' enables unsafe rebasing or amending. It is assumed that old 
and new\n"
+           "       backing file match exactly. For rebasing, the image doesn't 
need a working\n"
+           "       backing file before rebasing in this case(useful for 
renaming the backing file).\n"
+           "       For amending, it doesn't open backing file(useful for 
moving images)\n"
            "  '-h' with or without a command shows this help and lists the 
supported formats\n"
            "  '-p' show progress of command (only certain commands)\n"
            "  '-q' use Quiet mode - do not print any output (except errors)\n"
@@ -3538,7 +3539,7 @@ static int img_amend(int argc, char **argv)
     QemuOptsList *create_opts = NULL;
     QemuOpts *opts = NULL;
     const char *fmt = NULL, *filename, *cache;
-    int flags;
+    int flags = 0;
     bool writethrough;
     bool quiet = false, progress = false;
     BlockBackend *blk = NULL;
@@ -3553,7 +3554,7 @@ static int img_amend(int argc, char **argv)
             {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
             {0, 0, 0, 0}
         };
-        c = getopt_long(argc, argv, ":ho:f:t:pq",
+        c = getopt_long(argc, argv, ":ho:f:t:pqu",
                         long_options, NULL);
         if (c == -1) {
             break;
@@ -3595,6 +3596,9 @@ static int img_amend(int argc, char **argv)
         case 'q':
             quiet = true;
             break;
+        case 'u':
+            flags |= BDRV_O_NO_BACKING;
+            break;
         case OPTION_OBJECT:
             opts = qemu_opts_parse_noisily(&qemu_object_opts,
                                            optarg, true);
@@ -3639,7 +3643,7 @@ static int img_amend(int argc, char **argv)
         goto out;
     }
 
-    flags = BDRV_O_RDWR;
+    flags |= BDRV_O_RDWR;
     ret = bdrv_parse_cache_mode(cache, &flags, &writethrough);
     if (ret < 0) {
         error_report("Invalid cache option: %s", cache);
-- 
1.8.3.1



Reply via email to