[PATCH v2 1/3] file-posix: populate pwrite_zeroes_alignment

Stefan Hajnoczi posted 3 patches 1 month, 1 week ago
Maintainers: Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>
[PATCH v2 1/3] file-posix: populate pwrite_zeroes_alignment
Posted by Stefan Hajnoczi 1 month, 1 week ago
Linux block devices require write zeroes alignment whereas files do not.

It may come as a surprise that block devices opened in buffered I/O mode
require the alignment for write zeroes requests although normal
read/write requests do not.

Therefore it is necessary to populate the pwrite_zeroes_alignment field.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 block/file-posix.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/block/file-posix.c b/block/file-posix.c
index 8c738674ce..827ffa77a5 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -1602,6 +1602,22 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
 
             bs->bl.pdiscard_alignment = dalign;
         }
+
+#ifdef __linux__
+        /*
+         * Linux requires logical block size alignment for write zeroes even
+         * when normal reads/writes do not require alignment.
+         */
+        if (!s->needs_alignment) {
+            ret = probe_logical_blocksize(s->fd,
+                                          &bs->bl.pwrite_zeroes_alignment);
+            if (ret < 0) {
+                error_setg_errno(errp, -ret,
+                                 "Failed to probe logical block size");
+                return;
+            }
+        }
+#endif /* __linux__ */
     }
 
     raw_refresh_zoned_limits(bs, &st, errp);
-- 
2.51.0
Re: [PATCH v2 1/3] file-posix: populate pwrite_zeroes_alignment
Posted by Vladimir Sementsov-Ogievskiy 1 month, 1 week ago
On 07.10.25 17:16, Stefan Hajnoczi wrote:
> Linux block devices require write zeroes alignment whereas files do not.
> 
> It may come as a surprise that block devices opened in buffered I/O mode
> require the alignment for write zeroes requests although normal
> read/write requests do not.
> 
> Therefore it is necessary to populate the pwrite_zeroes_alignment field.
> 
> Signed-off-by: Stefan Hajnoczi<stefanha@redhat.com>


Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>

-- 
Best regards,
Vladimir