[PATCH v2 0/3] block: use pwrite_zeroes_alignment when writing first sector

Stefan Hajnoczi posted 3 patches 4 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20251007141700.71891-1-stefanha@redhat.com
Maintainers: Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>
include/system/block-backend-io.h             |  1 +
block.c                                       |  3 +-
block/block-backend.c                         | 11 ++++
block/file-posix.c                            | 16 +++++
tests/qemu-iotests/tests/loop-create-file     | 59 +++++++++++++++++++
tests/qemu-iotests/tests/loop-create-file.out |  8 +++
6 files changed, 97 insertions(+), 1 deletion(-)
create mode 100755 tests/qemu-iotests/tests/loop-create-file
create mode 100644 tests/qemu-iotests/tests/loop-create-file.out
[PATCH v2 0/3] block: use pwrite_zeroes_alignment when writing first sector
Posted by Stefan Hajnoczi 4 months ago
v2:
- Simplify condition to if (!s->needs_alignment) in patch 1 [Vladimir]

This series fixes a bug I introduced in commit 5634622bcb33 ("file-posix: allow
BLKZEROOUT with -t writeback"). The Linux fallocate(2) and ioctl(BLKZEROOUT)
syscalls require logical block size alignment of the offset and length, even
when the file is opened in buffered I/O mode where read/write operations do not
require alignment.

The fix is to populate the pwrite_zeroes_alignment block limits field and to
use that limit in create_file_fallback_zero_first_sector().

One issue I want to raise is that pwrite_zeroes_alignment is an "optimal
alignment" hint. Hence create_file_fallback_zero_first_sector() had to be
modified to honor the limit explicitly. The block layer doesn't automatically
apply padding in order to align requests. This is different from how QEMU's
block layer pwrite/pread works, where it does automatically apply padding and
read/modify/write as necessary. If you want consistency, please let me know.

Stefan Hajnoczi (3):
  file-posix: populate pwrite_zeroes_alignment
  block: use pwrite_zeroes_alignment when writing first sector
  iotests: add Linux loop device image creation test

 include/system/block-backend-io.h             |  1 +
 block.c                                       |  3 +-
 block/block-backend.c                         | 11 ++++
 block/file-posix.c                            | 16 +++++
 tests/qemu-iotests/tests/loop-create-file     | 59 +++++++++++++++++++
 tests/qemu-iotests/tests/loop-create-file.out |  8 +++
 6 files changed, 97 insertions(+), 1 deletion(-)
 create mode 100755 tests/qemu-iotests/tests/loop-create-file
 create mode 100644 tests/qemu-iotests/tests/loop-create-file.out

-- 
2.51.0
Re: [PATCH v2 0/3] block: use pwrite_zeroes_alignment when writing first sector
Posted by Kevin Wolf 2 months, 2 weeks ago
Am 07.10.2025 um 16:16 hat Stefan Hajnoczi geschrieben:
> v2:
> - Simplify condition to if (!s->needs_alignment) in patch 1 [Vladimir]
> 
> This series fixes a bug I introduced in commit 5634622bcb33 ("file-posix: allow
> BLKZEROOUT with -t writeback"). The Linux fallocate(2) and ioctl(BLKZEROOUT)
> syscalls require logical block size alignment of the offset and length, even
> when the file is opened in buffered I/O mode where read/write operations do not
> require alignment.
> 
> The fix is to populate the pwrite_zeroes_alignment block limits field and to
> use that limit in create_file_fallback_zero_first_sector().
> 
> One issue I want to raise is that pwrite_zeroes_alignment is an "optimal
> alignment" hint. Hence create_file_fallback_zero_first_sector() had to be
> modified to honor the limit explicitly. The block layer doesn't automatically
> apply padding in order to align requests. This is different from how QEMU's
> block layer pwrite/pread works, where it does automatically apply padding and
> read/modify/write as necessary. If you want consistency, please let me know.

Thanks, applied to the block branch.

Kevin
Re: [PATCH v2 0/3] block: use pwrite_zeroes_alignment when writing first sector
Posted by Fiona Ebner 2 months, 2 weeks ago
Am 07.10.25 um 6:07 PM schrieb Stefan Hajnoczi:
> v2:
> - Simplify condition to if (!s->needs_alignment) in patch 1 [Vladimir]
> 
> This series fixes a bug I introduced in commit 5634622bcb33 ("file-posix: allow
> BLKZEROOUT with -t writeback"). The Linux fallocate(2) and ioctl(BLKZEROOUT)
> syscalls require logical block size alignment of the offset and length, even
> when the file is opened in buffered I/O mode where read/write operations do not
> require alignment.
> 
> The fix is to populate the pwrite_zeroes_alignment block limits field and to
> use that limit in create_file_fallback_zero_first_sector().
> 
> One issue I want to raise is that pwrite_zeroes_alignment is an "optimal
> alignment" hint. Hence create_file_fallback_zero_first_sector() had to be
> modified to honor the limit explicitly. The block layer doesn't automatically
> apply padding in order to align requests. This is different from how QEMU's
> block layer pwrite/pread works, where it does automatically apply padding and
> read/modify/write as necessary. If you want consistency, please let me know.
> 
> Stefan Hajnoczi (3):
>   file-posix: populate pwrite_zeroes_alignment
>   block: use pwrite_zeroes_alignment when writing first sector
>   iotests: add Linux loop device image creation test
> 
>  include/system/block-backend-io.h             |  1 +
>  block.c                                       |  3 +-
>  block/block-backend.c                         | 11 ++++
>  block/file-posix.c                            | 16 +++++
>  tests/qemu-iotests/tests/loop-create-file     | 59 +++++++++++++++++++
>  tests/qemu-iotests/tests/loop-create-file.out |  8 +++
>  6 files changed, 97 insertions(+), 1 deletion(-)
>  create mode 100755 tests/qemu-iotests/tests/loop-create-file
>  create mode 100644 tests/qemu-iotests/tests/loop-create-file.out
> 

Thank you for the fix!

Tested-by: Fiona Ebner <f.ebner@proxmox.com>
Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
Re: [PATCH v2 0/3] block: use pwrite_zeroes_alignment when writing first sector
Posted by Fiona Ebner 2 months, 2 weeks ago
Am 19.11.25 um 4:40 PM schrieb Fiona Ebner:
> Am 07.10.25 um 6:07 PM schrieb Stefan Hajnoczi:
>> v2:
>> - Simplify condition to if (!s->needs_alignment) in patch 1 [Vladimir]
>>
>> This series fixes a bug I introduced in commit 5634622bcb33 ("file-posix: allow
>> BLKZEROOUT with -t writeback"). The Linux fallocate(2) and ioctl(BLKZEROOUT)
>> syscalls require logical block size alignment of the offset and length, even
>> when the file is opened in buffered I/O mode where read/write operations do not
>> require alignment.
>>
>> The fix is to populate the pwrite_zeroes_alignment block limits field and to
>> use that limit in create_file_fallback_zero_first_sector().
>>
>> One issue I want to raise is that pwrite_zeroes_alignment is an "optimal
>> alignment" hint. Hence create_file_fallback_zero_first_sector() had to be
>> modified to honor the limit explicitly. The block layer doesn't automatically
>> apply padding in order to align requests. This is different from how QEMU's
>> block layer pwrite/pread works, where it does automatically apply padding and
>> read/modify/write as necessary. If you want consistency, please let me know.
>>
>> Stefan Hajnoczi (3):
>>   file-posix: populate pwrite_zeroes_alignment
>>   block: use pwrite_zeroes_alignment when writing first sector
>>   iotests: add Linux loop device image creation test
>>
>>  include/system/block-backend-io.h             |  1 +
>>  block.c                                       |  3 +-
>>  block/block-backend.c                         | 11 ++++
>>  block/file-posix.c                            | 16 +++++
>>  tests/qemu-iotests/tests/loop-create-file     | 59 +++++++++++++++++++
>>  tests/qemu-iotests/tests/loop-create-file.out |  8 +++
>>  6 files changed, 97 insertions(+), 1 deletion(-)
>>  create mode 100755 tests/qemu-iotests/tests/loop-create-file
>>  create mode 100644 tests/qemu-iotests/tests/loop-create-file.out
>>
> 
> Thank you for the fix!
> 
> Tested-by: Fiona Ebner <f.ebner@proxmox.com>
> Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>

Oh, and CC qemu-stable, because 5634622bcb33 ("file-posix: allow
BLKZEROOUT with -t writeback") is in 10.1.