Re: [PATCH] btrfs: don't warn if discard range is not aligned to sector

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jan 16, 2024 at 07:42:39PM +1030, Qu Wenruo wrote:
> 
> 
> On 2024/1/16 06:08, David Sterba wrote:
> > There's a warning in btrfs_issue_discard() when the range is not aligned
> > to 512 bytes, originally added in 4d89d377bbb0 ("btrfs:
> > btrfs_issue_discard ensure offset/length are aligned to sector
> > boundaries"). We can't do sub-sector writes anyway so the adjustment is
> > the only thing that we can do and the warning is unnecessary.
> >
> > CC: stable@xxxxxxxxxxxxxxx # 4.19+
> > Reported-by: syzbot+4a4f1eba14eb5c3417d1@xxxxxxxxxxxxxxxxxxxxxxxxx
> > Signed-off-by: David Sterba <dsterba@xxxxxxxx>
> > ---
> >   fs/btrfs/extent-tree.c | 3 ++-
> >   1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> > index 6d680031211a..8e8cc1111277 100644
> > --- a/fs/btrfs/extent-tree.c
> > +++ b/fs/btrfs/extent-tree.c
> > @@ -1260,7 +1260,8 @@ static int btrfs_issue_discard(struct block_device *bdev, u64 start, u64 len,
> >   	u64 bytes_left, end;
> >   	u64 aligned_start = ALIGN(start, 1 << SECTOR_SHIFT);
> >
> > -	if (WARN_ON(start != aligned_start)) {
> > +	/* Adjust the range to be aligned to 512B sectors if necessary. */
> > +	if (start != aligned_start) {
> >   		len -= aligned_start - start;
> >   		len = round_down(len, 1 << SECTOR_SHIFT);
> >   		start = aligned_start;
> Can we do one step further in mkfs and device add, by rounding down the
> device size to btrfs sector boundary?

This is not device size but the range that gets passed to discard. The
start and size get converted to the 512B units anyway when calling
blkdev_issue_discard(), so nothing else needs to be done.




[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux