diff --git a/block/blk-mq-sched.c b/block/blk-mq-sched.c index b942b38000e534552bfe1d44e6763fa5451fbd55..98c6a97729f24dadcc68b27d95e4098cd12953d8 100644 --- a/block/blk-mq-sched.c +++ b/block/blk-mq-sched.c @@ -18,9 +18,8 @@ #include "blk-mq-tag.h" #include "blk-wbt.h" -void blk_mq_sched_assign_ioc(struct request *rq) +struct io_cq *blk_mq_sched_get_icq(struct request_queue *q) { - struct request_queue *q = rq->q; struct io_context *ioc; struct io_cq *icq; @@ -28,22 +27,27 @@ void blk_mq_sched_assign_ioc(struct request *rq) if (unlikely(!current->io_context)) create_task_io_context(current, GFP_ATOMIC, q->node); - /* - * May not have an IO context if it's a passthrough request - */ + /* May not have an IO context if context creation failed */ ioc = current->io_context; if (!ioc) - return; + return NULL; spin_lock_irq(&q->queue_lock); icq = ioc_lookup_icq(ioc, q); spin_unlock_irq(&q->queue_lock); + if (icq) + return icq; + return ioc_create_icq(ioc, q, GFP_ATOMIC); +} +EXPORT_SYMBOL(blk_mq_sched_get_icq); - if (!icq) { - icq = ioc_create_icq(ioc, q, GFP_ATOMIC); - if (!icq) - return; - } +void blk_mq_sched_assign_ioc(struct request *rq) +{ + struct io_cq *icq; + + icq = blk_mq_sched_get_icq(rq->q); + if (!icq) + return; get_io_context(icq->ioc); rq->elv.icq = icq; } diff --git a/block/blk-mq-sched.h b/block/blk-mq-sched.h index 25d1034952b650882c0f715be87db75aaf627e1b..add651ec06da71ed0f39c4ed5c33755fb0a3416c 100644 --- a/block/blk-mq-sched.h +++ b/block/blk-mq-sched.h @@ -8,6 +8,7 @@ #define MAX_SCHED_RQ (16 * BLKDEV_DEFAULT_RQ) +struct io_cq *blk_mq_sched_get_icq(struct request_queue *q); void blk_mq_sched_assign_ioc(struct request *rq); bool blk_mq_sched_try_merge(struct request_queue *q, struct bio *bio,