From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: Tejun Heo <tj@kernel.org>, Coly Li <colyli@suse.de>,
Song Liu <song@kernel.org>,
dm-devel@redhat.com, linux-bcache@vger.kernel.org,
linux-raid@vger.kernel.org, linux-s390@vger.kernel.org,
linux-block@vger.kernel.org
Subject: [PATCH 4/9] block: simplify submit_bio_checks a bit
Date: Tue, 1 Dec 2020 17:54:19 +0100 [thread overview]
Message-ID: <20201201165424.2030647-5-hch@lst.de> (raw)
In-Reply-To: <20201201165424.2030647-1-hch@lst.de>
Merge a few checks for whole devices vs partitions to streamline the
sanity checks.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/blk-core.c | 40 ++++++++++++++--------------------------
1 file changed, 14 insertions(+), 26 deletions(-)
diff --git a/block/blk-core.c b/block/blk-core.c
index 95005a8db5ab2f..3a8fef64d36bc1 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -691,11 +691,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)
{
- const int op = bio_op(bio);
-
- if (part->bd_read_only && op_is_write(op)) {
+ if (op_is_write(bio_op(bio)) && bio->bi_bdev->bd_read_only) {
char b[BDEVNAME_SIZE];
if (op_is_flush(bio->bi_opf) && !bio_sectors(bio))
@@ -703,7 +701,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;
}
@@ -724,8 +722,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 &&
@@ -740,27 +739,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);
}
- ret = 0;
-out:
- return ret;
+ return 0;
}
/*
@@ -820,16 +812,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
--
2.29.2
next prev parent reply other threads:[~2020-12-01 16:55 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-01 16:54 store a pointer to the block_device in struct bio (again) Christoph Hellwig
2020-12-01 16:54 ` [PATCH 1/9] brd: remove the end of device check in brd_do_bvec Christoph Hellwig
2020-12-02 22:39 ` Tejun Heo
2020-12-01 16:54 ` [PATCH 2/9] dcssblk: " Christoph Hellwig
2020-12-02 22:39 ` Tejun Heo
2020-12-01 16:54 ` [PATCH 3/9] block: store a block_device pointer in struct bio Christoph Hellwig
2020-12-02 22:54 ` Tejun Heo
2020-12-03 6:39 ` Ming Lei
2020-12-03 7:10 ` Ming Lei
2020-12-03 8:29 ` Christoph Hellwig
2020-12-03 9:32 ` Ming Lei
2020-12-03 20:53 ` Keith Busch
2020-12-01 16:54 ` Christoph Hellwig [this message]
2020-12-02 22:55 ` [PATCH 4/9] block: simplify submit_bio_checks a bit Tejun Heo
2020-12-01 16:54 ` [PATCH 5/9] block: use ->bi_bdev for bio based I/O accounting Christoph Hellwig
2020-12-02 23:05 ` Tejun Heo
2020-12-01 16:54 ` [PATCH 6/9] blk-mq: use ->bi_bdev for " Christoph Hellwig
2020-12-02 23:06 ` Tejun Heo
2020-12-01 16:54 ` [PATCH 7/9] block: add a disk_uevent helper Christoph Hellwig
2020-12-02 23:08 ` Tejun Heo
2020-12-01 16:54 ` [PATCH 8/9] block: remove DISK_PITER_REVERSE Christoph Hellwig
2020-12-02 23:15 ` Tejun Heo
2020-12-01 16:54 ` [PATCH 9/9] block: use an xarray for disk->part_tbl Christoph Hellwig
2020-12-02 23:22 ` Tejun Heo
2020-12-02 22:35 ` store a pointer to the block_device in struct bio (again) Tejun Heo
2020-12-02 22:37 ` Tejun Heo
2020-12-04 16:43 ` Jens Axboe
2020-12-07 18:56 ` Qian Cai
2020-12-07 19:01 ` Christoph Hellwig
2020-12-07 20:20 ` Jens Axboe
2020-12-08 11:04 ` Christoph Hellwig
2020-12-08 13:08 ` Qian Cai
2020-12-08 13:38 ` Daniel Wagner
2020-12-08 14:15 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201201165424.2030647-5-hch@lst.de \
--to=hch@lst.de \
--cc=axboe@kernel.dk \
--cc=colyli@suse.de \
--cc=dm-devel@redhat.com \
--cc=linux-bcache@vger.kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=song@kernel.org \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox