Skip to content

Commit 83c9c54

Browse files
Ming Leiaxboe
authored andcommitted
fs: move guard_bio_eod() after bio_set_op_attrs
Commit 85a8ce6 ("block: add bio_truncate to fix guard_bio_eod") adds bio_truncate() for handling bio EOD. However, bio_truncate() doesn't use the passed 'op' parameter from guard_bio_eod's callers. So bio_trunacate() may retrieve wrong 'op', and zering pages may not be done for READ bio. Fixes this issue by moving guard_bio_eod() after bio_set_op_attrs() in submit_bh_wbc() so that bio_truncate() can always retrieve correct op info. Meantime remove the 'op' parameter from guard_bio_eod() because it isn't used any more. Cc: Carlos Maiolino <[email protected]> Cc: [email protected] Fixes: 85a8ce6 ("block: add bio_truncate to fix guard_bio_eod") Signed-off-by: Ming Lei <[email protected]> Fold in kerneldoc and bio_op() change. Signed-off-by: Jens Axboe <[email protected]>
1 parent 5741579 commit 83c9c54

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

block/bio.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,16 @@ void zero_fill_bio_iter(struct bio *bio, struct bvec_iter start)
538538
}
539539
EXPORT_SYMBOL(zero_fill_bio_iter);
540540

541+
/**
542+
* bio_truncate - truncate the bio to small size of @new_size
543+
* @bio: the bio to be truncated
544+
* @new_size: new size for truncating the bio
545+
*
546+
* Description:
547+
* Truncate the bio to new size of @new_size. If bio_op(bio) is
548+
* REQ_OP_READ, zero the truncated part. This function should only
549+
* be used for handling corner cases, such as bio eod.
550+
*/
541551
void bio_truncate(struct bio *bio, unsigned new_size)
542552
{
543553
struct bio_vec bv;
@@ -548,7 +558,7 @@ void bio_truncate(struct bio *bio, unsigned new_size)
548558
if (new_size >= bio->bi_iter.bi_size)
549559
return;
550560

551-
if (bio_data_dir(bio) != READ)
561+
if (bio_op(bio) != REQ_OP_READ)
552562
goto exit;
553563

554564
bio_for_each_segment(bv, bio, iter) {

fs/buffer.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3031,7 +3031,7 @@ static void end_bio_bh_io_sync(struct bio *bio)
30313031
* errors, this only handles the "we need to be able to
30323032
* do IO at the final sector" case.
30333033
*/
3034-
void guard_bio_eod(int op, struct bio *bio)
3034+
void guard_bio_eod(struct bio *bio)
30353035
{
30363036
sector_t maxsector;
30373037
struct hd_struct *part;
@@ -3095,15 +3095,15 @@ static int submit_bh_wbc(int op, int op_flags, struct buffer_head *bh,
30953095
bio->bi_end_io = end_bio_bh_io_sync;
30963096
bio->bi_private = bh;
30973097

3098-
/* Take care of bh's that straddle the end of the device */
3099-
guard_bio_eod(op, bio);
3100-
31013098
if (buffer_meta(bh))
31023099
op_flags |= REQ_META;
31033100
if (buffer_prio(bh))
31043101
op_flags |= REQ_PRIO;
31053102
bio_set_op_attrs(bio, op, op_flags);
31063103

3104+
/* Take care of bh's that straddle the end of the device */
3105+
guard_bio_eod(bio);
3106+
31073107
if (wbc) {
31083108
wbc_init_bio(wbc, bio);
31093109
wbc_account_cgroup_owner(wbc, bh->b_page, bh->b_size);

fs/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static inline int __sync_blockdev(struct block_device *bdev, int wait)
3838
/*
3939
* buffer.c
4040
*/
41-
extern void guard_bio_eod(int rw, struct bio *bio);
41+
extern void guard_bio_eod(struct bio *bio);
4242
extern int __block_write_begin_int(struct page *page, loff_t pos, unsigned len,
4343
get_block_t *get_block, struct iomap *iomap);
4444

fs/mpage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static struct bio *mpage_bio_submit(int op, int op_flags, struct bio *bio)
6262
{
6363
bio->bi_end_io = mpage_end_io;
6464
bio_set_op_attrs(bio, op, op_flags);
65-
guard_bio_eod(op, bio);
65+
guard_bio_eod(bio);
6666
submit_bio(bio);
6767
return NULL;
6868
}

0 commit comments

Comments
 (0)