public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] lib/tst_device.c: Add exception handling of function tst_find_free_loopdev
@ 2021-03-10  8:10 Zhao Gongyi
  2021-03-10 11:13 ` Petr Vorel
  2021-03-10 12:20 ` Li Wang
  0 siblings, 2 replies; 8+ messages in thread
From: Zhao Gongyi @ 2021-03-10  8:10 UTC (permalink / raw)
  To: ltp

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.

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


^ permalink raw reply related	[flat|nested] 8+ messages in thread
* [LTP] [PATCH] lib/tst_device.c: Add exception handling of function tst_find_free_loopdev
@ 2021-03-12  7:18 zhaogongyi
  0 siblings, 0 replies; 8+ messages in thread
From: zhaogongyi @ 2021-03-12  7:18 UTC (permalink / raw)
  To: ltp

Hi Petr, Li,

At first, it seems ok that using ST_RETRY_FUNC macro to try more times for race condition.

In addition, when "loopdevno = ioctl(fd, LOOP_CTL_GET_FREE)" get free loop device i, and 
the loop device file /dev/loop%i has been removed?set_dev_path will return 1 and set " /dev/block/loop%i " 
in path. It might happened in many Embedded Systems because the test process's id is root always. So we could 
also Add exception handling?

Thanks!

Best Regards,
Gongyi

> 
> Hi,
> 
> > > 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.
> 
> +1
> 
> Kind regards,
> Petr

^ permalink raw reply	[flat|nested] 8+ messages in thread
* [LTP] [PATCH] lib/tst_device.c: Add exception handling of function tst_find_free_loopdev
@ 2021-03-12  9:54 zhaogongyi
  2021-03-12 10:56 ` Cyril Hrubis
  0 siblings, 1 reply; 8+ messages in thread
From: zhaogongyi @ 2021-03-12  9:54 UTC (permalink / raw)
  To: ltp

Hi!
> In addition, when "loopdevno = ioctl(fd, LOOP_CTL_GET_FREE)" get free
> loop device i, and the loop device file /dev/loop%i has been removed?
> set_dev_path will return 1 and set " /dev/block/loop%i "
> in path. It might happened in many Embedded Systems because the test
> process's id is root always. So we could also Add exception handling?

Or maybe we can try to create it when node doesn't exist?
	mknod("/dev/loop%i", S_IFBLK|0644, makedev(7, i))

-----------------------------------------------------------
> 
> Hi Petr, Li,
> 
> At first, it seems ok that using ST_RETRY_FUNC macro to try more times for
> race condition.
> 
> In addition, when "loopdevno = ioctl(fd, LOOP_CTL_GET_FREE)" get free
> loop device i, and the loop device file /dev/loop%i has been removed?
> set_dev_path will return 1 and set " /dev/block/loop%i "
> in path. It might happened in many Embedded Systems because the test
> process's id is root always. So we could also Add exception handling?
> 
> Thanks!
> 
> Best Regards,
> Gongyi
> 
> >
> > Hi,
> >
> > > > 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.
> >
> > +1
> >
> > Kind regards,
> > Petr

^ permalink raw reply	[flat|nested] 8+ messages in thread
* [LTP] [PATCH] lib/tst_device.c: Add exception handling of function tst_find_free_loopdev
@ 2021-03-15 12:06 zhaogongyi
  0 siblings, 0 replies; 8+ messages in thread
From: zhaogongyi @ 2021-03-15 12:06 UTC (permalink / raw)
  To: ltp

Hi Cyril,

I mean that /dev/loopX maybe removed by mistake after we get a free loop dev /dev/loopX. And in this case, we could try to create it or report error info immediately?

Actually?it seems there has no Sufficient reason to do it.

Thanks so much!

Best Regards,
Gongyi

> 
> Hi!
> > > In addition, when "loopdevno = ioctl(fd, LOOP_CTL_GET_FREE)" get
> > > free loop device i, and the loop device file /dev/loop%i has been
> removed??
> > > set_dev_path will return 1 and set " /dev/block/loop%i "
> > > in path. It might happened in many Embedded Systems because the
> test
> > > process's id is root always. So we could also Add exception handling?
> >
> > Or maybe we can try to create it when node doesn't exist?
> > 	mknod("/dev/loop%i", S_IFBLK|0644, makedev(7, i))
> 
> I do not really get what happens on your system. It looks like dev fs is not
> properly populated, which would be bug in your system rather than in the
> test library.
> 
> What is the state of /dev/loop* and /dev/block/loop* before you attempt
> to run the test?
> 
> --
> Cyril Hrubis
> chrubis@suse.cz

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-03-15 12:06 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2021-03-10 14:03   ` Petr Vorel
  -- strict thread matches above, loose matches on Subject: below --
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox