Skip to contentSkip to conversation

nfs_lib: Unify remote directory creation

PATCH New Petr Vorel 2 participants 6 messages Mar 11, 2020 – Mar 13, 2020

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH v2 1/3 nfs_lib: Unify remote directory creation

remote directory creation can be done by tst_rhost_run() also on netns. This simplifies code a bit.

---
Changes v1-v2:
* remove changes in nfs_mount() (to keep using netns)

 testcases/network/nfs/nfs_stress/nfs_lib.sh | 8 --------
 1 file changed, 8 deletions(-)
testcases/network/nfs/nfs_stress/nfs_lib.sh +0 -8
index 66f2fb038..f233976c7 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
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v2 2/3 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 enabled (parsing all configs) and return TCONF when disabled. Also detect UDP enabled by default by default, when config has commented default values.

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.

---
Changes v1-v2:
* detect UDP also on IPv6 ("udp6")
* use Simplified regexp

 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 f233976c7..3d447783d 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 '^[# ]*udp *= *y' /etc/nfs.conf $config"
+}
+
 nfs_setup_server()
 {
 	local export_cmd="exportfs -i -o fsid=$$,no_root_squash,rw *:$remote_dir"
@@ -98,6 +107,10 @@ nfs_setup()
 		type=$(get_socket_type $n)
 		tst_res TINFO "setup NFSv$i, socket type $type"
 
+		if [ "$type" = "udp" -o "$type" = "udp6" ] && ! 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
author
#2 lore raw

PATCH v2 3/3 nfs_lib: Add option to run traffic via lo on netns

In reply to Petr Vorel

When $LTP_NFS_NETNS_USE_LO set and test is using netns ($TST_USE_NETNS set) NFS traffic will go through lo interface instead of ltp_ns_veth* netns interfaces. This can be useful for debugging whether test failures are related to veth/netns.

---
Changes v1-v2:
* new commit

 testcases/network/nfs/nfs_stress/nfs_lib.sh | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
testcases/network/nfs/nfs_stress/nfs_lib.sh +7 -1
index 3d447783d..b7c372afb 100644
@@ -31,6 +31,11 @@ TST_NEEDS_CMDS="$TST_NEEDS_CMDS mount exportfs"
 TST_SETUP="${TST_SETUP:-nfs_setup}"
 TST_CLEANUP="${TST_CLEANUP:-nfs_cleanup}"
 
+# When set and test is using netns ($TST_USE_NETNS set) NFS traffic will go
+# through lo interface instead of ltp_ns_veth* netns interfaces (useful for
+# debugging whether test failures are related to veth/netns).
+LTP_NFS_NETNS_USE_LO=
+
 . tst_net.sh
 
 get_socket_type()
@@ -52,6 +57,7 @@ nfs_server_udp_enabled()
 
 	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 '^[# ]*udp *= *y' /etc/nfs.conf $config"
 }
 
@@ -80,7 +86,7 @@ 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
+	if [ -n "$LTP_NETNS" ] && [ -z "$LTP_NFS_NETNS_USE_LO" ]; then
 		tst_rhost_run -s -c "$mnt_cmd"
 		return
 	fi
Signature · 1 line
2.25.1
author
#3 lore raw

PATCH v2 3/3 nfs_lib: Add option to run traffic via lo on netns

Hi Alexey,

...

Quoted 1 line
testcases/network/nfs/nfs_stress/nfs_lib.sh +0 -0

...

testcases/network/nfs/nfs_stress/nfs_lib.sh TST_NEEDS_CMDS="$TST_NEEDS_CMDS mount exportfs" · line 37

Quoted 4 lines
testcases/network/nfs/nfs_stress/nfs_lib.sh +4 -0
+# When set and test is using netns ($TST_USE_NETNS set) NFS traffic will go
+# through lo interface instead of ltp_ns_veth* netns interfaces (useful for
+# debugging whether test failures are related to veth/netns).
+LTP_NFS_NETNS_USE_LO=

Sorry, this needs to be
LTP_NFS_NETNS_USE_LO=${LTP_NFS_NETNS_USE_LO:-}

+ suggest different name, if you don't like this.

Kind regards,
Petr

#4 lore raw

PATCH v2 3/3 nfs_lib: Add option to run traffic via lo on netns

Quoted 12 lines · Petr Vorel

Hi Alexey,

...

Quoted 1 line
testcases/network/nfs/nfs_stress/nfs_lib.sh +0 -0

...

testcases/network/nfs/nfs_stress/nfs_lib.sh TST_NEEDS_CMDS="$TST_NEEDS_CMDS mount exportfs" · line 37

Quoted 4 lines
testcases/network/nfs/nfs_stress/nfs_lib.sh +4 -0
+# When set and test is using netns ($TST_USE_NETNS set) NFS traffic will go
+# through lo interface instead of ltp_ns_veth* netns interfaces (useful for
+# debugging whether test failures are related to veth/netns).
+LTP_NFS_NETNS_USE_LO=

Sorry, this needs to be
LTP_NFS_NETNS_USE_LO=${LTP_NFS_NETNS_USE_LO:-}

Quoted 5 lines

+ suggest different name, if you don't like this.

Kind regards,
Petr

Hi Petr, the patch-series LGTM,