Skip to contentSkip to conversation

lib: Retry safe_clone() on ENOSPC|EUSERS

PATCH Superseded Petr Vorel 3 participants 3 messages Mar 28, 2022 – Mar 30, 2022 Library code

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH v2 1/1 lib: Retry safe_clone() on ENOSPC|EUSERS

In some tests we are creating the namespaces faster than they are being asynchronously cleaned up in the kernel:

$ sudo ./userns08 -i 10
userns08.c:65: TPASS: Denied write access to ./restricted : EACCES (13)
userns08.c:65: TPASS: Denied write access to ./restricted : EACCES (13)
userns08.c:65: TPASS: Denied write access to ./restricted : EACCES (13)
userns08.c:65: TPASS: Denied write access to ./restricted : EACCES (13)
userns08.c:65: TPASS: Denied write access to ./restricted : EACCES (13)
userns08.c:36: TBROK: clone3 failed: ENOSPC (28)

Thus retrying the clone() on ENOSPC (or EUSERS for kernel < 4.9).

---
changes v1->v2:
* use TST_RETRY_FN_EXP_BACKOFF() (Cyril)

NOTE: 0.1s seems to be safe, although using TST_RETRY_FUNC() with 1s (the default) would be of course OK.

Kind regards,
Petr

 lib/tst_test.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/tst_test.c +4 -1
index 384c73e163..2e89d954ec 100644
@@ -436,6 +436,9 @@ pid_t safe_fork(const char *filename, unsigned int lineno)
 	return pid;
 }
 
+/* too fast creating namespaces => retrying */
+#define TST_CHECK_ENOSPC(x) ((x) >= 0 || !(errno == ENOSPC || errno == EUSERS))
+
 pid_t safe_clone(const char *file, const int lineno,
 		 const struct tst_clone_args *args)
 {
@@ -444,7 +447,7 @@ pid_t safe_clone(const char *file, const int lineno,
 	if (!tst_test->forks_child)
 		tst_brk(TBROK, "test.forks_child must be set!");
 
-	pid = tst_clone(args);
+	pid = TST_RETRY_FN_EXP_BACKOFF(tst_clone(args), TST_CHECK_ENOSPC, 0.1);
 
 	switch (pid) {
 	case -1:
Signature · 5 lines
2.35.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi!

Quoted 13 lines

In some tests we are creating the namespaces faster than they are being asynchronously cleaned up in the kernel:

$ sudo ./userns08 -i 10
userns08.c:65: TPASS: Denied write access to ./restricted : EACCES (13)
userns08.c:65: TPASS: Denied write access to ./restricted : EACCES (13)
userns08.c:65: TPASS: Denied write access to ./restricted : EACCES (13)
userns08.c:65: TPASS: Denied write access to ./restricted : EACCES (13)
userns08.c:65: TPASS: Denied write access to ./restricted : EACCES (13)
userns08.c:36: TBROK: clone3 failed: ENOSPC (28)

Thus retrying the clone() on ENOSPC (or EUSERS for kernel < 4.9).

Quoted 8 lines

---
changes v1->v2:
* use TST_RETRY_FN_EXP_BACKOFF() (Cyril)

NOTE: 0.1s seems to be safe, although using TST_RETRY_FUNC() with 1s (the default) would be of course OK.

I would just put in the default 1s to make things extra safe even on slow hardware.

lib/tst_test.c pid_t safe_fork(const char *filename, unsigned int lineno) · line 440

Quoted 13 lines
 lib/tst_test.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/tst_test.c +2 -0
index 384c73e163..2e89d954ec 100644
@@ -436,6 +436,9 @@ pid_t safe_fork(const char *filename, unsigned int lineno)
 	return pid;
 }
 
+/* too fast creating namespaces => retrying */
+#define TST_CHECK_ENOSPC(x) ((x) >= 0 || !(errno == ENOSPC || errno == EUSERS))

Reading the manual page I do not think that we have to retry on EUSERS, that used to be the return value where we reached limit of nested namespaces and that is not going go away if we retry.

Otherwise the rest looks good.

Quoted 12 lines
lib/tst_test.c +1 -1
 pid_t safe_clone(const char *file, const int lineno,
 		 const struct tst_clone_args *args)
 {
@@ -444,7 +447,7 @@ pid_t safe_clone(const char *file, const int lineno,
 	if (!tst_test->forks_child)
 		tst_brk(TBROK, "test.forks_child must be set!");
 
-	pid = tst_clone(args);
+	pid = TST_RETRY_FN_EXP_BACKOFF(tst_clone(args), TST_CHECK_ENOSPC, 0.1);
 
 	switch (pid) {
 	case -1:
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Hi Cyril, all,

Quoted 7 lines
Quoted 3 lines

NOTE: 0.1s seems to be safe, although using TST_RETRY_FUNC() with 1s (the default) would be of course OK.

I would just put in the default 1s to make things extra safe even on slow hardware.

+1
...

Quoted 10 lines
Quoted 3 lines
(quoted diff) +2 -0
+/* too fast creating namespaces => retrying */
+#define TST_CHECK_ENOSPC(x) ((x) >= 0 || !(errno == ENOSPC || errno 

== EUSERS))

Reading the manual page I do not think that we have to retry on EUSERS, that used to be the return value where we reached limit of nested namespaces and that is not going go away if we retry.

Otherwise the rest looks good.

Fixed both and merged.

Kind regards,
Petrb

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp