Skip to contentSkip to conversation

sys_block_queue01: Accept plain "none" in queue/scheduler

PATCH Superseded Darren Chang via ltp 3 participants 8 messages Nov 18 – Nov 20

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sys_block_queue01: Accept plain "none" in queue/scheduler

On kernels older than 6.5, bio-based block devices (such as dm, ram, zram, and pmem) expose queue/scheduler with plain "none" (without brackets). Kernels before 6.14 also output plain "none" for blk-mq devices with BLK_MQ_F_NO_SCHED.

These cases were removed in kernel 6.5 (commit 6d85ebf95c44) and kernel 6.14 (commit e7602bb4f3a1), but older kernels still fail the test because TST_SYSFS_ASSERT_CHOICE() expects one bracketed token:

TFAIL: /sys/block/dm-87/queue/scheduler has 0 selected tokens, expected exactly 1

Read queue/scheduler first and pass if the value is exact "none". Keep TCONF when the file is missing, and use TST_SYSFS_ASSERT_CHOICE() for all other values.

Fixes f35242c9cc22 ("testcases: sysfs: Add sys_block_queue01")
---
 .../kernel/sysfs/block/sys_block_queue01.c    | 38 ++++++++++++++++---
 1 file changed, 33 insertions(+), 5 deletions(-)
testcases/kernel/sysfs/block/sys_block_queue01.c +33 -5
index 38564139a..ce1f945fd 100644
@@ -16,7 +16,13 @@
  * - read_ahead_kb, nr_requests and discard_max_bytes are non-negative
  * - nr_requests is greater than zero
  * - rotational, add_random, iostats are boolean (0 or 1)
- * - scheduler is a valid bracketed-choice file with exactly one active scheduler
+ * - scheduler is a valid bracketed-choice file with exactly one active
+ *   scheduler, or plain ``none`` without brackets for devices that do not
+ *   support I/O schedulers (bio-based devices such as dm, ram, zram, pmem on
+ *   kernels prior to 6.5 before commit 6d85ebf95c44 "blk-sysfs: add a new
+ *   attr_group for blk_mq", and blk-mq queues with BLK_MQ_F_NO_SCHED prior to
+ *   6.14 before commit e7602bb4f3a1 "block: remove BLK_MQ_F_NO_SCHED", where
+ *   elv_iosched_show() emits "none\n")
  *
  * All checks skip gracefully with TCONF when a particular attribute is not
  * present, since the set of exported queue attributes differs between kernel
@@ -36,6 +42,31 @@ static const char *const sched_allowed[] = {
 	"kyber", "bfq", "anticipatory", NULL
 };
 
+static void check_scheduler(const char *dev)
+{
+	char sched[64];
+
+	if (!TST_SYSFS_READ_STR(sched, sizeof(sched),
+				PATH_SYS_BLOCK "/%s/queue/scheduler", dev)) {
+		tst_res(TCONF, PATH_SYS_BLOCK "/%s/queue/scheduler does not exist",
+			dev);
+		return;
+	}
+
+	/*
+	 * elv_iosched_show() emits plain "none\n" without brackets for queues
+	 * that do not support I/O schedulers (bio-based devices prior to 6.5,
+	 * and BLK_MQ_F_NO_SCHED devices prior to 6.14).
+	 */
+	if (!strcmp(sched, "none")) {
+		tst_res(TPASS, PATH_SYS_BLOCK "/%s/queue/scheduler = 'none'", dev);
+		return;
+	}
+
+	TST_SYSFS_ASSERT_CHOICE(sched_allowed, NULL, 0,
+				PATH_SYS_BLOCK "/%s/queue/scheduler", dev);
+}
+
 static void check_cross(const char *dev)
 {
 	TST_SYSFS_ASSERT_LE_SUFFIX("logical_block_size", "physical_block_size",
@@ -50,8 +81,6 @@ static void check_cross(const char *dev)
 
 static void check_device(const char *dev)
 {
-	char sched[64];
-
 	tst_res(TINFO, "Checking block device '%s'", dev);
 
 	TST_SYSFS_ASSERT_POW2(PATH_SYS_BLOCK "/%s/queue/logical_block_size", dev);
@@ -68,8 +97,7 @@ static void check_device(const char *dev)
 	TST_SYSFS_ASSERT_BOOL(PATH_SYS_BLOCK "/%s/queue/add_random", dev);
 	TST_SYSFS_ASSERT_BOOL(PATH_SYS_BLOCK "/%s/queue/iostats", dev);
 
-	TST_SYSFS_ASSERT_CHOICE(sched_allowed, sched, sizeof(sched),
-				PATH_SYS_BLOCK "/%s/queue/scheduler", dev);
+	check_scheduler(dev);
 
 	check_cross(dev);
 }
Signature · 5 lines
2.56.1.703.gf848ed807c-goog


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi!

testcases/kernel/sysfs/block/sys_block_queue01.c static const char *const sched_allowed[] = { · line 67

Quoted 12 lines
testcases/kernel/sysfs/block/sys_block_queue01.c +12 -0
+	/*
+	 * elv_iosched_show() emits plain "none\n" without brackets for queues
+	 * that do not support I/O schedulers (bio-based devices prior to 6.5,
+	 * and BLK_MQ_F_NO_SCHED devices prior to 6.14).
+	 */
+	if (!strcmp(sched, "none")) {
+		tst_res(TPASS, PATH_SYS_BLOCK "/%s/queue/scheduler = 'none'", dev);
+		return;
+	}
+
+	TST_SYSFS_ASSERT_CHOICE(sched_allowed, NULL, 0,
+				PATH_SYS_BLOCK "/%s/queue/scheduler", dev);

This does not make any sense. Why haven't you simply added "none" to the sched_allowed array instead?

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw
In reply to Darren Chang via ltp

Hi Cyril,

Quoted 2 lines

This does not make any sense. Why haven't you simply added "none" to the sched_allowed array instead?

"none" is already in sched_allowed[] (line 35 before this patch).

The test fails because elv_iosched_show() prints "none\n" without brackets, not "[none]\n". TST_SYSFS_ASSERT_CHOICE() requires one bracketed token, so it fails with "0 selected tokens, expected exactly 1".

Regards,
Darren

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Hi!

Quoted 8 lines
Quoted 2 lines

This does not make any sense. Why haven't you simply added "none" to the sched_allowed array instead?

"none" is already in sched_allowed[] (line 35 before this patch).

The test fails because elv_iosched_show() prints "none\n" without brackets, not "[none]\n". TST_SYSFS_ASSERT_CHOICE() requires one bracketed token, so it fails with "0 selected tokens, expected exactly 1".

Sorry missed, that, I should have read the commit message better.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw
In reply to Darren Chang via ltp

Hi!

Quoted 35 lines
Fixes f35242c9cc22 ("testcases: sysfs: Add sys_block_queue01")
---
 .../kernel/sysfs/block/sys_block_queue01.c    | 38 ++++++++++++++++---
 1 file changed, 33 insertions(+), 5 deletions(-)
testcases/kernel/sysfs/block/sys_block_queue01.c +13 -1
index 38564139a..ce1f945fd 100644
@@ -16,7 +16,13 @@
  * - read_ahead_kb, nr_requests and discard_max_bytes are non-negative
  * - nr_requests is greater than zero
  * - rotational, add_random, iostats are boolean (0 or 1)
- * - scheduler is a valid bracketed-choice file with exactly one active scheduler
+ * - scheduler is a valid bracketed-choice file with exactly one active
+ *   scheduler, or plain ``none`` without brackets for devices that do not
+ *   support I/O schedulers (bio-based devices such as dm, ram, zram, pmem on
+ *   kernels prior to 6.5 before commit 6d85ebf95c44 "blk-sysfs: add a new
+ *   attr_group for blk_mq", and blk-mq queues with BLK_MQ_F_NO_SCHED prior to
+ *   6.14 before commit e7602bb4f3a1 "block: remove BLK_MQ_F_NO_SCHED", where
+ *   elv_iosched_show() emits "none\n")
  *
  * All checks skip gracefully with TCONF when a particular attribute is not
  * present, since the set of exported queue attributes differs between kernel
@@ -36,6 +42,31 @@ static const char *const sched_allowed[] = {
 	"kyber", "bfq", "anticipatory", NULL
 };
 
+static void check_scheduler(const char *dev)
+{
+	char sched[64];
+
+	if (!TST_SYSFS_READ_STR(sched, sizeof(sched),
+				PATH_SYS_BLOCK "/%s/queue/scheduler", dev)) {

testcases/kernel/sysfs/block/sys_block_queue01.c static const char *const sched_allowed[] = { · line 60

Quoted 10 lines
testcases/kernel/sysfs/block/sys_block_queue01.c +10 -0
+		tst_res(TCONF, PATH_SYS_BLOCK "/%s/queue/scheduler does not exist",
+			dev);
+		return;
+	}
+
+	/*
+	 * elv_iosched_show() emits plain "none\n" without brackets for queues
+	 * that do not support I/O schedulers (bio-based devices prior to 6.5,
+	 * and BLK_MQ_F_NO_SCHED devices prior to 6.14).
+	 */

The description in the top level comment is enough, I wouldn't add this comment here.

testcases/kernel/sysfs/block/sys_block_queue01.c static const char *const sched_allowed[] = { · line 64

Quoted 4 lines
testcases/kernel/sysfs/block/sys_block_queue01.c +4 -0
+	if (!strcmp(sched, "none")) {
+		tst_res(TPASS, PATH_SYS_BLOCK "/%s/queue/scheduler = 'none'", dev);
+		return;
+	}

If this happens only in older kernels the check should be done only on older kernels too. So we need tst_kvercmp() in the test setup that would set allow_plain_none flag.

Quoted 29 lines
testcases/kernel/sysfs/block/sys_block_queue01.c +5 -4
+	TST_SYSFS_ASSERT_CHOICE(sched_allowed, NULL, 0,
+				PATH_SYS_BLOCK "/%s/queue/scheduler", dev);
+}
+
 static void check_cross(const char *dev)
 {
 	TST_SYSFS_ASSERT_LE_SUFFIX("logical_block_size", "physical_block_size",
@@ -50,8 +81,6 @@ static void check_cross(const char *dev)
 
 static void check_device(const char *dev)
 {
-	char sched[64];
-
 	tst_res(TINFO, "Checking block device '%s'", dev);
 
 	TST_SYSFS_ASSERT_POW2(PATH_SYS_BLOCK "/%s/queue/logical_block_size", dev);
@@ -68,8 +97,7 @@ static void check_device(const char *dev)
 	TST_SYSFS_ASSERT_BOOL(PATH_SYS_BLOCK "/%s/queue/add_random", dev);
 	TST_SYSFS_ASSERT_BOOL(PATH_SYS_BLOCK "/%s/queue/iostats", dev);
 
-	TST_SYSFS_ASSERT_CHOICE(sched_allowed, sched, sizeof(sched),
-				PATH_SYS_BLOCK "/%s/queue/scheduler", dev);
+	check_scheduler(dev);
 
 	check_cross(dev);
 }
Signature · 1 line
2.56.1.703.gf848ed807c-goog
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

PATCH v2 1/1 sys_block_queue01: Accept plain "none" in queue/scheduler

In reply to Darren Chang via ltp

On kernels older than 6.5, bio-based block devices (such as dm, ram, zram, and pmem) expose queue/scheduler with plain "none" (without brackets). Kernels 6.2 to 6.13 also print plain "none" for blk-mq devices with BLK_MQ_F_NO_SCHED.

These cases were removed in kernel 6.5 (commit 6d85ebf95c44) and kernel 6.14 (commit e7602bb4f3a1), but older kernels still fail the test because TST_SYSFS_ASSERT_CHOICE() expects one bracketed token:

TFAIL: /sys/block/dm-87/queue/scheduler has 0 selected tokens, expected exactly 1

Accept exact "none" on kernels older than 6.14. Newer kernels keep the strict check.

Fixes f35242c9cc22 ("testcases: sysfs: Add sys_block_queue01")

---
Changes in v2:
- Accept plain "none" only on kernels older than 6.14, using tst_kvercmp() in setup() (Cyril)
- Drop the comment in check_scheduler() (Cyril)

---
 .../kernel/sysfs/block/sys_block_queue01.c    | 42 ++++++++++++++++---
 1 file changed, 37 insertions(+), 5 deletions(-)
testcases/kernel/sysfs/block/sys_block_queue01.c +37 -5
index 38564139a..68af8462c 100644
@@ -16,11 +16,22 @@
  * - read_ahead_kb, nr_requests and discard_max_bytes are non-negative
  * - nr_requests is greater than zero
  * - rotational, add_random, iostats are boolean (0 or 1)
- * - scheduler is a valid bracketed-choice file with exactly one active scheduler
+ * - scheduler is a valid bracketed-choice file with exactly one active
+ *   scheduler, or plain ``none`` without brackets on kernels older than 6.14
  *
  * All checks skip gracefully with TCONF when a particular attribute is not
  * present, since the set of exported queue attributes differs between kernel
  * versions and device types.
+ *
+ * Kernels older than 6.14 report plain ``none`` in scheduler for queues that
+ * do not support I/O schedulers:
+ *
+ * - bio-based devices (dm, ram, zram, pmem), until commit 6d85ebf95c44
+ *   (``blk-sysfs: add a new attr_group for blk_mq``) in kernel 6.5 stopped
+ *   exporting scheduler for them
+ * - blk-mq queues with BLK_MQ_F_NO_SCHED since kernel 6.2, until commit
+ *   e7602bb4f3a1 (``block: remove BLK_MQ_F_NO_SCHED``) in kernel 6.14 removed
+ *   the flag
  */
 
 #include <string.h>
@@ -30,12 +41,30 @@
 #include "tst_sysfs_assert.h"
 #include "tst_path_defs.h"
 
+static int allow_plain_none;
+
 /* schedulers that have existed in mainline over time */
 static const char *const sched_allowed[] = {
 	"none", "noop", "deadline", "mq-deadline", "cfq",
 	"kyber", "bfq", "anticipatory", NULL
 };
 
+static void check_scheduler(const char *dev)
+{
+	char sched[64];
+
+	if (allow_plain_none &&
+	    TST_SYSFS_READ_STR(sched, sizeof(sched),
+			       PATH_SYS_BLOCK "/%s/queue/scheduler", dev) &&
+	    !strcmp(sched, "none")) {
+		tst_res(TPASS, PATH_SYS_BLOCK "/%s/queue/scheduler = 'none'", dev);
+		return;
+	}
+
+	TST_SYSFS_ASSERT_CHOICE(sched_allowed, NULL, 0,
+				PATH_SYS_BLOCK "/%s/queue/scheduler", dev);
+}
+
 static void check_cross(const char *dev)
 {
 	TST_SYSFS_ASSERT_LE_SUFFIX("logical_block_size", "physical_block_size",
@@ -50,8 +79,6 @@ static void check_cross(const char *dev)
 
 static void check_device(const char *dev)
 {
-	char sched[64];
-
 	tst_res(TINFO, "Checking block device '%s'", dev);
 
 	TST_SYSFS_ASSERT_POW2(PATH_SYS_BLOCK "/%s/queue/logical_block_size", dev);
@@ -68,12 +95,16 @@ static void check_device(const char *dev)
 	TST_SYSFS_ASSERT_BOOL(PATH_SYS_BLOCK "/%s/queue/add_random", dev);
 	TST_SYSFS_ASSERT_BOOL(PATH_SYS_BLOCK "/%s/queue/iostats", dev);
 
-	TST_SYSFS_ASSERT_CHOICE(sched_allowed, sched, sizeof(sched),
-				PATH_SYS_BLOCK "/%s/queue/scheduler", dev);
+	check_scheduler(dev);
 
 	check_cross(dev);
 }
 
+static void setup(void)
+{
+	allow_plain_none = tst_kvercmp(6, 14, 0) < 0;
+}
+
 static void run(void)
 {
 	DIR *dir;
@@ -101,5 +132,6 @@ static void run(void)
 }
 
 static struct tst_test test = {
+	.setup = setup,
 	.test_all = run,
 };
Signature · 5 lines
2.56.1.708.g77570a6a1d-goog


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

Hi Darren,

Quoted 1 line · Darren Chang

sys_block_queue01: Accept plain "none" in queue/scheduler

Verdict - Reviewed

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp