Skip to content

Commit

Permalink
block: do not reassig ->bi_bdev when partition remapping
Browse files Browse the repository at this point in the history
There is no good reason to reassign ->bi_bdev when remapping the
partition-relative block number to the device wide one, as all the
information required by the drivers comes from the gendisk anyway.

Keeping the original ->bi_bdev alive will allow to greatly simplify
the partition-away I/O accounting.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Christoph Hellwig authored and Jens Axboe committed Jan 25, 2021
1 parent 2f9f622 commit 30c5d34
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions block/blk-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ static int blk_partition_remap(struct bio *bio)
bio->bi_iter.bi_sector -
p->bd_start_sect);
}
bio->bi_bdev = bdev_whole(p);
bio_set_flag(bio, BIO_REMAPPED);
return 0;
}

Expand Down Expand Up @@ -817,7 +817,8 @@ static noinline_for_stack bool submit_bio_checks(struct bio *bio)
goto end_io;
if (unlikely(bio_check_eod(bio)))
goto end_io;
if (bio->bi_bdev->bd_partno && unlikely(blk_partition_remap(bio)))
if (bio->bi_bdev->bd_partno && !bio_flagged(bio, BIO_REMAPPED) &&
unlikely(blk_partition_remap(bio)))
goto end_io;

/*
Expand Down
2 changes: 2 additions & 0 deletions include/linux/bio.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ extern const char *bio_devname(struct bio *bio, char *buffer);

#define bio_set_dev(bio, bdev) \
do { \
bio_clear_flag(bio, BIO_REMAPPED); \
if ((bio)->bi_bdev != (bdev)) \
bio_clear_flag(bio, BIO_THROTTLED); \
(bio)->bi_bdev = (bdev); \
Expand All @@ -493,6 +494,7 @@ do { \

#define bio_copy_dev(dst, src) \
do { \
bio_clear_flag(dst, BIO_REMAPPED); \
(dst)->bi_bdev = (src)->bi_bdev; \
bio_clone_blkg_association(dst, src); \
} while (0)
Expand Down
1 change: 1 addition & 0 deletions include/linux/blk_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ enum {
* of this bio. */
BIO_CGROUP_ACCT, /* has been accounted to a cgroup */
BIO_TRACKED, /* set if bio goes through the rq_qos path */
BIO_REMAPPED,
BIO_FLAG_LAST
};

Expand Down

0 comments on commit 30c5d34

Please sign in to comment.