Skip to contentSkip to conversation

containers/netns/: fix kernel supporting check

PATCH New Guangwen Feng 2 participants 6 messages Sep 15, 2015 – Sep 22, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 containers/netns/: fix kernel supporting check

On RHEL5.11GA, test result should be TCONF but not TFAIL since setns() is not supported, so fix this.

---
 testcases/kernel/containers/netns/netns_helper.sh | 8 +++++++-
 testcases/kernel/containers/netns/netns_sysfs.sh  | 9 ++++++++-
 testcases/kernel/containers/share/ns_exec.c       | 6 ++----
 3 files changed, 17 insertions(+), 6 deletions(-)
testcases/kernel/containers/netns/netns_helper.sh +7 -1
index cea1541..f9d6cba 100755
@@ -188,8 +188,14 @@ netns_ns_exec_setup()
 		tst_brkm TBROK "unable to create a new network namespace"
 	fi
 
-	$NS_EXEC $NS_HANDLE0 ip link add veth0 type veth peer name veth1 || \
+	$NS_EXEC $NS_HANDLE0 ip link add veth0 type veth peer name veth1
+	if [ $? -eq 32 ]; then
+		tst_brkm TCONF "setns not supported"
+	fi
+
+	if [ $? -ne 0 ]; then
 		tst_brkm TBROK "unable to create veth pair devices"
+	fi
 
 	$NS_EXEC $NS_HANDLE0 ns_ifmove veth1 $NS_HANDLE1
 	if [ $? -eq 0 ]; then
testcases/kernel/containers/netns/netns_sysfs.sh +8 -1
index c10fa36..6c95a7d 100755
@@ -43,8 +43,15 @@ TST_CLEANUP=cleanup
 ls /sys/class/net >sysfs_before
 
 
-ns_exec $NS_HANDLE ip link add dummy0 type dummy || \
+ns_exec $NS_HANDLE ip link add dummy0 type dummy
+if [ $? -eq 32 ]; then
+	tst_brkm TCONF "setns not supported"
+fi
+
+if [ $? -ne 0 ]; then
 	tst_brkm TBROK "failed to add a new dummy device"
+fi
+
 ns_exec $NS_HANDLE mount -t sysfs none /sys 2>/dev/null
 
 ns_exec $NS_HANDLE test -d /sys/class/net/dummy0
testcases/kernel/containers/share/ns_exec.c +2 -4
index e2f068c..9148b46 100644
@@ -86,10 +86,8 @@ int main(int argc, char *argv[])
 	int i, rv, pid;
 
 	rv = syscall(__NR_setns, -1, 0);
-	if (rv == -1 && errno == ENOSYS) {
-		tst_resm(TINFO, "setns is not supported in the kernel");
-		return 1;
-	}
+	if (rv == -1 && errno == ENOSYS)
+		tst_brkm(TCONF, NULL, "setns is not supported in the kernel");
 
 	if (argc < 3) {
 		tst_resm(TINFO, "%s <NS_PID> <PROGRAM> [ARGS]\n", argv[0]);
Signature · 1 line
1.8.4.2
#1 lore raw

PATCH 1/1 containers/netns/: fix kernel supporting check

----- Original Message -----

Quoted 23 lines

From: "Guangwen Feng" <[email protected]>
To: [email protected]
Sent: Tuesday, 15 September, 2015 1:16:31 PM
Subject: [LTP] [PATCH] containers/netns/: fix kernel supporting check

On RHEL5.11GA, test result should be TCONF but not TFAIL since setns() is not supported, so fix this.

---
 testcases/kernel/containers/netns/netns_helper.sh | 8 +++++++-
 testcases/kernel/containers/netns/netns_sysfs.sh  | 9 ++++++++-
 testcases/kernel/containers/share/ns_exec.c       | 6 ++----
 3 files changed, 17 insertions(+), 6 deletions(-)
testcases/kernel/containers/netns/netns_helper.sh +0 -0
index cea1541..f9d6cba 100755
@@ -188,8 +188,14 @@ netns_ns_exec_setup()
 		tst_brkm TBROK "unable to create a new network namespace"
 	fi

testcases/kernel/containers/netns/netns_helper.sh netns_ns_exec_setup() · line 198

Quoted 10 lines
testcases/kernel/containers/netns/netns_helper.sh +7 -1
 
-	$NS_EXEC $NS_HANDLE0 ip link add veth0 type veth peer name veth1 || \
+	$NS_EXEC $NS_HANDLE0 ip link add veth0 type veth peer name veth1
+	if [ $? -eq 32 ]; then
+		tst_brkm TCONF "setns not supported"
+	fi
+
+	if [ $? -ne 0 ]; then
 		tst_brkm TBROK "unable to create veth pair devices"
+	fi

I'd suggest putting setns() check in a separate function, which we then call as part of setup for these testcases.

netns_setup() already makes couple checks, can it check for setns() availability too at the beginning of the test?

netns_sysfs.sh is not using netns_helper.sh helper, so it would need to call that function too as part of its setup.

Regards,
Jan

Quoted 50 lines
testcases/kernel/containers/netns/netns_helper.sh +0 -0
 	$NS_EXEC $NS_HANDLE0 ns_ifmove veth1 $NS_HANDLE1
 	if [ $? -eq 0 ]; then
testcases/kernel/containers/netns/netns_sysfs.sh +8 -1
index c10fa36..6c95a7d 100755
@@ -43,8 +43,15 @@ TST_CLEANUP=cleanup
 ls /sys/class/net >sysfs_before
 
 
-ns_exec $NS_HANDLE ip link add dummy0 type dummy || \
+ns_exec $NS_HANDLE ip link add dummy0 type dummy
+if [ $? -eq 32 ]; then
+	tst_brkm TCONF "setns not supported"
+fi
+
+if [ $? -ne 0 ]; then
 	tst_brkm TBROK "failed to add a new dummy device"
+fi
+
 ns_exec $NS_HANDLE mount -t sysfs none /sys 2>/dev/null
 
 ns_exec $NS_HANDLE test -d /sys/class/net/dummy0
testcases/kernel/containers/share/ns_exec.c +2 -5
index e2f068c..9148b46 100644
@@ -86,10 +86,8 @@ int main(int argc, char *argv[])
 	int i, rv, pid;
 
 	rv = syscall(__NR_setns, -1, 0);
-	if (rv == -1 && errno == ENOSYS) {
-		tst_resm(TINFO, "setns is not supported in the kernel");
-		return 1;
-	}
+	if (rv == -1 && errno == ENOSYS)
+		tst_brkm(TCONF, NULL, "setns is not supported in the kernel");
 
 	if (argc < 3) {
 		tst_resm(TINFO, "%s <NS_PID> <PROGRAM> [ARGS]\n", argv[0]);
--

1.8.4.2

--
Mailing list info: http://lists.linux.it/listinfo/ltp

#2 lore raw

PATCH 1/1 containers/netns/: fix kernel supporting check

Hi!
Thanks for your reply!

Quoted 40 lines · Jan Stancek

----- Original Message -----

Quoted 23 lines

From: "Guangwen Feng" <[email protected]>
To: [email protected]
Sent: Tuesday, 15 September, 2015 1:16:31 PM
Subject: [LTP] [PATCH] containers/netns/: fix kernel supporting check

On RHEL5.11GA, test result should be TCONF but not TFAIL since setns() is not supported, so fix this.

---
 testcases/kernel/containers/netns/netns_helper.sh | 8 +++++++-
 testcases/kernel/containers/netns/netns_sysfs.sh  | 9 ++++++++-
 testcases/kernel/containers/share/ns_exec.c       | 6 ++----
 3 files changed, 17 insertions(+), 6 deletions(-)
testcases/kernel/containers/netns/netns_helper.sh +0 -0
index cea1541..f9d6cba 100755
@@ -188,8 +188,14 @@ netns_ns_exec_setup()
 		tst_brkm TBROK "unable to create a new network namespace"
 	fi

testcases/kernel/containers/netns/netns_helper.sh netns_ns_exec_setup() · line 198

Quoted 10 lines
testcases/kernel/containers/netns/netns_helper.sh +7 -1
 
-	$NS_EXEC $NS_HANDLE0 ip link add veth0 type veth peer name veth1 || \
+	$NS_EXEC $NS_HANDLE0 ip link add veth0 type veth peer name veth1
+	if [ $? -eq 32 ]; then
+		tst_brkm TCONF "setns not supported"
+	fi
+
+	if [ $? -ne 0 ]; then
 		tst_brkm TBROK "unable to create veth pair devices"
+	fi

I'd suggest putting setns() check in a separate function, which we then call as part of setup for these testcases.

Quoted 6 lines

netns_setup() already makes couple checks, can it check for setns() availability too at the beginning of the test?

netns_sysfs.sh is not using netns_helper.sh helper, so it would need to call that function too as part of its setup.

OK, thanks!
I will rewrite the patch according to your suggestion.

Best Regards,
Guangwen Feng

Quoted 55 lines

Regards,
Jan

Quoted 47 lines
testcases/kernel/containers/netns/netns_helper.sh +0 -0
 	$NS_EXEC $NS_HANDLE0 ns_ifmove veth1 $NS_HANDLE1
 	if [ $? -eq 0 ]; then
testcases/kernel/containers/netns/netns_sysfs.sh +8 -1
index c10fa36..6c95a7d 100755
@@ -43,8 +43,15 @@ TST_CLEANUP=cleanup
 ls /sys/class/net >sysfs_before
 
 
-ns_exec $NS_HANDLE ip link add dummy0 type dummy || \
+ns_exec $NS_HANDLE ip link add dummy0 type dummy
+if [ $? -eq 32 ]; then
+	tst_brkm TCONF "setns not supported"
+fi
+
+if [ $? -ne 0 ]; then
 	tst_brkm TBROK "failed to add a new dummy device"
+fi
+
 ns_exec $NS_HANDLE mount -t sysfs none /sys 2>/dev/null
 
 ns_exec $NS_HANDLE test -d /sys/class/net/dummy0
testcases/kernel/containers/share/ns_exec.c +2 -5
index e2f068c..9148b46 100644
@@ -86,10 +86,8 @@ int main(int argc, char *argv[])
 	int i, rv, pid;
 
 	rv = syscall(__NR_setns, -1, 0);
-	if (rv == -1 && errno == ENOSYS) {
-		tst_resm(TINFO, "setns is not supported in the kernel");
-		return 1;
-	}
+	if (rv == -1 && errno == ENOSYS)
+		tst_brkm(TCONF, NULL, "setns is not supported in the kernel");
 
 	if (argc < 3) {
 		tst_resm(TINFO, "%s <NS_PID> <PROGRAM> [ARGS]\n", argv[0]);
--

1.8.4.2

Quoted 3 lines

--
Mailing list info: http://lists.linux.it/listinfo/ltp

.

#3 lore raw

PATCH v2 1/1 containers/netns/: fix kernel supporting check

On RHEL5.11GA, test result should be TCONF but not TFAIL since setns() is not supported, so fix this.

---
 testcases/kernel/containers/netns/netns_helper.sh |  4 +++
 testcases/kernel/containers/netns/netns_sysfs.sh  |  5 ++++
 testcases/kernel/containers/share/setns_check.c   | 32 +++++++++++++++++++++++
 3 files changed, 41 insertions(+)
 create mode 100644 testcases/kernel/containers/share/setns_check.c
testcases/kernel/containers/netns/netns_helper.sh +4 -0
index cea1541..ac08125 100755
@@ -110,6 +110,10 @@ netns_setup()
 
 	case "$1" in
 	ns_exec)
+		setns_check
+		if [ $? -eq 32 ]; then
+			tst_brkm TCONF "setns not supported"
+		fi
 		netns_ns_exec_setup
 		TST_CLEANUP=netns_ns_exec_cleanup
 		;;
testcases/kernel/containers/netns/netns_sysfs.sh +5 -0
index c10fa36..06de00f 100755
@@ -26,6 +26,11 @@ TCID="netns_sysfs"
 TST_TOTAL=2
 . test.sh
 
+setns_check
+if [ $? -eq 32 ]; then
+	tst_brkm TCONF "setns not supported"
+fi
+
 cleanup()
 {
 	tst_rmdir
testcases/kernel/containers/share/setns_check.c new file +32 -0
new file mode 100644
index 0000000..7ba891c
@@ -0,0 +1,32 @@
+/* Copyright (c) 2015 Fujitsu Ltd.
+ * Author: Guangwen Feng <[email protected]>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of version 2 the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ ***********************************************************************
+ * Check for setns() availability, should be called before ns_exec.
+ *
+ */
+
+#include "test.h"
+#include "linux_syscall_numbers.h"
+
+char *TCID = "setns_check";
+
+int main(void)
+{
+	if (syscall(__NR_setns, -1, 0) == -1 && errno == ENOSYS)
+		tst_brkm(TCONF, NULL, "setns is not supported in the kernel");
+	else
+		return 0;
+}
Signature · 1 line
1.8.4.2
#4 lore raw

PATCH v2 1/1 containers/netns/: fix kernel supporting check

----- Original Message -----

Quoted 10 lines

From: "Guangwen Feng" <[email protected]>
To: [email protected]
Cc: [email protected], "Guangwen Feng" <[email protected]>
Sent: Monday, 21 September, 2015 4:01:14 AM
Subject: [PATCH v2] containers/netns/: fix kernel supporting check

On RHEL5.11GA, test result should be TCONF but not TFAIL since setns() is not supported, so fix this.

I slightly modified description, added setns_check to .gitignore, tested on RHEL5.6 and pushed.

Thanks,
Jan

Quoted 84 lines
---
 testcases/kernel/containers/netns/netns_helper.sh |  4 +++
 testcases/kernel/containers/netns/netns_sysfs.sh  |  5 ++++
 testcases/kernel/containers/share/setns_check.c   | 32
 +++++++++++++++++++++++
 3 files changed, 41 insertions(+)
 create mode 100644 testcases/kernel/containers/share/setns_check.c
testcases/kernel/containers/netns/netns_helper.sh +4 -0
index cea1541..ac08125 100755
@@ -110,6 +110,10 @@ netns_setup()
 
 	case "$1" in
 	ns_exec)
+		setns_check
+		if [ $? -eq 32 ]; then
+			tst_brkm TCONF "setns not supported"
+		fi
 		netns_ns_exec_setup
 		TST_CLEANUP=netns_ns_exec_cleanup
 		;;
testcases/kernel/containers/netns/netns_sysfs.sh +5 -0
index c10fa36..06de00f 100755
@@ -26,6 +26,11 @@ TCID="netns_sysfs"
 TST_TOTAL=2
 . test.sh
 
+setns_check
+if [ $? -eq 32 ]; then
+	tst_brkm TCONF "setns not supported"
+fi
+
 cleanup()
 {
 	tst_rmdir
testcases/kernel/containers/share/setns_check.c new file +32 -1
new file mode 100644
index 0000000..7ba891c
@@ -0,0 +1,32 @@
+/* Copyright (c) 2015 Fujitsu Ltd.
+ * Author: Guangwen Feng <[email protected]>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of version 2 the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ ***********************************************************************
+ * Check for setns() availability, should be called before ns_exec.
+ *
+ */
+
+#include "test.h"
+#include "linux_syscall_numbers.h"
+
+char *TCID = "setns_check";
+
+int main(void)
+{
+	if (syscall(__NR_setns, -1, 0) == -1 && errno == ENOSYS)
+		tst_brkm(TCONF, NULL, "setns is not supported in the kernel");
+	else
+		return 0;
+}
--

1.8.4.2

#5 lore raw

PATCH v2 1/1 containers/netns/: fix kernel supporting check

Hi!

Quoted 11 lines · Jan Stancek

----- Original Message -----

Quoted 6 lines

From: "Guangwen Feng" <[email protected]>
To: [email protected]
Cc: [email protected], "Guangwen Feng" <[email protected]>
Sent: Monday, 21 September, 2015 4:01:14 AM
Subject: [PATCH v2] containers/netns/: fix kernel supporting check

Quoted 8 lines
Quoted 4 lines

On RHEL5.11GA, test result should be TCONF but not TFAIL since setns() is not supported, so fix this.

I slightly modified description, added setns_check to .gitignore, tested on RHEL5.6 and pushed.

Many thanks!

Best Regards,
Guangwen Feng

Quoted 89 lines

Thanks,
Jan

Quoted 81 lines
---
 testcases/kernel/containers/netns/netns_helper.sh |  4 +++
 testcases/kernel/containers/netns/netns_sysfs.sh  |  5 ++++
 testcases/kernel/containers/share/setns_check.c   | 32
 +++++++++++++++++++++++
 3 files changed, 41 insertions(+)
 create mode 100644 testcases/kernel/containers/share/setns_check.c
testcases/kernel/containers/netns/netns_helper.sh +4 -0
index cea1541..ac08125 100755
@@ -110,6 +110,10 @@ netns_setup()
 
 	case "$1" in
 	ns_exec)
+		setns_check
+		if [ $? -eq 32 ]; then
+			tst_brkm TCONF "setns not supported"
+		fi
 		netns_ns_exec_setup
 		TST_CLEANUP=netns_ns_exec_cleanup
 		;;
testcases/kernel/containers/netns/netns_sysfs.sh +5 -0
index c10fa36..06de00f 100755
@@ -26,6 +26,11 @@ TCID="netns_sysfs"
 TST_TOTAL=2
 . test.sh
 
+setns_check
+if [ $? -eq 32 ]; then
+	tst_brkm TCONF "setns not supported"
+fi
+
 cleanup()
 {
 	tst_rmdir
testcases/kernel/containers/share/setns_check.c new file +32 -1
new file mode 100644
index 0000000..7ba891c
@@ -0,0 +1,32 @@
+/* Copyright (c) 2015 Fujitsu Ltd.
+ * Author: Guangwen Feng <[email protected]>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of version 2 the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ ***********************************************************************
+ * Check for setns() availability, should be called before ns_exec.
+ *
+ */
+
+#include "test.h"
+#include "linux_syscall_numbers.h"
+
+char *TCID = "setns_check";
+
+int main(void)
+{
+	if (syscall(__NR_setns, -1, 0) == -1 && errno == ENOSYS)
+		tst_brkm(TCONF, NULL, "setns is not supported in the kernel");
+	else
+		return 0;
+}
--
Quoted 3 lines

1.8.4.2

.