lib/tst_device.c: Add exception handling of function tst_find_free_loopdev
PATCH 1/1 lib/tst_device.c: Add exception handling of function tst_find_free_loopdev
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.
--- lib/tst_device.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
lib/tst_device.c +7 -2
@@ -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
PATCH 1/1 lib/tst_device.c: Add exception handling of function tst_find_free_loopdev
Hi Gongyi,
Quoted 2 lines
Because of race condition or abnormal env,
set_dev_pathmay be return 1. And whenset_dev_pathreturn 1 intst_find_free_loopdev,
You mean return 0, right?
Quoted 1 line
we should return Immediately.
Not really sure about this patch, mainly question for others. Could you please more describe your problem?
Kind regards,
Petr
PATCH 1/1 lib/tst_device.c: Add exception handling of function tst_find_free_loopdev
In reply to Zhao GongyiHi Gongyi,
Quoted 4 lines · Zhao Gongyi
Because of race condition or abnormal env,
set_dev_pathmay be return 1. And whenset_dev_pathreturn 1 intst_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.
Quoted 34 lines
Signed-off-by Zhao Gongyi <[email protected]>--- lib/tst_device.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)lib/tst_device.c +7
-3@@ -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
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20210310/d3a354e5/attachment.htm>
PATCH 1/1 lib/tst_device.c: Add exception handling of function tst_find_free_loopdev
Hi,
Quoted 10 lines
Quoted 3 lines
Because of race condition or abnormal env,
set_dev_pathmay be return 1. And whenset_dev_pathreturn 1 intst_find_free_loopdev, we should return Immediately.If there exists a race condition, I firstly think of the
TST_RETRY_FUNCmacro
to try more times for theset_dev_path. That might help to get the function success
in the follow-up tries.
+1
Kind regards,
Petr