From: John Garry john.g.garry@oracle.com
maillist inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I9VTE3 CVE: NA
Reference: https://lore.kernel.org/all/20240326133813.3224593-1-john.g.garry@oracle.com...
--------------------------------
Currently blk_queue_get_max_sectors() is passed a enum req_op. In future the value returned from blk_queue_get_max_sectors() may depend on certain request flags, so pass a request pointer.
Reviewed-by: Christoph Hellwig hch@lst.de Reviewed-by: Keith Busch kbusch@kernel.org Signed-off-by: John Garry john.g.garry@oracle.com Signed-off-by: Long Li leo.lilong@huawei.com --- block/blk-core.c | 2 +- drivers/block/rnbd/rnbd-srv-dev.h | 3 +-- include/linux/blkdev.h | 10 ++++++---- 3 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/block/blk-core.c b/block/blk-core.c index f91f8e8be482..7950063c0345 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -1155,7 +1155,7 @@ EXPORT_SYMBOL(submit_bio); static blk_status_t blk_cloned_rq_check_limits(struct request_queue *q, struct request *rq) { - unsigned int max_sectors = blk_queue_get_max_sectors(q, req_op(rq)); + unsigned int max_sectors = blk_queue_get_max_sectors(rq);
if (blk_rq_sectors(rq) > max_sectors) { /* diff --git a/drivers/block/rnbd/rnbd-srv-dev.h b/drivers/block/rnbd/rnbd-srv-dev.h index 0eb23850afb9..e41ce52ab8f1 100644 --- a/drivers/block/rnbd/rnbd-srv-dev.h +++ b/drivers/block/rnbd/rnbd-srv-dev.h @@ -66,8 +66,7 @@ static inline int rnbd_dev_get_max_discard_sects(const struct rnbd_dev *dev) if (!blk_queue_discard(bdev_get_queue(dev->bdev))) return 0;
- return blk_queue_get_max_sectors(bdev_get_queue(dev->bdev), - REQ_OP_DISCARD); + return bdev_get_queue(dev->bdev)->limits.max_discard_sectors; }
static inline int rnbd_dev_get_discard_granularity(const struct rnbd_dev *dev) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 50b4fd0a0687..2d6747877f7c 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1082,9 +1082,11 @@ static inline struct bio_vec req_bvec(struct request *rq) return mp_bvec_iter_bvec(rq->bio->bi_io_vec, rq->bio->bi_iter); }
-static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q, - int op) +static inline unsigned int blk_queue_get_max_sectors(struct request *rq) { + struct request_queue *q = rq->q; + int op = req_op(rq); + if (unlikely(op == REQ_OP_DISCARD || op == REQ_OP_SECURE_ERASE)) return min(q->limits.max_discard_sectors, UINT_MAX >> SECTOR_SHIFT); @@ -1132,10 +1134,10 @@ static inline unsigned int blk_rq_get_max_sectors(struct request *rq, if (!q->limits.chunk_sectors || req_op(rq) == REQ_OP_DISCARD || req_op(rq) == REQ_OP_SECURE_ERASE) - return blk_queue_get_max_sectors(q, req_op(rq)); + return blk_queue_get_max_sectors(rq);
return min(blk_max_size_offset(q, offset, 0), - blk_queue_get_max_sectors(q, req_op(rq))); + blk_queue_get_max_sectors(rq)); }
static inline unsigned int blk_rq_count_bios(struct request *rq)