[PATCH 3/4] FIXUP: iomap: also apply IOMAP_DIO_FSBLOCK_ALIGNED to the iomap range

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

Not just the bios created by bio_iov_iter_get_pages need to be aligned
to the file system block size when IOMAP_DIO_FSBLOCK_ALIGNED is used,
but also the iomap mapped region. Use the local alignment variable
for this check as well.

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

diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index 8d094d6f5f3e..13def8418659 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -338,9 +338,6 @@ static int iomap_dio_bio_iter(struct iomap_iter *iter, struct iomap_dio *dio)
size_t orig_count;
unsigned int alignment;

- if ((pos | length) & (bdev_logical_block_size(iomap->bdev) - 1))
- return -EINVAL;
-
/*
* 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.
@@ -350,6 +347,9 @@ static int iomap_dio_bio_iter(struct iomap_iter *iter, struct iomap_dio *dio)
else
alignment = bdev_logical_block_size(iomap->bdev);

+ if ((pos | length) & (alignment - 1))
+ return -EINVAL;
+
if (dio->flags & IOMAP_DIO_WRITE) {
bio_opf |= REQ_OP_WRITE;

--
2.47.3