qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	qemu-block@nongnu.org, Jean-Louis Dupond <jean-louis@dupond.be>,
	Hanna Reitz <hreitz@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>
Subject: [PATCH 1/3] file-posix: populate pwrite_zeroes_alignment
Date: Thu,  2 Oct 2025 14:39:58 -0400	[thread overview]
Message-ID: <20251002184000.410486-2-stefanha@redhat.com> (raw)
In-Reply-To: <20251002184000.410486-1-stefanha@redhat.com>

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 although regular 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 | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/block/file-posix.c b/block/file-posix.c
index 8c738674ce..05c92c824d 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -1602,6 +1602,23 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
 
             bs->bl.pdiscard_alignment = dalign;
         }
+
+#ifdef __linux__
+        /*
+         * When request_alignment > 1, pwrite_zeroes_alignment does not need to
+         * be set explicitly. When request_alignment == 1, it must be set
+         * explicitly because Linux requires logical block size alignment.
+         */
+        if (bs->bl.request_alignment == 1) {
+            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



  reply	other threads:[~2025-10-02 19:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-02 18:39 [PATCH 0/3] block: use pwrite_zeroes_alignment when writing first sector Stefan Hajnoczi
2025-10-02 18:39 ` Stefan Hajnoczi [this message]
2025-10-03  7:55   ` [PATCH 1/3] file-posix: populate pwrite_zeroes_alignment Vladimir Sementsov-Ogievskiy
2025-10-06 14:57     ` Stefan Hajnoczi
2025-10-07  9:08       ` Vladimir Sementsov-Ogievskiy
2025-10-03  8:04   ` Vladimir Sementsov-Ogievskiy
2025-10-06 14:46     ` Stefan Hajnoczi
2025-10-02 18:39 ` [PATCH 2/3] block: use pwrite_zeroes_alignment when writing first sector Stefan Hajnoczi
2025-10-03  7:56   ` Vladimir Sementsov-Ogievskiy
2025-10-02 18:40 ` [PATCH 3/3] iotests: add Linux loop device image creation test Stefan Hajnoczi
2025-10-03  7:52 ` [PATCH 0/3] block: use pwrite_zeroes_alignment when writing first sector Vladimir Sementsov-Ogievskiy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251002184000.410486-2-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=hreitz@redhat.com \
    --cc=jean-louis@dupond.be \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).