|
|
ffd6ed |
From bd0016617d064694d8d2a8cd4e05fceb6788dd50 Mon Sep 17 00:00:00 2001
|
|
|
ffd6ed |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
ffd6ed |
Date: Wed, 12 Aug 2015 16:34:16 +0100
|
|
|
ffd6ed |
Subject: [PATCH] disk-create: Allow preallocation off/metadata/full.
|
|
|
ffd6ed |
|
|
|
ffd6ed |
For raw, this allows "off" as a synonym for "sparse" (to make it
|
|
|
ffd6ed |
consistent with qcow2).
|
|
|
ffd6ed |
|
|
|
ffd6ed |
For qcow2, this allows "sparse" as a synonym for "off".
|
|
|
ffd6ed |
|
|
|
ffd6ed |
It also adds qcow2 "full" preallocation, which is actually mapped to
|
|
|
ffd6ed |
the qemu option "falloc" (see arguments about this on the qemu-devel
|
|
|
ffd6ed |
mailing list, which we lost).
|
|
|
ffd6ed |
|
|
|
ffd6ed |
This also updates the test.
|
|
|
ffd6ed |
|
|
|
ffd6ed |
(cherry picked from commit 66daad38f37c8975c4b6bcb760094cf4490fef14)
|
|
|
ffd6ed |
---
|
|
|
ffd6ed |
generator/actions.ml | 13 +++++++------
|
|
|
ffd6ed |
src/create.c | 16 ++++++++++++----
|
|
|
ffd6ed |
tests/create/test-disk-create.sh | 3 +++
|
|
|
ffd6ed |
3 files changed, 22 insertions(+), 10 deletions(-)
|
|
|
ffd6ed |
|
|
|
ffd6ed |
diff --git a/generator/actions.ml b/generator/actions.ml
|
|
|
ffd6ed |
index ca0208b..397b532 100644
|
|
|
ffd6ed |
--- a/generator/actions.ml
|
|
|
ffd6ed |
+++ b/generator/actions.ml
|
|
|
ffd6ed |
@@ -3109,13 +3109,14 @@ The other optional parameters are:
|
|
|
ffd6ed |
|
|
|
ffd6ed |
=item C<preallocation>
|
|
|
ffd6ed |
|
|
|
ffd6ed |
-If format is C<raw>, then this can be either C<sparse> or C<full>
|
|
|
ffd6ed |
-to create a sparse or fully allocated file respectively. The default
|
|
|
ffd6ed |
-is C<sparse>.
|
|
|
ffd6ed |
+If format is C<raw>, then this can be either C<off> (or C<sparse>)
|
|
|
ffd6ed |
+or C<full> to create a sparse or fully allocated file respectively.
|
|
|
ffd6ed |
+The default is C<off>.
|
|
|
ffd6ed |
|
|
|
ffd6ed |
-If format is C<qcow2>, then this can be either C<off> or
|
|
|
ffd6ed |
-C<metadata>. Preallocating metadata can be faster when doing lots
|
|
|
ffd6ed |
-of writes, but uses more space. The default is C<off>.
|
|
|
ffd6ed |
+If format is C<qcow2>, then this can be C<off> (or C<sparse>),
|
|
|
ffd6ed |
+C<metadata> or C<full>. Preallocating metadata can be faster
|
|
|
ffd6ed |
+when doing lots of writes, but uses more space.
|
|
|
ffd6ed |
+The default is C<off>.
|
|
|
ffd6ed |
|
|
|
ffd6ed |
=item C<compat>
|
|
|
ffd6ed |
|
|
|
ffd6ed |
diff --git a/src/create.c b/src/create.c
|
|
|
ffd6ed |
index 4e619c0..35a80a4 100644
|
|
|
ffd6ed |
--- a/src/create.c
|
|
|
ffd6ed |
+++ b/src/create.c
|
|
|
ffd6ed |
@@ -1,5 +1,5 @@
|
|
|
ffd6ed |
/* libguestfs
|
|
|
ffd6ed |
- * Copyright (C) 2012 Red Hat Inc.
|
|
|
ffd6ed |
+ * Copyright (C) 2012-2015 Red Hat Inc.
|
|
|
ffd6ed |
*
|
|
|
ffd6ed |
* This library is free software; you can redistribute it and/or
|
|
|
ffd6ed |
* modify it under the terms of the GNU Lesser General Public
|
|
|
ffd6ed |
@@ -139,7 +139,8 @@ disk_create_raw (guestfs_h *g, const char *filename, int64_t size,
|
|
|
ffd6ed |
return -1;
|
|
|
ffd6ed |
}
|
|
|
ffd6ed |
if (optargs->bitmask & GUESTFS_DISK_CREATE_PREALLOCATION_BITMASK) {
|
|
|
ffd6ed |
- if (STREQ (optargs->preallocation, "sparse"))
|
|
|
ffd6ed |
+ if (STREQ (optargs->preallocation, "off") ||
|
|
|
ffd6ed |
+ STREQ (optargs->preallocation, "sparse"))
|
|
|
ffd6ed |
allocated = 0;
|
|
|
ffd6ed |
else if (STREQ (optargs->preallocation, "full"))
|
|
|
ffd6ed |
allocated = 1;
|
|
|
ffd6ed |
@@ -267,8 +268,15 @@ disk_create_qcow2 (guestfs_h *g, const char *orig_filename, int64_t size,
|
|
|
ffd6ed |
}
|
|
|
ffd6ed |
}
|
|
|
ffd6ed |
if (optargs->bitmask & GUESTFS_DISK_CREATE_PREALLOCATION_BITMASK) {
|
|
|
ffd6ed |
- preallocation = optargs->preallocation;
|
|
|
ffd6ed |
- if (STRNEQ (preallocation, "off") && STRNEQ (preallocation, "metadata")) {
|
|
|
ffd6ed |
+ if (STREQ (optargs->preallocation, "off") ||
|
|
|
ffd6ed |
+ STREQ (optargs->preallocation, "sparse"))
|
|
|
ffd6ed |
+ preallocation = "off";
|
|
|
ffd6ed |
+ else if (STREQ (optargs->preallocation, "metadata"))
|
|
|
ffd6ed |
+ preallocation = "metadata";
|
|
|
ffd6ed |
+ else if (STREQ (optargs->preallocation, "full"))
|
|
|
ffd6ed |
+ /* Ugh: https://lists.gnu.org/archive/html/qemu-devel/2014-08/msg03863.html */
|
|
|
ffd6ed |
+ preallocation = "falloc";
|
|
|
ffd6ed |
+ else {
|
|
|
ffd6ed |
error (g, _("invalid value for preallocation parameter '%s'"),
|
|
|
ffd6ed |
preallocation);
|
|
|
ffd6ed |
return -1;
|
|
|
ffd6ed |
diff --git a/tests/create/test-disk-create.sh b/tests/create/test-disk-create.sh
|
|
|
ffd6ed |
index 93dc706..e18d6da 100755
|
|
|
ffd6ed |
--- a/tests/create/test-disk-create.sh
|
|
|
ffd6ed |
+++ b/tests/create/test-disk-create.sh
|
|
|
ffd6ed |
@@ -27,11 +27,14 @@ rm -f disk*.img file:*.img
|
|
|
ffd6ed |
|
|
|
ffd6ed |
guestfish <
|
|
|
ffd6ed |
disk-create disk1.img raw 256K
|
|
|
ffd6ed |
+ disk-create disk2.img raw 256K preallocation:off
|
|
|
ffd6ed |
disk-create disk2.img raw 256K preallocation:sparse
|
|
|
ffd6ed |
disk-create disk3.img raw 256K preallocation:full
|
|
|
ffd6ed |
disk-create disk4.img qcow2 256K
|
|
|
ffd6ed |
disk-create disk5.img qcow2 256K preallocation:off
|
|
|
ffd6ed |
+ disk-create disk5.img qcow2 256K preallocation:sparse
|
|
|
ffd6ed |
disk-create disk6.img qcow2 256K preallocation:metadata
|
|
|
ffd6ed |
+ disk-create disk6.img qcow2 256K preallocation:full
|
|
|
ffd6ed |
disk-create disk7.img qcow2 256K compat:1.1
|
|
|
ffd6ed |
disk-create disk8.img qcow2 256K clustersize:128K
|
|
|
ffd6ed |
disk-create disk9.img qcow2 -1 backingfile:disk1.img compat:1.1
|
|
|
ffd6ed |
--
|
|
|
ffd6ed |
1.8.3.1
|
|
|
ffd6ed |
|