All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yu Kuai <yukuai3@huawei.com>
To: <axboe@kernel.dk>
Cc: <linux-block@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<yukuai3@huawei.com>, <yi.zhang@huawei.com>
Subject: [PATCH RESEND] blk-mq: fix possible creation failure for 'debugfs_dir'
Date: Fri, 15 Apr 2022 11:56:07 +0800	[thread overview]
Message-ID: <20220415035607.1836495-1-yukuai3@huawei.com> (raw)

'q->debugfs_dir' is created in blk_register_queue(), however, it's not
removed in blk_unregister_queue() and is delayed to blk_release_queue().
Thus it's possible that del_gendisk() is done and blk_release_queue()
is not called yet, and in the mean time blk_register_queue() is called
for the new device with the same name. In this case, kernel will
compalin about creation failure for 'debugfs_dir' like following:

debugfs: Directory 'nullb1' with parent 'block' already present!

Fix the problem by moving forward the removal of 'debgfs_dir' to
blk_unregister_queue().

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 block/blk-sysfs.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 88bd41d4cb59..15fc3f0786e3 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -779,11 +779,6 @@ static void blk_release_queue(struct kobject *kobj)
 	if (queue_is_mq(q))
 		blk_mq_release(q);
 
-	blk_trace_shutdown(q);
-	mutex_lock(&q->debugfs_mutex);
-	debugfs_remove_recursive(q->debugfs_dir);
-	mutex_unlock(&q->debugfs_mutex);
-
 	if (queue_is_mq(q))
 		blk_mq_debugfs_unregister(q);
 
@@ -951,5 +946,11 @@ void blk_unregister_queue(struct gendisk *disk)
 
 	mutex_unlock(&q->sysfs_dir_lock);
 
+	blk_trace_shutdown(q);
+	mutex_lock(&q->debugfs_mutex);
+	blk_mq_debugfs_unregister_hctxs(q);
+	debugfs_remove_recursive(q->debugfs_dir);
+	mutex_unlock(&q->debugfs_mutex);
+
 	kobject_put(&disk_to_dev(disk)->kobj);
 }
-- 
2.31.1


             reply	other threads:[~2022-04-15  3:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-15  3:56 Yu Kuai [this message]
2022-04-20  2:10 ` [PATCH RESEND] blk-mq: fix possible creation failure for 'debugfs_dir' Jens Axboe
2022-04-20  3:40 ` Williams, Dan J

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220415035607.1836495-1-yukuai3@huawei.com \
    --to=yukuai3@huawei.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yi.zhang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.