diff mbox series

block: only zero page for bio of REQ_OP_READ in bio_truncate

Message ID 20200109085640.14589-1-ming.lei@redhat.com (mailing list archive)
State New, archived
Headers show
Series block: only zero page for bio of REQ_OP_READ in bio_truncate | expand

Commit Message

Ming Lei Jan. 9, 2020, 8:56 a.m. UTC
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")
Reported-by: Christoph Hellwig <hch@infradead.org>
Cc: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 block/bio.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Comments

Jens Axboe Jan. 9, 2020, 2:57 p.m. UTC | #1
On 1/9/20 1:56 AM, Ming Lei wrote:
> 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.
diff mbox series

Patch

diff --git a/block/bio.c b/block/bio.c
index 006bcc52a77e..94d697217887 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -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) {