Linux Test Project
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Sebastian Chlad <sebastianchlad@gmail.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v2] lib: tst_device: Use exponential backoff for loop device detach
Date: Fri, 30 Oct 2026 12:28:46 +0100	[thread overview]
Message-ID: <20261030112846.GA68558@pevik> (raw)
In-Reply-To: <20261027142747.19192-1-sebastianchlad@gmail.com>

Hi Seba,

> 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 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().

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)

> Suggested-by: Cyril Hrubis <chrubis@suse.cz>
> Signed-off-by: Sebastian Chlad <sebastianchlad@gmail.com>
> ---
> 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/20261022115410.23845-1-sebastian.chlad@suse.com/

>  lib/tst_device.c | 32 +++++++++++++++++---------------
>  1 file changed, 17 insertions(+), 15 deletions(-)

> diff --git a/lib/tst_device.c b/lib/tst_device.c
> index 00304711b..bf77c9ded 100644
> --- a/lib/tst_device.c
> +++ b/lib/tst_device.c
> @@ -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));

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!

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

> +		goto exit;
>  	}

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

  parent reply	other threads:[~2026-10-30 11:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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
2026-10-27 14:27 ` [LTP] [PATCH v2] lib: tst_device: Use exponential backoff for loop device detach Sebastian Chlad
2026-10-27 19:04   ` [LTP] " linuxtestproject.agent
2026-10-30 11:28   ` Petr Vorel [this message]
2026-10-30 17:11   ` [LTP] [PATCH v2] " Petr Vorel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261030112846.GA68558@pevik \
    --to=pvorel@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=sebastianchlad@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox