Skip to content

Commit 99d055b

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: remove per-disk debugfs files in blk_unregister_queue
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> Link: https://lore.kernel.org/r/20220614074827.458955-4-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 5cf9c91 commit 99d055b

File tree

4 files changed

+8
-25
lines changed

4 files changed

+8
-25
lines changed

block/blk-mq-debugfs.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -840,14 +840,6 @@ void blk_mq_debugfs_register_rqos(struct rq_qos *rqos)
840840
debugfs_create_files(rqos->debugfs_dir, rqos, rqos->ops->debugfs_attrs);
841841
}
842842

843-
void blk_mq_debugfs_unregister_queue_rqos(struct request_queue *q)
844-
{
845-
lockdep_assert_held(&q->debugfs_mutex);
846-
847-
debugfs_remove_recursive(q->rqos_debugfs_dir);
848-
q->rqos_debugfs_dir = NULL;
849-
}
850-
851843
void blk_mq_debugfs_register_sched_hctx(struct request_queue *q,
852844
struct blk_mq_hw_ctx *hctx)
853845
{

block/blk-mq-debugfs.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ void blk_mq_debugfs_unregister_sched_hctx(struct blk_mq_hw_ctx *hctx);
3535

3636
void blk_mq_debugfs_register_rqos(struct rq_qos *rqos);
3737
void blk_mq_debugfs_unregister_rqos(struct rq_qos *rqos);
38-
void blk_mq_debugfs_unregister_queue_rqos(struct request_queue *q);
3938
#else
4039
static inline void blk_mq_debugfs_register(struct request_queue *q)
4140
{
@@ -82,10 +81,6 @@ static inline void blk_mq_debugfs_register_rqos(struct rq_qos *rqos)
8281
static inline void blk_mq_debugfs_unregister_rqos(struct rq_qos *rqos)
8382
{
8483
}
85-
86-
static inline void blk_mq_debugfs_unregister_queue_rqos(struct request_queue *q)
87-
{
88-
}
8984
#endif
9085

9186
#ifdef CONFIG_BLK_DEBUG_FS_ZONED

block/blk-rq-qos.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,6 @@ void rq_qos_wait(struct rq_wait *rqw, void *private_data,
294294

295295
void rq_qos_exit(struct request_queue *q)
296296
{
297-
mutex_lock(&q->debugfs_mutex);
298-
blk_mq_debugfs_unregister_queue_rqos(q);
299-
mutex_unlock(&q->debugfs_mutex);
300-
301297
while (q->rq_qos) {
302298
struct rq_qos *rqos = q->rq_qos;
303299
q->rq_qos = rqos->next;

block/blk-sysfs.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -779,13 +779,6 @@ static void blk_release_queue(struct kobject *kobj)
779779
if (queue_is_mq(q))
780780
blk_mq_release(q);
781781

782-
mutex_lock(&q->debugfs_mutex);
783-
blk_trace_shutdown(q);
784-
debugfs_remove_recursive(q->debugfs_dir);
785-
q->debugfs_dir = NULL;
786-
q->sched_debugfs_dir = NULL;
787-
mutex_unlock(&q->debugfs_mutex);
788-
789782
bioset_exit(&q->bio_split);
790783

791784
if (blk_queue_has_srcu(q))
@@ -946,8 +939,15 @@ void blk_unregister_queue(struct gendisk *disk)
946939
/* Now that we've deleted all child objects, we can delete the queue. */
947940
kobject_uevent(&q->kobj, KOBJ_REMOVE);
948941
kobject_del(&q->kobj);
949-
950942
mutex_unlock(&q->sysfs_dir_lock);
951943

944+
mutex_lock(&q->debugfs_mutex);
945+
blk_trace_shutdown(q);
946+
debugfs_remove_recursive(q->debugfs_dir);
947+
q->debugfs_dir = NULL;
948+
q->sched_debugfs_dir = NULL;
949+
q->rqos_debugfs_dir = NULL;
950+
mutex_unlock(&q->debugfs_mutex);
951+
952952
kobject_put(&disk_to_dev(disk)->kobj);
953953
}

0 commit comments

Comments
 (0)