Skip to contentSkip to conversation

syscalls: Check for leftover partition info in loopdev ioctl tests

PATCH In review Martin Doucha 4 participants 5 messages Apr 6, 2022 – Oct 10, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 syscalls: Check for leftover partition info in loopdev ioctl tests

Due to a kernel bug, successful ioctl09 and ioctl_loop01 test runs sometimes leave behind stale partition info on the loop device they used, which then causes mkfs.vfat to fail in later tests. Check that partition info was properly removed in cleanup.

---

This does not fix the mkfs.vfat failures but it makes the true cause visible. We could add a workaround for the mkfs.vfat failures by simply initializing the loop device with the LO_FLAGS_PARTSCAN flag by default, or at least when stale partition info is found by tst_find_free_loopdev().

 testcases/kernel/syscalls/ioctl/ioctl09.c      | 12 +++++++++++-
 testcases/kernel/syscalls/ioctl/ioctl_loop01.c |  6 ++++++
 2 files changed, 17 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/ioctl/ioctl09.c +11 -1
index 9728ecb9c..09867a5c5 100644
@@ -19,7 +19,7 @@
        ({ value ? TST_RETVAL_EQ0(x) : TST_RETVAL_NOTNULL(x); })
 
 static char dev_path[1024];
-static int dev_num, attach_flag, dev_fd;
+static int dev_num = -1, attach_flag, dev_fd;
 static char loop_partpath[1026], sys_loop_partpath[1026];
 
 static void change_partition(const char *const cmd[])
@@ -102,6 +102,16 @@ static void cleanup(void)
 		SAFE_CLOSE(dev_fd);
 	if (attach_flag)
 		tst_detach_device(dev_path);
+
+	if (dev_num < 0)
+		return;
+
+	sprintf(sys_loop_partpath, "/sys/block/loop%d/loop%dp1", dev_num,
+		dev_num);
+	sprintf(loop_partpath, "%sp1", dev_path);
+
+	if (!access(sys_loop_partpath, F_OK) || !access(loop_partpath, F_OK))
+		tst_res(TWARN, "Partition info was not cleared from loop dev");
 }
 
 static struct tst_test test = {
testcases/kernel/syscalls/ioctl/ioctl_loop01.c +6 -0
index 734d803d5..17168ae04 100644
@@ -135,6 +135,12 @@ static void cleanup(void)
 		SAFE_CLOSE(dev_fd);
 	if (attach_flag)
 		tst_detach_device(dev_path);
+
+	if (!*sys_loop_partpath || !*loop_partpath)
+		return;
+
+	if (!access(sys_loop_partpath, F_OK) || !access(loop_partpath, F_OK))
+		tst_res(TWARN, "Partition info was not cleared from loop dev");
 }
 
 static struct tst_test test = {
Signature · 5 lines
2.35.1


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

Hi Martin,

Quoted 4 lines

Due to a kernel bug, successful ioctl09 and ioctl_loop01 test runs sometimes leave behind stale partition info on the loop device they used, which then causes mkfs.vfat to fail in later tests. Check that partition info was properly removed in cleanup.

Thanks!

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw
In reply to Martin Doucha

Hi!

Quoted 5 lines

Due to a kernel bug, successful ioctl09 and ioctl_loop01 test runs sometimes leave behind stale partition info on the loop device they used, which then causes mkfs.vfat to fail in later tests. Check that partition info was properly removed in cleanup.

Quoted 7 lines

---

This does not fix the mkfs.vfat failures but it makes the true cause visible. We could add a workaround for the mkfs.vfat failures by simply initializing the loop device with the LO_FLAGS_PARTSCAN flag by default, or at least when stale partition info is found by tst_find_free_loopdev().

I guess that it would be cleaner to put the stale partition info detection into the loop library. We can print a warning there and then do the workaround.

Also do we want to add a regression test for the stale partition info? Should be easy enough. Or at least add the hash of the kernel commit that fixed it to the ioctl tests?

Quoted 57 lines
 testcases/kernel/syscalls/ioctl/ioctl09.c      | 12 +++++++++++-
 testcases/kernel/syscalls/ioctl/ioctl_loop01.c |  6 ++++++
 2 files changed, 17 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/ioctl/ioctl09.c +11 -1
index 9728ecb9c..09867a5c5 100644
@@ -19,7 +19,7 @@
        ({ value ? TST_RETVAL_EQ0(x) : TST_RETVAL_NOTNULL(x); })
 
 static char dev_path[1024];
-static int dev_num, attach_flag, dev_fd;
+static int dev_num = -1, attach_flag, dev_fd;
 static char loop_partpath[1026], sys_loop_partpath[1026];
 
 static void change_partition(const char *const cmd[])
@@ -102,6 +102,16 @@ static void cleanup(void)
 		SAFE_CLOSE(dev_fd);
 	if (attach_flag)
 		tst_detach_device(dev_path);
+
+	if (dev_num < 0)
+		return;
+
+	sprintf(sys_loop_partpath, "/sys/block/loop%d/loop%dp1", dev_num,
+		dev_num);
+	sprintf(loop_partpath, "%sp1", dev_path);
+
+	if (!access(sys_loop_partpath, F_OK) || !access(loop_partpath, F_OK))
+		tst_res(TWARN, "Partition info was not cleared from loop dev");
 }
 
 static struct tst_test test = {
testcases/kernel/syscalls/ioctl/ioctl_loop01.c +6 -0
index 734d803d5..17168ae04 100644
@@ -135,6 +135,12 @@ static void cleanup(void)
 		SAFE_CLOSE(dev_fd);
 	if (attach_flag)
 		tst_detach_device(dev_path);
+
+	if (!*sys_loop_partpath || !*loop_partpath)
+		return;
+
+	if (!access(sys_loop_partpath, F_OK) || !access(loop_partpath, F_OK))
+		tst_res(TWARN, "Partition info was not cleared from loop dev");
 }
 
 static struct tst_test test = {
Signature · 5 lines
2.35.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw
Quoted 9 lines · Cyril Hrubis

Hi!

Quoted 8 lines

Due to a kernel bug, successful ioctl09 and ioctl_loop01 test runs sometimes leave behind stale partition info on the loop device they used, which then causes mkfs.vfat to fail in later tests. Check that partition info was properly removed in cleanup.

---

Quoted 8 lines
Quoted 4 lines

This does not fix the mkfs.vfat failures but it makes the true cause visible. We could add a workaround for the mkfs.vfat failures by simply initializing the loop device with the LO_FLAGS_PARTSCAN flag by default, or at least when stale partition info is found by tst_find_free_loopdev().

I guess that it would be cleaner to put the stale partition info detection into the loop library. We can print a warning there and then do the workaround.

The workaround needs to be added into tst_attach_device(). It doesn't make sense to add it to test cleanup, in part because tst_detach_device() can and occasionally does fail on timeout.

On the other hand, we need a cleanup check in ioctl tests which create partitions on loop devices, otherwise they'll leave garbage behind silently.

Quoted 3 lines

Also do we want to add a regression test for the stale partition info? Should be easy enough. Or at least add the hash of the kernel commit that fixed it to the ioctl tests?

I haven't investigated deep enough to find out how to reliably trigger the bug or which patch fixed it (if any). Regression test would be nice but it's not a trivial task at the moment.

Signature · 10 lines
Martin Doucha   [email protected]
QA Engineer for Software Maintenance
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic

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

Hello,

Quoted 26 lines · Martin Doucha
Quoted 9 lines · Cyril Hrubis

Hi!

Quoted 8 lines

Due to a kernel bug, successful ioctl09 and ioctl_loop01 test runs sometimes leave behind stale partition info on the loop device they used, which then causes mkfs.vfat to fail in later tests. Check that partition info was properly removed in cleanup.

---

Quoted 8 lines
Quoted 4 lines

This does not fix the mkfs.vfat failures but it makes the true cause visible. We could add a workaround for the mkfs.vfat failures by simply initializing the loop device with the LO_FLAGS_PARTSCAN flag by default, or at least when stale partition info is found by tst_find_free_loopdev().

I guess that it would be cleaner to put the stale partition info detection into the loop library. We can print a warning there and then do the workaround.

The workaround needs to be added into tst_attach_device(). It doesn't make sense to add it to test cleanup, in part because tst_detach_device() can and occasionally does fail on timeout.

On the other hand, we need a cleanup check in ioctl tests which create partitions on loop devices, otherwise they'll leave garbage behind silently.

Quoted 7 lines
Quoted 3 lines

Also do we want to add a regression test for the stale partition info? Should be easy enough. Or at least add the hash of the kernel commit that fixed it to the ioctl tests?

I haven't investigated deep enough to find out how to reliably trigger the bug or which patch fixed it (if any). Regression test would be nice but it's not a trivial task at the moment.

I'm trying to cleanup patchwork and I'm not sure what the resolution to this was?

If this has not been resolved elsewhere and nobody wants to work on this further then I would be in favor of merging the patch. The information is then available for others to investigate.

Signature · 5 lines
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp