diff mbox series

[V2,1/2] block: don't call into iov_iter_revert if nothing is left

Message ID 20231109082827.2276696-2-ming.lei@redhat.com (mailing list archive)
State New, archived
Headers show
Series block: try to make aligned bio in case of big chunk IO | expand

Commit Message

Ming Lei Nov. 9, 2023, 8:28 a.m. UTC
Most of times all pages are just added to bio, and nothing is left, so
not necessary to call into iov_iter_revert().

Same with block size alignment handling.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 block/bio.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

Christoph Hellwig Nov. 9, 2023, 2:35 p.m. UTC | #1
>  	if (bio->bi_bdev) {
>  		size_t trim = size & (bdev_logical_block_size(bio->bi_bdev) - 1);
> -		iov_iter_revert(iter, trim);
> -		size -= trim;
> +
> +		if (trim) {
> +			iov_iter_revert(iter, trim);
> +			size -= trim;
> +		}

We also need to fix this.  This isn't supposed to be called without
a bdev set, but Kent broke this.  But if we don't have a bdev
we need to pass the block size manually and still do the revert if needed.
diff mbox series

Patch

diff --git a/block/bio.c b/block/bio.c
index 816d412c06e9..09a5e71a0372 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1262,8 +1262,11 @@  static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
 
 	if (bio->bi_bdev) {
 		size_t trim = size & (bdev_logical_block_size(bio->bi_bdev) - 1);
-		iov_iter_revert(iter, trim);
-		size -= trim;
+
+		if (trim) {
+			iov_iter_revert(iter, trim);
+			size -= trim;
+		}
 	}
 
 	if (unlikely(!size)) {
@@ -1286,7 +1289,8 @@  static int __bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
 		offset = 0;
 	}
 
-	iov_iter_revert(iter, left);
+	if (left)
+		iov_iter_revert(iter, left);
 out:
 	while (i < nr_pages)
 		bio_release_page(bio, pages[i++]);