Re: [LTP] [PATCH] detach_device: Wait until the kernel frees the loop device

Cyril Hrubis
2015-06-10T10:09:51Z

Hi!
> Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
> ---
> lib/tst_device.c | 17 ++++++-----------
> 1 files changed, 6 insertions(+), 11 deletions(-)
>
> diff --git a/lib/tst_device.c b/lib/tst_device.c
> index 3bded53..9a92fc8 100644
> --- a/lib/tst_device.c
> +++ b/lib/tst_device.c
> @@ -150,30 +150,25 @@ static void attach_device(void (*cleanup_fn)(void),
>
> static void detach_device(void (*cleanup_fn)(void), const char *dev)
> {
> - int dev_fd, err, i;
> + int dev_fd, ret, i;
>
> dev_fd = SAFE_OPEN(cleanup_fn, dev, O_RDONLY);
>
> - /* keep trying to clear LOOPDEV fd if EBUSY, a quick succession
> + /* keep trying to clear LOOPDEV until we get ENXIO, a quick succession
> * of attach/detach might not give udev enough time to complete */
> for (i = 0; i < 40; i++) {
> - if (ioctl(dev_fd, LOOP_CLR_FD, 0) == 0) {
> + ret = ioctl(dev_fd, LOOP_CLR_FD, 0);
> +
> + if (ret && (errno == ENXIO)) {
> close(dev_fd);
> return;
> }
> - if (errno != EBUSY) {
> - err = errno;
> - close(dev_fd);
> - tst_brkm(TBROK, cleanup_fn,
> - "ioctl(%s, LOOP_CLR_FD, 0) failed: %s",
> - dev, tst_strerrno(err));
> - }

I would be a bit more verbose and would print an TINFO or TWARN message
if we get error different from the expected EBUSY or ENXIO.

Otherwise it looks fine, acked.

--
Cyril Hrubis
chrubis@suse.cz