Skip to content

Commit a05e671

Browse files
committed
nfs_lib.sh: Cleanup local and remote directories setup
Logic for creating local and remote directories was on more places. Create get_local_dir() and get_remote_dir() functions to keep it on single place. Now both directories are the same, this is a preparation for "nfs: Run on btrfs, ext4, xfs", which uses TST_ALL_FILESYSTEMS=1 (remote directory will be on the loop device). local dir is needed in nfs_mount(), but was defined in nfs_setup() and reused local variable with shell inheritance (ugly!), because there were all parameters from loop. Similarly, remote dir is needed in both nfs_mount() and nfs_setup_server(), but created with shell inheritance in nfs_setup(). Pass these params to nfs_mount() and nfs_setup_server() and define variables with new functions get_local_dir() and get_remote_dir(). Use get_remote_dir() in nfs_get_remote_path(). Move cd to local directory to the end of nfs_mount() (it used to cd after nfs_mount(), but only if -v parameter contained single version, but it does not harm to always cd). Link: https://lore.kernel.org/ltp/[email protected]/ Acked-by: Cyril Hrubis <[email protected]> Signed-off-by: Petr Vorel <[email protected]>
1 parent 045f229 commit a05e671

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

testcases/network/nfs/nfs_stress/nfs_lib.sh

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22
# SPDX-License-Identifier: GPL-2.0-or-later
3-
# Copyright (c) Linux Test Project, 2016-2022
3+
# Copyright (c) Linux Test Project, 2016-2023
44
# Copyright (c) 2015-2018 Oracle and/or its affiliates. All Rights Reserved.
55
# Copyright (c) International Business Machines Corp., 2001
66

@@ -53,6 +53,24 @@ get_socket_type()
5353
done
5454
}
5555

56+
# directory mounted by NFS client
57+
get_local_dir()
58+
{
59+
local v="$1"
60+
local n="$2"
61+
62+
echo "$TST_TMPDIR/$v/$n"
63+
}
64+
65+
# directory on NFS server
66+
get_remote_dir()
67+
{
68+
local v="$1"
69+
local n="$2"
70+
71+
echo "$TST_TMPDIR/$v/$n"
72+
}
73+
5674
nfs_get_remote_path()
5775
{
5876
local v
@@ -63,7 +81,7 @@ nfs_get_remote_path()
6381
done
6482

6583
v=${1:-$v}
66-
echo "$TST_TMPDIR/$v/$type"
84+
echo "$(get_remote_dir $v $type)"
6785
}
6886

6987
nfs_server_udp_enabled()
@@ -78,8 +96,8 @@ nfs_server_udp_enabled()
7896

7997
nfs_setup_server()
8098
{
81-
82-
local fsid="$1"
99+
local remote_dir="$1"
100+
local fsid="$2"
83101
local export_cmd="exportfs -i -o fsid=$fsid,no_root_squash,rw *:$remote_dir"
84102

85103
[ -z "$fsid" ] && tst_brk TBROK "empty fsid"
@@ -97,10 +115,14 @@ nfs_setup_server()
97115

98116
nfs_mount()
99117
{
100-
local opts="$1"
118+
local local_dir="$1"
119+
local remote_dir="$2"
120+
local opts="$3"
101121
local host_type=rhost
102122
local mount_dir
103123

124+
mkdir -p "$local_dir"
125+
104126
tst_net_use_netns && host_type=
105127

106128
if [ $TST_IPV6 ]; then
@@ -131,6 +153,8 @@ nfs_mount()
131153

132154
tst_brk TBROK "mount command failed"
133155
fi
156+
157+
cd "$local_dir"
134158
}
135159

136160
nfs_setup()
@@ -162,20 +186,12 @@ nfs_setup()
162186
tst_brk TCONF "UDP support disabled on NFS server"
163187
fi
164188

165-
local_dir="$TST_TMPDIR/$i/$n"
166-
remote_dir="$TST_TMPDIR/$i/$type"
167-
mkdir -p $local_dir
168-
169-
nfs_setup_server $(($$ + n))
170-
171-
nfs_mount "-o proto=$type,vers=$i"
189+
remote_dir="$(get_remote_dir $i $type)"
190+
nfs_setup_server "$remote_dir" "$(($$ + n))"
191+
nfs_mount "$(get_local_dir $i $n)" "$remote_dir" "-o proto=$type,vers=$i"
172192

173193
n=$(( n + 1 ))
174194
done
175-
176-
if [ "$n" -eq 1 ]; then
177-
cd ${VERSION}/0
178-
fi
179195
}
180196

181197
nfs_cleanup()
@@ -190,15 +206,15 @@ nfs_cleanup()
190206

191207
local n=0
192208
for i in $VERSION; do
193-
local_dir="$TST_TMPDIR/$i/$n"
209+
local_dir="$(get_local_dir $i $n)"
194210
grep -q "$local_dir" /proc/mounts && umount $local_dir
195211
n=$(( n + 1 ))
196212
done
197213

198214
n=0
199215
for i in $VERSION; do
200216
type=$(get_socket_type $n)
201-
remote_dir="$TST_TMPDIR/$i/$type"
217+
remote_dir="$(get_remote_dir $i $type)"
202218
tst_rhost_run -c "test -d $remote_dir && exportfs -u *:$remote_dir"
203219
tst_rhost_run -c "test -d $remote_dir && rm -rf $remote_dir"
204220
n=$(( n + 1 ))

0 commit comments

Comments
 (0)