block: move sysfs_lock into elevator_init
authorChristoph Hellwig <hch@lst.de>
Thu, 31 May 2018 17:11:39 +0000 (19:11 +0200)
committerJens Axboe <axboe@kernel.dk>
Fri, 1 Jun 2018 13:38:19 +0000 (07:38 -0600)
Both callers take just around so function call, so move it in.
Also remove the now pointless blk_mq_sched_init wrapper.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>
Tested-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-core.c
block/blk-mq-sched.c
block/blk-mq-sched.h
block/blk-mq.c
block/elevator.c

index 18b691c93b63445e9cb55f114f1f86a50fe6f15f..cd573a33a6f361185ecb1747d1655835a0b2e72e 100644 (file)
@@ -1175,16 +1175,8 @@ int blk_init_allocated_queue(struct request_queue *q)
 
        q->sg_reserved_size = INT_MAX;
 
-       /* Protect q->elevator from elevator_change */
-       mutex_lock(&q->sysfs_lock);
-
-       /* init elevator */
-       if (elevator_init(q)) {
-               mutex_unlock(&q->sysfs_lock);
+       if (elevator_init(q))
                goto out_exit_flush_rq;
-       }
-
-       mutex_unlock(&q->sysfs_lock);
        return 0;
 
 out_exit_flush_rq:
index fd4f68d61df0fa61ab6a3993d2d1e4cebe2fc77b..b1f06088cee51c1a4865e942078fc7c7748bba98 100644 (file)
@@ -647,14 +647,3 @@ void blk_mq_exit_sched(struct request_queue *q, struct elevator_queue *e)
        blk_mq_sched_tags_teardown(q);
        q->elevator = NULL;
 }
-
-int blk_mq_sched_init(struct request_queue *q)
-{
-       int ret;
-
-       mutex_lock(&q->sysfs_lock);
-       ret = elevator_init(q);
-       mutex_unlock(&q->sysfs_lock);
-
-       return ret;
-}
index 1e9c9018ace127977acdb67e41fefc20955b1991..0cb8f938dff9d6a9b2fd3f6b519790c6f9f7b805 100644 (file)
@@ -33,8 +33,6 @@ int blk_mq_sched_init_hctx(struct request_queue *q, struct blk_mq_hw_ctx *hctx,
 void blk_mq_sched_exit_hctx(struct request_queue *q, struct blk_mq_hw_ctx *hctx,
                            unsigned int hctx_idx);
 
-int blk_mq_sched_init(struct request_queue *q);
-
 static inline bool
 blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio)
 {
index 3d3952301b3e1e7674339fe588e0c092872d5d14..858d6edff4d351c298ac0a69dd8b84642cd56157 100644 (file)
@@ -2573,7 +2573,7 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
        if (!(set->flags & BLK_MQ_F_NO_SCHED)) {
                int ret;
 
-               ret = blk_mq_sched_init(q);
+               ret = elevator_init(q);
                if (ret)
                        return ERR_PTR(ret);
        }
index 9276540af2a17de0a6484f3649d758fba53c2ae9..d6480e70816eae5bfe829a5617d26b6e7a5ffe93 100644 (file)
@@ -202,16 +202,15 @@ static void elevator_release(struct kobject *kobj)
 int elevator_init(struct request_queue *q)
 {
        struct elevator_type *e = NULL;
-       int err;
+       int err = 0;
 
        /*
         * q->sysfs_lock must be held to provide mutual exclusion between
         * elevator_switch() and here.
         */
-       lockdep_assert_held(&q->sysfs_lock);
-
+       mutex_lock(&q->sysfs_lock);
        if (unlikely(q->elevator))
-               return 0;
+               goto out_unlock;
 
        /*
         * Use the default elevator specified by config boot param for
@@ -237,7 +236,7 @@ int elevator_init(struct request_queue *q)
                        if (q->nr_hw_queues == 1)
                                e = elevator_get(q, "mq-deadline", false);
                        if (!e)
-                               return 0;
+                               goto out_unlock;
                } else
                        e = elevator_get(q, CONFIG_DEFAULT_IOSCHED, false);
 
@@ -255,6 +254,8 @@ int elevator_init(struct request_queue *q)
                err = e->ops.sq.elevator_init_fn(q, e);
        if (err)
                elevator_put(e);
+out_unlock:
+       mutex_unlock(&q->sysfs_lock);
        return err;
 }