Merge tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
[platform/kernel/linux-starfive.git] / block / blk-sysfs.c
index 5e81e65..88bd41d 100644 (file)
@@ -10,7 +10,6 @@
 #include <linux/backing-dev.h>
 #include <linux/blktrace_api.h>
 #include <linux/blk-mq.h>
-#include <linux/blk-cgroup.h>
 #include <linux/debugfs.h>
 
 #include "blk.h"
@@ -18,6 +17,7 @@
 #include "blk-mq-debugfs.h"
 #include "blk-mq-sched.h"
 #include "blk-wbt.h"
+#include "blk-cgroup.h"
 #include "blk-throttle.h"
 
 struct queue_sysfs_entry {
@@ -738,27 +738,6 @@ static void blk_free_queue_rcu(struct rcu_head *rcu_head)
        kmem_cache_free(blk_get_queue_kmem_cache(blk_queue_has_srcu(q)), q);
 }
 
-/* Unconfigure the I/O scheduler and dissociate from the cgroup controller. */
-static void blk_exit_queue(struct request_queue *q)
-{
-       /*
-        * Since the I/O scheduler exit code may access cgroup information,
-        * perform I/O scheduler exit before disassociating from the block
-        * cgroup controller.
-        */
-       if (q->elevator) {
-               ioc_clear_queue(q);
-               elevator_exit(q);
-       }
-
-       /*
-        * Remove all references to @q from the block cgroup controller before
-        * restoring @q->queue_lock to avoid that restoring this pointer causes
-        * e.g. blkcg_print_blkgs() to crash.
-        */
-       blkcg_exit_queue(q);
-}
-
 /**
  * blk_release_queue - releases all allocated resources of the request_queue
  * @kobj: pointer to a kobject, whose container is a request_queue
@@ -786,12 +765,12 @@ static void blk_release_queue(struct kobject *kobj)
 
        might_sleep();
 
+       percpu_ref_exit(&q->q_usage_counter);
+
        if (q->poll_stat)
                blk_stat_remove_callback(q, q->poll_cb);
        blk_stat_free_callback(q->poll_cb);
 
-       blk_exit_queue(q);
-
        blk_free_queue_stats(q->stats);
        kfree(q->poll_stat);
 
@@ -879,6 +858,10 @@ int blk_register_queue(struct gendisk *disk)
                        goto put_dev;
        }
 
+       ret = blk_crypto_sysfs_register(q);
+       if (ret)
+               goto put_dev;
+
        blk_queue_flag_set(QUEUE_FLAG_REGISTERED, q);
        wbt_enable_default(q);
        blk_throtl_register_queue(q);
@@ -909,6 +892,7 @@ unlock:
        return ret;
 
 put_dev:
+       elv_unregister_queue(q);
        disk_unregister_independent_access_ranges(disk);
        mutex_unlock(&q->sysfs_lock);
        mutex_unlock(&q->sysfs_dir_lock);
@@ -953,16 +937,18 @@ void blk_unregister_queue(struct gendisk *disk)
         */
        if (queue_is_mq(q))
                blk_mq_unregister_dev(disk_to_dev(disk), q);
-
-       kobject_uevent(&q->kobj, KOBJ_REMOVE);
-       kobject_del(&q->kobj);
+       blk_crypto_sysfs_unregister(q);
        blk_trace_remove_sysfs(disk_to_dev(disk));
 
        mutex_lock(&q->sysfs_lock);
-       if (q->elevator)
-               elv_unregister_queue(q);
+       elv_unregister_queue(q);
        disk_unregister_independent_access_ranges(disk);
        mutex_unlock(&q->sysfs_lock);
+
+       /* Now that we've deleted all child objects, we can delete the queue. */
+       kobject_uevent(&q->kobj, KOBJ_REMOVE);
+       kobject_del(&q->kobj);
+
        mutex_unlock(&q->sysfs_dir_lock);
 
        kobject_put(&disk_to_dev(disk)->kobj);