[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH for-2.10 13/16] block/qcow2: qcow2_calc_size_usa
From: |
Stefan Hajnoczi |
Subject: |
Re: [Qemu-devel] [PATCH for-2.10 13/16] block/qcow2: qcow2_calc_size_usage() for truncate |
Date: |
Mon, 20 Mar 2017 11:26:37 +0000 |
User-agent: |
Mutt/1.7.1 (2016-10-04) |
On Mon, Mar 13, 2017 at 10:41:14PM +0100, Max Reitz wrote:
> This patch extends qcow2_calc_size_usage() so it can calculate the
> additional space needed for preallocating image growth.
>
> Signed-off-by: Max Reitz <address@hidden>
> ---
> block/qcow2.c | 137
> +++++++++++++++++++++++++++++++++++++++++-----------------
> 1 file changed, 98 insertions(+), 39 deletions(-)
>
> diff --git a/block/qcow2.c b/block/qcow2.c
> index 21b2b3cd53..80fb815b15 100644
> --- a/block/qcow2.c
> +++ b/block/qcow2.c
> @@ -2101,7 +2101,15 @@ done:
> return ret;
> }
>
> -static uint64_t qcow2_calc_size_usage(uint64_t new_size,
> +/**
> + * Returns the number of bytes that must be allocated in the underlying file
> + * to accomodate an image growth from @current_size to @new_size.
> + *
> + * @current_size must be 0 when creating a new image. In that case, @bs is
> + * ignored; otherwise it must be valid.
> + */
> +static uint64_t qcow2_calc_size_usage(BlockDriverState *bs,
> + uint64_t current_size, uint64_t
> new_size,
> int cluster_bits, int refcount_order)
> {
> size_t cluster_size = 1u << cluster_bits;
> @@ -2122,47 +2130,97 @@ static uint64_t qcow2_calc_size_usage(uint64_t
> new_size,
> refblock_bits = cluster_bits - (refcount_order - 3);
> refblock_size = 1 << refblock_bits;
>
> - /* header: 1 cluster */
> - meta_size += cluster_size;
> -
> - /* total size of L2 tables */
> - nl2e = aligned_total_size / cluster_size;
> - nl2e = align_offset(nl2e, cluster_size / sizeof(uint64_t));
> - meta_size += nl2e * sizeof(uint64_t);
> + if (!current_size) {
This massive if statement effectively makes two functions: the old
qcow2_calc_size_usage() and the new qcow2_calc_size_change(bs) function.
It might be nicer to split the two functions.
signature.asc
Description: PGP signature
- [Qemu-devel] [PATCH for-2.10 09/16] block/qcow2: Generalize preallocate(), (continued)
- [Qemu-devel] [PATCH for-2.10 09/16] block/qcow2: Generalize preallocate(), Max Reitz, 2017/03/13
- [Qemu-devel] [PATCH for-2.10 10/16] block/qcow2: Lock s->lock in preallocate(), Max Reitz, 2017/03/13
- [Qemu-devel] [PATCH for-2.10 11/16] block/qcow2: Metadata preallocation for truncate, Max Reitz, 2017/03/13
- [Qemu-devel] [PATCH for-2.10 12/16] block/qcow2: Extract qcow2_calc_size_usage(), Max Reitz, 2017/03/13
- [Qemu-devel] [PATCH for-2.10 13/16] block/qcow2: qcow2_calc_size_usage() for truncate, Max Reitz, 2017/03/13
- Re: [Qemu-devel] [PATCH for-2.10 13/16] block/qcow2: qcow2_calc_size_usage() for truncate,
Stefan Hajnoczi <=
- [Qemu-devel] [PATCH for-2.10 14/16] block/qcow2: falloc/full preallocating growth, Max Reitz, 2017/03/13
[Qemu-devel] [PATCH for-2.10 15/16] iotests: Add preallocated resize test for raw, Max Reitz, 2017/03/13
[Qemu-devel] [PATCH for-2.10 16/16] iotests: Add preallocated growth test for qcow2, Max Reitz, 2017/03/13