Prepare for managing hctx mapping via xarray by adding one helper of blk_mq_get_hctx(). No functional change. Signed-off-by: Ming Lei <ming.lei@xxxxxxxxxx> --- block/blk-mq-sysfs.c | 2 +- block/blk-mq.c | 4 ++-- block/blk-mq.h | 2 +- include/linux/blk-mq.h | 8 +++++++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/block/blk-mq-sysfs.c b/block/blk-mq-sysfs.c index 674786574075..22950e764536 100644 --- a/block/blk-mq-sysfs.c +++ b/block/blk-mq-sysfs.c @@ -279,7 +279,7 @@ int __blk_mq_register_dev(struct device *dev, struct request_queue *q) unreg: while (--i >= 0) - blk_mq_unregister_hctx(q->queue_hw_ctx[i]); + blk_mq_unregister_hctx(blk_mq_get_hctx(q, i)); kobject_uevent(q->mq_kobj, KOBJ_REMOVE); kobject_del(q->mq_kobj); diff --git a/block/blk-mq.c b/block/blk-mq.c index 5ce6a8289cff..d01c1693a3d4 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -71,7 +71,7 @@ static int blk_mq_poll_stats_bkt(const struct request *rq) static inline struct blk_mq_hw_ctx *blk_qc_to_hctx(struct request_queue *q, blk_qc_t qc) { - return q->queue_hw_ctx[(qc & ~BLK_QC_T_INTERNAL) >> BLK_QC_T_SHIFT]; + return blk_mq_get_hctx(q, (qc & ~BLK_QC_T_INTERNAL) >> BLK_QC_T_SHIFT); } static inline struct request *blk_qc_to_rq(struct blk_mq_hw_ctx *hctx, @@ -573,7 +573,7 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q, * If not tell the caller that it should skip this queue. */ ret = -EXDEV; - data.hctx = q->queue_hw_ctx[hctx_idx]; + data.hctx = blk_mq_get_hctx(q, hctx_idx); if (!blk_mq_hw_queue_mapped(data.hctx)) goto out_queue_exit; cpu = cpumask_first_and(data.hctx->cpumask, cpu_online_mask); diff --git a/block/blk-mq.h b/block/blk-mq.h index 948791ea2a3e..804668457f88 100644 --- a/block/blk-mq.h +++ b/block/blk-mq.h @@ -83,7 +83,7 @@ static inline struct blk_mq_hw_ctx *blk_mq_map_queue_type(struct request_queue * enum hctx_type type, unsigned int cpu) { - return q->queue_hw_ctx[q->tag_set->map[type].mq_map[cpu]]; + return blk_mq_get_hctx(q, q->tag_set->map[type].mq_map[cpu]); } static inline enum hctx_type blk_mq_get_hctx_type(unsigned int flags) diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index 3a41d50b85d3..3d949b1968f3 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -916,9 +916,15 @@ static inline void *blk_mq_rq_to_pdu(struct request *rq) return rq + 1; } +static inline struct blk_mq_hw_ctx *blk_mq_get_hctx(struct request_queue *q, + unsigned int hctx_idx) +{ + return q->queue_hw_ctx[hctx_idx]; +} + #define queue_for_each_hw_ctx(q, hctx, i) \ for ((i) = 0; (i) < (q)->nr_hw_queues && \ - ({ hctx = (q)->queue_hw_ctx[i]; 1; }); (i)++) + ({ hctx = blk_mq_get_hctx((q), (i)); 1; }); (i)++) #define hctx_for_each_ctx(hctx, ctx, i) \ for ((i) = 0; (i) < (hctx)->nr_ctx && \ -- 2.31.1