diff mbox series

[4/4] btrfs: split bios to the fs sector size boundary

Message ID 20241101052206.437530-5-hch@lst.de (mailing list archive)
State New
Headers show
Series [1/4] block: fix bio_split_rw_at to take zone_write_granularity into account | expand

Commit Message

Christoph Hellwig Nov. 1, 2024, 5:21 a.m. UTC
Btrfs like other file systems can't really deal with I/O not aligned to
it's internal block size (which strangely is called sector size in
btrfs), but the block layer split helper doesn't even know about that.

Round down the split boundary so that all I/Os are aligned.

Fixes: d5e4377d5051 ("btrfs: split zone append bios in btrfs_submit_bio")
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/btrfs/bio.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

Damien Le Moal Nov. 1, 2024, 5:40 a.m. UTC | #1
On 11/1/24 14:21, Christoph Hellwig wrote:
> Btrfs like other file systems can't really deal with I/O not aligned to
> it's internal block size (which strangely is called sector size in
> btrfs), but the block layer split helper doesn't even know about that.
> 
> Round down the split boundary so that all I/Os are aligned.
> 
> Fixes: d5e4377d5051 ("btrfs: split zone append bios in btrfs_submit_bio")
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Looks OK to me.

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Johannes Thumshirn Nov. 4, 2024, 10:45 a.m. UTC | #2
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Naohiro Aota Nov. 5, 2024, 6 a.m. UTC | #3
On Fri, Nov 01, 2024 at 06:21:47AM GMT, Christoph Hellwig wrote:
> Btrfs like other file systems can't really deal with I/O not aligned to
> it's internal block size (which strangely is called sector size in
> btrfs), but the block layer split helper doesn't even know about that.
> 
> Round down the split boundary so that all I/Os are aligned.
> 
> Fixes: d5e4377d5051 ("btrfs: split zone append bios in btrfs_submit_bio")
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  fs/btrfs/bio.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)

Looks good to me.

Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com>
diff mbox series

Patch

diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c
index 0f096e226908..299b9a0ed68b 100644
--- a/fs/btrfs/bio.c
+++ b/fs/btrfs/bio.c
@@ -660,8 +660,15 @@  static u64 btrfs_append_map_length(struct btrfs_bio *bbio, u64 map_length)
 	map_length = min(map_length, bbio->fs_info->max_zone_append_size);
 	sector_offset = bio_split_rw_at(&bbio->bio, &bbio->fs_info->limits,
 					&nr_segs, map_length);
-	if (sector_offset)
-		return sector_offset << SECTOR_SHIFT;
+	if (sector_offset) {
+		/*
+		 * bio_split_rw_at could split at a size smaller than the
+		 * file system sector size and thus cause unaligned I/Os.
+		 * Fix that by always rounding down to the nearest boundary.
+		 */
+		return ALIGN_DOWN(sector_offset << SECTOR_SHIFT,
+				  bbio->fs_info->sectorsize);
+	}
 	return map_length;
 }