Skip to contentSkip to conversation

readahead02: fix read_ahead_kb file not found

PATCH New [email protected] 2 participants 3 messages Aug 27, 2016 – Aug 31, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 readahead02: fix read_ahead_kb file not found

From: Naresh Kamboju <[email protected]>

Test case is looking for read_ahead_kb file on a partition device (8:2) and not on block device (8:0). The appropriate block device that hold the partition can see the corrent queue/read_ahead_kb entry.

Before patch readahead02 test broken,
readahead02 1 TBROK : safe_file_ops.c:144: Failed to open FILE
'/sys/dev/block/8:2/queue/read_ahead_kb' for reading at readahead02.c:197: errno=ENOENT(2): No such file or directory

After applying patch,

readahead02    0  TINFO  :  creating test file of size: 67108864
readahead02    0  TINFO  :  max readahead size is: 131072
readahead02    0  TINFO  :  read_testfile(0)
readahead02    0  TINFO  :  max readahead size is: 131072
readahead02    0  TINFO  :  read_testfile(1)
readahead02    0  TINFO  :  max readahead size is: 131072
readahead02    1  TPASS  :  expected ret success - returned value = 0
readahead02    2  TPASS  :  offset is still at 0 as expected
readahead02    0  TINFO  :  read_testfile(0) took: 1437202 usec
readahead02    0  TINFO  :  read_testfile(1) took: 1361915 usec
readahead02    0  TINFO  :  read_testfile(0) read: 67108864 bytes
readahead02    0  TINFO  :  read_testfile(1) read: 0 bytes
readahead02    3  TPASS  :  readahead saved some I/O
readahead02    0  TINFO  :  cache can hold at least: 157404 kB
readahead02    0  TINFO  :  read_testfile(0) used cache: 65332 kB
readahead02    0  TINFO  :  read_testfile(1) used cache: 65636 kB
readahead02    4  TPASS  :  using cache as expected

Patch tested on aarch64 and x86_64.

---
 testcases/kernel/syscalls/readahead/readahead02.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/syscalls/readahead/readahead02.c +1 -1
index 53278be..70d918d 100644
@@ -193,7 +193,7 @@ static long get_device_readahead(const char *fname)
 	if (stat(fname, &st) == -1)
 		tst_brkm(TBROK | TERRNO, cleanup, "stat");
 	snprintf(buf, sizeof(buf), "/sys/dev/block/%d:%d/queue/read_ahead_kb",
-		 major(st.st_dev), minor(st.st_dev));
+		 major(st.st_dev), minor(st.st_dev) & ~31);
 	SAFE_FILE_SCANF(cleanup, buf, "%ld", &ra_kb);
 
 	return ra_kb * 1024;
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 readahead02: fix read_ahead_kb file not found

Hi!

testcases/kernel/syscalls/readahead/readahead02.c static long get_device_readahead(const char *fname) · line 196

Quoted 6 lines
testcases/kernel/syscalls/readahead/readahead02.c +1 -1
@@ -193,7 +193,7 @@ static long get_device_readahead(const char *fname)
 	if (stat(fname, &st) == -1)
 		tst_brkm(TBROK | TERRNO, cleanup, "stat");
 	snprintf(buf, sizeof(buf), "/sys/dev/block/%d:%d/queue/read_ahead_kb",
-		 major(st.st_dev), minor(st.st_dev));
+		 major(st.st_dev), minor(st.st_dev) & ~31);

So we clear lower five bits of the minor number here. Why exactly that amount?

Shouldn't we just pass zero as a minor number there anyway?

Quoted 6 lines
testcases/kernel/syscalls/readahead/readahead02.c +0 -0
 	SAFE_FILE_SCANF(cleanup, buf, "%ld", &ra_kb);
 
 	return ra_kb * 1024;
Signature · 1 line
1.9.1
Signature · 2 lines
Cyril Hrubis
[email protected]
#2 lore raw

PATCH 1/1 readahead02: fix read_ahead_kb file not found

Quoted 11 lines · Cyril Hrubis

Hi!

testcases/kernel/syscalls/readahead/readahead02.c static long get_device_readahead(const char *fname) · line 196

Quoted 6 lines
testcases/kernel/syscalls/readahead/readahead02.c +1 -1
@@ -193,7 +193,7 @@ static long get_device_readahead(const char *fname)
      if (stat(fname, &st) == -1)
              tst_brkm(TBROK | TERRNO, cleanup, "stat");
      snprintf(buf, sizeof(buf), "/sys/dev/block/%d:%d/queue/read_ahead_kb",
-              major(st.st_dev), minor(st.st_dev));
+              major(st.st_dev), minor(st.st_dev) & ~31);

So we clear lower five bits of the minor number here. Why exactly that amount?

Shouldn't we just pass zero as a minor number there anyway?

For block device like sda the read_ahead_kb is present in 8:0. if it sdb it is present at 8:16. like wise
8:0 sda
8:16 sdb
8:32 sdc
8:48 sdd

I changed my patch to clear lower four bits of the minor number

  minor(st.st_dev) & ~15);

- Naresh

Quoted 11 lines
Quoted 7 lines
testcases/kernel/syscalls/readahead/readahead02.c +0 -1
      SAFE_FILE_SCANF(cleanup, buf, "%ld", &ra_kb);
 
      return ra_kb * 1024;
--

1.9.1

--
Cyril Hrubis
[email protected]