Whamcloud - gitweb
LU-8275 tests: add flag to enable secret shared key for tests
[fs/lustre-release.git] / lustre / tests / setup-nfs.sh
1 #!/bin/bash
2 #set -x
3 EXPORT_OPTS=${EXPORT_OPTS:-"rw,async,no_root_squash"}
4
5 setup_nfs() {
6         local NFS_VER=${1}
7         local MNTPNT=${2}
8         local LUSTRE_CLIENT=${3}
9         local NFS_CLIENTS=${4}
10         local nfs_climntpt=${5:-$MNTPNT}
11
12     local export_opts_v=$EXPORT_OPTS
13
14     echo "Exporting Lustre filesystem..."
15
16     if [ "$NFS_VER" = "4" ]; then
17         export_opts_v="$EXPORT_OPTS,fsid=0"
18         do_nodes $LUSTRE_CLIENT "mkdir -p /var/lib/nfs/v4recovery"
19     fi
20
21     do_nodes $LUSTRE_CLIENT,$NFS_CLIENTS "grep -q rpc_pipefs' ' /proc/mounts ||\
22         { mkdir -p /var/lib/nfs/rpc_pipefs && \
23         mount -t rpc_pipefs sunrpc /var/lib/nfs/rpc_pipefs; }" || return 1
24     sleep 5
25
26         do_nodes $LUSTRE_CLIENT "chkconfig --list nfsserver > /dev/null 2>&1 &&
27                                  service nfsserver restart ||
28                                  service nfs restart" || return 1
29
30         do_nodes $NFS_CLIENTS "chkconfig --list rpcidmapd 2>/dev/null |
31                                grep -q rpcidmapd && service rpcidmapd restart ||
32                                true"
33
34     do_nodes $LUSTRE_CLIENT "exportfs -o $export_opts_v *:$MNTPNT \
35         && exportfs -v" || return 1
36
37     echo -e "\nMounting NFS clients (version $NFS_VER)..."
38
39         do_nodes $NFS_CLIENTS "mkdir -p $nfs_climntpt" || return 1
40         if [ "$NFS_VER" = "4" ]; then
41                 do_nodes $NFS_CLIENTS \
42                         "mount -t nfs$NFS_VER -o async \
43                         $LUSTRE_CLIENT:/ $nfs_climntpt" || return 1
44         else
45                 do_nodes $NFS_CLIENTS \
46                         "mount -t nfs -o nfsvers=$NFS_VER,async \
47                         $LUSTRE_CLIENT:$MNTPNT $nfs_climntpt" || return 1
48         fi
49         return 0
50 }
51
52 cleanup_nfs() {
53         local MNTPNT=${1}
54         local LUSTRE_CLIENT=${2}
55         local NFS_CLIENTS=${3}
56
57         echo -e "\nUnmounting NFS clients..."
58         do_nodes $NFS_CLIENTS "umount -f $MNTPNT" || true
59
60         echo -e "\nUnexporting Lustre filesystem..."
61         do_nodes $NFS_CLIENTS "chkconfig --list rpcidmapd 2>/dev/null |
62                                grep -q rpcidmapd && service rpcidmapd stop ||
63                                true"
64
65         do_nodes $LUSTRE_CLIENT "chkconfig --list nfsserver > /dev/null 2>&1 &&
66                                  service nfsserver stop || service nfs stop" ||
67                                 return 1
68
69     do_nodes $LUSTRE_CLIENT "exportfs -u *:$MNTPNT"
70
71     do_nodes $LUSTRE_CLIENT "exportfs -v"
72 }