btrfs: don't warn if discard range is not aligned to sector
authorDavid Sterba <dsterba@suse.com>
Mon, 15 Jan 2024 19:30:26 +0000 (20:30 +0100)
committerDavid Sterba <dsterba@suse.com>
Thu, 18 Jan 2024 22:35:57 +0000 (23:35 +0100)
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@vger.kernel.org # 4.19+
Reported-by: syzbot+4a4f1eba14eb5c3417d1@syzkaller.appspotmail.com
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent-tree.c

index 6d680031211a1c6e97c937fe9add708a7bf8bb66..8e8cc11112772dfd020217e30d74fe138c3151ca 100644 (file)
@@ -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;