From: Stefan Hajnoczi <stefanha@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Cc: qemu-devel@nongnu.org, Kevin Wolf <kwolf@redhat.com>,
qemu-block@nongnu.org, Jean-Louis Dupond <jean-louis@dupond.be>,
Hanna Reitz <hreitz@redhat.com>
Subject: Re: [PATCH 1/3] file-posix: populate pwrite_zeroes_alignment
Date: Mon, 6 Oct 2025 10:46:09 -0400 [thread overview]
Message-ID: <20251006144609.GA21887@fedora> (raw)
In-Reply-To: <f4aa2d8a-0bc4-476e-aee0-0770a4bbd396@yandex-team.ru>
[-- Attachment #1: Type: text/plain, Size: 2109 bytes --]
On Fri, Oct 03, 2025 at 11:04:38AM +0300, Vladimir Sementsov-Ogievskiy wrote:
> On 02.10.25 21:39, 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 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) {
>
> would "if (!s->needs_alignment) {" be a more visual check? This way reader will not have to analyze
> raw_probe_alignment, and understand that needs_alignment=false is the only path for block device
> to have request_alignment==1.
Yes, that would make it easier to understand. Thanks!
>
> > + 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);
>
>
> --
> Best regards,
> Vladimir
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2025-10-06 14:47 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 ` [PATCH 1/3] file-posix: populate pwrite_zeroes_alignment Stefan Hajnoczi
2025-10-03 7:55 ` 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 [this message]
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=20251006144609.GA21887@fedora \
--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 \
--cc=vsementsov@yandex-team.ru \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.