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: linux-kselftest@vger.kernel.org, Ming Lei <ming.lei@redhat.com>
Subject: [PATCH 01/11] selftests: ublk: make ublk_stop_io_daemon() more reliable
Date: Mon,  3 Mar 2025 20:43:11 +0800	[thread overview]
Message-ID: <20250303124324.3563605-2-ming.lei@redhat.com> (raw)
In-Reply-To: <20250303124324.3563605-1-ming.lei@redhat.com>

Improve ublk_stop_io_daemon() in the following ways:

- don't wait if ->ublksrv_pid becomes -1, which means that the disk
has been stopped

- don't wait if ublk char device doesn't exist any more, so we can
avoid to rely on inoitfy for wait until the char device is closed

And this way may reduce time of delete command a lot.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 tools/testing/selftests/ublk/kublk.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/tools/testing/selftests/ublk/kublk.c b/tools/testing/selftests/ublk/kublk.c
index b65bdaf7e281..2072d880fdc4 100644
--- a/tools/testing/selftests/ublk/kublk.c
+++ b/tools/testing/selftests/ublk/kublk.c
@@ -691,13 +691,14 @@ static int ublk_start_daemon(const struct dev_ctx *ctx, struct ublk_dev *dev)
 	return ret;
 }
 
-static int wait_ublk_dev(char *dev_name, int evt_mask, unsigned timeout)
+static int wait_ublk_dev(const char *path, int evt_mask, unsigned timeout)
 {
 #define EV_SIZE (sizeof(struct inotify_event))
 #define EV_BUF_LEN (128 * (EV_SIZE + 16))
 	struct pollfd pfd;
 	int fd, wd;
 	int ret = -EINVAL;
+	const char *dev_name = basename(path);
 
 	fd = inotify_init();
 	if (fd < 0) {
@@ -761,18 +762,23 @@ static int ublk_stop_io_daemon(const struct ublk_dev *dev)
 	char ublkc[64];
 	int ret = 0;
 
+	if (daemon_pid < 0)
+		return 0;
+
 	/* daemon may be dead already */
 	if (kill(daemon_pid, 0) < 0)
 		goto wait;
 
-	/*
-	 * Wait until ublk char device is closed, when our daemon is shutdown
-	 */
-	snprintf(ublkc, sizeof(ublkc), "%s%d", "ublkc", dev_id);
-	ret = wait_ublk_dev(ublkc, IN_CLOSE_WRITE, 10);
-	/* double check and inotify may not be 100% reliable */
+	snprintf(ublkc, sizeof(ublkc), "/dev/%s%d", "ublkc", dev_id);
+
+	/* ublk char device may be gone already */
+	if (access(ublkc, F_OK) != 0)
+		goto wait;
+
+	/* Wait until ublk char device is closed, when the daemon is shutdown */
+	ret = wait_ublk_dev(ublkc, IN_CLOSE, 10);
+	/* double check and since it may be closed before starting inotify */
 	if (ret == -ETIMEDOUT)
-		/* the daemon doesn't exist now if kill(0) fails */
 		ret = kill(daemon_pid, 0) < 0;
 wait:
 	waitpid(daemon_pid, NULL, 0);
@@ -910,8 +916,6 @@ static int __cmd_dev_del(struct dev_ctx *ctx)
 				__func__, dev->dev_info.ublksrv_pid, number, ret);
 	ublk_ctrl_del_dev(dev);
 fail:
-	if (ret >= 0)
-		ret = ublk_ctrl_get_info(dev);
 	ublk_ctrl_deinit(dev);
 
 	return (ret >= 0) ? 0 : ret;
-- 
2.47.0


  reply	other threads:[~2025-03-03 12:43 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-03 12:43 [PATCH 00/11] selftests: ublk: bug fixes & consolidation Ming Lei
2025-03-03 12:43 ` Ming Lei [this message]
2025-03-03 21:31   ` [PATCH 01/11] selftests: ublk: make ublk_stop_io_daemon() more reliable Keith Busch
2025-03-03 12:43 ` [PATCH 02/11] selftests: ublk: fix build failure Ming Lei
2025-03-03 21:31   ` Keith Busch
2025-03-03 12:43 ` [PATCH 03/11] selftests: ublk: add --foreground command line Ming Lei
2025-03-03 21:31   ` Keith Busch
2025-03-03 12:43 ` [PATCH 04/11] selftests: ublk: fix parsing '-a' argument Ming Lei
2025-03-03 21:32   ` Keith Busch
2025-03-03 12:43 ` [PATCH 05/11] selftests: ublk: support shellcheck and fix all warning Ming Lei
2025-03-03 12:43 ` [PATCH 06/11] selftests: ublk: don't pass ${dev_id} to _cleanup_test() Ming Lei
2025-03-03 12:43 ` [PATCH 07/11] selftests: ublk: move zero copy feature check into _add_ublk_dev() Ming Lei
2025-03-03 12:43 ` [PATCH 08/11] selftests: ublk: load/unload ublk_drv when preparing & cleaning up tests Ming Lei
2025-03-03 12:43 ` [PATCH 09/11] selftests: ublk: add one stress test for covering IO vs. removing device Ming Lei
2025-03-03 12:43 ` [PATCH 10/11] selftests: ublk: add stress test for covering IO vs. killing ublk server Ming Lei
2025-03-03 12:43 ` [PATCH 11/11] selftests: ublk: improve test usability Ming Lei
2025-03-10 15:09 ` [PATCH 00/11] selftests: ublk: bug fixes & consolidation Ming Lei
2025-03-10 15:17   ` Jens Axboe
2025-03-11  4:35     ` Ming Lei
2025-03-11 13:28       ` Jens Axboe
2025-03-10 15:18 ` Jens Axboe

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=20250303124324.3563605-2-ming.lei@redhat.com \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    /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