[Pkg-libvirt-commits] [libguestfs] 245/266: v2v: Add some defensive code to test for the broken qcow2 overlay bug.

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:42:51 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag debian/1%1.27.35-1
in repository libguestfs.

commit 9fb2b82dbe32463858c7116d129d48c528729088
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Mon Sep 1 12:21:51 2014 +0100

    v2v: Add some defensive code to test for the broken qcow2 overlay bug.
    
    In commit 53e0d3ea5fc703066f0eb92a49eaf8be18961e7e I fixed a cause of
    disk corruption in the overlay file during conversion.
    
    To ensure this doesn't occur again unexpectedly, add a simple test to
    the virt-v2v code and to the tests.
---
 v2v/test-v2v-real-conversions.sh | 11 +++++++++++
 v2v/v2v.ml                       | 17 ++++++++++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/v2v/test-v2v-real-conversions.sh b/v2v/test-v2v-real-conversions.sh
index 6a246b0..9c1c281 100755
--- a/v2v/test-v2v-real-conversions.sh
+++ b/v2v/test-v2v-real-conversions.sh
@@ -65,6 +65,17 @@ EOF
       # Test the libvirt XML metadata and a disk was created.
       test -f $d/$n.xml
       test -f $d/$n-sda
+
+      # Test the disk has a similar size to the original.
+      size_before="$(du $file | awk '{print $1}')"
+      size_after="$(du $d/$n-sda | awk '{print $1}')"
+      diff="$(( 100 * size_after / size_before ))"
+      if test $diff -lt 50; then
+          echo "$0: disk image may have been corrupted or truncated"
+          echo "size_before=$size_before size_after=$size_after diff=$diff"
+          ls -l $file $d/$n-sda
+          exit 1
+      fi
     fi
 done
 
diff --git a/v2v/v2v.ml b/v2v/v2v.ml
index a4f20b3..4d3f6ae 100644
--- a/v2v/v2v.ml
+++ b/v2v/v2v.ml
@@ -109,6 +109,11 @@ let rec main () =
         if verbose then printf "%s\n%!" cmd;
         if Sys.command cmd <> 0 then
           error (f_"qemu-img command failed, see earlier errors");
+
+        (* Sanity check created overlay (see below). *)
+        if not ((new G.guestfs ())#disk_has_backing_file overlay_file) then
+          error (f_"internal error: qemu-img did not create overlay with backing file");
+
         overlay_file, source
     ) source.s_disks in
 
@@ -224,6 +229,16 @@ let rec main () =
           (i+1) nr_disks t.target_file t.target_format;
         if verbose then printf "%s%!" (string_of_target t);
 
+        (* We noticed that qemu sometimes corrupts the qcow2 file on
+         * exit.  This only seemed to happen with lazy_refcounts was
+         * used.  The symptom was that the header wasn't written back
+         * to the disk correctly and the file appeared to have no
+         * backing file.  Just sanity check this here.
+         *)
+        let overlay_file = t.target_overlay.ov_overlay_file in
+        if not ((new G.guestfs ())#disk_has_backing_file overlay_file) then
+          error (f_"internal error: qemu corrupted the overlay file");
+
         (* It turns out that libguestfs's disk creation code is
          * considerably more flexible and easier to use than qemu-img, so
          * create the disk explicitly using libguestfs then pass the
@@ -246,7 +261,7 @@ let rec main () =
         let cmd =
           sprintf "qemu-img convert%s -n -f qcow2 -O %s %s %s"
             (if not quiet then " -p" else "")
-            (quote t.target_format) (quote t.target_overlay.ov_overlay_file)
+            (quote t.target_format) (quote overlay_file)
             (quote t.target_file) in
         if verbose then printf "%s\n%!" cmd;
         if Sys.command cmd <> 0 then

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list