[PATCH 2/4] FIXUP: iomap: aligning to larger than fs block size doesn't make sense

Christoph Hellwig
2025-10-23T13:56:12Z

All of the VFS and helpers assume that the file system block size must
be larger or equal to the device block size. So doing a max of both
doesn't really make much sense. Siplify the code in iomap_dio_bio_iter
to do a simple if/else.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/iomap/direct-io.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index ce9cbd2bace0..8d094d6f5f3e 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -336,17 +336,19 @@ static int iomap_dio_bio_iter(struct iomap_iter *iter, struct iomap_dio *dio)
int nr_pages, ret = 0;
u64 copied = 0;
size_t orig_count;
- unsigned int alignment = bdev_logical_block_size(iomap->bdev);
+ unsigned int alignment;

if ((pos | length) & (bdev_logical_block_size(iomap->bdev) - 1))
return -EINVAL;

/*
- * Align to the larger one of bdev and fs block size, to meet the
- * alignment requirement of both layers.
+ * File systems that write out of place and always allocate new blocks
+ * need each bio to be block aligned as that's the unit of allocation.
*/
if (dio->flags & IOMAP_DIO_FSBLOCK_ALIGNED)
- alignment = max(alignment, fs_block_size);
+ alignment = fs_block_size;
+ else
+ alignment = bdev_logical_block_size(iomap->bdev);

if (dio->flags & IOMAP_DIO_WRITE) {
bio_opf |= REQ_OP_WRITE;
--
2.47.3