Currently the 'allocation' element is not used when creating new images
with qemu-img. This patch interprets a non-zero value as a request to
preallocate metadata when a qcow2 image is created.
Bug:
https://bugzilla.redhat.com/show_bug.cgi?id=684793
---
src/storage/storage_backend.c | 19 +++++++++++++------
1 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 41a19a1..bf6f7cc 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -669,10 +669,15 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
int imgformat = -1;
virCommandPtr cmd = NULL;
bool do_encryption = (vol->target.encryption != NULL);
+ bool preallocate = false;
unsigned long long int size_arg;
virCheckFlags(0, -1);
+ /* qcow2: preallocate metadata if requested allocation is non-zero */
+ if (vol->allocation > 0 && vol->target.format ==
VIR_STORAGE_FILE_QCOW2)
+ preallocate = true;
+
const char *type = virStorageFileFormatTypeToString(vol->target.format);
const char *backingType = vol->backingStore.path ?
virStorageFileFormatTypeToString(vol->backingStore.format) : NULL;
@@ -842,12 +847,14 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
vol->target.path, NULL);
virCommandAddArgFormat(cmd, "%lluK", size_arg);
- if (do_encryption) {
- if (imgformat == QEMU_IMG_BACKING_FORMAT_OPTIONS) {
- virCommandAddArgList(cmd, "-o", "encryption=on",
NULL);
- } else {
- virCommandAddArg(cmd, "-e");
- }
+ if (imgformat == QEMU_IMG_BACKING_FORMAT_OPTIONS &&
+ (do_encryption || preallocate)) {
+ virCommandAddArg(cmd, "-o");
+ virCommandAddArgFormat(cmd, "%s%s%s", do_encryption ?
"encryption=on" : "",
+ (do_encryption && preallocate) ? ","
: "",
+ preallocate ? "preallocation=metadata" :
"");
+ } else if (do_encryption){
+ virCommandAddArg(cmd, "-e");
}
}
--
1.7.8.6