Unverified Commit f2ffc6af authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!11645 block: backport debugfs patches

Merge Pull Request from: @ci-robot 
 
PR sync from: Yu Kuai <yukuai3@huawei.com>
https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/5GEVUIWYAWGEKGTBD45EXOGR5TOCUIIJ/ 
Christoph Hellwig (2):
  block: serialize all debugfs operations using q->debugfs_mutex
  block: remove per-disk debugfs files in blk_unregister_queue

Greg Kroah-Hartman (2):
  blk-mq: no need to check return value of debugfs_create functions
  blk-mq: fix up placement of debugfs directory of queue files

Jan Kara (1):
  blktrace: Avoid sparse warnings when assigning q->blk_trace

Luis Chamberlain (3):
  blktrace: break out of blktrace setup on concurrent calls
  blktrace: annotate required lock on do_blk_trace_setup()
  block: create the request_queue debugfs_dir on registration

Ming Lei (1):
  blk-mq: don't create hctx debugfs dir until q->debugfs_dir is created

Saravanan D (1):
  blk-mq: Fix spurious debugfs directory creation during initialization

Yu Kuai (3):
  block: shutdown blktrace in blk_release_queue()
  block: protect blk_mq_debugfs_register/unregister_hctx() with
    'debugfs_mutex'
  block: fix kabi broken in struct request_queue


-- 
2.39.2
 
https://gitee.com/openeuler/kernel/issues/IAGRKP 
 
Link:https://gitee.com/openeuler/kernel/pulls/11645

 

Reviewed-by: default avatarzhangyi (F) <yi.zhang@huawei.com>
Reviewed-by: default avatarXu Kuohai <xukuohai@huawei.com>
Signed-off-by: default avatarZhang Changzhong <zhangchangzhong@huawei.com>
parents 3bbb0f88 5eba33fc
Loading
Loading
Loading
Loading
+1 −7
Original line number Diff line number Diff line
@@ -45,9 +45,7 @@
#include "blk-rq-qos.h"
#include "blk-io-hierarchy/stats.h"

#ifdef CONFIG_DEBUG_FS
struct dentry *blk_debugfs_root;
#endif

EXPORT_TRACEPOINT_SYMBOL_GPL(block_bio_remap);
EXPORT_TRACEPOINT_SYMBOL_GPL(block_rq_remap);
@@ -1346,9 +1344,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id,

	kobject_init(&q->kobj, &blk_queue_ktype);

#ifdef CONFIG_BLK_DEV_IO_TRACE
	mutex_init(&q->blk_trace_mutex);
#endif
	mutex_init(&q->debugfs_mutex);
	mutex_init(&q->sysfs_lock);
	mutex_init(&q_wrapper->sysfs_dir_lock);
	spin_lock_init(&q->__queue_lock);
@@ -4307,9 +4303,7 @@ int __init blk_dev_init(void)

	init_blk_queue_async_dispatch();

#ifdef CONFIG_DEBUG_FS
	blk_debugfs_root = debugfs_create_dir("block", NULL);
#endif

	return 0;
}
+6 −0
Original line number Diff line number Diff line
@@ -198,6 +198,8 @@ void blk_mq_debugfs_register_hierarchy(struct request_queue *q,
	struct blk_io_hierarchy_stats *stats =
		queue_to_wrapper(q)->io_hierarchy_stats;

	lockdep_assert_held(&q->debugfs_mutex);

	if (!blk_mq_hierarchy_registered(q, stage) ||
	    !blk_mq_debugfs_enabled(q))
		return;
@@ -211,6 +213,8 @@ void blk_mq_debugfs_unregister_hierarchy(struct request_queue *q,
	struct blk_io_hierarchy_stats *stats =
		queue_to_wrapper(q)->io_hierarchy_stats;

	lockdep_assert_held(&q->debugfs_mutex);

	if (!blk_mq_hierarchy_registered(q, stage) ||
	    !blk_mq_debugfs_enabled(q))
		return;
@@ -223,6 +227,8 @@ void blk_mq_debugfs_create_default_hierarchy_attr(struct request_queue *q)
	struct blk_io_hierarchy_stats *stats =
		queue_to_wrapper(q)->io_hierarchy_stats;

	lockdep_assert_held(&q->debugfs_mutex);

	if (!blk_mq_debugfs_enabled(q))
		return;

+8 −0
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ void blk_mq_debugfs_register_hierarchy_stats(struct request_queue *q)
	struct blk_io_hierarchy_stats *stats;
	enum stage_group stage;

	lockdep_assert_held(&q->debugfs_mutex);

	stats = queue_to_wrapper(q)->io_hierarchy_stats;
	if (!stats || !blk_mq_debugfs_enabled(q))
		return;
@@ -203,8 +205,10 @@ void blk_mq_register_hierarchy(struct request_queue *q, enum stage_group stage)

	blk_mq_freeze_queue(q);

	mutex_lock(&q->debugfs_mutex);
	WRITE_ONCE(stats->hstage[stage], hstage);
	blk_mq_debugfs_register_hierarchy(q, stage);
	mutex_unlock(&q->debugfs_mutex);

	blk_mq_unfreeze_queue(q);
}
@@ -220,6 +224,8 @@ void blk_mq_unregister_hierarchy(struct request_queue *q,
	if (!blk_mq_hierarchy_registered(q, stage))
		return;

	mutex_lock(&q->debugfs_mutex);

	blk_mq_debugfs_unregister_hierarchy(q, stage);
	blk_io_hierarchy_iodump_exit(q, stage);

@@ -230,6 +236,8 @@ void blk_mq_unregister_hierarchy(struct request_queue *q,
	spin_unlock(&stats->hstage_lock);

	kfree(hstage);

	mutex_unlock(&q->debugfs_mutex);
}
EXPORT_SYMBOL_GPL(blk_mq_unregister_hierarchy);

+62 −96
Original line number Diff line number Diff line
@@ -823,38 +823,25 @@ static const struct blk_mq_debugfs_attr blk_mq_debugfs_ctx_attrs[] = {
	{},
};

bool debugfs_create_files(struct dentry *parent, void *data,
void debugfs_create_files(struct dentry *parent, void *data,
			  const struct blk_mq_debugfs_attr *attr)
{
	if (IS_ERR_OR_NULL(parent))
		return false;
		return;

	d_inode(parent)->i_private = data;

	for (; attr->name; attr++) {
		if (!debugfs_create_file(attr->name, attr->mode, parent,
					 (void *)attr, &blk_mq_debugfs_fops))
			return false;
	}
	return true;
	for (; attr->name; attr++)
		debugfs_create_file(attr->name, attr->mode, parent,
				    (void *)attr, &blk_mq_debugfs_fops);
}

int blk_mq_debugfs_register(struct request_queue *q)
void blk_mq_debugfs_register(struct request_queue *q)
{
	struct blk_mq_hw_ctx *hctx;
	int i;

	if (!blk_debugfs_root)
		return -ENOENT;

	q->debugfs_dir = debugfs_create_dir(kobject_name(q->kobj.parent),
					    blk_debugfs_root);
	if (!q->debugfs_dir)
		return -ENOMEM;

	if (!debugfs_create_files(q->debugfs_dir, q,
				  blk_mq_debugfs_queue_attrs))
		goto err;
	debugfs_create_files(q->debugfs_dir, q, blk_mq_debugfs_queue_attrs);

	/*
	 * blk_mq_init_sched() attempted to do this already, but q->debugfs_dir
@@ -866,29 +853,16 @@ int blk_mq_debugfs_register(struct request_queue *q)

	/* Similarly, blk_mq_init_hctx() couldn't do this previously. */
	queue_for_each_hw_ctx(q, hctx, i) {
		if (!hctx->debugfs_dir && blk_mq_debugfs_register_hctx(q, hctx))
			goto err;
		if (q->elevator && !hctx->sched_debugfs_dir &&
		    blk_mq_debugfs_register_sched_hctx(q, hctx))
			goto err;
		if (!hctx->debugfs_dir)
			blk_mq_debugfs_register_hctx(q, hctx);
		if (q->elevator && !hctx->sched_debugfs_dir)
			blk_mq_debugfs_register_sched_hctx(q, hctx);
	}

	blk_mq_debugfs_register_hierarchy_stats(q);
	return 0;

err:
	blk_mq_debugfs_unregister(q);
	return -ENOMEM;
}

void blk_mq_debugfs_unregister(struct request_queue *q)
{
	debugfs_remove_recursive(q->debugfs_dir);
	q->sched_debugfs_dir = NULL;
	q->debugfs_dir = NULL;
}

static int blk_mq_debugfs_register_ctx(struct blk_mq_hw_ctx *hctx,
static void blk_mq_debugfs_register_ctx(struct blk_mq_hw_ctx *hctx,
					struct blk_mq_ctx *ctx)
{
	struct dentry *ctx_dir;
@@ -896,64 +870,51 @@ static int blk_mq_debugfs_register_ctx(struct blk_mq_hw_ctx *hctx,

	snprintf(name, sizeof(name), "cpu%u", ctx->cpu);
	ctx_dir = debugfs_create_dir(name, hctx->debugfs_dir);
	if (!ctx_dir)
		return -ENOMEM;

	if (!debugfs_create_files(ctx_dir, ctx, blk_mq_debugfs_ctx_attrs))
		return -ENOMEM;

	return 0;
	debugfs_create_files(ctx_dir, ctx, blk_mq_debugfs_ctx_attrs);
}

int blk_mq_debugfs_register_hctx(struct request_queue *q,
void blk_mq_debugfs_register_hctx(struct request_queue *q,
				  struct blk_mq_hw_ctx *hctx)
{
	struct blk_mq_ctx *ctx;
	char name[20];
	int i;

	lockdep_assert_held(&q->debugfs_mutex);

	if (!q->debugfs_dir)
		return -ENOENT;
		return;

	snprintf(name, sizeof(name), "hctx%u", hctx->queue_num);
	hctx->debugfs_dir = debugfs_create_dir(name, q->debugfs_dir);
	if (!hctx->debugfs_dir)
		return -ENOMEM;

	if (!debugfs_create_files(hctx->debugfs_dir, hctx,
				  blk_mq_debugfs_hctx_attrs))
		goto err;
	debugfs_create_files(hctx->debugfs_dir, hctx, blk_mq_debugfs_hctx_attrs);

	hctx_for_each_ctx(hctx, ctx, i) {
		if (blk_mq_debugfs_register_ctx(hctx, ctx))
			goto err;
	}

	return 0;

err:
	blk_mq_debugfs_unregister_hctx(hctx);
	return -ENOMEM;
	hctx_for_each_ctx(hctx, ctx, i)
		blk_mq_debugfs_register_ctx(hctx, ctx);
}

void blk_mq_debugfs_unregister_hctx(struct blk_mq_hw_ctx *hctx)
{
	lockdep_assert_held(&hctx->queue->debugfs_mutex);

	if (!hctx->queue->debugfs_dir)
		return;
	debugfs_remove_recursive(hctx->debugfs_dir);
	hctx->sched_debugfs_dir = NULL;
	hctx->debugfs_dir = NULL;
}

int blk_mq_debugfs_register_hctxs(struct request_queue *q)
void blk_mq_debugfs_register_hctxs(struct request_queue *q)
{
	struct blk_mq_hw_ctx *hctx;
	int i;

	queue_for_each_hw_ctx(q, hctx, i) {
		if (blk_mq_debugfs_register_hctx(q, hctx))
			return -ENOMEM;
	}

	return 0;
	mutex_lock(&q->debugfs_mutex);
	queue_for_each_hw_ctx(q, hctx, i)
		blk_mq_debugfs_register_hctx(q, hctx);
	mutex_unlock(&q->debugfs_mutex);
}

void blk_mq_debugfs_unregister_hctxs(struct request_queue *q)
@@ -961,66 +922,71 @@ void blk_mq_debugfs_unregister_hctxs(struct request_queue *q)
	struct blk_mq_hw_ctx *hctx;
	int i;

	mutex_lock(&q->debugfs_mutex);
	queue_for_each_hw_ctx(q, hctx, i)
		blk_mq_debugfs_unregister_hctx(hctx);
	mutex_unlock(&q->debugfs_mutex);
}

int blk_mq_debugfs_register_sched(struct request_queue *q)
void blk_mq_debugfs_register_sched(struct request_queue *q)
{
	struct elevator_type *e = q->elevator->type;

	lockdep_assert_held(&q->debugfs_mutex);

	/*
	 * If the parent directory has not been created yet, return, we will be
	 * called again later on and the directory/files will be created then.
	 */
	if (!q->debugfs_dir)
		return -ENOENT;
		return;

	if (!e->queue_debugfs_attrs)
		return 0;
		return;

	q->sched_debugfs_dir = debugfs_create_dir("sched", q->debugfs_dir);
	if (!q->sched_debugfs_dir)
		return -ENOMEM;

	if (!debugfs_create_files(q->sched_debugfs_dir, q,
				  e->queue_debugfs_attrs))
		goto err;

	return 0;

err:
	blk_mq_debugfs_unregister_sched(q);
	return -ENOMEM;
	debugfs_create_files(q->sched_debugfs_dir, q, e->queue_debugfs_attrs);
}

void blk_mq_debugfs_unregister_sched(struct request_queue *q)
{
	lockdep_assert_held(&q->debugfs_mutex);

	debugfs_remove_recursive(q->sched_debugfs_dir);
	q->sched_debugfs_dir = NULL;
}

int blk_mq_debugfs_register_sched_hctx(struct request_queue *q,
void blk_mq_debugfs_register_sched_hctx(struct request_queue *q,
					struct blk_mq_hw_ctx *hctx)
{
	struct elevator_type *e = q->elevator->type;

	lockdep_assert_held(&q->debugfs_mutex);

	/*
	 * If the parent debugfs directory has not been created yet, return;
	 * We will be called again later on with appropriate parent debugfs
	 * directory from blk_register_queue()
	 */
	if (!hctx->debugfs_dir)
		return -ENOENT;
		return;

	if (!e->hctx_debugfs_attrs)
		return 0;
		return;

	hctx->sched_debugfs_dir = debugfs_create_dir("sched",
						     hctx->debugfs_dir);
	if (!hctx->sched_debugfs_dir)
		return -ENOMEM;

	if (!debugfs_create_files(hctx->sched_debugfs_dir, hctx,
				  e->hctx_debugfs_attrs))
		return -ENOMEM;

	return 0;
	debugfs_create_files(hctx->sched_debugfs_dir, hctx,
			     e->hctx_debugfs_attrs);
}

void blk_mq_debugfs_unregister_sched_hctx(struct blk_mq_hw_ctx *hctx)
{
	lockdep_assert_held(&hctx->queue->debugfs_mutex);

	if (!hctx->queue->debugfs_dir)
		return;
	debugfs_remove_recursive(hctx->sched_debugfs_dir);
	hctx->sched_debugfs_dir = NULL;
}
+13 −23
Original line number Diff line number Diff line
@@ -19,21 +19,20 @@ void debugfs_rq_show(struct seq_file *m, struct request *rq);
int __blk_mq_debugfs_rq_show(struct seq_file *m, struct request *rq);
int blk_mq_debugfs_rq_show(struct seq_file *m, void *v);

int blk_mq_debugfs_register(struct request_queue *q);
void blk_mq_debugfs_unregister(struct request_queue *q);
int blk_mq_debugfs_register_hctx(struct request_queue *q,
void blk_mq_debugfs_register(struct request_queue *q);
void blk_mq_debugfs_register_hctx(struct request_queue *q,
				 struct blk_mq_hw_ctx *hctx);
void blk_mq_debugfs_unregister_hctx(struct blk_mq_hw_ctx *hctx);
int blk_mq_debugfs_register_hctxs(struct request_queue *q);
void blk_mq_debugfs_register_hctxs(struct request_queue *q);
void blk_mq_debugfs_unregister_hctxs(struct request_queue *q);

int blk_mq_debugfs_register_sched(struct request_queue *q);
void blk_mq_debugfs_register_sched(struct request_queue *q);
void blk_mq_debugfs_unregister_sched(struct request_queue *q);
int blk_mq_debugfs_register_sched_hctx(struct request_queue *q,
void blk_mq_debugfs_register_sched_hctx(struct request_queue *q,
				       struct blk_mq_hw_ctx *hctx);
void blk_mq_debugfs_unregister_sched_hctx(struct blk_mq_hw_ctx *hctx);

bool debugfs_create_files(struct dentry *parent, void *data,
void debugfs_create_files(struct dentry *parent, void *data,
			  const struct blk_mq_debugfs_attr *attr);

static inline bool blk_mq_debugfs_enabled(struct request_queue *q)
@@ -42,47 +41,38 @@ static inline bool blk_mq_debugfs_enabled(struct request_queue *q)
}

#else
static inline int blk_mq_debugfs_register(struct request_queue *q)
{
	return 0;
}

static inline void blk_mq_debugfs_unregister(struct request_queue *q)
static inline void blk_mq_debugfs_register(struct request_queue *q)
{
}

static inline int blk_mq_debugfs_register_hctx(struct request_queue *q,
static inline void blk_mq_debugfs_register_hctx(struct request_queue *q,
						struct blk_mq_hw_ctx *hctx)
{
	return 0;
}

static inline void blk_mq_debugfs_unregister_hctx(struct blk_mq_hw_ctx *hctx)
{
}

static inline int blk_mq_debugfs_register_hctxs(struct request_queue *q)
static inline void blk_mq_debugfs_register_hctxs(struct request_queue *q)
{
	return 0;
}

static inline void blk_mq_debugfs_unregister_hctxs(struct request_queue *q)
{
}

static inline int blk_mq_debugfs_register_sched(struct request_queue *q)
static inline void blk_mq_debugfs_register_sched(struct request_queue *q)
{
	return 0;
}

static inline void blk_mq_debugfs_unregister_sched(struct request_queue *q)
{
}

static inline int blk_mq_debugfs_register_sched_hctx(struct request_queue *q,
static inline void blk_mq_debugfs_register_sched_hctx(struct request_queue *q,
						      struct blk_mq_hw_ctx *hctx)
{
	return 0;
}

static inline void blk_mq_debugfs_unregister_sched_hctx(struct blk_mq_hw_ctx *hctx)
Loading