Skip to contentSkip to conversation

lib: Retry safe_clone() on ENOSPC|EUSERS

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

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH 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. Thus retrying the clone() on ENOSPC (or EUSERS for kernel < 4.9).

Before:

$ 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)

With fix:

$ sudo ./userns08 -i 10
userns08.c:67: TPASS: Denied write access to ./restricted : EACCES (13)
userns08.c:67: TPASS: Denied write access to ./restricted : EACCES (13)
userns08.c:67: TPASS: Denied write access to ./restricted : EACCES (13)
userns08.c:67: TPASS: Denied write access to ./restricted : EACCES (13)
userns08.c:67: TPASS: Denied write access to ./restricted : EACCES (13)
userns08.c:38: TINFO: clone3() failed => retrying: ENOSPC (28)
userns08.c:67: TPASS: Denied write access to ./restricted : EACCES (13)
userns08.c:67: TPASS: Denied write access to ./restricted : EACCES (13)
userns08.c:67: TPASS: Denied write access to ./restricted : EACCES (13)
userns08.c:67: TPASS: Denied write access to ./restricted : EACCES (13)
userns08.c:67: TPASS: Denied write access to ./restricted : EACCES (13)
---
 lib/tst_test.c | 8 ++++++++
 1 file changed, 8 insertions(+)
lib/tst_test.c +8 -0
index 384c73e163..527d265d0a 100644
@@ -446,6 +446,14 @@ pid_t safe_clone(const char *file, const int lineno,
 
 	pid = tst_clone(args);
 
+	/* too fast creating namespaces => retrying */
+	if (pid < 0 && (errno == ENOSPC || errno == EUSERS)) {
+		tst_res_(file, lineno, TINFO | TERRNO, "%s() failed => retrying",
+				 pid == -2 ? "clone" : "clone3");
+		usleep(100000);
+		pid = tst_clone(args);
+	}
+
 	switch (pid) {
 	case -1:
 		tst_brk_(file, lineno, TBROK | TERRNO, "clone3 failed");
Signature · 5 lines
2.35.1


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

Hi!

lib/tst_test.c pid_t safe_clone(const char *file, const int lineno, · line 454

Quoted 6 lines
lib/tst_test.c +6 -0
+	/* too fast creating namespaces => retrying */
+	if (pid < 0 && (errno == ENOSPC || errno == EUSERS)) {
+		tst_res_(file, lineno, TINFO | TERRNO, "%s() failed => retrying",
+				 pid == -2 ? "clone" : "clone3");
+		usleep(100000);
+		pid = tst_clone(args);

Wouldn't it make sense to use the exponential backof macro we have in tst_common.h?

Signature · 5 lines
Cyril Hrubis
[email protected]

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

Hi!

lib/tst_test.c pid_t safe_clone(const char *file, const int lineno, · line 454

Quoted 6 lines
lib/tst_test.c +6 -0
+	/* too fast creating namespaces => retrying */
+	if (pid < 0 && (errno == ENOSPC || errno == EUSERS)) {
+		tst_res_(file, lineno, TINFO | TERRNO, "%s() failed => retrying",
+				 pid == -2 ? "clone" : "clone3");
+		usleep(100000);
+		pid = tst_clone(args);

Wouldn't it make sense to use the exponential backof macro we have in tst_common.h?

+1 => I'll send v2.

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