[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH v2 6/6] qcow2: Add full image preallocation opti
From: |
Hu Tao |
Subject: |
[Qemu-devel] [RFC PATCH v2 6/6] qcow2: Add full image preallocation option |
Date: |
Wed, 27 Nov 2013 10:15:44 +0800 |
This adds a preallocation=full mode to qcow2 image creation, which
creates a non-sparse image file.
Signed-off-by: Hu Tao <address@hidden>
---
block/qcow2.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index a23fade..492c5e6 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1385,7 +1385,7 @@ static int qcow2_change_backing_file(BlockDriverState *bs,
return qcow2_update_header(bs);
}
-static int preallocate(BlockDriverState *bs)
+static int preallocate(BlockDriverState *bs, enum prealloc_mode mode)
{
uint64_t nb_sectors;
uint64_t offset;
@@ -1394,6 +1394,8 @@ static int preallocate(BlockDriverState *bs)
int ret;
QCowL2Meta *meta;
+ assert(mode != PREALLOC_OFF);
+
nb_sectors = bdrv_getlength(bs) >> 9;
offset = 0;
@@ -1424,6 +1426,13 @@ static int preallocate(BlockDriverState *bs)
offset += num << 9;
}
+ if (mode == PREALLOC_FULL) {
+ ret = bdrv_preallocate(bs->file, 0, bdrv_getlength(bs));
+ if (ret < 0) {
+ return ret;
+ }
+ }
+
/*
* It is expected that the image file is large enough to actually contain
* all of the allocated clusters (otherwise we get failing reads after
@@ -1572,11 +1581,11 @@ static int qcow2_create2(const char *filename, int64_t
total_size,
}
}
- /* And if we're supposed to preallocate metadata, do that now */
+ /* And if we're supposed to preallocate data, do that now */
if (prealloc) {
BDRVQcowState *s = bs->opaque;
qemu_co_mutex_lock(&s->lock);
- ret = preallocate(bs);
+ ret = preallocate(bs, prealloc);
qemu_co_mutex_unlock(&s->lock);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not preallocate metadata");
@@ -1632,6 +1641,8 @@ static int qcow2_create(const char *filename,
QEMUOptionParameter *options,
prealloc = PREALLOC_OFF;
} else if (!strcmp(options->value.s, "metadata")) {
prealloc = PREALLOC_METADATA;
+ } else if (!strcmp(options->value.s, "full")) {
+ prealloc = PREALLOC_FULL;
} else {
error_setg(errp, "Invalid preallocation mode: '%s'",
options->value.s);
@@ -2221,7 +2232,7 @@ static QEMUOptionParameter qcow2_create_options[] = {
{
.name = BLOCK_OPT_PREALLOC,
.type = OPT_STRING,
- .help = "Preallocation mode (allowed values: off, metadata)"
+ .help = "Preallocation mode (allowed values: off, metadata, full)"
},
{
.name = BLOCK_OPT_LAZY_REFCOUNTS,
--
1.8.3.1
- [Qemu-devel] [RFC PATCH v2 3/6] block/raw-posix: implement bdrv_preallocate, (continued)
- [Qemu-devel] [RFC PATCH v2 3/6] block/raw-posix: implement bdrv_preallocate, Hu Tao, 2013/11/26
- [Qemu-devel] [RFC PATCH v2 5/6] qcow2: implement bdrv_preallocate, Hu Tao, 2013/11/26
- Re: [Qemu-devel] [RFC PATCH v2 5/6] qcow2: implement bdrv_preallocate, Fam Zheng, 2013/11/26
- Re: [Qemu-devel] [RFC PATCH v2 5/6] qcow2: implement bdrv_preallocate, Hu Tao, 2013/11/27
- Re: [Qemu-devel] [RFC PATCH v2 5/6] qcow2: implement bdrv_preallocate, Fam Zheng, 2013/11/27
- Re: [Qemu-devel] [RFC PATCH v2 5/6] qcow2: implement bdrv_preallocate, Peter Lieven, 2013/11/27
- Re: [Qemu-devel] [RFC PATCH v2 5/6] qcow2: implement bdrv_preallocate, Fam Zheng, 2013/11/27
- Re: [Qemu-devel] [RFC PATCH v2 5/6] qcow2: implement bdrv_preallocate, Peter Lieven, 2013/11/27
[Qemu-devel] [RFC PATCH v2 4/6] raw-posix: Add full image preallocation option, Hu Tao, 2013/11/26
[Qemu-devel] [RFC PATCH v2 6/6] qcow2: Add full image preallocation option,
Hu Tao <=
Re: [Qemu-devel] [RFC PATCH v2 0/6] qemu-img: add preallocation=full, Fam Zheng, 2013/11/26