Re: [PATCH 2/7] block: align the bio after building it
From: Keith Busch <kbusch@kernel.org>
Date: 2025-08-04 14:08:41
Also in:
linux-fsdevel, lkml
From: Keith Busch <kbusch@kernel.org>
Date: 2025-08-04 14:08:41
Also in:
linux-fsdevel, lkml
On Mon, Aug 04, 2025 at 08:54:00AM +0200, Hannes Reinecke wrote:
On 8/2/25 01:47, Keith Busch wrote:quoted
+static int bio_align_to_lbs(struct bio *bio, struct iov_iter *iter) +{ + struct block_device *bdev = bio->bi_bdev; + size_t nbytes; + + if (!bdev) + return 0; + + nbytes = bio->bi_iter.bi_size & (bdev_logical_block_size(bdev) - 1); + if (!nbytes) + return 0; + + bio_revert(bio, nbytes); + iov_iter_revert(iter, nbytes); + if (!bio->bi_iter.bi_size) + return -EFAULT; + + return 0; +} + /** * bio_iov_iter_get_pages - add user or kernel pages to a bio * @bio: bio to add pages to@@ -1336,6 +1355,7 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) ret = __bio_iov_iter_get_pages(bio, iter); } while (!ret && iov_iter_count(iter) && !bio_full(bio, 0)); + ret = bio_align_to_lbs(bio, iter); return bio->bi_vcnt ? 0 : ret;Wouldn't that cause the error from bio_align_to_lba() to be ignored if bio->bi_vcnt is greater than 0?
That returns an error only if the alignment reduces the size to 0, so there would be a bug somewhere if bi_vcnt is not also 0 in that case.