[PATCH V10 06/19] fs/buffer.c: use bvec iterator to truncate the bio

From: Ming Lei
Date: Thu Nov 15 2018 - 03:55:00 EST


Once multi-page bvec is enabled, the last bvec may include more than one
page, this patch use bvec_last_segment() to truncate the bio.

Cc: Dave Chinner <dchinner@xxxxxxxxxx>
Cc: Kent Overstreet <kent.overstreet@xxxxxxxxx>
Cc: Mike Snitzer <snitzer@xxxxxxxxxx>
Cc: dm-devel@xxxxxxxxxx
Cc: Alexander Viro <viro@xxxxxxxxxxxxxxxxxx>
Cc: linux-fsdevel@xxxxxxxxxxxxxxx
Cc: Shaohua Li <shli@xxxxxxxxxx>
Cc: linux-raid@xxxxxxxxxxxxxxx
Cc: linux-erofs@xxxxxxxxxxxxxxxx
Cc: David Sterba <dsterba@xxxxxxxx>
Cc: linux-btrfs@xxxxxxxxxxxxxxx
Cc: Darrick J. Wong <darrick.wong@xxxxxxxxxx>
Cc: linux-xfs@xxxxxxxxxxxxxxx
Cc: Gao Xiang <gaoxiang25@xxxxxxxxxx>
Cc: Christoph Hellwig <hch@xxxxxx>
Cc: Theodore Ts'o <tytso@xxxxxxx>
Cc: linux-ext4@xxxxxxxxxxxxxxx
Cc: Coly Li <colyli@xxxxxxx>
Cc: linux-bcache@xxxxxxxxxxxxxxx
Cc: Boaz Harrosh <ooo@xxxxxxxxxxxxxxx>
Cc: Bob Peterson <rpeterso@xxxxxxxxxx>
Cc: cluster-devel@xxxxxxxxxx
Signed-off-by: Ming Lei <ming.lei@xxxxxxxxxx>
---
fs/buffer.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index 1286c2b95498..fa37ad52e962 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -3032,7 +3032,10 @@ void guard_bio_eod(int op, struct bio *bio)

/* ..and clear the end of the buffer for reads */
if (op == REQ_OP_READ) {
- zero_user(bvec->bv_page, bvec->bv_offset + bvec->bv_len,
+ struct bio_vec bv;
+
+ bvec_last_segment(bvec, &bv);
+ zero_user(bv.bv_page, bv.bv_offset + bv.bv_len,
truncated_bytes);
}
}
--
2.9.5