All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zorro Lang <zlang@kernel.org>
To: fstests@vger.kernel.org
Cc: io-uring@vger.kernel.org
Subject: [PATCH v2 3/3] common/rc: notrun if io_uring is disabled by sysctl
Date: Tue, 12 Mar 2024 00:20:29 +0800	[thread overview]
Message-ID: <20240311162029.1102849-4-zlang@kernel.org> (raw)
In-Reply-To: <20240311162029.1102849-1-zlang@kernel.org>

If kernel supports io_uring, userspace still can/might disable that
supporting by set /proc/sys/kernel/io_uring_disabled=2. Let's notrun
if io_uring is disabled by that way.

Signed-off-by: Zorro Lang <zlang@kernel.org>
---
 README        |  6 ++++++
 common/rc     | 10 ++++++++++
 src/feature.c | 19 ++++++++++++-------
 3 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/README b/README
index c46690c4..477136de 100644
--- a/README
+++ b/README
@@ -142,6 +142,12 @@ Setup Environment
    https://www.lscdweb.com/registered/udf_verifier.html, then copy the udf_test
    binary to xfstests/src/.
 
+8. (optional) To do io_uring related testing, please make sure below 3 things:
+     1) kernel is built with CONFIG_IO_URING=y
+     2) sysctl -w kernel.io_uring_disabled=0 (or set it to 2 to disable io_uring
+        testing dynamically if kernel supports)
+     3) install liburing development package contains liburing.h before building
+        fstests
 
 For example, to run the tests with loopback partitions:
 
diff --git a/common/rc b/common/rc
index 50dde313..1406d8d9 100644
--- a/common/rc
+++ b/common/rc
@@ -2317,6 +2317,8 @@ _require_aiodio()
 # this test requires that the kernel supports IO_URING
 _require_io_uring()
 {
+	local n
+
 	$here/src/feature -R
 	case $? in
 	0)
@@ -2324,6 +2326,14 @@ _require_io_uring()
 	1)
 		_notrun "kernel does not support IO_URING"
 		;;
+	2)
+		n=$(sysctl -n kernel.io_uring_disabled 2>/dev/null)
+		if [ "$n" != "0" ];then
+			_notrun "io_uring isn't enabled totally by admin"
+		else
+			_fail "unexpected EPERM error, please check selinux or something else"
+		fi
+		;;
 	*)
 		_fail "unexpected error testing for IO_URING support"
 		;;
diff --git a/src/feature.c b/src/feature.c
index 941f96fb..7e474ce5 100644
--- a/src/feature.c
+++ b/src/feature.c
@@ -232,15 +232,20 @@ check_uring_support(void)
 	int err;
 
 	err = io_uring_queue_init(1, &ring, 0);
-	if (err == 0)
+	switch (err) {
+	case 0:
 		return 0;
-
-	if (err == -ENOSYS) /* CONFIG_IO_URING=n */
+	case -ENOSYS:
+		/* CONFIG_IO_URING=n */
 		return 1;
-
-	fprintf(stderr, "unexpected error from io_uring_queue_init(): %s\n",
-		strerror(-err));
-	return 2;
+	case -EPERM:
+		/* Might be due to sysctl io_uring_disabled isn't 0 */
+		return 2;
+	default:
+		fprintf(stderr, "unexpected error from io_uring_queue_init(): %s\n",
+			strerror(-err));
+		return 100;
+	}
 #else
 	/* liburing is unavailable, assume IO_URING is unsupported */
 	return 1;
-- 
2.43.0


  parent reply	other threads:[~2024-03-11 16:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-11 16:20 [PATCH v2 0/3] fstests: fix io_uring testing Zorro Lang
2024-03-11 16:20 ` [PATCH v2 1/3] fsstress: check io_uring_queue_init errno properly Zorro Lang
2024-03-11 16:20 ` [PATCH v2 2/3] fsstress: bypass io_uring testing if io_uring_queue_init returns EPERM Zorro Lang
2024-03-11 16:20 ` Zorro Lang [this message]
2024-03-11 16:29   ` [PATCH v2 3/3] common/rc: notrun if io_uring is disabled by sysctl Darrick J. Wong

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=20240311162029.1102849-4-zlang@kernel.org \
    --to=zlang@kernel.org \
    --cc=fstests@vger.kernel.org \
    --cc=io-uring@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 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.