[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 for-2.10 11/16] block/qcow2: Metadata preallocati
From: |
Max Reitz |
Subject: |
[Qemu-devel] [PATCH v2 for-2.10 11/16] block/qcow2: Metadata preallocation for truncate |
Date: |
Mon, 3 Apr 2017 18:09:31 +0200 |
We can support PREALLOC_MODE_METADATA by invoking preallocate() in
qcow2_truncate().
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
---
block/qcow2.c | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index f665cd21dc..bb0bd5561c 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2539,10 +2539,11 @@ static int qcow2_truncate(BlockDriverState *bs, int64_t
offset,
PreallocMode prealloc, Error **errp)
{
BDRVQcow2State *s = bs->opaque;
+ uint64_t old_length;
int64_t new_l1_size;
int ret;
- if (prealloc != PREALLOC_MODE_OFF) {
+ if (prealloc != PREALLOC_MODE_OFF && prealloc != PREALLOC_MODE_METADATA) {
error_setg(errp, "Unsupported preallocation mode '%s'",
PreallocMode_lookup[prealloc]);
return -ENOTSUP;
@@ -2559,8 +2560,10 @@ static int qcow2_truncate(BlockDriverState *bs, int64_t
offset,
return -ENOTSUP;
}
+ old_length = bs->total_sectors * 512;
+
/* shrinking is currently not supported */
- if (offset < bs->total_sectors * 512) {
+ if (offset < old_length) {
error_setg(errp, "qcow2 doesn't support shrinking images yet");
return -ENOTSUP;
}
@@ -2572,6 +2575,23 @@ static int qcow2_truncate(BlockDriverState *bs, int64_t
offset,
return ret;
}
+ switch (prealloc) {
+ case PREALLOC_MODE_OFF:
+ break;
+
+ case PREALLOC_MODE_METADATA:
+ ret = preallocate(bs, old_length, offset);
+ if (ret < 0) {
+ error_setg_errno(errp, -ret, "Preallocation failed, image may now "
+ "occupy more space than necessary");
+ return ret;
+ }
+ break;
+
+ default:
+ g_assert_not_reached();
+ }
+
/* write updated header.size */
offset = cpu_to_be64(offset);
ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, size),
--
2.12.1
- [Qemu-devel] [PATCH v2 for-2.10 06/16] block/file-posix: Extract raw_regular_truncate(), (continued)
- [Qemu-devel] [PATCH v2 for-2.10 06/16] block/file-posix: Extract raw_regular_truncate(), Max Reitz, 2017/04/03
- [Qemu-devel] [PATCH v2 for-2.10 07/16] block/file-posix: Generalize raw_regular_truncate, Max Reitz, 2017/04/03
- [Qemu-devel] [PATCH v2 for-2.10 09/16] block/qcow2: Generalize preallocate(), Max Reitz, 2017/04/03
- [Qemu-devel] [PATCH v2 for-2.10 10/16] block/qcow2: Lock s->lock in preallocate(), Max Reitz, 2017/04/03
- [Qemu-devel] [PATCH v2 for-2.10 11/16] block/qcow2: Metadata preallocation for truncate,
Max Reitz <=
- [Qemu-devel] [PATCH v2 for-2.10 12/16] block/qcow2: Extract qcow2_calc_size_usage(), Max Reitz, 2017/04/03
- [Qemu-devel] [PATCH v2 for-2.10 13/16] block/qcow2: qcow2_calc_size_usage() for truncate, Max Reitz, 2017/04/03
- [Qemu-devel] [PATCH v2 for-2.10 14/16] block/qcow2: falloc/full preallocating growth, Max Reitz, 2017/04/03
- [Qemu-devel] [PATCH v2 for-2.10 15/16] iotests: Add preallocated resize test for raw, Max Reitz, 2017/04/03
- [Qemu-devel] [PATCH v2 for-2.10 16/16] iotests: Add preallocated growth test for qcow2, Max Reitz, 2017/04/03