aboutsummaryrefslogtreecommitdiffstats
path: root/block/blk-core.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2021-01-24 11:02:35 +0100
committerJens Axboe <axboe@kernel.dk>2021-01-24 18:17:20 -0700
commit2f9f6221b9b9944e96c80455b469a6f0269c558b (patch)
tree5b086d1afdf5e08613d20c029d457bde85233df9 /block/blk-core.c
parentblock: store a block_device pointer in struct bio (diff)
downloadlinux-dev-2f9f6221b9b9944e96c80455b469a6f0269c558b.tar.xz
linux-dev-2f9f6221b9b9944e96c80455b469a6f0269c558b.zip
block: simplify submit_bio_checks a bit
Merge a few checks for whole devices vs partitions to streamline the sanity checks. Signed-off-by: Christoph Hellwig <hch@lst.de> Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/blk-core.c')
-rw-r--r--block/blk-core.c39
1 files changed, 14 insertions, 25 deletions
diff --git a/block/blk-core.c b/block/blk-core.c
index a3a54cd86c9c..64f69022de96 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -692,9 +692,9 @@ static inline bool should_fail_request(struct block_device *part,
#endif /* CONFIG_FAIL_MAKE_REQUEST */
-static inline bool bio_check_ro(struct bio *bio, struct block_device *part)
+static inline bool bio_check_ro(struct bio *bio)
{
- if (op_is_write(bio_op(bio)) && bdev_read_only(part)) {
+ if (op_is_write(bio_op(bio)) && bdev_read_only(bio->bi_bdev)) {
char b[BDEVNAME_SIZE];
if (op_is_flush(bio->bi_opf) && !bio_sectors(bio))
@@ -702,7 +702,7 @@ static inline bool bio_check_ro(struct bio *bio, struct block_device *part)
WARN_ONCE(1,
"Trying to write to read-only block-device %s (partno %d)\n",
- bio_devname(bio, b), part->bd_partno);
+ bio_devname(bio, b), bio->bi_bdev->bd_partno);
/* Older lvm-tools actually trigger this */
return false;
}
@@ -723,8 +723,9 @@ ALLOW_ERROR_INJECTION(should_fail_bio, ERRNO);
* This may well happen - the kernel calls bread() without checking the size of
* the device, e.g., when mounting a file system.
*/
-static inline int bio_check_eod(struct bio *bio, sector_t maxsector)
+static inline int bio_check_eod(struct bio *bio)
{
+ sector_t maxsector = bdev_nr_sectors(bio->bi_bdev);
unsigned int nr_sectors = bio_sectors(bio);
if (nr_sectors && maxsector &&
@@ -739,28 +740,20 @@ static inline int bio_check_eod(struct bio *bio, sector_t maxsector)
/*
* Remap block n of partition p to block n+start(p) of the disk.
*/
-static inline int blk_partition_remap(struct bio *bio)
+static int blk_partition_remap(struct bio *bio)
{
struct block_device *p = bio->bi_bdev;
- int ret = -EIO;
if (unlikely(should_fail_request(p, bio->bi_iter.bi_size)))
- goto out;
- if (unlikely(bio_check_ro(bio, p)))
- goto out;
-
+ return -EIO;
if (bio_sectors(bio)) {
- if (bio_check_eod(bio, bdev_nr_sectors(p)))
- goto out;
bio->bi_iter.bi_sector += p->bd_start_sect;
trace_block_bio_remap(bio, p->bd_dev,
bio->bi_iter.bi_sector -
p->bd_start_sect);
}
bio->bi_bdev = bdev_whole(p);
- ret = 0;
-out:
- return ret;
+ return 0;
}
/*
@@ -820,16 +813,12 @@ static noinline_for_stack bool submit_bio_checks(struct bio *bio)
if (should_fail_bio(bio))
goto end_io;
-
- if (bio->bi_bdev->bd_partno) {
- if (unlikely(blk_partition_remap(bio)))
- goto end_io;
- } else {
- if (unlikely(bio_check_ro(bio, bdev_whole(bdev))))
- goto end_io;
- if (unlikely(bio_check_eod(bio, get_capacity(bdev->bd_disk))))
- goto end_io;
- }
+ if (unlikely(bio_check_ro(bio)))
+ goto end_io;
+ if (unlikely(bio_check_eod(bio)))
+ goto end_io;
+ if (bio->bi_bdev->bd_partno && unlikely(blk_partition_remap(bio)))
+ goto end_io;
/*
* Filter flush bio's early so that bio based drivers without flush