]> www.infradead.org Git - users/hch/block.git/commitdiff
block: remove per-disk debugfs files in blk_unregister_queue
authorChristoph Hellwig <hch@lst.de>
Fri, 27 May 2022 16:09:35 +0000 (18:09 +0200)
committerChristoph Hellwig <hch@lst.de>
Mon, 30 May 2022 13:13:14 +0000 (15:13 +0200)
The block debugfs files are created in blk_register_queue, which is
called by add_disk and use a naming scheme based on the disk_name.
After del_gendisk returns that name can be reused and thus we must not
leave these debugfs files around, otherwise the kernel is unhappy
and spews messages like:

Directory XXXXX with parent 'block' already present!

and the newly created devices will not have working debugfs files.

Move the unregistration to blk_unregister_queue instead (which matches
the sysfs unregistration) to make sure the debugfs life time rules match
those of the disk name.

As part of the move also make sure the whole debugfs unregistration is
inside a single debugfs_mutex critical section.

Note that this breaks blktests block/002, which checks that the debugfs
directory has not been removed while blktests is running, but that
particular check should simply be removed from the test case.

Signed-off-by: Christoph Hellwig <hch@lst.de>
block/blk-mq-debugfs.c
block/blk-mq-debugfs.h
block/blk-sysfs.c
block/genhd.c

index bee80fc5620525e1765f84920325163133ef69ab..6bda8dd7a271fc277ae792e8ec59a69a616d3cd9 100644 (file)
@@ -836,14 +836,6 @@ void blk_mq_debugfs_register_rqos(struct rq_qos *rqos)
        debugfs_create_files(rqos->debugfs_dir, rqos, rqos->ops->debugfs_attrs);
 }
 
-void blk_mq_debugfs_unregister_queue_rqos(struct request_queue *q)
-{
-       lockdep_assert_held(&q->debugfs_mutex);
-
-       debugfs_remove_recursive(q->rqos_debugfs_dir);
-       q->rqos_debugfs_dir = NULL;
-}
-
 void blk_mq_debugfs_register_sched_hctx(struct request_queue *q,
                                        struct blk_mq_hw_ctx *hctx)
 {
index 771d4583287885df513bc072108e937e5fe8af9b..9c7d4b6117d41ed343dab8c20b1859da2b9c6f60 100644 (file)
@@ -35,7 +35,6 @@ void blk_mq_debugfs_unregister_sched_hctx(struct blk_mq_hw_ctx *hctx);
 
 void blk_mq_debugfs_register_rqos(struct rq_qos *rqos);
 void blk_mq_debugfs_unregister_rqos(struct rq_qos *rqos);
-void blk_mq_debugfs_unregister_queue_rqos(struct request_queue *q);
 #else
 static inline void blk_mq_debugfs_register(struct request_queue *q)
 {
@@ -82,10 +81,6 @@ static inline void blk_mq_debugfs_register_rqos(struct rq_qos *rqos)
 static inline void blk_mq_debugfs_unregister_rqos(struct rq_qos *rqos)
 {
 }
-
-static inline void blk_mq_debugfs_unregister_queue_rqos(struct request_queue *q)
-{
-}
 #endif
 
 #ifdef CONFIG_BLK_DEBUG_FS_ZONED
index 6e4801b217a792cf9b01354efe771d3a61d60def..9b905e9443e49606e09311757985eddeebc6cbef 100644 (file)
@@ -779,13 +779,6 @@ static void blk_release_queue(struct kobject *kobj)
        if (queue_is_mq(q))
                blk_mq_release(q);
 
-       mutex_lock(&q->debugfs_mutex);
-       blk_trace_shutdown(q);
-       debugfs_remove_recursive(q->debugfs_dir);
-       q->debugfs_dir = NULL;
-       q->sched_debugfs_dir = NULL;
-       mutex_unlock(&q->debugfs_mutex);
-
        bioset_exit(&q->bio_split);
 
        if (blk_queue_has_srcu(q))
@@ -946,8 +939,15 @@ void blk_unregister_queue(struct gendisk *disk)
        /* 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);
 
+       mutex_lock(&q->debugfs_mutex);
+       blk_trace_shutdown(q);
+       debugfs_remove_recursive(q->debugfs_dir);
+       q->debugfs_dir = NULL;
+       q->sched_debugfs_dir = NULL;
+       q->rqos_debugfs_dir = NULL;
+       mutex_unlock(&q->debugfs_mutex);
+
        kobject_put(&disk_to_dev(disk)->kobj);
 }
index 9f4eb7516df7e1578d691c51cd4652aa928101e5..36532b93184191e08f5ab8048ecb6ce99cfc33ee 100644 (file)
@@ -1122,10 +1122,6 @@ static void disk_release_mq(struct request_queue *q)
 {
        blk_mq_cancel_work_sync(q);
 
-       mutex_lock(&q->debugfs_mutex);
-       blk_mq_debugfs_unregister_queue_rqos(q);
-       mutex_unlock(&q->debugfs_mutex);
-
        /*
         * There can't be any non non-passthrough bios in flight here, but
         * requests stay around longer, including passthrough ones so we