[ovirt-users] Problem with backing-file, how to fix the backing-chain ?

Adam Litke alitke at redhat.com
Wed Oct 19 14:55:23 UTC 2016


On 19/10/16 14:43 +0200, Claudio Soprano wrote:
>Hi Adam, we tried your solution.
>
>This is our situation with the current VM that has 2 disks
>
>base -> snap1 -> snap2 -> snap3 -> snap4 -> snap5 -> .. -> snap15 for 
>each disk
>
>We tried to do
>
>qemu-img rebase -u -b base snap1
>
>results OK
>
>qemu-img rebase -u -b snap1 snap2
>
>results:
>
>qemu-img: Could not open 'snap2': Backing file name too long
>
>our qemu version is
>
>qemu-img version 2.3.0 (qemu-kvm-ev-2.3.0-31.el7.16.1), Copyright (c) 
>2004-2008 Fabrice Bellard
>
>How do you think can we resolve ?

I talked with the qemu developers about this issue and the best way to
fix this is by using a patched version of qemu-img that ignores
invalid backing_file values when doing an unsafe rebase.  Here is what
you will need to do to fix your images.

1. Save the attached patch
2. Grab a copy of the latest qemu.git
3. Apply the patch to the source
4. Install qemu build dependencies
5. Build qemu
6. Run the built version of qemu-img when fixing your chain as I
   suggested above:

        ./qemu-img rebase -u -b snap1 snap2

The patch disables other qemu-img functionality since you should not
be using this for anything but the rebase part.  After the rebase you
can use the system qemu-img binary to check the image.  Please try
this on one VM disk and make sure everything is okay.

-- 
Adam Litke
-------------- next part --------------
diff --git a/block/qcow2.c b/block/qcow2.c
index 0e53a4d..f8f388f 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1118,9 +1118,8 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
         len = header.backing_file_size;
         if (len > MIN(1023, s->cluster_size - header.backing_file_offset) ||
             len >= sizeof(bs->backing_file)) {
-            error_setg(errp, "Backing file name too long");
-            ret = -EINVAL;
-            goto fail;
+            error_report("Backing file too long... truncating for unsafe rebase\n");
+            len = 1023;
         }
         ret = bdrv_pread(bs->file, header.backing_file_offset,
                          bs->backing_file, len);
diff --git a/qemu-img.c b/qemu-img.c
index 02c07b9..69de2e6 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -2879,6 +2879,9 @@ static int img_rebase(int argc, char **argv)
         }
     }
 
+    if (unsafe != 1)
+        error_exit("This version of qemu-img only supports unsafe rebase (-u)\n");
+
     if (quiet) {
         progress = 0;
     }
@@ -4217,6 +4220,13 @@ int main(int argc, char **argv)
     trace_init_file(trace_file);
     qemu_set_log(LOG_TRACE);
 
+    error_report("WARNING: This is a modified qemu-img to be used for fixing images\n"
+                 "with backing files that are too long.  Do NOT use for any other\n"
+                 "purpose.\n");
+
+    if (strcmp(cmdname, "rebase"))
+        error_exit("This patched version of qemu-img only supports 'rebase'");
+
     /* find the command */
     for (cmd = img_cmds; cmd->name != NULL; cmd++) {
         if (!strcmp(cmdname, cmd->name)) {


More information about the Users mailing list