]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blobdiff - block/blk-mq.c
blk-mq: remove alloc_hctx and free_hctx methods
[mirror_ubuntu-artful-kernel.git] / block / blk-mq.c
index 04ef7ecb3c7fadf37a6801fc1a9b4976e4f50d8d..f27fe44230c2f9555a7fc7e1c567663961d8212a 100644 (file)
@@ -1,3 +1,9 @@
+/*
+ * Block multiqueue core code
+ *
+ * Copyright (C) 2013-2014 Jens Axboe
+ * Copyright (C) 2013-2014 Christoph Hellwig
+ */
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/backing-dev.h>
@@ -264,47 +270,30 @@ __blk_mq_alloc_request(struct request_queue *q, struct blk_mq_hw_ctx *hctx,
        return NULL;
 }
 
-
-static struct request *blk_mq_alloc_request_pinned(struct request_queue *q,
-                                                  int rw, gfp_t gfp,
-                                                  bool reserved)
-{
-       struct request *rq;
-
-       do {
-               struct blk_mq_ctx *ctx = blk_mq_get_ctx(q);
-               struct blk_mq_hw_ctx *hctx = q->mq_ops->map_queue(q, ctx->cpu);
-
-               rq = __blk_mq_alloc_request(q, hctx, ctx, rw, gfp & ~__GFP_WAIT,
-                                               reserved);
-               if (rq)
-                       break;
-
-               if (gfp & __GFP_WAIT) {
-                       __blk_mq_run_hw_queue(hctx);
-                       blk_mq_put_ctx(ctx);
-               } else {
-                       blk_mq_put_ctx(ctx);
-                       break;
-               }
-
-               blk_mq_wait_for_tags(hctx, reserved);
-       } while (1);
-
-       return rq;
-}
-
 struct request *blk_mq_alloc_request(struct request_queue *q, int rw, gfp_t gfp,
                bool reserved)
 {
+       struct blk_mq_ctx *ctx;
+       struct blk_mq_hw_ctx *hctx;
        struct request *rq;
 
        if (blk_mq_queue_enter(q))
                return NULL;
 
-       rq = blk_mq_alloc_request_pinned(q, rw, gfp, reserved);
-       if (rq)
-               blk_mq_put_ctx(rq->mq_ctx);
+       ctx = blk_mq_get_ctx(q);
+       hctx = q->mq_ops->map_queue(q, ctx->cpu);
+
+       rq = __blk_mq_alloc_request(q, hctx, ctx, rw, gfp & ~__GFP_WAIT,
+                                   reserved);
+       if (!rq && (gfp & __GFP_WAIT)) {
+               __blk_mq_run_hw_queue(hctx);
+               blk_mq_put_ctx(ctx);
+
+               ctx = blk_mq_get_ctx(q);
+               hctx = q->mq_ops->map_queue(q, ctx->cpu);
+               rq =  __blk_mq_alloc_request(q, hctx, ctx, rw, gfp, reserved);
+       }
+       blk_mq_put_ctx(ctx);
        return rq;
 }
 EXPORT_SYMBOL(blk_mq_alloc_request);
@@ -1180,12 +1169,14 @@ static struct request *blk_mq_map_request(struct request_queue *q,
        trace_block_getrq(q, bio, rw);
        rq = __blk_mq_alloc_request(q, hctx, ctx, rw, GFP_ATOMIC, false);
        if (unlikely(!rq)) {
+               __blk_mq_run_hw_queue(hctx);
                blk_mq_put_ctx(ctx);
                trace_block_sleeprq(q, bio, rw);
-               rq = blk_mq_alloc_request_pinned(q, rw, __GFP_WAIT|GFP_ATOMIC,
-                                                       false);
-               ctx = rq->mq_ctx;
+
+               ctx = blk_mq_get_ctx(q);
                hctx = q->mq_ops->map_queue(q, ctx->cpu);
+               rq = __blk_mq_alloc_request(q, hctx, ctx, rw,
+                                           __GFP_WAIT|GFP_ATOMIC, false);
        }
 
        hctx->queued++;
@@ -1344,21 +1335,6 @@ struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *q, const int cpu)
 }
 EXPORT_SYMBOL(blk_mq_map_queue);
 
-struct blk_mq_hw_ctx *blk_mq_alloc_single_hw_queue(struct blk_mq_tag_set *set,
-                                                  unsigned int hctx_index,
-                                                  int node)
-{
-       return kzalloc_node(sizeof(struct blk_mq_hw_ctx), GFP_KERNEL, node);
-}
-EXPORT_SYMBOL(blk_mq_alloc_single_hw_queue);
-
-void blk_mq_free_single_hw_queue(struct blk_mq_hw_ctx *hctx,
-                                unsigned int hctx_index)
-{
-       kfree(hctx);
-}
-EXPORT_SYMBOL(blk_mq_free_single_hw_queue);
-
 static void blk_mq_free_rq_map(struct blk_mq_tag_set *set,
                struct blk_mq_tags *tags, unsigned int hctx_idx)
 {
@@ -1599,7 +1575,7 @@ static void blk_mq_free_hw_queues(struct request_queue *q,
 
        queue_for_each_hw_ctx(q, hctx, i) {
                free_cpumask_var(hctx->cpumask);
-               set->ops->free_hctx(hctx, i);
+               kfree(hctx);
        }
 }
 
@@ -1820,7 +1796,8 @@ struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *set)
        for (i = 0; i < set->nr_hw_queues; i++) {
                int node = blk_mq_hw_queue_to_node(map, i);
 
-               hctxs[i] = set->ops->alloc_hctx(set, i, node);
+               hctxs[i] = kzalloc_node(sizeof(struct blk_mq_hw_ctx),
+                                       GFP_KERNEL, node);
                if (!hctxs[i])
                        goto err_hctxs;
 
@@ -1907,7 +1884,7 @@ err_hctxs:
                if (!hctxs[i])
                        break;
                free_cpumask_var(hctxs[i]->cpumask);
-               set->ops->free_hctx(hctxs[i], i);
+               kfree(hctxs[i]);
        }
 err_map:
        kfree(hctxs);
@@ -1992,9 +1969,7 @@ int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set)
        if (set->queue_depth < set->reserved_tags + BLK_MQ_TAG_MIN)
                return -EINVAL;
 
-       if (!set->nr_hw_queues ||
-           !set->ops->queue_rq || !set->ops->map_queue ||
-           !set->ops->alloc_hctx || !set->ops->free_hctx)
+       if (!set->nr_hw_queues || !set->ops->queue_rq || !set->ops->map_queue)
                return -EINVAL;