Home | History | Annotate | Download | only in nfs_stress
      1 # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
      2 # Copyright (c) International Business Machines  Corp., 2001
      3 #
      4 # This program is free software; you can redistribute it and/or
      5 # modify it under the terms of the GNU General Public License as
      6 # published by the Free Software Foundation; either version 2 of
      7 # the License, or (at your option) any later version.
      8 #
      9 # This program is distributed in the hope that it would be useful,
     10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 # GNU General Public License for more details.
     13 #
     14 # You should have received a copy of the GNU General Public License
     15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
     16 
     17 nfs_setup()
     18 {
     19 	VERSION=${VERSION:=3}
     20 	NFILES=${NFILES:=1000}
     21 	SOCKET_TYPE="${SOCKET_TYPE:=udp}${TST_IPV6}"
     22 	NFS_TYPE=${NFS_TYPE:=nfs}
     23 
     24 	tst_check_cmds mount exportfs
     25 
     26 	tst_tmpdir
     27 
     28 	# Check if current filesystem is NFS
     29 	if [ "$(stat -f . | grep "Type: nfs")" ]; then
     30 		tst_brkm TCONF "Cannot run nfs-stress test on mounted NFS"
     31 	fi
     32 
     33 	tst_resm TINFO "NFS_TYPE: $NFS_TYPE, NFS VERSION: $VERSION"
     34 	tst_resm TINFO "NFILES: $NFILES, SOCKET_TYPE: $SOCKET_TYPE"
     35 
     36 	if [ "$NFS_TYPE" != "nfs4" ]; then
     37 		OPTS=${OPTS:="-o proto=$SOCKET_TYPE,vers=$VERSION "}
     38 	fi
     39 
     40 	tst_rhost_run -s -c "mkdir -p $TST_TMPDIR"
     41 
     42 	if [ $TST_IPV6 ]; then
     43 		REMOTE_DIR="[$(tst_ipaddr rhost)]:$TST_TMPDIR"
     44 	else
     45 		REMOTE_DIR="$(tst_ipaddr rhost):$TST_TMPDIR"
     46 	fi
     47 
     48 	if [ "$NFS_TYPE" = "nfs4" ]; then
     49 		tst_rhost_run -s -c "mkdir -p /export$TST_TMPDIR"
     50 		tst_rhost_run -s -c "mount --bind $TST_TMPDIR /export$TST_TMPDIR"
     51 		tst_rhost_run -s -c "exportfs -o no_root_squash,rw,nohide,\
     52 			insecure,no_subtree_check *:$TST_TMPDIR"
     53 	else
     54 		tst_rhost_run -s -c "exportfs -i -o no_root_squash,rw \
     55 			*:$TST_TMPDIR"
     56 	fi
     57 
     58 	tst_resm TINFO "Mounting NFS '$REMOTE_DIR' with options '$OPTS'"
     59 	ROD mount -t $NFS_TYPE $OPTS $REMOTE_DIR $TST_TMPDIR
     60 	cd $TST_TMPDIR
     61 }
     62 
     63 nfs_cleanup()
     64 {
     65 	tst_resm TINFO "Cleaning up testcase"
     66 	cd $LTPROOT
     67 	grep -q "$TST_TMPDIR" /proc/mounts && umount $TST_TMPDIR
     68 
     69 	tst_rhost_run -c "exportfs -u *:$TST_TMPDIR"
     70 	tst_rhost_run -c "rm -rf $TST_TMPDIR"
     71 }
     72