[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: |
Eric Blake |
Subject: |
Re: [PATCH v5 4/9] qcow2: Support BDRV_REQ_ZERO_WRITE for truncate |
Date: |
Wed, 22 Apr 2020 10:33:25 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 |
On 4/22/20 10:21 AM, 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(+)
@@ -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);
This rounds up beyond the new size...
+
+ /* Use zero clusters as much as we can */
+ ret = qcow2_cluster_zeroize(bs, zero_start, zero_end - zero_start, 0);
and then requests that the extra be zeroed. Does that always work, even
when it results in pdrv_co_pwrite_zeroes beyond the end of s->data_file?
If so,
Reviewed-by: Eric Blake <address@hidden>
otherwise, you may have to treat the tail specially, the same way you
treated an unaligned head.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
Re: [PATCH v5 4/9] qcow2: Support BDRV_REQ_ZERO_WRITE for truncate, Max Reitz, 2020/04/23