public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] syscalls/ioctl_loop05: Get the logic_block_size dynamically
@ 2020-06-09  8:33 Yang Xu
  2020-06-09  9:24 ` Jan Stancek
  0 siblings, 1 reply; 30+ messages in thread
From: Yang Xu @ 2020-06-09  8:33 UTC (permalink / raw)
  To: ltp

In loop driver code, the sb_bsize was calculated as below
sb_bsize = bdev_logical_block_size(inode->i_sb->s_bdev),

it is the super block's block size that the backing file's inode belongs to,
not by using the st_blksize member of stat struct(it uses inode->i_blkbits).

IMO, we don't have the direct ioctl to get this size, just try it from 512 to page_size.

Also, "offset is ignored" belongs to the last test(less than logical_block_size) but not
the second test(equal to logical_block_size).

Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
---
 .../kernel/syscalls/ioctl/ioctl_loop05.c      | 21 ++++++++-----------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/testcases/kernel/syscalls/ioctl/ioctl_loop05.c b/testcases/kernel/syscalls/ioctl/ioctl_loop05.c
index a96997823..09326042f 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_loop05.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_loop05.c
@@ -71,7 +71,7 @@ static void verify_ioctl_loop(void)
 	TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo), TST_RETVAL_EQ0);
 	TEST(ioctl(dev_fd, LOOP_SET_DIRECT_IO, 1));
 	if (TST_RET == 0) {
-		tst_res(TPASS, "LOOP_SET_DIRECT_IO succeeded, offset is ignored");
+		tst_res(TPASS, "LOOP_SET_DIRECT_IO succeeded");
 		check_dio_value(1);
 		SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 0);
 	} else {
@@ -84,7 +84,7 @@ static void verify_ioctl_loop(void)
 
 	TEST(ioctl(dev_fd, LOOP_SET_DIRECT_IO, 1));
 	if (TST_RET == 0) {
-		tst_res(TPASS, "LOOP_SET_DIRECT_IO succeeded");
+		tst_res(TPASS, "LOOP_SET_DIRECT_IO succeeded, offset is ignored");
 		SAFE_IOCTL(dev_fd, LOOP_SET_DIRECT_IO, 0);
 		return;
 	}
@@ -96,8 +96,7 @@ static void verify_ioctl_loop(void)
 
 static void setup(void)
 {
-	int fd;
-	struct stat buf;
+	int pg_size = getpagesize();
 
 	if (tst_fs_type(".") == TST_TMPFS_MAGIC)
 		tst_brk(TCONF, "tmpfd doesn't support O_DIRECT flag");
@@ -109,13 +108,6 @@ static void setup(void)
 	sprintf(sys_loop_diopath, "/sys/block/loop%d/loop/dio", dev_num);
 	tst_fill_file("test.img", 0, 1024, 1024);
 
-	fd = SAFE_OPEN("test.img", O_RDONLY);
-	SAFE_FSTAT(fd, &buf);
-	SAFE_CLOSE(fd);
-
-	logical_block_size = buf.st_blksize;
-	tst_res(TINFO, "backing dev logical_block_size is %d", logical_block_size);
-
 	tst_attach_device(dev_path, "test.img");
 	attach_flag = 1;
 	dev_fd = SAFE_OPEN(dev_path, O_RDWR);
@@ -130,7 +122,12 @@ static void setup(void)
 	 *   size of loop is bigger than the backing device's and the loop
 	 *   needn't transform transfer.
 	 */
-	TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_BLOCK_SIZE, logical_block_size), TST_RETVAL_EQ0);
+	for (logical_block_size = 512; logical_block_size < pg_size; logical_block_size += 512) {
+		TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_BLOCK_SIZE, logical_block_size), TST_RETVAL_EQ0);
+		if (ioctl(dev_fd, LOOP_SET_DIRECT_IO, 1) == 0)
+			break;
+	}
+	tst_res(TINFO, "backing dev logical_block_size is %d", logical_block_size);
 }
 
 static void cleanup(void)
-- 
2.23.0




^ permalink raw reply related	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2020-07-02 13:17 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-09  8:33 [LTP] [PATCH] syscalls/ioctl_loop05: Get the logic_block_size dynamically Yang Xu
2020-06-09  9:24 ` Jan Stancek
2020-06-09  9:48   ` Yang Xu
2020-06-09 10:16     ` Jan Stancek
2020-06-09 10:46       ` Yang Xu
2020-06-09 11:01         ` Jan Stancek
2020-06-10  1:19           ` Yang Xu
2020-06-10  5:37           ` [LTP] [PATCH v2] syscalls/ioctl_loop05: Use correct blockdev to get logical_block_size Yang Xu
2020-06-10 10:13             ` Jan Stancek
2020-06-10 10:42               ` Yang Xu
2020-06-10 12:19                 ` Yang Xu
2020-06-10 13:04                   ` Jan Stancek
2020-06-11  4:56                     ` Yang Xu
2020-06-11  5:32                     ` [LTP] [PATCH v3] " Yang Xu
2020-06-11 11:09                       ` Jan Stancek
2020-06-12  2:57                         ` Yang Xu
2020-06-24  5:07                           ` Yang Xu
2020-06-24 11:32                       ` Cyril Hrubis
2020-06-24 13:06                         ` Jan Stancek
2020-06-25 17:10                         ` Yang Xu
2020-06-28  7:42                         ` [LTP] [PATCH v4 1/2] tst_device: Add new api tst_find_backing_dev(path, dev) Yang Xu
2020-06-28  7:42                           ` [LTP] [PATCH v4 2/2] syscalls/ioctl_loop05: Use correct blockdev to get logical_block_size Yang Xu
2020-06-29  7:56                           ` [LTP] [PATCH v4 1/2] tst_device: Add new api tst_find_backing_dev(path, dev) Jan Stancek
2020-06-29 10:37                             ` Yang Xu
2020-06-29 11:08                               ` Jan Stancek
2020-06-29 11:41                                 ` [LTP] [PATCH v5 " Yang Xu
2020-06-29 11:41                                   ` [LTP] [PATCH v5 2/2] syscalls/ioctl_loop05: Use correct blockdev to get logical_block_size Yang Xu
2020-07-02  9:18                                   ` [LTP] [PATCH v5 1/2] tst_device: Add new api tst_find_backing_dev(path, dev) Jan Stancek
2020-07-02 12:27                                     ` Cyril Hrubis
2020-07-02 13:17                                       ` Jan Stancek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox