Richard W.M. Jones
2015-Aug-12 15:57 UTC
[Libguestfs] [PATCH 1/2] disk-create: Allow preallocation off/metadata/full.
For raw, this allows "off" as a synonym for "sparse" (to
make it
consistent with qcow2).
For qcow2, this allows "sparse" as a synonym for "off".
It also adds qcow2 "full" preallocation, which is actually mapped to
the qemu option "falloc" (see arguments about this on the qemu-devel
mailing list, which we lost).
This also updates the test.
---
generator/actions.ml | 13 +++++++------
src/create.c | 16 ++++++++++++----
tests/create/test-disk-create.sh | 3 +++
3 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/generator/actions.ml b/generator/actions.ml
index d0d6a21..1c22f9f 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -3174,13 +3174,14 @@ The other optional parameters are:
=item C<preallocation>
-If format is C<raw>, then this can be either C<sparse> or
C<full>
-to create a sparse or fully allocated file respectively. The default
-is C<sparse>.
+If format is C<raw>, then this can be either C<off> (or
C<sparse>)
+or C<full> to create a sparse or fully allocated file respectively.
+The default is C<off>.
-If format is C<qcow2>, then this can be either C<off> or
-C<metadata>. Preallocating metadata can be faster when doing lots
-of writes, but uses more space. The default is C<off>.
+If format is C<qcow2>, then this can be C<off> (or
C<sparse>),
+C<metadata> or C<full>. Preallocating metadata can be faster
+when doing lots of writes, but uses more space.
+The default is C<off>.
=item C<compat>
diff --git a/src/create.c b/src/create.c
index 46bee7c..e9bac95 100644
--- a/src/create.c
+++ b/src/create.c
@@ -1,5 +1,5 @@
/* libguestfs
- * Copyright (C) 2012 Red Hat Inc.
+ * Copyright (C) 2012-2015 Red Hat Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -140,7 +140,8 @@ disk_create_raw (guestfs_h *g, const char *filename, int64_t
size,
return -1;
}
if (optargs->bitmask & GUESTFS_DISK_CREATE_PREALLOCATION_BITMASK) {
- if (STREQ (optargs->preallocation, "sparse"))
+ if (STREQ (optargs->preallocation, "off") ||
+ STREQ (optargs->preallocation, "sparse"))
allocated = 0;
else if (STREQ (optargs->preallocation, "full"))
allocated = 1;
@@ -273,8 +274,15 @@ disk_create_qcow2 (guestfs_h *g, const char *orig_filename,
int64_t size,
}
}
if (optargs->bitmask & GUESTFS_DISK_CREATE_PREALLOCATION_BITMASK) {
- preallocation = optargs->preallocation;
- if (STRNEQ (preallocation, "off") && STRNEQ
(preallocation, "metadata")) {
+ if (STREQ (optargs->preallocation, "off") ||
+ STREQ (optargs->preallocation, "sparse"))
+ preallocation = "off";
+ else if (STREQ (optargs->preallocation, "metadata"))
+ preallocation = "metadata";
+ else if (STREQ (optargs->preallocation, "full"))
+ /* Ugh:
https://lists.gnu.org/archive/html/qemu-devel/2014-08/msg03863.html */
+ preallocation = "falloc";
+ else {
error (g, _("invalid value for preallocation parameter
'%s'"),
preallocation);
return -1;
diff --git a/tests/create/test-disk-create.sh b/tests/create/test-disk-create.sh
index 93dc706..e18d6da 100755
--- a/tests/create/test-disk-create.sh
+++ b/tests/create/test-disk-create.sh
@@ -27,11 +27,14 @@ rm -f disk*.img file:*.img
guestfish <<EOF
disk-create disk1.img raw 256K
+ disk-create disk2.img raw 256K preallocation:off
disk-create disk2.img raw 256K preallocation:sparse
disk-create disk3.img raw 256K preallocation:full
disk-create disk4.img qcow2 256K
disk-create disk5.img qcow2 256K preallocation:off
+ disk-create disk5.img qcow2 256K preallocation:sparse
disk-create disk6.img qcow2 256K preallocation:metadata
+ disk-create disk6.img qcow2 256K preallocation:full
disk-create disk7.img qcow2 256K compat:1.1
disk-create disk8.img qcow2 256K clustersize:128K
disk-create disk9.img qcow2 -1 backingfile:disk1.img compat:1.1
--
2.5.0
Richard W.M. Jones
2015-Aug-12 15:57 UTC
[Libguestfs] [PATCH 2/2] v2v: -oa preallocated for qcow2 output now fully allocates the file (RHBZ#1251909).
When the output format is qcow2 and -oa preallocated is used,
previously it would only allocate the metadata. That was a regression
over previous behaviour of virt-v2v 0.9. Change it so it allocates
the full file size in this case.
---
v2v/Makefile.am | 1 +
v2v/test-v2v-oa-option.sh | 70 +++++++++++++++++++++++++++++++++++++++++++++++
v2v/v2v.ml | 6 ++--
3 files changed, 73 insertions(+), 4 deletions(-)
create mode 100755 v2v/test-v2v-oa-option.sh
diff --git a/v2v/Makefile.am b/v2v/Makefile.am
index e957a15..93d225b 100644
--- a/v2v/Makefile.am
+++ b/v2v/Makefile.am
@@ -241,6 +241,7 @@ TESTS += \
test-v2v-o-qemu.sh \
test-v2v-o-rhev.sh \
test-v2v-o-vdsm-options.sh \
+ test-v2v-oa-option.sh \
test-v2v-of-option.sh \
test-v2v-on-option.sh \
test-v2v-print-source.sh \
diff --git a/v2v/test-v2v-oa-option.sh b/v2v/test-v2v-oa-option.sh
new file mode 100755
index 0000000..c1a555a
--- /dev/null
+++ b/v2v/test-v2v-oa-option.sh
@@ -0,0 +1,70 @@
+#!/bin/bash -
+# libguestfs virt-v2v test script
+# Copyright (C) 2014-2015 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+# Test virt-v2v -oa (sparse/preallocated) option.
+
+unset CDPATH
+export LANG=C
+set -e
+
+if [ -n "$SKIP_TEST_V2V_OA_OPTION_SH" ]; then
+ echo "$0: test skipped because environment variable is set"
+ exit 77
+fi
+
+if [ "$(guestfish get-backend)" = "uml" ]; then
+ echo "$0: test skipped because UML backend does not support network or
qcow2"
+ exit 77
+fi
+
+abs_top_builddir="$(cd ..; pwd)"
+libvirt_uri="test://$abs_top_builddir/tests/guests/guests.xml"
+
+f=../tests/guests/windows.img
+if ! test -f $f || ! test -s $f; then
+ echo "$0: test skipped because phony Windows image was not
created"
+ exit 77
+fi
+
+virt_tools_data_dir=${VIRT_TOOLS_DATA_DIR:-/usr/share/virt-tools}
+if ! test -r $virt_tools_data_dir/rhsrvany.exe; then
+ echo "$0: test skipped because rhsrvany.exe is not installed"
+ exit 77
+fi
+
+d=test-v2v-windows-conversion.d
+rm -rf $d
+mkdir $d
+
+$VG virt-v2v --debug-gc \
+ -i libvirt -ic "$libvirt_uri" windows \
+ -o local -os $d -oa preallocated -of qcow2
+
+# Test the disk is qcow2 format.
+if [ "$(guestfish disk-format $d/windows-sda)" != qcow2 ]; then
+ echo "$0: test failed: output is not qcow2"
+ exit 1
+fi
+
+# Test the disk is fully allocated.
+if [ "$(du -m $d/windows-sda | awk '{print $1}')" -lt 500 ];
then
+ echo "$0: test failed: output is not preallocated"
+ exit 1
+fi
+
+rm -r $d
diff --git a/v2v/v2v.ml b/v2v/v2v.ml
index 242f129..4c41ed5 100644
--- a/v2v/v2v.ml
+++ b/v2v/v2v.ml
@@ -378,10 +378,8 @@ let rec main () (* What output preallocation
mode should we use? *)
let preallocation match t.target_format, output_alloc
with
- | "raw", Sparse -> Some "sparse"
- | "raw", Preallocated -> Some "full"
- | "qcow2", Sparse -> Some "off" (* ? *)
- | "qcow2", Preallocated -> Some "metadata"
+ | ("raw"|"qcow2"), Sparse -> Some
"sparse"
+ | ("raw"|"qcow2"), Preallocated -> Some
"full"
| _ -> None (* ignore -oa flag for other formats *) in
let compat match t.target_format with "qcow2"
-> Some "1.1" | _ -> None in
--
2.5.0
Reasonably Related Threads
- [PATCH v2v] v2v: Allow output to block devices (RHBZ#1868690).
- [PATCH v3 07/13] v2v: factor out copying of output data
- Re: [PATCH v2v] v2v: Allow output to block devices (RHBZ#1868690).
- preallocation=full Vs preallocation=metadata
- [PATCH] v2v: -o null: Force output format to be raw sparse.