Skip to content

Commit 18fbda9

Browse files
osandovaxboe
authored andcommitted
block: use same block debugfs directory for blk-mq and blktrace
When I added the blk-mq debugging information to debugfs, I didn't notice that blktrace also creates a "block" directory in debugfs. Make them use the same dentry, now created in the core block code. Based on a patch from Jens. Signed-off-by: Omar Sandoval <osandov@fb.com> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent a428d31 commit 18fbda9

File tree

6 files changed

+21
-29
lines changed

6 files changed

+21
-29
lines changed

block/blk-core.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <linux/ratelimit.h>
3434
#include <linux/pm_runtime.h>
3535
#include <linux/blk-cgroup.h>
36+
#include <linux/debugfs.h>
3637

3738
#define CREATE_TRACE_POINTS
3839
#include <trace/events/block.h>
@@ -42,6 +43,10 @@
4243
#include "blk-mq-sched.h"
4344
#include "blk-wbt.h"
4445

46+
#ifdef CONFIG_DEBUG_FS
47+
struct dentry *blk_debugfs_root;
48+
#endif
49+
4550
EXPORT_TRACEPOINT_SYMBOL_GPL(block_bio_remap);
4651
EXPORT_TRACEPOINT_SYMBOL_GPL(block_rq_remap);
4752
EXPORT_TRACEPOINT_SYMBOL_GPL(block_bio_complete);
@@ -3441,5 +3446,9 @@ int __init blk_dev_init(void)
34413446
blk_requestq_cachep = kmem_cache_create("request_queue",
34423447
sizeof(struct request_queue), 0, SLAB_PANIC, NULL);
34433448

3449+
#ifdef CONFIG_DEBUG_FS
3450+
blk_debugfs_root = debugfs_create_dir("block", NULL);
3451+
#endif
3452+
34443453
return 0;
34453454
}

block/blk-mq-debugfs.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/debugfs.h>
2020

2121
#include <linux/blk-mq.h>
22+
#include "blk.h"
2223
#include "blk-mq.h"
2324
#include "blk-mq-tag.h"
2425

@@ -28,8 +29,6 @@ struct blk_mq_debugfs_attr {
2829
const struct file_operations *fops;
2930
};
3031

31-
static struct dentry *block_debugfs_root;
32-
3332
static int blk_mq_debugfs_seq_open(struct inode *inode, struct file *file,
3433
const struct seq_operations *ops)
3534
{
@@ -665,10 +664,10 @@ static const struct blk_mq_debugfs_attr blk_mq_debugfs_ctx_attrs[] = {
665664

666665
int blk_mq_debugfs_register(struct request_queue *q, const char *name)
667666
{
668-
if (!block_debugfs_root)
667+
if (!blk_debugfs_root)
669668
return -ENOENT;
670669

671-
q->debugfs_dir = debugfs_create_dir(name, block_debugfs_root);
670+
q->debugfs_dir = debugfs_create_dir(name, blk_debugfs_root);
672671
if (!q->debugfs_dir)
673672
goto err;
674673

@@ -771,8 +770,3 @@ void blk_mq_debugfs_unregister_hctxs(struct request_queue *q)
771770
debugfs_remove_recursive(q->mq_debugfs_dir);
772771
q->mq_debugfs_dir = NULL;
773772
}
774-
775-
void blk_mq_debugfs_init(void)
776-
{
777-
block_debugfs_root = debugfs_create_dir("block", NULL);
778-
}

block/blk-mq.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2817,8 +2817,6 @@ void blk_mq_enable_hotplug(void)
28172817

28182818
static int __init blk_mq_init(void)
28192819
{
2820-
blk_mq_debugfs_init();
2821-
28222820
cpuhp_setup_state_multi(CPUHP_BLK_MQ_DEAD, "block/mq:dead", NULL,
28232821
blk_mq_hctx_notify_dead);
28242822

block/blk-mq.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,11 @@ extern void blk_mq_hctx_kobj_init(struct blk_mq_hw_ctx *hctx);
8585
* debugfs helpers
8686
*/
8787
#ifdef CONFIG_BLK_DEBUG_FS
88-
void blk_mq_debugfs_init(void);
8988
int blk_mq_debugfs_register(struct request_queue *q, const char *name);
9089
void blk_mq_debugfs_unregister(struct request_queue *q);
9190
int blk_mq_debugfs_register_hctxs(struct request_queue *q);
9291
void blk_mq_debugfs_unregister_hctxs(struct request_queue *q);
9392
#else
94-
static inline void blk_mq_debugfs_init(void)
95-
{
96-
}
97-
9893
static inline int blk_mq_debugfs_register(struct request_queue *q,
9994
const char *name)
10095
{

block/blk.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
/* Max future timer expiry for timeouts */
1515
#define BLK_MAX_TIMEOUT (5 * HZ)
1616

17+
#ifdef CONFIG_DEBUG_FS
18+
extern struct dentry *blk_debugfs_root;
19+
#endif
20+
1721
struct blk_flush_queue {
1822
unsigned int flush_queue_delayed:1;
1923
unsigned int flush_pending_idx:1;

kernel/trace/blktrace.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include <linux/uaccess.h>
2929
#include <linux/list.h>
3030

31+
#include "../../block/blk.h"
32+
3133
#include <trace/events/block.h>
3234

3335
#include "trace_output.h"
@@ -292,9 +294,6 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
292294
local_irq_restore(flags);
293295
}
294296

295-
static struct dentry *blk_tree_root;
296-
static DEFINE_MUTEX(blk_tree_mutex);
297-
298297
static void blk_trace_free(struct blk_trace *bt)
299298
{
300299
debugfs_remove(bt->msg_file);
@@ -468,17 +467,10 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
468467

469468
ret = -ENOENT;
470469

471-
mutex_lock(&blk_tree_mutex);
472-
if (!blk_tree_root) {
473-
blk_tree_root = debugfs_create_dir("block", NULL);
474-
if (!blk_tree_root) {
475-
mutex_unlock(&blk_tree_mutex);
476-
goto err;
477-
}
478-
}
479-
mutex_unlock(&blk_tree_mutex);
470+
if (!blk_debugfs_root)
471+
goto err;
480472

481-
dir = debugfs_create_dir(buts->name, blk_tree_root);
473+
dir = debugfs_create_dir(buts->name, blk_debugfs_root);
482474

483475
if (!dir)
484476
goto err;

0 commit comments

Comments
 (0)