Linux Test Project
 help / color / mirror / Atom feed
* [LTP] [PATCH] lib: tst_device: Scale loop device detach timeout
@ 2026-10-22 11:54 Sebastian Chlad
  2026-10-22 13:07 ` Cyril Hrubis
  2026-10-22 13:32 ` [LTP] " linuxtestproject.agent
  0 siblings, 2 replies; 4+ messages in thread
From: Sebastian Chlad @ 2026-10-22 11:54 UTC (permalink / raw)
  To: ltp

From: Sebastian Chlad <sebastianchlad@gmail.com>

detach_loop_fd() retries LOOP_CLR_FD 40 times in 50ms steps, a fixed
2s timeout that ignores LTP_TIMEOUT_MUL. When another process still
holds the loop device at cleanup for longer than that, e.g. on a
loaded machine, the test ends with a spurious
"ioctl(/dev/loopN, LOOP_CLR_FD, 0) no ENXIO for too long" TWARN.

Scale the number of retries with tst_multiply_timeout(), which attach
already uses since d90d20046 ("lib: Use backoff polling to wait for
loop device nodes"). The default stays 2s, multiplied by 4 on kernels
with slow kconfig options and by LTP_TIMEOUT_MUL. The 50ms polling
step is kept, so the detach still finishes shortly after the device
is released.

Signed-off-by: Sebastian Chlad <sebastianchlad@gmail.com>
---
 lib/tst_device.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/tst_device.c b/lib/tst_device.c
index 00304711b..79e1fe0fb 100644
--- a/lib/tst_device.c
+++ b/lib/tst_device.c
@@ -251,7 +251,8 @@ uint64_t tst_get_device_size(const char *dev_path)
 
 static int detach_loop_fd(const char *dev, int *dev_fd)
 {
-	int ret, i, retval = 1;
+	int ret, retval = 1;
+	unsigned int i, retries = tst_multiply_timeout(40);
 
 	/* keep trying to clear LOOPDEV until we get ENXIO, a quick succession
 	 * of attach/detach might not give udev enough time to complete
@@ -259,7 +260,7 @@ static int detach_loop_fd(const char *dev, int *dev_fd)
 	 * Since 18048c1af783 ("loop: Fix a race between loop detach and loop open")
 	 * device is detached only after last close.
 	 */
-	for (i = 0; i < 40; i++) {
+	for (i = 0; i < retries; i++) {
 		ret = ioctl(*dev_fd, LOOP_CLR_FD, 0);
 
 		if (ret && (errno == ENXIO)) {
-- 
2.51.0


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

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

end of thread, other threads:[~2026-10-22 13:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-22 11:54 [LTP] [PATCH] lib: tst_device: Scale loop device detach timeout Sebastian Chlad
2026-10-22 13:07 ` Cyril Hrubis
2026-10-22 13:09   ` Cyril Hrubis
2026-10-22 13:32 ` [LTP] " linuxtestproject.agent

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