[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v5 4/9] qcow2: Support BDRV_REQ_ZERO_WRITE for truncate
From: |
Max Reitz |
Subject: |
Re: [PATCH v5 4/9] qcow2: Support BDRV_REQ_ZERO_WRITE for truncate |
Date: |
Thu, 23 Apr 2020 12:53:15 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 |
On 22.04.20 17:21, Kevin Wolf wrote:
> If BDRV_REQ_ZERO_WRITE is set and we're extending the image, calling
> qcow2_cluster_zeroize() with flags=0 does the right thing: It doesn't
> undo any previous preallocation, but just adds the zero flag to all
> relevant L2 entries. If an external data file is in use, a write_zeroes
> request to the data file is made instead.
>
> Signed-off-by: Kevin Wolf <address@hidden>
> ---
> block/qcow2.c | 30 ++++++++++++++++++++++++++++++
> 1 file changed, 30 insertions(+)
>
> diff --git a/block/qcow2.c b/block/qcow2.c
> index 9cfbdfc939..bd632405d1 100644
> --- a/block/qcow2.c
> +++ b/block/qcow2.c
[...]
> @@ -4214,6 +4215,35 @@ static int coroutine_fn
> qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
> g_assert_not_reached();
> }
>
> + if ((flags & BDRV_REQ_ZERO_WRITE) && offset > old_length) {
> + uint64_t zero_start = QEMU_ALIGN_UP(old_length, s->cluster_size);
> + uint64_t zero_end = QEMU_ALIGN_UP(offset, s->cluster_size);
> +
> + /* Use zero clusters as much as we can */
> + ret = qcow2_cluster_zeroize(bs, zero_start, zero_end - zero_start,
> 0);
It’s kind of a pity that this changes the cluster mappings that were
established when using falloc/full preallocation already (i.e., they
become preallocated zero clusters then, so when writing to them, we need
COW again).
But falloc/full preallocation do not guarantee that the new data is
zero, so I suppose this is the only thing we can reasonably do.
I personally don’t really care about whether zero_end is aligned or not,
so either way:
Reviewed-by: Max Reitz <address@hidden>
signature.asc
Description: OpenPGP digital signature
- Re: [PATCH v5 3/9] block-backend: Add flags to blk_truncate(), (continued)
Re: [PATCH v5 4/9] qcow2: Support BDRV_REQ_ZERO_WRITE for truncate,
Max Reitz <=
[PATCH v5 5/9] raw-format: Support BDRV_REQ_ZERO_WRITE for truncate, Kevin Wolf, 2020/04/22
[PATCH v5 6/9] file-posix: Support BDRV_REQ_ZERO_WRITE for truncate, Kevin Wolf, 2020/04/22
[PATCH v5 9/9] iotests: Test committing to short backing file, Kevin Wolf, 2020/04/22
[PATCH v5 8/9] iotests: Filter testfiles out in filter_img_info(), Kevin Wolf, 2020/04/22