public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>, linux-block@vger.kernel.org
Cc: Nilay Shroff <nilay@linux.ibm.com>,
	Christoph Hellwig <hch@lst.de>, Ming Lei <ming.lei@redhat.com>
Subject: [PATCH 2/2] block: avoid unnecessary queue freeze in elevator_set_none()
Date: Wed,  7 May 2025 20:04:03 +0800	[thread overview]
Message-ID: <20250507120406.3028670-3-ming.lei@redhat.com> (raw)
In-Reply-To: <20250507120406.3028670-1-ming.lei@redhat.com>

elevator_set_none() is called when deleting disk, in which queue has been
un-registered, and elevator switch can't happen any more.

So if q->elevator is NULL, it is not necessary to freeze queue and drain
IO any more.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 block/elevator.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/block/elevator.c b/block/elevator.c
index e1386b84a415..35f4de749dcd 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -754,8 +754,18 @@ void elevator_set_none(struct request_queue *q)
 		.name	= "none",
 		.quiesce_queue = true,
 	};
+	bool need_change;
 	int err;
 
+	WARN_ON_ONCE(blk_queue_registered(q));
+
+	/* queue has been unregisted, elevator can't be switched anymore */
+	mutex_lock(&q->elevator_lock);
+	need_change = !!q->elevator;
+	mutex_unlock(&q->elevator_lock);
+	if (!need_change)
+		return;
+
 	err = elevator_change(q, &ctx);
 	if (err < 0)
 		pr_warn("%s: set none elevator failed %d\n", __func__, err);
-- 
2.47.0


  parent reply	other threads:[~2025-05-07 12:04 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-07 12:04 [PATCH 0/2] block: fix hang in elevator_change() and improve elevator_set_none Ming Lei
2025-05-07 12:04 ` [PATCH 1/2] block: move queue quiesce into elevator_change() Ming Lei
2025-05-07 13:53   ` Christoph Hellwig
2025-05-07 14:28     ` Ming Lei
2025-05-07 14:48       ` Ming Lei
2025-05-07 19:05       ` Nilay Shroff
2025-05-08  3:02         ` Ming Lei
2025-05-08  5:03       ` Christoph Hellwig
2025-05-08  8:03         ` Ming Lei
2025-05-07 12:04 ` Ming Lei [this message]
2025-05-07 13:54   ` [PATCH 2/2] block: avoid unnecessary queue freeze in elevator_set_none() Christoph Hellwig
2025-05-08  3:57     ` Ming Lei
2025-05-08  5:04       ` Christoph Hellwig
2025-05-08  8:16         ` Ming Lei
2025-05-07 19:20   ` Nilay Shroff
2025-05-08  4:31 ` [PATCH 0/2] block: fix hang in elevator_change() and improve elevator_set_none Shinichiro Kawasaki

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=20250507120406.3028670-3-ming.lei@redhat.com \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    --cc=nilay@linux.ibm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox