From: Cyril Hrubis <chrubis@suse.cz>
To: Petr Vorel <pvorel@suse.cz>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v4 24/31] testcases: sysfs: Add sys_block_loop01
Date: Mon, 7 Sep 2026 17:14:07 +0200 [thread overview]
Message-ID: <ap7Uv_3UV-TBntFa@yuki.lan> (raw)
In-Reply-To: <20260903171142.GJ1107507@pevik>
Hi!
> > + 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.
That's what the LO_FLAGS_AUTOCLEAR is for, the file is supposed to be
detached when last fd pointing to the device is closed.
> > +}
> > +
> > +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);
I do not like adding code "just in case" it's usually more confusing
that keeping it that way.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-09-07 15:14 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-27 11:21 [LTP] [PATCH v3 00/31] Add sysfs sanity tests Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 01/31] lib: Add tst_sysfs_assert Cyril Hrubis
2026-09-03 14:57 ` Petr Vorel
2026-09-03 15:08 ` Cyril Hrubis
2026-09-03 15:34 ` Petr Vorel
2026-09-03 15:03 ` Petr Vorel
2026-09-03 15:25 ` Petr Vorel
2026-08-27 11:21 ` [LTP] [PATCH v4 02/31] testcases: sysfs: Add sys_power01 Cyril Hrubis
2026-08-27 14:04 ` [LTP] lib: Add tst_sysfs_assert linuxtestproject.agent
2026-08-27 11:21 ` [LTP] [PATCH v4 03/31] testcases: sysfs: Add sys_kernel01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 04/31] testcases: sysfs: Add sys_clocksource01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 05/31] testcases: sysfs: Add sys_node01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 06/31] testcases: sysfs: Add sys_cpu_topology01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 07/31] testcases: sysfs: Add sys_cpu_topology02 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 08/31] testcases: sysfs: Add sys_cpu_vulnerabilities01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 09/31] testcases: sysfs: Add sys_cpu_smt01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 10/31] testcases: sysfs: Add sys_cpu_cache01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 11/31] testcases: sysfs: Add sys_clockevents01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 12/31] testcases: sysfs: Add sys_ata01 Cyril Hrubis
2026-09-03 15:59 ` Petr Vorel
2026-08-27 11:21 ` [LTP] [PATCH v4 13/31] testcases: sysfs: Add sys_bdi01 Cyril Hrubis
2026-09-03 16:05 ` Petr Vorel
2026-08-27 11:21 ` [LTP] [PATCH v4 14/31] testcases: sysfs: sys_hwmon01 Cyril Hrubis
2026-09-03 16:21 ` Petr Vorel
2026-08-27 11:21 ` [LTP] [PATCH v4 15/31] testcases: sysfs: sys_leds01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 16/31] testcases: sysfs: Add sys_wakeup01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 17/31] testcases: sysfs: Add sys_rtc01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 18/31] testcases: sysfs: Add sys_thermal01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 19/31] tst_netdevice: Add two more helper macros Cyril Hrubis
2026-09-03 16:43 ` Petr Vorel
2026-08-27 11:21 ` [LTP] [PATCH v4 20/31] testcases: sysfs: Add sys_net01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 21/31] testcases: sysfs: Add sys_net02 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 22/31] testcases: sysfs: Add sys_net03 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 23/31] testcases: sysfs: Add sys_net04 Cyril Hrubis
2026-09-03 17:03 ` Petr Vorel
2026-08-27 11:21 ` [LTP] [PATCH v4 24/31] testcases: sysfs: Add sys_block_loop01 Cyril Hrubis
2026-09-03 17:11 ` Petr Vorel
2026-09-07 15:14 ` Cyril Hrubis [this message]
2026-08-27 11:21 ` [LTP] [PATCH v4 25/31] testcases: sysfs: Add sys_block_queue01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 26/31] testcases: sysfs: Add sys_block_size01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 27/31] testcases: sysfs: Add sys_hugepages01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 28/31] testcases: sysfs: Add sys_hugepages02 Cyril Hrubis
2026-09-03 14:44 ` Petr Vorel
2026-09-03 14:49 ` Cyril Hrubis
2026-09-03 15:38 ` Petr Vorel
2026-09-03 17:21 ` Petr Vorel
2026-08-27 11:21 ` [LTP] [PATCH v4 29/31] testcases: sysfs: Add sys_ksm01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 30/31] testcases: sysfs: Add sys_mm_swap01 Cyril Hrubis
2026-08-27 11:21 ` [LTP] [PATCH v4 31/31] testcases: sysfs: Add sys_thp01 Cyril Hrubis
2026-08-28 8:32 ` [LTP] [PATCH v3 00/31] Add sysfs sanity tests Li Wang
2026-09-03 17:24 ` Petr Vorel
2026-09-04 8:44 ` Petr Vorel
2026-09-08 8:35 ` Cyril Hrubis
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=ap7Uv_3UV-TBntFa@yuki.lan \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
--cc=pvorel@suse.cz \
/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