[LTP] [PATCH v4 24/31] testcases: sysfs: Add sys_block_loop01

Petr Vorel pvorel@suse.cz
Thu Sep 3 19:11:42 CEST 2026


Hi Cyril,

...
> +	if (tst_attach_device(dev_path, BACKING_FILE)) {
> +		tst_res(TFAIL, "Failed to attach %s to %s for autoclear check",
> +			BACKING_FILE, dev_path);
> +		return;
> +	}
> +	attached = 1;
> +
> +	fd = SAFE_OPEN(dev_path, O_RDWR);
> +	info.lo_flags = LO_FLAGS_AUTOCLEAR;
> +	SAFE_IOCTL(fd, LOOP_SET_STATUS64, &info);
> +	SAFE_CLOSE(fd);
> +
> +	/* autoclear runs asynchronously off a kernel workqueue, poll for it */
> +	size = TST_RETRY_FN_EXP_BACKOFF(read_loop_size(), TST_RETVAL_EQ0, 5);
> +
> +	if (size == 0) {
> +		tst_res(TPASS, "Device auto-detached");
> +		attached = 0;
> +	} else {
> +		tst_res(TFAIL, "Device did not auto-detach in time");
> +		tst_detach_device(dev_path);
> +		attached = 0;
> +	}
nit: attached = 0 can be only once here below if/else.
Also, I'm not sure why it's set to 0 because tst_detach_device() was not called,
but obviously I just miss something obvious.

> +}
> +
> +static void run(void)
> +{
> +	if (tst_attach_device(dev_path, BACKING_FILE))
> +		tst_brk(TBROK, "Failed to attach %s to %s", BACKING_FILE,
> +			dev_path);
> +	attached = 1;
> +
> +	check_attached();
> +	check_reconfigured();
> +
> +	if (tst_detach_device(dev_path))
IMHO it'd be safer to guard this with check attached in case of later code changes:

	if (attached && tst_detach_device(dev_path))
		tst_brk(TBROK, "Failed to detach %s", dev_path);

Kind regards,
Petr

> +		tst_brk(TBROK, "Failed to detach %s", dev_path);
> +	attached = 0;


More information about the ltp mailing list