[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 78/85] block/qcow2: Generalize preallocate()
From: |
Max Reitz |
Subject: |
[Qemu-block] [PULL 78/85] block/qcow2: Generalize preallocate() |
Date: |
Tue, 11 Jul 2017 18:08:07 +0200 |
This patch adds two new parameters to the preallocate() function so we
will be able to use it not just for preallocating a new image but also
for preallocated image growth.
The offset parameter allows the caller to specify a virtual offset from
which to start preallocating. For newly created images this is always 0,
but for preallocating growth this will be the old image length.
The new_length parameter specifies the supposed new length of the image
(basically the "end offset" for preallocation). During image truncation,
bdrv_getlength() will return the old image length so we cannot rely on
its return value then.
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
Message-id: address@hidden
Signed-off-by: Max Reitz <address@hidden>
---
block/qcow2.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index 0f44780..1ee8452 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2476,17 +2476,24 @@ static int qcow2_set_up_encryption(BlockDriverState
*bs, const char *encryptfmt,
}
-static int preallocate(BlockDriverState *bs)
+/**
+ * Preallocates metadata structures for data clusters between @offset (in the
+ * guest disk) and @new_length (which is thus generally the new guest disk
+ * size).
+ *
+ * Returns: 0 on success, -errno on failure.
+ */
+static int preallocate(BlockDriverState *bs,
+ uint64_t offset, uint64_t new_length)
{
uint64_t bytes;
- uint64_t offset;
uint64_t host_offset = 0;
unsigned int cur_bytes;
int ret;
QCowL2Meta *meta;
- bytes = bdrv_getlength(bs);
- offset = 0;
+ assert(offset <= new_length);
+ bytes = new_length - offset;
while (bytes) {
cur_bytes = MIN(bytes, INT_MAX);
@@ -2830,7 +2837,7 @@ static int qcow2_create2(const char *filename, int64_t
total_size,
if (prealloc != PREALLOC_MODE_OFF) {
BDRVQcow2State *s = blk_bs(blk)->opaque;
qemu_co_mutex_lock(&s->lock);
- ret = preallocate(blk_bs(blk));
+ ret = preallocate(blk_bs(blk), 0, total_size);
qemu_co_mutex_unlock(&s->lock);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not preallocate metadata");
--
2.9.4
- [Qemu-block] [PULL 67/85] qemu-img: add measure subcommand, (continued)
- [Qemu-block] [PULL 67/85] qemu-img: add measure subcommand, Max Reitz, 2017/07/11
- [Qemu-block] [PULL 70/85] block: Add PreallocMode to BD.bdrv_truncate(), Max Reitz, 2017/07/11
- [Qemu-block] [PULL 69/85] iotests: add test 178 for qemu-img measure, Max Reitz, 2017/07/11
- [Qemu-block] [PULL 71/85] block: Add PreallocMode to bdrv_truncate(), Max Reitz, 2017/07/11
- [Qemu-block] [PULL 72/85] block: Add PreallocMode to blk_truncate(), Max Reitz, 2017/07/11
- [Qemu-block] [PULL 73/85] qemu-img: Expose PreallocMode for resizing, Max Reitz, 2017/07/11
- [Qemu-block] [PULL 74/85] block/file-posix: Small fixes in raw_create(), Max Reitz, 2017/07/11
- [Qemu-block] [PULL 75/85] block/file-posix: Extract raw_regular_truncate(), Max Reitz, 2017/07/11
- [Qemu-block] [PULL 76/85] block/file-posix: Generalize raw_regular_truncate, Max Reitz, 2017/07/11
- [Qemu-block] [PULL 77/85] block/file-posix: Preallocation for truncate, Max Reitz, 2017/07/11
- [Qemu-block] [PULL 78/85] block/qcow2: Generalize preallocate(),
Max Reitz <=
- [Qemu-block] [PULL 79/85] block/qcow2: Lock s->lock in preallocate(), Max Reitz, 2017/07/11
- [Qemu-block] [PULL 80/85] block/qcow2: Metadata preallocation for truncate, Max Reitz, 2017/07/11
- [Qemu-block] [PULL 81/85] block/qcow2: Add qcow2_refcount_area(), Max Reitz, 2017/07/11
- [Qemu-block] [PULL 82/85] block/qcow2: Rename "fail_block" to just "fail", Max Reitz, 2017/07/11
- [Qemu-block] [PULL 83/85] block/qcow2: falloc/full preallocating growth, Max Reitz, 2017/07/11
- [Qemu-block] [PULL 84/85] iotests: Add preallocated resize test for raw, Max Reitz, 2017/07/11
- [Qemu-block] [PULL 85/85] iotests: Add preallocated growth test for qcow2, Max Reitz, 2017/07/11
- Re: [Qemu-block] [Qemu-devel] [PULL 00/85] Block layer patches, Peter Maydell, 2017/07/13