mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

Blame SOURCES/0223-v2v-oa-preallocated-for-qcow2-output-now-fully-alloc.patch

ffd6ed
From d82301351a501167389b839dda8b87ffbe40d2f5 Mon Sep 17 00:00:00 2001
ffd6ed
From: "Richard W.M. Jones" <rjones@redhat.com>
ffd6ed
Date: Wed, 12 Aug 2015 16:47:22 +0100
ffd6ed
Subject: [PATCH] v2v: -oa preallocated for qcow2 output now fully allocates
ffd6ed
 the file (RHBZ#1251909).
ffd6ed
ffd6ed
When the output format is qcow2 and -oa preallocated is used,
ffd6ed
previously it would only allocate the metadata.  That was a regression
ffd6ed
over previous behaviour of virt-v2v 0.9.  Change it so it allocates
ffd6ed
the full file size in this case.
ffd6ed
ffd6ed
(cherry picked from commit 42b6bb12dcbc5103044a9099d71f17a82009e7de)
ffd6ed
---
ffd6ed
 v2v/Makefile.am           |  1 +
ffd6ed
 v2v/test-v2v-oa-option.sh | 70 +++++++++++++++++++++++++++++++++++++++++++++++
ffd6ed
 v2v/v2v.ml                |  6 ++--
ffd6ed
 3 files changed, 73 insertions(+), 4 deletions(-)
ffd6ed
 create mode 100755 v2v/test-v2v-oa-option.sh
ffd6ed
ffd6ed
diff --git a/v2v/Makefile.am b/v2v/Makefile.am
ffd6ed
index 98e54de..87e3c3b 100644
ffd6ed
--- a/v2v/Makefile.am
ffd6ed
+++ b/v2v/Makefile.am
ffd6ed
@@ -242,6 +242,7 @@ TESTS += \
ffd6ed
 	test-v2v-o-qemu.sh \
ffd6ed
 	test-v2v-o-rhev.sh \
ffd6ed
 	test-v2v-o-vdsm-options.sh \
ffd6ed
+	test-v2v-oa-option.sh \
ffd6ed
 	test-v2v-of-option.sh \
ffd6ed
 	test-v2v-on-option.sh \
ffd6ed
 	test-v2v-print-source.sh \
ffd6ed
diff --git a/v2v/test-v2v-oa-option.sh b/v2v/test-v2v-oa-option.sh
ffd6ed
new file mode 100755
ffd6ed
index 0000000..c1a555a
ffd6ed
--- /dev/null
ffd6ed
+++ b/v2v/test-v2v-oa-option.sh
ffd6ed
@@ -0,0 +1,70 @@
ffd6ed
+#!/bin/bash -
ffd6ed
+# libguestfs virt-v2v test script
ffd6ed
+# Copyright (C) 2014-2015 Red Hat Inc.
ffd6ed
+#
ffd6ed
+# This program is free software; you can redistribute it and/or modify
ffd6ed
+# it under the terms of the GNU General Public License as published by
ffd6ed
+# the Free Software Foundation; either version 2 of the License, or
ffd6ed
+# (at your option) any later version.
ffd6ed
+#
ffd6ed
+# This program is distributed in the hope that it will be useful,
ffd6ed
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
ffd6ed
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ffd6ed
+# GNU General Public License for more details.
ffd6ed
+#
ffd6ed
+# You should have received a copy of the GNU General Public License
ffd6ed
+# along with this program; if not, write to the Free Software
ffd6ed
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
ffd6ed
+
ffd6ed
+# Test virt-v2v -oa (sparse/preallocated) option.
ffd6ed
+
ffd6ed
+unset CDPATH
ffd6ed
+export LANG=C
ffd6ed
+set -e
ffd6ed
+
ffd6ed
+if [ -n "$SKIP_TEST_V2V_OA_OPTION_SH" ]; then
ffd6ed
+    echo "$0: test skipped because environment variable is set"
ffd6ed
+    exit 77
ffd6ed
+fi
ffd6ed
+
ffd6ed
+if [ "$(guestfish get-backend)" = "uml" ]; then
ffd6ed
+    echo "$0: test skipped because UML backend does not support network or qcow2"
ffd6ed
+    exit 77
ffd6ed
+fi
ffd6ed
+
ffd6ed
+abs_top_builddir="$(cd ..; pwd)"
ffd6ed
+libvirt_uri="test://$abs_top_builddir/tests/guests/guests.xml"
ffd6ed
+
ffd6ed
+f=../tests/guests/windows.img
ffd6ed
+if ! test -f $f || ! test -s $f; then
ffd6ed
+    echo "$0: test skipped because phony Windows image was not created"
ffd6ed
+    exit 77
ffd6ed
+fi
ffd6ed
+
ffd6ed
+virt_tools_data_dir=${VIRT_TOOLS_DATA_DIR:-/usr/share/virt-tools}
ffd6ed
+if ! test -r $virt_tools_data_dir/rhsrvany.exe; then
ffd6ed
+    echo "$0: test skipped because rhsrvany.exe is not installed"
ffd6ed
+    exit 77
ffd6ed
+fi
ffd6ed
+
ffd6ed
+d=test-v2v-windows-conversion.d
ffd6ed
+rm -rf $d
ffd6ed
+mkdir $d
ffd6ed
+
ffd6ed
+$VG virt-v2v --debug-gc \
ffd6ed
+    -i libvirt -ic "$libvirt_uri" windows \
ffd6ed
+    -o local -os $d -oa preallocated -of qcow2
ffd6ed
+
ffd6ed
+# Test the disk is qcow2 format.
ffd6ed
+if [ "$(guestfish disk-format $d/windows-sda)" != qcow2 ]; then
ffd6ed
+    echo "$0: test failed: output is not qcow2"
ffd6ed
+    exit 1
ffd6ed
+fi
ffd6ed
+
ffd6ed
+# Test the disk is fully allocated.
ffd6ed
+if [ "$(du -m $d/windows-sda | awk '{print $1}')" -lt 500 ]; then
ffd6ed
+    echo "$0: test failed: output is not preallocated"
ffd6ed
+    exit 1
ffd6ed
+fi
ffd6ed
+
ffd6ed
+rm -r $d
ffd6ed
diff --git a/v2v/v2v.ml b/v2v/v2v.ml
ffd6ed
index c18039f..b79fd42 100644
ffd6ed
--- a/v2v/v2v.ml
ffd6ed
+++ b/v2v/v2v.ml
ffd6ed
@@ -370,10 +370,8 @@ let rec main () =
ffd6ed
           (* What output preallocation mode should we use? *)
ffd6ed
           let preallocation =
ffd6ed
             match t.target_format, output_alloc with
ffd6ed
-            | "raw", `Sparse -> Some "sparse"
ffd6ed
-            | "raw", `Preallocated -> Some "full"
ffd6ed
-            | "qcow2", `Sparse -> Some "off" (* ? *)
ffd6ed
-            | "qcow2", `Preallocated -> Some "metadata"
ffd6ed
+            | ("raw"|"qcow2"), `Sparse -> Some "sparse"
ffd6ed
+            | ("raw"|"qcow2"), `Preallocated -> Some "full"
ffd6ed
             | _ -> None (* ignore -oa flag for other formats *) in
ffd6ed
           let compat =
ffd6ed
             match t.target_format with "qcow2" -> Some "1.1" | _ -> None in
ffd6ed
-- 
ffd6ed
1.8.3.1
ffd6ed