[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH for-2.10 09/16] block/qcow2: Generalize preallocate(
From: |
Max Reitz |
Subject: |
[Qemu-block] [PATCH for-2.10 09/16] block/qcow2: Generalize preallocate() |
Date: |
Mon, 13 Mar 2017 22:40:38 +0100 |
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>
---
block/qcow2.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index 210646b60f..9abdf9e0fb 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2034,17 +2034,16 @@ static int qcow2_change_backing_file(BlockDriverState
*bs,
return qcow2_update_header(bs);
}
-static int preallocate(BlockDriverState *bs)
+static int preallocate(BlockDriverState *bs, int64_t offset, int64_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);
@@ -2313,7 +2312,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.12.0
- Re: [Qemu-block] [Qemu-devel] [PATCH for-2.10 04/16] qemu-img: Expose PreallocMode for resizing, (continued)
- [Qemu-block] [PATCH for-2.10 05/16] block/file-posix: Small fixes in raw_create(), Max Reitz, 2017/03/13
- [Qemu-block] [PATCH for-2.10 06/16] block/file-posix: Extract raw_regular_truncate(), Max Reitz, 2017/03/13
- [Qemu-block] [PATCH for-2.10 07/16] block/file-posix: Generalize raw_regular_truncate, Max Reitz, 2017/03/13
- [Qemu-block] [PATCH for-2.10 08/16] block/file-posix: Preallocation for truncate, Max Reitz, 2017/03/13
- [Qemu-block] [PATCH for-2.10 09/16] block/qcow2: Generalize preallocate(),
Max Reitz <=
- [Qemu-block] [PATCH for-2.10 10/16] block/qcow2: Lock s->lock in preallocate(), Max Reitz, 2017/03/13
- [Qemu-block] [PATCH for-2.10 11/16] block/qcow2: Metadata preallocation for truncate, Max Reitz, 2017/03/13
- [Qemu-block] [PATCH for-2.10 12/16] block/qcow2: Extract qcow2_calc_size_usage(), Max Reitz, 2017/03/13
- [Qemu-block] [PATCH for-2.10 13/16] block/qcow2: qcow2_calc_size_usage() for truncate, Max Reitz, 2017/03/13