Skip to contentSkip to conversation

nfs_lib: Unify testing on netns

PATCH New Petr Vorel 2 participants 7 messages Mar 5, 2020 – Mar 11, 2020

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH 1/2 nfs_lib: Unify testing on netns

There is no need to run tests on opposite client/server when using $TST_USE_NETNS based setup. It's enough just to set lhost IP address. This simplifies code a bit.

---
 testcases/network/nfs/nfs_stress/nfs_lib.sh | 13 -------------
 1 file changed, 13 deletions(-)
testcases/network/nfs/nfs_stress/nfs_lib.sh +0 -13
index 66f2fb038..2d5535dc5 100644
@@ -50,14 +50,6 @@ nfs_setup_server()
 {
 	local export_cmd="exportfs -i -o fsid=$$,no_root_squash,rw *:$remote_dir"
 
-	if [ -n "$LTP_NETNS" ]; then
-		if [ ! -d $remote_dir ]; then
-			mkdir -p $remote_dir
-			ROD $export_cmd
-		fi
-		return
-	fi
-
 	if ! tst_rhost_run -c "test -d $remote_dir"; then
 		tst_rhost_run -s -c "mkdir -p $remote_dir; $export_cmd"
 	fi
@@ -79,11 +71,6 @@ nfs_mount()
 	local mnt_cmd="mount -t nfs $opts $mount_dir $local_dir"
 
 	tst_res TINFO "Mounting NFS: $mnt_cmd"
-	if [ -n "$LTP_NETNS" ]; then
-		tst_rhost_run -s -c "$mnt_cmd"
-		return
-	fi
-
 	ROD $mnt_cmd
 }
 
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 2/2 nfs: Detect disabled UDP

nfs-utils disabled serving NFS over UDP in version 2.2.1, which produce TBROK:

nfs01 1 TBROK: 'mount -t nfs -o proto=udp,vers=3 10.0.0.2:/tmp/LTP_nfs01.3pixnljzEv/3/udp /tmp/LTP_nfs01.3pixnljzEv/3/0' failed on '': 'mount.nfs: requested NFS version or transport protocol is not supported'

Detect UDP configuration (parsing all configs) and return TCONF when disabled.

NOTE: Debian based distros still use older version, once it upgrades, it will might keep using current configuration files (/etc/default/nfs-kernel-server, /etc/default/nfs-common), therefore code might need to be adjusted.

---
 testcases/network/nfs/nfs_stress/nfs_lib.sh | 13 +++++++++++++
 1 file changed, 13 insertions(+)
testcases/network/nfs/nfs_stress/nfs_lib.sh +13 -0
index 2d5535dc5..2ba79dfdd 100644
@@ -46,6 +46,15 @@ get_socket_type()
 	done
 }
 
+nfs_server_udp_enabled()
+{
+	local config f
+
+	tst_rhost_run -c "[ -f /etc/nfs.conf ]" || return 0
+	config=$(tst_rhost_run -c 'for f in $(grep ^include.*= '/etc/nfs.conf' | cut -d = -f2); do [ -f $f ] && printf "$f "; done')
+	tst_rhost_run -c "grep -q '^[[:space:]]*udp[[:space:]]*=[[:space:]]*y' /etc/nfs.conf $config"
+}
+
 nfs_setup_server()
 {
 	local export_cmd="exportfs -i -o fsid=$$,no_root_squash,rw *:$remote_dir"
@@ -93,6 +102,10 @@ nfs_setup()
 		type=$(get_socket_type $n)
 		tst_res TINFO "setup NFSv$i, socket type $type"
 
+		if [ "$type" = "udp" ] && ! nfs_server_udp_enabled; then
+			tst_brk TCONF "UDP support disabled on NFS server"
+		fi
+
 		local_dir="$TST_TMPDIR/$i/$n"
 		remote_dir="$TST_TMPDIR/$i/$type"
 		mkdir -p $local_dir
Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/2 nfs: Detect disabled UDP

Quoted 25 lines · Petr Vorel

nfs-utils disabled serving NFS over UDP in version 2.2.1, which produce TBROK:

nfs01 1 TBROK: 'mount -t nfs -o proto=udp,vers=3 10.0.0.2:/tmp/LTP_nfs01.3pixnljzEv/3/udp /tmp/LTP_nfs01.3pixnljzEv/3/0' failed on '': 'mount.nfs: requested NFS version or transport protocol is not supported'

Detect UDP configuration (parsing all configs) and return TCONF when disabled.

NOTE: Debian based distros still use older version, once it upgrades, it will might keep using current configuration files (/etc/default/nfs-kernel-server, /etc/default/nfs-common), therefore code might need to be adjusted.

---
 testcases/network/nfs/nfs_stress/nfs_lib.sh | 13 +++++++++++++
 1 file changed, 13 insertions(+)
testcases/network/nfs/nfs_stress/nfs_lib.sh +0 -0
index 2d5535dc5..2ba79dfdd 100644

testcases/network/nfs/nfs_stress/nfs_lib.sh get_socket_type() · line 55

Quoted 10 lines
testcases/network/nfs/nfs_stress/nfs_lib.sh +7 -0
@@ -46,6 +46,15 @@ get_socket_type()
 	done
 }
 
+nfs_server_udp_enabled()
+{
+	local config f
+
+	tst_rhost_run -c "[ -f /etc/nfs.conf ]" || return 0
+	config=$(tst_rhost_run -c 'for f in $(grep ^include.*= '/etc/nfs.conf' | cut -d = -f2); do [ -f $f ] && printf "$f "; done')
+	tst_rhost_run -c "grep -q '^[[:space:]]*udp[[:space:]]*=[[:space:]]*y' /etc/nfs.conf $config"

Looks like the pattern doesn't detect when udp enabled by default and the config has commented default values, i.e. '# udp=y'.

grep '^[# ]*udp *= *y' /etc/nfs.conf $config

Quoted 17 lines
testcases/network/nfs/nfs_stress/nfs_lib.sh +6 -0
+}
+
 nfs_setup_server()
 {
 	local export_cmd="exportfs -i -o fsid=$$,no_root_squash,rw *:$remote_dir"
@@ -93,6 +102,10 @@ nfs_setup()
 		type=$(get_socket_type $n)
 		tst_res TINFO "setup NFSv$i, socket type $type"
 
+		if [ "$type" = "udp" ] && ! nfs_server_udp_enabled; then
+			tst_brk TCONF "UDP support disabled on NFS server"
+		fi
+
 		local_dir="$TST_TMPDIR/$i/$n"
 		remote_dir="$TST_TMPDIR/$i/$type"
 		mkdir -p $local_dir
author
#3 lore raw

PATCH 2/2 nfs: Detect disabled UDP

Hi Alexey,

Quoted 7 lines

testcases/network/nfs/nfs_stress/nfs_lib.sh get_socket_type() · line 55

Quoted 1 line
testcases/network/nfs/nfs_stress/nfs_lib.sh +1 -0
+	tst_rhost_run -c "grep -q '^[[:space:]]*udp[[:space:]]*=[[:space:]]*y' /etc/nfs.conf $config"

Looks like the pattern doesn't detect when udp enabled by default and the config has commented default values, i.e. '# udp=y'.

grep '^[# ]*udp *= *y' /etc/nfs.conf $config

Correct, this should be covered.
I'll send v2 with your much simpler regex, although I hoped we'd have something error prone than just relying on content of config files. But IMHO checking nfs-utils version cannot be easily done:

1) exportfs (which we require) does not print version (could be checked in strings $(which exportfs), but we don't want unnecessary string dependency).
2) checking nfsstat (which will be probably presented on the server and even we don't require it's presented, via if tst_cmd_available nfsstat && ...) can be done, but we probably don't want to bother to parse it's version (UDP was disabled in fbd7623d, which was in added in 2.1.2-rc2 and actually released in 2.2.1).

Kind regards,
Petr

#4 lore raw

PATCH 1/2 nfs_lib: Unify testing on netns

In reply to Petr Vorel

Hi Petr,

Quoted 3 lines · Petr Vorel

There is no need to run tests on opposite client/server when using $TST_USE_NETNS based setup. It's enough just to set lhost IP address. This simplifies code a bit.

It changes the testcase, this way nfs traffic will go through lo interface, the test won't use ltp_ns_veth* and netns.

We could add the knob for this scenario with LTP_NFS_USE_NETNS={1|0}?

Quoted 38 lines
---
 testcases/network/nfs/nfs_stress/nfs_lib.sh | 13 -------------
 1 file changed, 13 deletions(-)
testcases/network/nfs/nfs_stress/nfs_lib.sh +0 -13
index 66f2fb038..2d5535dc5 100644
@@ -50,14 +50,6 @@ nfs_setup_server()
 {
 	local export_cmd="exportfs -i -o fsid=$$,no_root_squash,rw *:$remote_dir"
 
-	if [ -n "$LTP_NETNS" ]; then
-		if [ ! -d $remote_dir ]; then
-			mkdir -p $remote_dir
-			ROD $export_cmd
-		fi
-		return
-	fi
-
 	if ! tst_rhost_run -c "test -d $remote_dir"; then
 		tst_rhost_run -s -c "mkdir -p $remote_dir; $export_cmd"
 	fi
@@ -79,11 +71,6 @@ nfs_mount()
 	local mnt_cmd="mount -t nfs $opts $mount_dir $local_dir"
 
 	tst_res TINFO "Mounting NFS: $mnt_cmd"
-	if [ -n "$LTP_NETNS" ]; then
-		tst_rhost_run -s -c "$mnt_cmd"
-		return
-	fi
-
 	ROD $mnt_cmd
 }
 
author
#5 lore raw

PATCH 1/2 nfs_lib: Unify testing on netns

Hi Alexey,

thanks for your review!

Quoted 6 lines
Quoted 3 lines

There is no need to run tests on opposite client/server when using $TST_USE_NETNS based setup. It's enough just to set lhost IP address. This simplifies code a bit.

It changes the testcase, this way nfs traffic will go through lo interface, the test won't use ltp_ns_veth* and netns.

Sorry, I didn't notice this.
BTW code nfs_setup_server could be run by tst_rhost_run() (code simplification), but that's a detail.

Quoted 1 line

We could add the knob for this scenario with LTP_NFS_USE_NETNS={1|0}?

Is this scenario useful? It does not look to me as a real world scenario, but if I'm wrong let's add it :).

Kind regards,
Petr

#6 lore raw

PATCH 1/2 nfs_lib: Unify testing on netns

Hi Petr,

Quoted 4 lines · Petr Vorel

Hi Alexey,

thanks for your review!

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

There is no need to run tests on opposite client/server when using $TST_USE_NETNS based setup. It's enough just to set lhost IP address. This simplifies code a bit.

It changes the testcase, this way nfs traffic will go through lo interface, the test won't use ltp_ns_veth* and netns.

Sorry, I didn't notice this.
BTW code nfs_setup_server could be run by tst_rhost_run() (code simplification),

Right

Quoted 5 lines

but that's a detail.

Quoted 1 line

We could add the knob for this scenario with LTP_NFS_USE_NETNS={1|0}?

Is this scenario useful? It does not look to me as a real world scenario, but if I'm wrong let's add it :).

Perhaps, it can be useful to find out if the test failure related to veth/netns...

Quoted 4 lines

Kind regards,
Petr