All of lore.kernel.org
 help / color / mirror / Atom feed
From: Li Wang <liwang@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] lib/tst_device.c: Add exception handling of function tst_find_free_loopdev
Date: Wed, 10 Mar 2021 20:20:48 +0800	[thread overview]
Message-ID: <CAEemH2dpSfc=fgRG1zwbBm1aLgRkbX8qECH7VPz+avBVLjmnDg@mail.gmail.com> (raw)
In-Reply-To: <20210310081048.27993-1-zhaogongyi@huawei.com>

Hi Gongyi,

On Wed, Mar 10, 2021 at 4:11 PM Zhao Gongyi <zhaogongyi@huawei.com> wrote:

> Because of race condition or abnormal env, set_dev_path may be
> return 1. And when set_dev_path return 1 in tst_find_free_loopdev,
> we should return Immediately.
>

If there exists a race condition, I firstly think of the TST_RETRY_FUNC
macro
to try more times for the set_dev_path. That might help to get the function
success
in the follow-up tries.



>
> Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
> ---
>  lib/tst_device.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/lib/tst_device.c b/lib/tst_device.c
> index c096b418b..51cf1ba7e 100644
> --- a/lib/tst_device.c
> +++ b/lib/tst_device.c
> @@ -83,8 +83,13 @@ int tst_find_free_loopdev(char *path, size_t path_len)
>                 rc = ioctl(ctl_fd, LOOP_CTL_GET_FREE);
>                 close(ctl_fd);
>                 if (rc >= 0) {
> -                       if (path)
> -                               set_dev_path(rc, path, path_len);
> +                       if (path)
> +                               if (!set_dev_path(rc, path, path_len)) {
> +                                       tst_resm(TINFO,
> +                                               "loop device not exist");
> +                                       return -1;
> +                               }
> +
>                         tst_resm(TINFO, "Found free device %d '%s'",
>                                 rc, path ?: "");
>                         return rc;
> --
> 2.17.1
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
>

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20210310/d3a354e5/attachment.htm>

  parent reply	other threads:[~2021-03-10 12:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-10  8:10 [LTP] [PATCH] lib/tst_device.c: Add exception handling of function tst_find_free_loopdev Zhao Gongyi
2021-03-10 11:13 ` Petr Vorel
2021-03-10 12:20 ` Li Wang [this message]
2021-03-10 14:03   ` Petr Vorel
2021-03-12  7:18 zhaogongyi
2021-03-12  9:54 zhaogongyi
2021-03-12 10:56 ` Cyril Hrubis
2021-03-15 12:06 zhaogongyi

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='CAEemH2dpSfc=fgRG1zwbBm1aLgRkbX8qECH7VPz+avBVLjmnDg@mail.gmail.com' \
    --to=liwang@redhat.com \
    --cc=ltp@lists.linux.it \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.