Skip to contentSkip to conversation

nfs_lib: Skip NFS versions disabled on server

PATCH Superseded Avinesh Kumar via ltp 3 participants 7 messages Aug 6 – Aug 11

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nfs_lib: Skip NFS versions disabled on server

From: Avinesh Kumar <[email protected]>

nfs06.sh mount several NFS versions in a single run (e.g. "3,4.0,4.1,4.2"). If the server has disabled one of the requested versions (reported via /proc/fs/nfsd/versions), the whole test currently aborts with TBROK on the failed mount instead of continuing with the versions that are supported.

nfs06 1 TINFO: setup NFSv4.0, socket type tcp
nfs06 1 TINFO: Mounting /var/tmp/LTP_nfs06.GHDqCwPYES/4.0/1
nfs06 1 TINFO: Mounting NFS: mount -v -t nfs -o proto=tcp,vers=4.0 10.0.0.2:/var/tmp/LTP_nfs06.GHDqCwPYES/mntpoint/4.0/tcp /var/tmp/LTP_nfs06.GHDqCwPYES/4.0/1 mount.nfs: mount(2): Invalid argument
mount.nfs: an incorrect mount option was specified for /var/tmp/LTP_nfs06.GHDqCwPYES/4.0/1
mount.nfs: timeout set for Wed Aug 5 08:06:38 2026
mount.nfs: trying text-based options 'proto=tcp,vers=4.0,addr=10.0.0.2,clientaddr=10.0.0.1'
nfs06 1 TBROK: mount command failed

Add nfs_server_vers_enabled() to check /proc/fs/nfsd/versions on the server, and nfs_filter_versions() to drop disabled versions from $VERSION (keeping $SOCKET_TYPE aligned by position) before mounting. If none of the requested versions are enabled, TCONF as before.

---
 testcases/network/nfs/nfs_stress/nfs_lib.sh | 56 ++++++++++++++++++++-
 1 file changed, 54 insertions(+), 2 deletions(-)
testcases/network/nfs/nfs_stress/nfs_lib.sh +54 -2
index 8bff3f23ae12..4065b000467e 100644
@@ -55,19 +55,24 @@ TST_NEEDS_DRIVERS="nfsd"
 # debugging whether test failures are related to veth/netns).
 LTP_NFS_NETNS_USE_LO=${LTP_NFS_NETNS_USE_LO:-}
 
-get_socket_type()
+get_socket_type_raw()
 {
 	local t
 	local k=0
 	for t in $SOCKET_TYPE; do
 		if [ "$k" -eq "$1" ]; then
-			echo "${t}${TST_IPV6}"
+			echo "$t"
 			return
 		fi
 		k=$(( k + 1 ))
 	done
 }
 
+get_socket_type()
+{
+	echo "$(get_socket_type_raw "$1")${TST_IPV6}"
+}
+
 # directory mounted by NFS client
 get_local_dir()
 {
@@ -109,6 +114,51 @@ nfs_server_udp_enabled()
 	tst_rhost_run -c "grep -q \"^[# ]*udp *= *y\" /etc/nfs.conf $config"
 }
 
+# nfs_server_vers_enabled VERS
+# Only returns false (1) when the server explicitly lists "-VERS" in
+# /proc/fs/nfsd/versions. If that file is unavailable or doesn't mention
+# VERS at all, defaults to true so the mount is still attempted.
+nfs_server_vers_enabled()
+{
+	local vers="$1"
+	local versions=" $(tst_rhost_run -c 'cat /proc/fs/nfsd/versions 2>/dev/null') "
+
+	case "$versions" in
+	*" -$vers "*) return 1;;
+	esac
+
+	return 0
+}
+
+# Drops NFS versions the server explicitly disabled from $VERSION, keeping
+# $SOCKET_TYPE entries aligned by position with what remains.
+nfs_filter_versions()
+{
+	local v type
+	local n=0
+	local new_version=
+	local new_socket_type=
+
+	for v in $VERSION; do
+		type=$(get_socket_type_raw $n)
+
+		if nfs_server_vers_enabled "$v"; then
+			new_version="$new_version $v"
+			new_socket_type="$new_socket_type $type"
+		else
+			tst_res TINFO "NFSv$v disabled on server, skipping"
+		fi
+
+		n=$(( n + 1 ))
+	done
+
+	[ -z "$new_version" ] && \
+		tst_brk TCONF "none of the requested NFS versions ($VERSION) are enabled on server"
+
+	VERSION="${new_version# }"
+	SOCKET_TYPE="${new_socket_type# }"
+}
+
 nfs_setup_server()
 {
 	local remote_dir="$1"
@@ -198,6 +248,8 @@ nfs_setup()
 
 	tst_res TINFO "$(mount.nfs -V)"
 
+	nfs_filter_versions
+
 	for i in $VERSION; do
 		type=$(get_socket_type $n)
 		tst_res TINFO "setup NFSv$i, socket type $type"
Signature · 5 lines
2.55.0


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

Hi Avinesh,

Quoted 1 line · Avinesh Kumar

nfs_lib: Skip NFS versions disabled on server

Verdict - Reviewed

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v1 1/1
#2 lore raw
In reply to Avinesh Kumar via ltp

Hi Avinesh,

Quoted 15 lines

nfs06.sh mount several NFS versions in a single run (e.g. "3,4.0,4.1,4.2"). If the server has disabled one of the requested versions (reported via /proc/fs/nfsd/versions), the whole test currently aborts with TBROK on the failed mount instead of continuing with the versions that are supported.

nfs06 1 TINFO: setup NFSv4.0, socket type tcp
nfs06 1 TINFO: Mounting /var/tmp/LTP_nfs06.GHDqCwPYES/4.0/1
nfs06 1 TINFO: Mounting NFS: mount -v -t nfs -o proto=tcp,vers=4.0 10.0.0.2:/var/tmp/LTP_nfs06.GHDqCwPYES/mntpoint/4.0/tcp /var/tmp/LTP_nfs06.GHDqCwPYES/4.0/1 mount.nfs: mount(2): Invalid argument
mount.nfs: an incorrect mount option was specified for /var/tmp/LTP_nfs06.GHDqCwPYES/4.0/1
mount.nfs: timeout set for Wed Aug 5 08:06:38 2026
mount.nfs: trying text-based options 'proto=tcp,vers=4.0,addr=10.0.0.2,clientaddr=10.0.0.1'
nfs06 1 TBROK: mount command failed

Quoted 4 lines

Add nfs_server_vers_enabled() to check /proc/fs/nfsd/versions on the server, and nfs_filter_versions() to drop disabled versions from $VERSION (keeping $SOCKET_TYPE aligned by position) before mounting. If none of the requested versions are enabled, TCONF as before.

Thanks for handling this!

LGTM? few notes below.

...

testcases/network/nfs/nfs_stress/nfs_lib.sh TST_NEEDS_DRIVERS="nfsd" · line 58

Quoted 2 lines
testcases/network/nfs/nfs_stress/nfs_lib.sh +1 -1
-get_socket_type()
+get_socket_type_raw()

very nit: slightly confusing type, because there is a "raw" socket SOCK_RAW. I guess any network programmer seeing this will think of that socket, e.g.:
socket(PF_INET, SOCK_RAW, ...);
socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);

But of course it can stay.

Quoted 27 lines

{

testcases/network/nfs/nfs_stress/nfs_lib.sh +8 -1
 	local t
 	local k=0
 	for t in $SOCKET_TYPE; do
 		if [ "$k" -eq "$1" ]; then
-			echo "${t}${TST_IPV6}"
+			echo "$t"
 			return
 		fi
 		k=$(( k + 1 ))
 	done
 }
 
+get_socket_type()
+{
+	echo "$(get_socket_type_raw "$1")${TST_IPV6}"
+}
+
 # directory mounted by NFS client
 get_local_dir()
 {
@@ -109,6 +114,51 @@ nfs_server_udp_enabled()
 	tst_rhost_run -c "grep -q \"^[# ]*udp *= *y\" /etc/nfs.conf $config"
 }
 
+# nfs_server_vers_enabled VERS
+# Only returns false (1) when the server explicitly lists "-VERS" in

testcases/network/nfs/nfs_stress/nfs_lib.sh nfs_server_udp_enabled() · line 128

Quoted 10 lines
testcases/network/nfs/nfs_stress/nfs_lib.sh +10 -0
+# /proc/fs/nfsd/versions. If that file is unavailable or doesn't mention
+# VERS at all, defaults to true so the mount is still attempted.
+nfs_server_vers_enabled()
+{
+	local vers="$1"
+	local versions=" $(tst_rhost_run -c 'cat /proc/fs/nfsd/versions 2>/dev/null') "
+
+	case "$versions" in
+	*" -$vers "*) return 1;;
+	esac

very nit: I was thinking if having the space in case would be slightly more readable, but probably not. I consider spaces in both versions as unnecessary (i.e. formatting error) but of course they are necessary.

	local versions="$(tst_rhost_run -c 'cat /proc/fs/nfsd/versions 2>/dev/null')"

	case " $versions " in

testcases/network/nfs/nfs_stress/nfs_lib.sh nfs_server_udp_enabled() · line 140

Quoted 12 lines
testcases/network/nfs/nfs_stress/nfs_lib.sh +12 -0
+
+	return 0
+}
+
+# Drops NFS versions the server explicitly disabled from $VERSION, keeping
+# $SOCKET_TYPE entries aligned by position with what remains.
+nfs_filter_versions()
+{
+	local v type
+	local n=0
+	local new_version=
+	local new_socket_type=

nit: it should be safe to use it without '=', right? local v type new_version new_socket_type

testcases/network/nfs/nfs_stress/nfs_lib.sh nfs_server_udp_enabled() · line 149

Quoted 9 lines
testcases/network/nfs/nfs_stress/nfs_lib.sh +9 -0
+
+	for v in $VERSION; do
+		type=$(get_socket_type_raw $n)
+
+		if nfs_server_vers_enabled "$v"; then
+			new_version="$new_version $v"
+			new_socket_type="$new_socket_type $type"
+		else
+			tst_res TINFO "NFSv$v disabled on server, skipping"

Could this be TCONF so that results summary at the end shows some TCONF? That indicates something was skipped.

+ tst_res TINFO "NFSv$v disabled on server, skipping"
+ tst_res TCONF "NFSv$v disabled on server, skipping"

testcases/network/nfs/nfs_stress/nfs_lib.sh nfs_server_udp_enabled() · line 156

Quoted 7 lines
testcases/network/nfs/nfs_stress/nfs_lib.sh +7 -0
+		fi
+
+		n=$(( n + 1 ))
+	done
+
+	[ -z "$new_version" ] && \
+		tst_brk TCONF "none of the requested NFS versions ($VERSION) are enabled on server"

nit: I would expect this would quit the test on system with
set -o errexit (equivalent of set -e), but magically it works.
FYI normally it's better if any test line exit with 0 => use || (or if ...; then ... fi) instead && i.e.

[ ... ] || tst_brk TCONF

But because it works it can stay.

testcases/network/nfs/nfs_stress/nfs_lib.sh nfs_server_udp_enabled() · line 159

Quoted 3 lines
testcases/network/nfs/nfs_stress/nfs_lib.sh +3 -0
+
+	VERSION="${new_version# }"
+	SOCKET_TYPE="${new_socket_type# }"

Fortunately removing leading space works also on dash, although at least some string operations aren't part of POSIX [1].

If this is ever problematic, we can fix it with:

	[ "$new_version" ] && new_version="$new_version $v" || new_version="$v"
	[ "$new_socket_type" ] && new_socket_type="$new_socket_type $type" || new_socket_type="$type"

But because removing leading space is not needed, because later code for t in $SOCKET_TYPE; do will handle that, I'd remove this part entirely.

FYI: (no leading/trailing space in parameters, no $t having just empty space:
SOCKET_TYPE=' udp tcp '; for t in $SOCKET_TYPE; do echo "'$t'"; done 'udp'
'tcp'

[1] https://mywiki.wooledge.org/Bashism#Parameter_Expansions

Kind regards,
Petr

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

Hi Petr,

Thanks for your review.

Quoted 7 lines

Thanks for handling this!

LGTM? few notes below.

...

Quoted 8 lines

testcases/network/nfs/nfs_stress/nfs_lib.sh TST_NEEDS_DRIVERS="nfsd" · line 58

Quoted 2 lines
testcases/network/nfs/nfs_stress/nfs_lib.sh +1 -1
-get_socket_type()
+get_socket_type_raw()

very nit: slightly confusing type, because there is a "raw" socket SOCK_RAW. I guess any network programmer seeing this will think of that socket, e.g.:
socket(PF_INET, SOCK_RAW, ...);
socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);

But of course it can stay.

How about get_socket_type_bare() ?

Quoted 32 lines
Quoted 13 lines
  {
  	local t
  	local k=0
  	for t in $SOCKET_TYPE; do
  		if [ "$k" -eq "$1" ]; then
testcases/network/nfs/nfs_stress/nfs_lib.sh +1 -1
-			echo "${t}${TST_IPV6}"
+			echo "$t"
  			return
  		fi
  		k=$(( k + 1 ))
  	done
  }

testcases/network/nfs/nfs_stress/nfs_lib.sh TST_NEEDS_DRIVERS="nfsd"

Quoted 10 lines
testcases/network/nfs/nfs_stress/nfs_lib.sh +8 -0
 
 
+nfs_server_vers_enabled()
+{
+	local vers="$1"
+	local versions=" $(tst_rhost_run -c 'cat /proc/fs/nfsd/versions 2>/dev/null') "
+
+	case "$versions" in
+	*" -$vers "*) return 1;;
+	esac

very nit: I was thinking if having the space in case would be slightly more readable, but probably not. I consider spaces in both versions as unnecessary (i.e. formatting error) but of course they are necessary.

	local versions="$(tst_rhost_run -c 'cat /proc/fs/nfsd/versions 2>/dev/null')"

	case " $versions " in
Quoted 14 lines

testcases/network/nfs/nfs_stress/nfs_lib.sh nfs_server_udp_enabled() · line 140

Quoted 12 lines
testcases/network/nfs/nfs_stress/nfs_lib.sh +12 -0
+
+	return 0
+}
+
+# Drops NFS versions the server explicitly disabled from $VERSION, keeping
+# $SOCKET_TYPE entries aligned by position with what remains.
+nfs_filter_versions()
+{
+	local v type
+	local n=0
+	local new_version=
+	local new_socket_type=

nit: it should be safe to use it without '=', right? local v type new_version new_socket_type

+1

Quoted 13 lines

testcases/network/nfs/nfs_stress/nfs_lib.sh nfs_server_udp_enabled() · line 149

Quoted 10 lines
testcases/network/nfs/nfs_stress/nfs_lib.sh +9 -0
+
+	for v in $VERSION; do
+		type=$(get_socket_type_raw $n)
+
+		if nfs_server_vers_enabled "$v"; then
+			new_version="$new_version $v"
+			new_socket_type="$new_socket_type $type"
+		else
+			tst_res TINFO "NFSv$v disabled on server, skipping"

Could this be TCONF so that results summary at the end shows some TCONF? That indicates something was skipped.

+1

Quoted 16 lines
(quoted diff) +2 -0
+			tst_res TINFO "NFSv$v disabled on server, skipping"
+			tst_res TCONF "NFSv$v disabled on server, skipping"

testcases/network/nfs/nfs_stress/nfs_lib.sh nfs_server_udp_enabled() · line 156

Quoted 8 lines
testcases/network/nfs/nfs_stress/nfs_lib.sh +7 -0
+		fi
+
+		n=$(( n + 1 ))
+	done
+
+	[ -z "$new_version" ] && \
+		tst_brk TCONF "none of the requested NFS versions ($VERSION) are enabled on server"

nit: I would expect this would quit the test on system with
set -o errexit (equivalent of set -e), but magically it works.
FYI normally it's better if any test line exit with 0 => use || (or if ...; then ... fi) instead && i.e.

Quoted 3 lines

[ ... ] || tst_brk TCONF

But because it works it can stay.

+1. I will switch to below for consistency.

	[ "$new_version" ] || \
		tst_brk TCONF ...
Quoted 8 lines

testcases/network/nfs/nfs_stress/nfs_lib.sh nfs_server_udp_enabled() · line 159

Quoted 4 lines
testcases/network/nfs/nfs_stress/nfs_lib.sh +3 -0
+
+	VERSION="${new_version# }"
+	SOCKET_TYPE="${new_socket_type# }"

Fortunately removing leading space works also on dash, although at least some string operations aren't part of POSIX [1].

Quoted 7 lines

If this is ever problematic, we can fix it with:

	[ "$new_version" ] && new_version="$new_version $v" || new_version="$v"
	[ "$new_socket_type" ] && new_socket_type="$new_socket_type $type" || new_socket_type="$type"

But because removing leading space is not needed, because later code for t in $SOCKET_TYPE; do will handle that, I'd remove this part entirely.

Actually we need to remove the leading space, otherwise we break nfsstat01 where $VERSION is being used as whole scalar value. case $VERSION in

I can switch to the solution you suggested here.

Quoted 10 lines

FYI: (no leading/trailing space in parameters, no $t having just empty space:
SOCKET_TYPE=' udp tcp '; for t in $SOCKET_TYPE; do echo "'$t'"; done 'udp'
'tcp'

[1] https://mywiki.wooledge.org/Bashism#Parameter_Expansions

Kind regards,
Petr

Regards,
Avinesh

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

Hi Avinesh,

Quoted 17 lines

Hi Petr,

Thanks for your review.

Quoted 12 lines

Thanks for handling this!

LGTM? few notes below.

...

testcases/network/nfs/nfs_stress/nfs_lib.sh TST_NEEDS_DRIVERS="nfsd" · line 58

Quoted 2 lines
testcases/network/nfs/nfs_stress/nfs_lib.sh +1 -1
-get_socket_type()
+get_socket_type_raw()

very nit: slightly confusing type, because there is a "raw" socket SOCK_RAW. I guess any network programmer seeing this will think of that socket, e.g.:
socket(PF_INET, SOCK_RAW, ...);
socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);

Quoted 3 lines
Quoted 1 line

But of course it can stay.

How about get_socket_type_bare() ?

+1

...

Quoted 15 lines
Quoted 14 lines
(quoted diff) +2 -0
+			tst_res TINFO "NFSv$v disabled on server, skipping"
+			tst_res TCONF "NFSv$v disabled on server, skipping"

testcases/network/nfs/nfs_stress/nfs_lib.sh nfs_server_udp_enabled() · line 156

Quoted 8 lines
testcases/network/nfs/nfs_stress/nfs_lib.sh +7 -0
+		fi
+
+		n=$(( n + 1 ))
+	done
+
+	[ -z "$new_version" ] && \
+		tst_brk TCONF "none of the requested NFS versions ($VERSION) are enabled on server"

nit: I would expect this would quit the test on system with
set -o errexit (equivalent of set -e), but magically it works.
FYI normally it's better if any test line exit with 0 => use || (or if ...; then ... fi) instead && i.e.

Quoted 6 lines
Quoted 3 lines

[ ... ] || tst_brk TCONF

But because it works it can stay.

+1. I will switch to below for consistency.

	[ "$new_version" ] || \
		tst_brk TCONF ...

Thank you!

Quoted 9 lines
Quoted 8 lines

testcases/network/nfs/nfs_stress/nfs_lib.sh nfs_server_udp_enabled() · line 159

Quoted 3 lines
testcases/network/nfs/nfs_stress/nfs_lib.sh +3 -0
+
+	VERSION="${new_version# }"
+	SOCKET_TYPE="${new_socket_type# }"

Fortunately removing leading space works also on dash, although at least some string operations aren't part of POSIX [1].

If this is ever problematic, we can fix it with:

Quoted 8 lines
Quoted 5 lines
	[ "$new_version" ] && new_version="$new_version $v" || new_version="$v"
	[ "$new_socket_type" ] && new_socket_type="$new_socket_type $type" || new_socket_type="$type"

But because removing leading space is not needed, because later code for t in $SOCKET_TYPE; do will handle that, I'd remove this part entirely.

Actually we need to remove the leading space, otherwise we break nfsstat01 where $VERSION is being used as whole scalar value. case $VERSION in

Thanks for info.

Quoted 1 line

I can switch to the solution you suggested here.

I checked LTP sources and we use in old scripts often ${...#...}. I was probably just too careful about portability.

Kind regards,
Petr

Quoted 12 lines
Quoted 9 lines

FYI: (no leading/trailing space in parameters, no $t having just empty space:
SOCKET_TYPE=' udp tcp '; for t in $SOCKET_TYPE; do echo "'$t'"; done 'udp'
'tcp'

[1] https://mywiki.wooledge.org/Bashism#Parameter_Expansions

Kind regards,
Petr

Regards,
Avinesh

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

PATCH v2 1/1 nfs_lib: Skip NFS versions disabled on server

In reply to Petr Vorel

From: Avinesh Kumar <[email protected]>

nfs06.sh mount several NFS versions in a single run (e.g. "3,4.0,4.1,4.2"). If the server has disabled one of the requested versions (reported via /proc/fs/nfsd/versions), the whole test currently aborts with TBROK on the failed mount instead of continuing with the versions that are supported.

nfs06 1 TINFO: setup NFSv4.0, socket type tcp
nfs06 1 TINFO: Mounting /var/tmp/LTP_nfs06.GHDqCwPYES/4.0/1
nfs06 1 TINFO: Mounting NFS: mount -v -t nfs -o proto=tcp,vers=4.0 10.0.0.2:/var/tmp/LTP_nfs06.GHDqCwPYES/mntpoint/4.0/tcp /var/tmp/LTP_nfs06.GHDqCwPYES/4.0/1 mount.nfs: mount(2): Invalid argument
mount.nfs: an incorrect mount option was specified for /var/tmp/LTP_nfs06.GHDqCwPYES/4.0/1
mount.nfs: timeout set for Wed Aug 5 08:06:38 2026
mount.nfs: trying text-based options 'proto=tcp,vers=4.0,addr=10.0.0.2,clientaddr=10.0.0.1'
nfs06 1 TBROK: mount command failed

Add nfs_server_vers_enabled() to check /proc/fs/nfsd/versions on the server, and nfs_filter_versions() to drop disabled versions from $VERSION (keeping $SOCKET_TYPE aligned by position) before mounting. If none of the requested versions are enabled, TCONF as before.

---
 testcases/network/nfs/nfs_stress/nfs_lib.sh | 54 ++++++++++++++++++++-
 1 file changed, 52 insertions(+), 2 deletions(-)
testcases/network/nfs/nfs_stress/nfs_lib.sh +52 -2
index 8bff3f23ae12..e86847151ee9 100644
@@ -55,19 +55,24 @@ TST_NEEDS_DRIVERS="nfsd"
 # debugging whether test failures are related to veth/netns).
 LTP_NFS_NETNS_USE_LO=${LTP_NFS_NETNS_USE_LO:-}
 
-get_socket_type()
+get_socket_type_bare()
 {
 	local t
 	local k=0
 	for t in $SOCKET_TYPE; do
 		if [ "$k" -eq "$1" ]; then
-			echo "${t}${TST_IPV6}"
+			echo "$t"
 			return
 		fi
 		k=$(( k + 1 ))
 	done
 }
 
+get_socket_type()
+{
+	echo "$(get_socket_type_bare "$1")${TST_IPV6}"
+}
+
 # directory mounted by NFS client
 get_local_dir()
 {
@@ -109,6 +114,49 @@ nfs_server_udp_enabled()
 	tst_rhost_run -c "grep -q \"^[# ]*udp *= *y\" /etc/nfs.conf $config"
 }
 
+# nfs_server_vers_enabled VERS
+# Only returns false (1) when the server explicitly lists "-VERS" in
+# /proc/fs/nfsd/versions. If that file is unavailable or doesn't mention
+# VERS at all, defaults to true so the mount is still attempted.
+nfs_server_vers_enabled()
+{
+	local vers="$1"
+	local versions=" $(tst_rhost_run -c 'cat /proc/fs/nfsd/versions 2>/dev/null') "
+
+	case "$versions" in
+	*" -$vers "*) return 1;;
+	esac
+
+	return 0
+}
+
+# Drops NFS versions the server explicitly disabled from $VERSION, keeping
+# $SOCKET_TYPE entries aligned by position with what remains.
+nfs_filter_versions()
+{
+	local v type new_version new_socket_type
+	local n=0
+
+	for v in $VERSION; do
+		type=$(get_socket_type_bare $n)
+
+		if nfs_server_vers_enabled "$v"; then
+			[ "$new_version" ] && new_version="$new_version $v" || new_version="$v"
+			[ "$new_socket_type" ] && new_socket_type="$new_socket_type $type" || new_socket_type="$type"
+		else
+			tst_res TCONF "NFSv$v disabled on server, skipping"
+		fi
+
+		n=$(( n + 1 ))
+	done
+
+	[ "$new_version" ] || \
+		tst_brk TCONF "none of the requested NFS versions ($VERSION) are enabled on server"
+
+	VERSION="$new_version"
+	SOCKET_TYPE="$new_socket_type"
+}
+
 nfs_setup_server()
 {
 	local remote_dir="$1"
@@ -198,6 +246,8 @@ nfs_setup()
 
 	tst_res TINFO "$(mount.nfs -V)"
 
+	nfs_filter_versions
+
 	for i in $VERSION; do
 		type=$(get_socket_type $n)
 		tst_res TINFO "setup NFSv$i, socket type $type"
Signature · 5 lines
2.55.0


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

Hi Avinesh,

Quoted 1 line · Avinesh Kumar

nfs_lib: Skip NFS versions disabled on server

Verdict - Reviewed

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

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