All of lore.kernel.org
 help / color / mirror / Atom feed
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:57:10 -0400	[thread overview]
Message-ID: <20251006145710.GB21887@fedora> (raw)
In-Reply-To: <dd50f99b-03d3-44ca-9f79-dde3dff1c3d4@yandex-team.ru>

[-- Attachment #1: Type: text/plain, Size: 2457 bytes --]

On Fri, Oct 03, 2025 at 10:55:09AM +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) {
> > +            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");
> 
> Isn't it too restrictive? Could we consider failed attempt to probe as permission
> to proceed without write-zeroes alignment? In raw_probe_alignment, we fallback
> to guessing request_alignment from memalign.

The logical block size alignment is required for write zeroes, otherwise
write zeroes will fail with EINVAL (not ENOTSUP).

There is no way to probe in the !needs_alignment case since read
requests don't require alignment and write zeroes would be destructive.

I think it's preferrable to fail here. This should never happen on a
Linux kernel because BLKSSZGET has been there since the initial git
import in 2005.

> 
> > +                return;
> > +            }
> > +        }
> > +#endif /* __linux__ */
> >       }
> >       raw_refresh_zoned_limits(bs, &st, errp);
> 
> 
> -- 
> Best regards,
> Vladimir
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2025-10-06 14:58 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 [this message]
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=20251006145710.GB21887@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.