diff mbox series

[v2,09/10] syscalls/ioctl_loop07: Add dio with logic block size error test

Message ID 1586429086-22975-9-git-send-email-xuyang2018.jy@cn.fujitsu.com
State Rejected
Headers show
Series [v2,01/10] lapi/loop.h: Add fallback for loop ioctl and flag | expand

Commit Message

Yang Xu April 9, 2020, 10:44 a.m. UTC
This is a basic ioctl test about loopdevice LOOP_SET_BLOCK_SIZE
and LOOP_SET_DIRECT_IO. When logical blocksize is 1024, set dio
with  512 offset will fail.

Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/ioctl/.gitignore    |  1 +
 .../kernel/syscalls/ioctl/ioctl_loop07.c      | 85 +++++++++++++++++++
 3 files changed, 87 insertions(+)
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop07.c

Comments

Cyril Hrubis April 22, 2020, 1:58 p.m. UTC | #1
Hi!
This test fails for me, i.e. the attempt to enabe direct IO succeeds. I
will have to have a closer look later on.
Yang Xu April 23, 2020, 6:06 a.m. UTC | #2
Hi Cyril


> Hi!
> This test fails for me, i.e. the attempt to enabe direct IO succeeds. I
> will have to have a closer look later on.
Now, I use 5.7.0-rc2 kernel to test, this case fails, I guess loop 
driver has changed its logic. I am trying.

ps: when run ioctl_loop01.c, I also met another problem that 
/dev/loop0p1 and  the corresponding sys file doesn't existed. dmesg 
report error "loop_reread_partitions: partition scan of loop0 () failed 
(rc=-16)". Also trying .
>
Yang Xu April 23, 2020, 10:12 a.m. UTC | #3
Hi Cyril

> Hi Cyril
> 
> 
>> Hi!
>> This test fails for me, i.e. the attempt to enabe direct IO succeeds. I
>> will have to have a closer look later on.
> Now, I use 5.7.0-rc2 kernel to test, this case fails, I guess loop 
> driver has changed its logic. I am trying.

I write this test on fedora31(tmp directory use tmpfs), so I got a 
pseudo pass when setting dio.

I misunderstood the meaning of the comment in the kernel.
kernel commet as below:
"We support direct I/O only if lo_offset is aligned with the
logical I/O size of backing device, and the logical block
size of loop is bigger than the backing device's and the loop
needn't transform transfer."

sb_bsize = bdev_logical_block_size(inode->i_sb->s_bdev);  //get block 
size from backing device
dio_align = sb_bsize - 1;

I use logic block size of loop(1024 > 512) , so this test pass.

Now, I think this test is meaningless and we can remove this.

Best Regards
Yang Xu
> 
> ps: when run ioctl_loop01.c, I also met another problem that 
> /dev/loop0p1 and  the corresponding sys file doesn't existed. dmesg 
> report error "loop_reread_partitions: partition scan of loop0 () failed 
> (rc=-16)". Also trying .
>>
Yang Xu April 24, 2020, 4:43 a.m. UTC | #4
Hi Cyril


> Hi Cyril
> 
>> Hi Cyril
>>
>>
>>> Hi!
>>> This test fails for me, i.e. the attempt to enabe direct IO succeeds. I
>>> will have to have a closer look later on.
>> Now, I use 5.7.0-rc2 kernel to test, this case fails, I guess loop 
>> driver has changed its logic. I am trying.
> 
> I write this test on fedora31(tmp directory use tmpfs), so I got a 
> pseudo pass when setting dio.
> 
> I misunderstood the meaning of the comment in the kernel.
> kernel commet as below:
> "We support direct I/O only if lo_offset is aligned with the
> logical I/O size of backing device, and the logical block
> size of loop is bigger than the backing device's and the loop
> needn't transform transfer."
> 
> sb_bsize = bdev_logical_block_size(inode->i_sb->s_bdev);  //get block 
> size from backing device
> dio_align = sb_bsize - 1;
> 
> I use logic block size of loop(1024 > 512) , so this test pass.
> 
> Now, I think this test is meaningless and we can remove this.
> 
> Best Regards
> Yang Xu
>>
>> ps: when run ioctl_loop01.c, I also met another problem that 
>> /dev/loop0p1 and  the corresponding sys file doesn't existed. dmesg 
>> report error "loop_reread_partitions: partition scan of loop0 () 
>> failed (rc=-16)". Also trying .
Kernel commit d3ef55362("block: fix busy device checking in 
blk_drop_partitions")  and commit cb6b771b05("block: fix busy device 
checking in blk_drop_partitions again") introduced this 
failure(ioctl_loop01, EBUSY error). more info see[1]

[1]https://lkml.org/lkml/2020/4/23/380
>>>
diff mbox series

Patch

diff --git a/runtest/syscalls b/runtest/syscalls
index e9b0a8f60..f83561724 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -534,6 +534,7 @@  ioctl_loop03 ioctl_loop03
 ioctl_loop04 ioctl_loop04
 ioctl_loop05 ioctl_loop05
 ioctl_loop06 ioctl_loop06
+ioctl_loop07 ioctl_loop07
 
 ioctl_ns01 ioctl_ns01
 ioctl_ns02 ioctl_ns02
diff --git a/testcases/kernel/syscalls/ioctl/.gitignore b/testcases/kernel/syscalls/ioctl/.gitignore
index ec19b4901..3a3d49adc 100644
--- a/testcases/kernel/syscalls/ioctl/.gitignore
+++ b/testcases/kernel/syscalls/ioctl/.gitignore
@@ -12,6 +12,7 @@ 
 /ioctl_loop04
 /ioctl_loop05
 /ioctl_loop06
+/ioctl_loop07
 /ioctl_ns01
 /ioctl_ns02
 /ioctl_ns03
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_loop07.c b/testcases/kernel/syscalls/ioctl/ioctl_loop07.c
new file mode 100644
index 000000000..c58a92b3c
--- /dev/null
+++ b/testcases/kernel/syscalls/ioctl/ioctl_loop07.c
@@ -0,0 +1,85 @@ 
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
+ *
+ * This is a basic ioctl test about loopdevice LOOP_SET_BLOCK_SIZE
+ * and LOOP_SET_DIRECT_IO.
+ * When blocksize is 1024(default align size is 512), set dio with
+ * 512 offset will fail.
+ */
+
+#include <stdio.h>
+#include <linux/loop.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include <sys/mount.h>
+#include "ioctl_loop_support.h"
+#include "lapi/loop.h"
+#include "tst_test.h"
+
+static char dev_path[1024], sys_loop_logicalpath[1024];
+static int dev_num, dev_fd, attach_flag, logical_block_size;
+
+static void verify_ioctl_loop(void)
+{
+	check_sys_value(sys_loop_logicalpath, 1024);
+	SAFE_IOCTL(dev_fd, BLKSSZGET, &logical_block_size);
+	if (logical_block_size == 1024)
+		tst_res(TPASS, "logical block size is 1024 by using BLKSSZGET ioctl");
+	else
+		tst_res(TFAIL, "expected logical block size is 1024 but got %d by using BLKSSZGET ioctl",
+				logical_block_size);
+	TEST(ioctl(dev_fd, LOOP_SET_DIRECT_IO, 1));
+	if (TST_RET == 0) {
+		tst_res(TFAIL, "LOOP_SET_DIRECT_IO succeeded unexpectedly");
+		return;
+	}
+	if (TST_ERR == EINVAL)
+		tst_res(TPASS | TTERRNO, "LOOP_SET_DIRECT_IO failed as expected");
+	else
+		tst_res(TFAIL | TTERRNO, "LOOP_SET_DIRECT_IO failed expected EINVAL got");
+}
+
+static void setup(void)
+{
+	struct loop_info loopinfo;
+
+	memset(&loopinfo, 0, sizeof(loopinfo));
+	loopinfo.lo_offset = 512;
+	dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path));
+	if (dev_num < 0)
+		tst_brk(TBROK, "Failed to find free loop device");
+
+	sprintf(sys_loop_logicalpath, "/sys/block/loop%d/queue/logical_block_size", dev_num);
+	tst_fill_file("test.img", 0, 1024 * 1024, 1);
+	tst_attach_device(dev_path, "test.img");
+	attach_flag = 1;
+
+	dev_fd = SAFE_OPEN(dev_path, O_RDWR);
+	TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo), TST_RETVAL_EQ0);
+	check_support_cmd(dev_fd, LOOP_SET_DIRECT_IO, 0, "LOOP_SET_DIRECT_IO");
+	check_support_cmd(dev_fd, LOOP_SET_BLOCK_SIZE, 512, "LOOP_SET_BLOCK_SIZE");
+	TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_BLOCK_SIZE, 1024), TST_RETVAL_EQ0);
+}
+
+static void cleanup(void)
+{
+	if (dev_fd > 0)
+		SAFE_CLOSE(dev_fd);
+	if (attach_flag)
+		tst_detach_device(dev_path);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_ioctl_loop,
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.needs_drivers = (const char *const []) {
+		"loop",
+		NULL
+	}
+};