lib: tst_device: Scale loop device detach timeout
PATCH 1/1 lib: tst_device: Scale loop device detach timeout
From: Sebastian Chlad <[email protected]>
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.
--- lib/tst_device.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
lib/tst_device.c +3 -2
@@ -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 )) {
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 6 lines
detach_loop_fd()retriesLOOP_CLR_FD40 times in 50ms steps, a fixed 2s timeout that ignoresLTP_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.
Quoted 6 lines
Scale the number of retries with
tst_multiply_timeout(), which attach already uses sinced90d20046("lib: Use backoff polling to wait for loop device nodes"). The default stays 2s, multiplied by 4 on kernels with slow kconfig options and byLTP_TIMEOUT_MUL. The 50ms polling step is kept, so the detach still finishes shortly after the device is released.
It would probably be better if we used the TST_RETRY_FN_EXP_BACKOFF() in the detach loop instead so that the deatch is fast on fast device but we do not poll unecessairly fast on slow devices.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 10 lines
Quoted 6 lines
Scale the number of retries with
tst_multiply_timeout(), which attach already uses sinced90d20046("lib: Use backoff polling to wait for loop device nodes"). The default stays 2s, multiplied by 4 on kernels with slow kconfig options and byLTP_TIMEOUT_MUL. The 50ms polling step is kept, so the detach still finishes shortly after the device is released.It would probably be better if we used the
TST_RETRY_FN_EXP_BACKOFF()in the detach loop instead so that the deatch is fast on fast device but we do not poll unecessairly fast on slow devices.
And that macro already scales the timeout with tst_multiply_timeout().
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Sebastian,
Quoted 1 line · Sebastian Chlad
lib:
tst_device: Scale loop device detach timeout
Verdict - Reviewed
---
Note:
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/1 lib: tst_device: Use exponential backoff for loop device detach
In reply to Sebastian Chladdetach_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 an unwanted "ioctl(/dev/loopN, LOOP_CLR_FD, 0) no ENXIO for too long" TWARN.
Use TST_RETRY_FN_EXP_BACKOFF() instead, as attach already does since d90d20046 ("lib: Use backoff polling to wait for loop device nodes"). The detach finishes quickly when the device is released right away, polling slows down when it is not, and the total timeout (about 2s by default) is scaled by tst_multiply_timeout().
---
Changes in v2:
- Use TST_RETRY_FN_EXP_BACKOFF() instead of scaling the retry count with tst_multiply_timeout() (Cyril).
- Link to v1:
https://lore.kernel.org/ltp/[email protected]/
lib/tst_device.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-)
lib/tst_device.c +17 -15
@@ -249,9 +249,14 @@ uint64_t tst_get_device_size(const char *dev_path)return size/1024 /1024 ; } +static int loop_clr_fd_busy (int dev_fd) +{ +return !ioctl (dev_fd,LOOP_CLR_FD ,0 ) || errno ==EBUSY ; +} +static int detach_loop_fd (const char *dev,int *dev_fd) { -int ret, i, retval =1 ; +int ret, retval =1 ;/* keep trying to clear LOOPDEV until we get ENXIO, a quick succession * of attach/detach might not give udev enough time to complete
@@ -259,22 +264,19 @@ 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++) { - ret =ioctl (*dev_fd,LOOP_CLR_FD ,0 ); + ret =TST_RETRY_FN_EXP_BACKOFF (loop_clr_fd_busy (*dev_fd), +TST_RETVAL_EQ0 ,2 ); -if (ret && (errno ==ENXIO )) { - retval =0 ; - goto exit; - } - -if (ret && (errno !=EBUSY )) { -tst_resm (TWARN , -"ioctl(%s, LOOP_CLR_FD, 0) unexpectedly failed with: %s" , - dev,tst_strerrno (errno)); - goto exit; - } +if (!ret && (errno ==ENXIO )) { + retval =0 ; + goto exit; + } -usleep (50000 ); +if (!ret) { +tst_resm (TWARN , +"ioctl(%s, LOOP_CLR_FD, 0) unexpectedly failed with: %s" , + dev,tst_strerrno (errno)); + goto exit; } tst_resm(TWARN,
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] lib: tst_device: Use exponential backoff for loop device detach
Hi Sebastian,
Quoted 1 line · Sebastian Chlad
lib:
tst_device: Use exponential backoff for loop device detach
Verdict - Reviewed
---
Note:
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2] lib: tst_device: Use exponential backoff for loop device detach
In reply to Sebastian ChladHi Seba,
Quoted 11 lines
detach_loop_fd()retriesLOOP_CLR_FD40 times in 50ms steps, a fixed 2s timeout that ignoresLTP_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 an unwanted "ioctl(/dev/loopN, LOOP_CLR_FD, 0)no ENXIO for too long" TWARN.Use
TST_RETRY_FN_EXP_BACKOFF()instead, as attach already does sinced90d20046("lib: Use backoff polling to wait for loop device nodes"). The detach finishes quickly when the device is released right away, polling slows down when it is not, and the total timeout (about 2s by default) is scaled bytst_multiply_timeout().
Out of curiosity, which of ioctl test is affected by this on a slow worker? Baremetal issue?
BTW ioctl_loop01 is not working with -i (not caused by this patch):
# ./testcases/kernel/syscalls/ioctl/ioctl_loop01 ... tst_buffers.c:57: TINFO: Test is using guarded buffers ioctl_loop01.c:82: TPASS: /sys/block/loop0/loop/partscan = 0 ioctl_loop01.c:83: TPASS: /sys/block/loop0/loop/autoclear = 0 ioctl_loop01.c:84: TPASS: /sys/block/loop0/loop/backing_file = '/tmp/LTP_iocMhKZxH/test.img' ioctl_loop01.c:57: TPASS: get expected lo_flag 12 ioctl_loop01.c:59: TPASS: /sys/block/loop0/loop/partscan = 1 ioctl_loop01.c:60: TPASS: /sys/block/loop0/loop/autoclear = 1 ioctl_loop01.c:69: TPASS: access /dev/loop0p1 succeeds ioctl_loop01.c:75: TPASS: access /sys/block/loop0/loop0p1 succeeds ioctl_loop01.c:90: TINFO: Test flag can be clear ioctl_loop01.c:57: TPASS: get expected lo_flag 8 ioctl_loop01.c:59: TPASS: /sys/block/loop0/loop/partscan = 1 ioctl_loop01.c:60: TPASS: /sys/block/loop0/loop/autoclear = 0 ioctl_loop01.c:69: TPASS: access /dev/loop0p1 succeeds ioctl_loop01.c:75: TPASS: access /sys/block/loop0/loop0p1 succeeds ioctl_loop01.c:82: TBROK: Failed to open FILE '/sys/block/loop0/loop/partscan' for reading: ENOENT (2)
Quoted 52 lines
Suggested-by Cyril Hrubis <[email protected]>Signed-off-by Sebastian Chlad <[email protected]>---
Changes in v2:
- UseTST_RETRY_FN_EXP_BACKOFF()instead of scaling the retry count withtst_multiply_timeout()(Cyril).
- Link to v1:
https://lore.kernel.org/ltp/[email protected]/lib/tst_device.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-)lib/tst_device.c +8
-14@@ -249,9 +249,14 @@ uint64_t tst_get_device_size(const char *dev_path)return size/1024 /1024 ; } +static int loop_clr_fd_busy (int dev_fd) +{ +return !ioctl (dev_fd,LOOP_CLR_FD ,0 ) || errno ==EBUSY ; +} +static int detach_loop_fd (const char *dev,int *dev_fd) { -int ret, i, retval =1 ; +int ret, retval =1 ;/* keep trying to clear LOOPDEV until we get ENXIO, a quick succession * of attach/detach might not give udev enough time to complete @@ -259,22 +264,19 @@ 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++) { - ret =ioctl (*dev_fd,LOOP_CLR_FD ,0 ); + ret =TST_RETRY_FN_EXP_BACKOFF (loop_clr_fd_busy (*dev_fd), +TST_RETVAL_EQ0 ,2 ); -if (ret && (errno ==ENXIO )) { - retval =0 ; - goto exit; - } - -if (ret && (errno !=EBUSY )) { -tst_resm (TWARN , -"ioctl(%s, LOOP_CLR_FD, 0) unexpectedly failed with: %s" , - dev,tst_strerrno (errno)); - goto exit; - }
lib/tst_device.c static int detach_loop_fd(const char *dev, int *dev_fd) · line 278
Quoted 10 lines
lib/tst_device.c +8
-1+if (!ret && (errno ==ENXIO )) { + retval =0 ; + goto exit; + } -usleep (50000 ); +if (!ret) { +tst_resm (TWARN , +"ioctl(%s, LOOP_CLR_FD, 0) unexpectedly failed with: %s" , + dev,tst_strerrno (errno));
nit: While you at it, could you change to use TERRNO?
tst_resm(TWARN | TERRNO, "ioctl(%s, LOOP_CLR_FD, 0) failed, dev);
But maybe it can be done as an separate effort (there are more tst_strerrno() calls).
The rest LGTM. Thanks!
Kind regards,
Petr
Quoted 2 lines
lib/tst_device.c +1
-0+ goto exit; }
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Petr Vorel
AppliedRe: [LTP] [PATCH v2] lib: tst_device: Use exponential backoff for loop device detach
In reply to Sebastian ChladHi all,
Merged, thanks!
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp