Skip to contentSkip to conversation

block: only zero page for bio of REQ_OP_READ in bio_truncate

PATCH In review Ming Lei 2 participants 2 messages Jan 9, 2020 Block layer

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH 1/1 block: only zero page for bio of REQ_OP_READ in bio_truncate

Commit 85a8ce62c2ea ("block: add bio_truncate to fix guard_bio_eod") adds bio_truncate() which changes to zero the truncated pages for any bio which direction is READ. This way may change the behavior of guard_bio_eod(), so change back to orginal behavior of just zeroing bio of REQ_OP_READ.

Meantime add kerneldoc for bio_truncate() as suggested by Christoph.

Fixes 85a8ce62c2ea ("block: add bio_truncate to fix guard_bio_eod")
Cc Christoph Hellwig <[email protected]>
---
 block/bio.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
block/bio.c +11 -1
index 006bcc52a77e..94d697217887 100644
@@ -538,6 +538,16 @@ void zero_fill_bio_iter(struct bio *bio, struct bvec_iter start)
 }
 EXPORT_SYMBOL(zero_fill_bio_iter);
 
+/**
+ * bio_truncate - truncate the bio to small size of @new_size
+ * @bio:	the bio to be truncated
+ * @new_size:	new size for truncating the bio
+ *
+ * Description:
+ *   Truncate the bio to new size of @new_size. If bio_op(bio) is
+ *   REQ_OP_READ, zero the truncated part. This function should only
+ *   be used for handling corner cases, such as bio eod.
+ */
 void bio_truncate(struct bio *bio, unsigned new_size)
 {
 	struct bio_vec bv;
@@ -548,7 +558,7 @@ void bio_truncate(struct bio *bio, unsigned new_size)
 	if (new_size >= bio->bi_iter.bi_size)
 		return;
 
-	if (bio_data_dir(bio) != READ)
+	if (bio_op(bio) != REQ_OP_READ)
 		goto exit;
 
 	bio_for_each_segment(bv, bio, iter) {
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 6 lines · Ming Lei

Commit 85a8ce62c2ea ("block: add bio_truncate to fix guard_bio_eod") adds bio_truncate() which changes to zero the truncated pages for any bio which direction is READ. This way may change the behavior of guard_bio_eod(), so change back to orginal behavior of just zeroing bio of REQ_OP_READ.

Meantime add kerneldoc for bio_truncate() as suggested by Christoph.

I'm going to fold this with the previous. Applied, thanks.

Signature · 1 line
Jens Axboe