Skip to content

Commit e8185b8

Browse files
author
Ming Lei
committed
block: add two helpers for registering/un-registering sched debugfs
JIRA: https://issues.redhat.com/browse/RHEL-106845 commit ed3896a Author: Ming Lei <ming.lei@redhat.com> Date: Mon May 5 22:17:43 2025 +0800 block: add two helpers for registering/un-registering sched debugfs Add blk_mq_sched_reg_debugfs()/blk_mq_sched_unreg_debugfs() to clean up sched init/exit code a bit. Register & unregister debugfs for sched & sched_hctx order is changed a bit, but it is safe because sched & sched_hctx is guaranteed to be ready when exporting via debugfs. Reviewed-by: Yu Kuai <yukuai3@huawei.com> Reviewed-by: Nilay Shroff <nilay@linux.ibm.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Ming Lei <ming.lei@redhat.com> Link: https://lore.kernel.org/r/20250505141805.2751237-6-ming.lei@redhat.com Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Ming Lei <ming.lei@redhat.com>
1 parent 3e9a5f6 commit e8185b8

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

block/blk-mq-sched.c

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,30 @@ static int blk_mq_init_sched_shared_tags(struct request_queue *queue)
434434
return 0;
435435
}
436436

437+
static void blk_mq_sched_reg_debugfs(struct request_queue *q)
438+
{
439+
struct blk_mq_hw_ctx *hctx;
440+
unsigned long i;
441+
442+
mutex_lock(&q->debugfs_mutex);
443+
blk_mq_debugfs_register_sched(q);
444+
queue_for_each_hw_ctx(q, hctx, i)
445+
blk_mq_debugfs_register_sched_hctx(q, hctx);
446+
mutex_unlock(&q->debugfs_mutex);
447+
}
448+
449+
static void blk_mq_sched_unreg_debugfs(struct request_queue *q)
450+
{
451+
struct blk_mq_hw_ctx *hctx;
452+
unsigned long i;
453+
454+
mutex_lock(&q->debugfs_mutex);
455+
queue_for_each_hw_ctx(q, hctx, i)
456+
blk_mq_debugfs_unregister_sched_hctx(hctx);
457+
blk_mq_debugfs_unregister_sched(q);
458+
mutex_unlock(&q->debugfs_mutex);
459+
}
460+
437461
/* caller must have a reference to @e, will grab another one if successful */
438462
int blk_mq_init_sched(struct request_queue *q, struct elevator_type *e)
439463
{
@@ -467,10 +491,6 @@ int blk_mq_init_sched(struct request_queue *q, struct elevator_type *e)
467491
if (ret)
468492
goto err_free_map_and_rqs;
469493

470-
mutex_lock(&q->debugfs_mutex);
471-
blk_mq_debugfs_register_sched(q);
472-
mutex_unlock(&q->debugfs_mutex);
473-
474494
queue_for_each_hw_ctx(q, hctx, i) {
475495
if (e->ops.init_hctx) {
476496
ret = e->ops.init_hctx(hctx, i);
@@ -482,11 +502,11 @@ int blk_mq_init_sched(struct request_queue *q, struct elevator_type *e)
482502
return ret;
483503
}
484504
}
485-
mutex_lock(&q->debugfs_mutex);
486-
blk_mq_debugfs_register_sched_hctx(q, hctx);
487-
mutex_unlock(&q->debugfs_mutex);
488505
}
489506

507+
/* sched is initialized, it is ready to export it via debugfs */
508+
blk_mq_sched_reg_debugfs(q);
509+
490510
return 0;
491511

492512
err_free_map_and_rqs:
@@ -524,22 +544,17 @@ void blk_mq_exit_sched(struct request_queue *q, struct elevator_queue *e)
524544
unsigned long i;
525545
unsigned int flags = 0;
526546

527-
queue_for_each_hw_ctx(q, hctx, i) {
528-
mutex_lock(&q->debugfs_mutex);
529-
blk_mq_debugfs_unregister_sched_hctx(hctx);
530-
mutex_unlock(&q->debugfs_mutex);
547+
/* unexport via debugfs before exiting sched */
548+
blk_mq_sched_unreg_debugfs(q);
531549

550+
queue_for_each_hw_ctx(q, hctx, i) {
532551
if (e->type->ops.exit_hctx && hctx->sched_data) {
533552
e->type->ops.exit_hctx(hctx, i);
534553
hctx->sched_data = NULL;
535554
}
536555
flags = hctx->flags;
537556
}
538557

539-
mutex_lock(&q->debugfs_mutex);
540-
blk_mq_debugfs_unregister_sched(q);
541-
mutex_unlock(&q->debugfs_mutex);
542-
543558
if (e->type->ops.exit_sched)
544559
e->type->ops.exit_sched(e);
545560
blk_mq_sched_tags_teardown(q, flags);

0 commit comments

Comments
 (0)