Commit 72f2f8f6 authored by Bart Van Assche's avatar Bart Van Assche Committed by Jens Axboe

blk-mq-debug: Introduce debugfs_create_files()

Replace the two debugfs_create_file() loops by a call to the new
debugfs_create_files() function. Add an empty element at the end
of the two attribute arrays such that the array size does not have
to be passed to debugfs_create_files().
Signed-off-by: default avatarBart Van Assche <bart.vanassche@sandisk.com>
Reviewed-by: default avatarOmar Sandoval <osandov@fb.com>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent 8c0f14ea
...@@ -652,6 +652,7 @@ static const struct blk_mq_debugfs_attr blk_mq_debugfs_hctx_attrs[] = { ...@@ -652,6 +652,7 @@ static const struct blk_mq_debugfs_attr blk_mq_debugfs_hctx_attrs[] = {
{"queued", 0600, &hctx_queued_fops}, {"queued", 0600, &hctx_queued_fops},
{"run", 0600, &hctx_run_fops}, {"run", 0600, &hctx_run_fops},
{"active", 0400, &hctx_active_fops}, {"active", 0400, &hctx_active_fops},
{},
}; };
static const struct blk_mq_debugfs_attr blk_mq_debugfs_ctx_attrs[] = { static const struct blk_mq_debugfs_attr blk_mq_debugfs_ctx_attrs[] = {
...@@ -659,6 +660,7 @@ static const struct blk_mq_debugfs_attr blk_mq_debugfs_ctx_attrs[] = { ...@@ -659,6 +660,7 @@ static const struct blk_mq_debugfs_attr blk_mq_debugfs_ctx_attrs[] = {
{"dispatched", 0600, &ctx_dispatched_fops}, {"dispatched", 0600, &ctx_dispatched_fops},
{"merged", 0600, &ctx_merged_fops}, {"merged", 0600, &ctx_merged_fops},
{"completed", 0600, &ctx_completed_fops}, {"completed", 0600, &ctx_completed_fops},
{},
}; };
int blk_mq_debugfs_register(struct request_queue *q, const char *name) int blk_mq_debugfs_register(struct request_queue *q, const char *name)
...@@ -687,27 +689,31 @@ void blk_mq_debugfs_unregister(struct request_queue *q) ...@@ -687,27 +689,31 @@ void blk_mq_debugfs_unregister(struct request_queue *q)
q->debugfs_dir = NULL; q->debugfs_dir = NULL;
} }
static bool debugfs_create_files(struct dentry *parent, void *data,
const struct blk_mq_debugfs_attr *attr)
{
for (; attr->name; attr++) {
if (!debugfs_create_file(attr->name, attr->mode, parent,
data, attr->fops))
return false;
}
return true;
}
static int blk_mq_debugfs_register_ctx(struct request_queue *q, static int blk_mq_debugfs_register_ctx(struct request_queue *q,
struct blk_mq_ctx *ctx, struct blk_mq_ctx *ctx,
struct dentry *hctx_dir) struct dentry *hctx_dir)
{ {
struct dentry *ctx_dir; struct dentry *ctx_dir;
char name[20]; char name[20];
int i;
snprintf(name, sizeof(name), "cpu%u", ctx->cpu); snprintf(name, sizeof(name), "cpu%u", ctx->cpu);
ctx_dir = debugfs_create_dir(name, hctx_dir); ctx_dir = debugfs_create_dir(name, hctx_dir);
if (!ctx_dir) if (!ctx_dir)
return -ENOMEM; return -ENOMEM;
for (i = 0; i < ARRAY_SIZE(blk_mq_debugfs_ctx_attrs); i++) { if (!debugfs_create_files(ctx_dir, ctx, blk_mq_debugfs_ctx_attrs))
const struct blk_mq_debugfs_attr *attr;
attr = &blk_mq_debugfs_ctx_attrs[i];
if (!debugfs_create_file(attr->name, attr->mode, ctx_dir, ctx,
attr->fops))
return -ENOMEM; return -ENOMEM;
}
return 0; return 0;
} }
...@@ -725,14 +731,8 @@ static int blk_mq_debugfs_register_hctx(struct request_queue *q, ...@@ -725,14 +731,8 @@ static int blk_mq_debugfs_register_hctx(struct request_queue *q,
if (!hctx_dir) if (!hctx_dir)
return -ENOMEM; return -ENOMEM;
for (i = 0; i < ARRAY_SIZE(blk_mq_debugfs_hctx_attrs); i++) { if (!debugfs_create_files(hctx_dir, hctx, blk_mq_debugfs_hctx_attrs))
const struct blk_mq_debugfs_attr *attr;
attr = &blk_mq_debugfs_hctx_attrs[i];
if (!debugfs_create_file(attr->name, attr->mode, hctx_dir, hctx,
attr->fops))
return -ENOMEM; return -ENOMEM;
}
hctx_for_each_ctx(hctx, ctx, i) { hctx_for_each_ctx(hctx, ctx, i) {
if (blk_mq_debugfs_register_ctx(q, ctx, hctx_dir)) if (blk_mq_debugfs_register_ctx(q, ctx, hctx_dir))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment