<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small">Hi Gongyi,</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Mar 10, 2021 at 4:11 PM Zhao Gongyi <<a href="mailto:zhaogongyi@huawei.com">zhaogongyi@huawei.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Because of race condition or abnormal env, set_dev_path may be<br>
return 1. And when set_dev_path return 1 in tst_find_free_loopdev,<br>
we should return Immediately.<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">If there exists a race condition, I firstly think of the TST_RETRY_FUNC macro</div><div class="gmail_default" style="font-size:small">to try more times for the set_dev_path. That might help to get the function success</div><div class="gmail_default" style="font-size:small">in the follow-up tries.</div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Signed-off-by: Zhao Gongyi <<a href="mailto:zhaogongyi@huawei.com" target="_blank">zhaogongyi@huawei.com</a>><br>
---<br>
 lib/tst_device.c | 9 +++++++--<br>
 1 file changed, 7 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/lib/tst_device.c b/lib/tst_device.c<br>
index c096b418b..51cf1ba7e 100644<br>
--- a/lib/tst_device.c<br>
+++ b/lib/tst_device.c<br>
@@ -83,8 +83,13 @@ int tst_find_free_loopdev(char *path, size_t path_len)<br>
                rc = ioctl(ctl_fd, LOOP_CTL_GET_FREE);<br>
                close(ctl_fd);<br>
                if (rc >= 0) {<br>
-                       if (path)<br>
-                               set_dev_path(rc, path, path_len);<br>
+                       if (path)<br>
+                               if (!set_dev_path(rc, path, path_len)) {<br>
+                                       tst_resm(TINFO,<br>
+                                               "loop device not exist");<br>
+                                       return -1;<br>
+                               }<br>
+<br>
                        tst_resm(TINFO, "Found free device %d '%s'",<br>
                                rc, path ?: "");<br>
                        return rc;<br>
--<br>
2.17.1<br>
<br>
<br>
-- <br>
Mailing list info: <a href="https://lists.linux.it/listinfo/ltp" rel="noreferrer" target="_blank">https://lists.linux.it/listinfo/ltp</a><br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div>