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 <[email protected]> > > --- > > 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
>
signature.asc
Description: PGP signature
