qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v3 2/2] Consider discard option when writing zeros


From: Stefan Hajnoczi
Subject: Re: [PATCH v3 2/2] Consider discard option when writing zeros
Date: Thu, 11 Jul 2024 11:05:52 +0200

On Fri, Jun 28, 2024 at 11:20:58PM +0300, Nir Soffer wrote:
> When opening an image with discard=off, we punch hole in the image when
> writing zeroes, making the image sparse. This breaks users that want to
> ensure that writes cannot fail with ENOSPACE by using fully allocated
> images[1].
> 
> bdrv_co_pwrite_zeroes() correctly disables BDRV_REQ_MAY_UNMAP if we
> opened the child without discard=unmap or discard=on. But we don't go
> through this function when accessing the top node. Move the check down
> to bdrv_co_do_pwrite_zeroes() which seems to be used in all code paths.
> 
> This change implements the documented behavior, punching holes only when
> opening the image with discard=on or discard=unmap. This may not be the
> best default but can improve it later.
> 
> The test depends on a file system supporting discard, deallocating the
> entire file when punching hole with the length of the entire file.
> Tested with xfs, ext4, and tmpfs.
> 
> [1] https://lists.nongnu.org/archive/html/qemu-discuss/2024-06/msg00003.html
> 
> Signed-off-by: Nir Soffer <nsoffer@redhat.com>
> ---
>  block/io.c                                    |   9 +-
>  tests/qemu-iotests/tests/write-zeroes-unmap   | 127 ++++++++++++++++++
>  .../qemu-iotests/tests/write-zeroes-unmap.out |  81 +++++++++++
>  3 files changed, 213 insertions(+), 4 deletions(-)
>  create mode 100755 tests/qemu-iotests/tests/write-zeroes-unmap
>  create mode 100644 tests/qemu-iotests/tests/write-zeroes-unmap.out

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]