aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--block/blk-lib.c3
-rw-r--r--block/blk-merge.c3
-rw-r--r--block/blk.h10
3 files changed, 13 insertions, 3 deletions
diff --git a/block/blk-lib.c b/block/blk-lib.c
index 76f867ea9a9b..d56fd159d2e8 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -57,8 +57,7 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
57 57
58 if (!req_sects) 58 if (!req_sects)
59 goto fail; 59 goto fail;
60 if (req_sects > UINT_MAX >> 9) 60 req_sects = min(req_sects, bio_allowed_max_sectors(q));
61 req_sects = UINT_MAX >> 9;
62 61
63 end_sect = sector + req_sects; 62 end_sect = sector + req_sects;
64 63
diff --git a/block/blk-merge.c b/block/blk-merge.c
index 208658a901c6..e7696c47489a 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -90,7 +90,8 @@ static struct bio *blk_bio_discard_split(struct request_queue *q,
90 /* Zero-sector (unknown) and one-sector granularities are the same. */ 90 /* Zero-sector (unknown) and one-sector granularities are the same. */
91 granularity = max(q->limits.discard_granularity >> 9, 1U); 91 granularity = max(q->limits.discard_granularity >> 9, 1U);
92 92
93 max_discard_sectors = min(q->limits.max_discard_sectors, UINT_MAX >> 9); 93 max_discard_sectors = min(q->limits.max_discard_sectors,
94 bio_allowed_max_sectors(q));
94 max_discard_sectors -= max_discard_sectors % granularity; 95 max_discard_sectors -= max_discard_sectors % granularity;
95 96
96 if (unlikely(!max_discard_sectors)) { 97 if (unlikely(!max_discard_sectors)) {
diff --git a/block/blk.h b/block/blk.h
index c85e53f21cdd..0089fefdf771 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -396,6 +396,16 @@ static inline unsigned long blk_rq_deadline(struct request *rq)
396} 396}
397 397
398/* 398/*
399 * The max size one bio can handle is UINT_MAX becasue bvec_iter.bi_size
400 * is defined as 'unsigned int', meantime it has to aligned to with logical
401 * block size which is the minimum accepted unit by hardware.
402 */
403static inline unsigned int bio_allowed_max_sectors(struct request_queue *q)
404{
405 return round_down(UINT_MAX, queue_logical_block_size(q)) >> 9;
406}
407
408/*
399 * Internal io_context interface 409 * Internal io_context interface
400 */ 410 */
401void get_io_context(struct io_context *ioc); 411void get_io_context(struct io_context *ioc);