From 473f115cbf18dd5229636c817d49b2c60471e227 Mon Sep 17 00:00:00 2001 From: Emmanuel Dreyfus Date: Tue, 19 Aug 2014 17:55:46 +0200 Subject: Regression test portability: mount Address various portability-related problems related to mount - In order to address the non-portability of NFS mount options, use the mount_nfs shell function everywhere, and use it to translate options. - Make sure NFS mounts are unmounted before shutting down the daemons in order to avoid deadlock. The change is done in every test that did not unmounted NFS mounts at the end of the script, and in global cleanup function as well. The force_umount shell function from volume.rc was duplicated as umount_nfs in nfs.rc so that we do not have to add an include on volume.rc for all NFS tests that do not need it. - The FUSE mount type on NetBSD is puffs|perfuse|fuse.glusterfs instead of just fuse.glusterfs, make the regexp configurable in include.rc - Finding wether the mount is RO or RW in mount output needs a system-dependent command configurable in include.rc - mount options in /proc/mounts may be limited to "rw", adjust the regexp for this case where there is no comma And while there change rm into rm -f in tests/basic/mount.t for removal opearation that should fail, since rm may ask for confirmation Change-Id: I1fb708486ec350b2885e2404879561c1020fa8fd BUG: 1129939 Signed-off-by: Emmanuel Dreyfus Reviewed-on: http://review.gluster.org/8494 Tested-by: Gluster Build System Reviewed-by: Harshavardhana Tested-by: Harshavardhana --- tests/basic/ec/nfs.t | 3 +++ tests/basic/mount.t | 16 +++++++++------- tests/basic/nufa.t | 6 +++++- tests/basic/quota.t | 3 ++- tests/basic/uss.t | 3 +++ tests/basic/volume-status.t | 7 ++++++- tests/bugs/bug-1043886.t | 3 +++ tests/bugs/bug-1070734.t | 3 +++ tests/bugs/bug-867253.t | 2 +- tests/bugs/bug-887145.t | 2 ++ tests/bugs/bug-927616.t | 2 ++ tests/include.rc | 24 ++++++++++++++++------- tests/nfs.rc | 46 ++++++++++++++++++++++++++++++++++++++++++++- 13 files changed, 101 insertions(+), 19 deletions(-) diff --git a/tests/basic/ec/nfs.t b/tests/basic/ec/nfs.t index 53ec30c92b..b2e51c03af 100644 --- a/tests/basic/ec/nfs.t +++ b/tests/basic/ec/nfs.t @@ -15,4 +15,7 @@ TEST mount_nfs $H0:/$V0 $N0 TEST dd if=/dev/zero of=$N0/test bs=1024k count=1k +## Before killing daemon to avoid deadlocks +EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" umount_nfs $N0 + cleanup diff --git a/tests/basic/mount.t b/tests/basic/mount.t index c77317f37f..d67bc8ab99 100755 --- a/tests/basic/mount.t +++ b/tests/basic/mount.t @@ -39,21 +39,21 @@ TEST $CLI volume set $V0 performance.stat-prefetch off; TEST glusterfs --entry-timeout=0 --attribute-timeout=0 -s $H0 --volfile-id $V0 $M0; ## Check consistent "rw" option -TEST 'mount -t fuse.glusterfs | grep -E "^$H0:$V0 .+ \(rw,"'; -TEST 'grep -E "^$H0:$V0 .+ ,?rw," /proc/mounts'; +TEST 'mount -t $MOUNT_TYPE_FUSE | grep -E "^$H0:$V0 "|$GREP_MOUNT_OPT_RW'; +TEST 'grep -E "^$H0:$V0 .+ ,?rw,?" /proc/mounts'; ## Mount FUSE with caching disabled (read-only) TEST glusterfs --entry-timeout=0 --attribute-timeout=0 --read-only -s $H0 --volfile-id $V0 $M1; ## Check consistent "ro" option -TEST 'mount -t fuse.glusterfs | grep -E "^$H0:$V0 .+ \(ro,"'; -TEST 'grep -E "^$H0:$V0 .+ ,?ro,.+" /proc/mounts'; +TEST 'mount -t $MOUNT_TYPE_FUSE | grep -E "^$H0:$V0 "|$GREP_MOUNT_OPT_RO'; +TEST 'grep -E "^$H0:$V0 .+ ,?ro(,.+)?" /proc/mounts'; ## Wait for volume to register with rpc.mountd EXPECT_WITHIN $NFS_EXPORT_TIMEOUT "1" is_nfs_export_available; ## Mount NFS -TEST mount -t nfs -o nolock,soft,intr $H0:/$V0 $N0; +TEST mount_nfs $H0:/$V0 $N0 nolock; ## Test for consistent views between NFS and FUSE mounts @@ -63,11 +63,13 @@ TEST ! touch $M1/newfile; TEST touch $M0/newfile; TEST stat $M1/newfile; TEST stat $N0/newfile; -TEST ! rm $M1/newfile; -TEST rm $N0/newfile; +TEST ! rm -f $M1/newfile; +TEST rm -f $N0/newfile; TEST ! stat $M0/newfile; TEST ! stat $M1/newfile; +## Before killing daemon to avoid deadlocks +EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" umount_nfs $N0 ## Finish up TEST $CLI volume stop $V0; diff --git a/tests/basic/nufa.t b/tests/basic/nufa.t index 0d4c229a0f..4235539c65 100644 --- a/tests/basic/nufa.t +++ b/tests/basic/nufa.t @@ -2,6 +2,7 @@ . $(dirname $0)/../include.rc . $(dirname $0)/../volume.rc +. $(dirname $0)/../nfs.rc cleanup; @@ -27,6 +28,9 @@ TEST glusterfs --entry-timeout=0 --attribute-timeout=0 --read-only -s $H0 --volf sleep 5; ## Mount NFS -TEST mount -t nfs -o nolock,soft,intr $H0:/$V0 $N0; +TEST mount_nfs $H0:/$V0 $N0 nolock; + +## Before killing daemon to avoid deadlocks +EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" umount_nfs $N0 cleanup; diff --git a/tests/basic/quota.t b/tests/basic/quota.t index 2fef251e48..1d23cfc868 100755 --- a/tests/basic/quota.t +++ b/tests/basic/quota.t @@ -2,6 +2,7 @@ . $(dirname $0)/../include.rc . $(dirname $0)/../volume.rc +. $(dirname $0)/../nfs.rc . $(dirname $0)/../dht.rc cleanup; @@ -97,7 +98,7 @@ EXPECT_WITHIN $MARKER_UPDATE_TIMEOUT "0Bytes" usage "/test_dir" # though this may change. ## ----------------------------- -TEST mount -t nfs -o nolock,soft,intr $H0:/$V0 $N0; +TEST mount_nfs $H0:/$V0 $N0 nolock; TEST $CLI volume quota $V0 limit-usage /test_dir 100MB TEST $CLI volume quota $V0 limit-usage /test_dir/in_test_dir 150MB diff --git a/tests/basic/uss.t b/tests/basic/uss.t index 8c6a8982ee..ad7fcaf270 100644 --- a/tests/basic/uss.t +++ b/tests/basic/uss.t @@ -243,4 +243,7 @@ TEST fd_close $fd1; TEST fd_close $fd2; TEST fd_close $fd3; +## Before killing daemon to avoid deadlocks +EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" umount_nfs $N0 + cleanup; diff --git a/tests/basic/volume-status.t b/tests/basic/volume-status.t index a91db3cc50..9b636cfa93 100644 --- a/tests/basic/volume-status.t +++ b/tests/basic/volume-status.t @@ -2,6 +2,7 @@ . $(dirname $0)/../include.rc . $(dirname $0)/../volume.rc +. $(dirname $0)/../nfs.rc cleanup; @@ -19,7 +20,7 @@ sleep 2 TEST glusterfs -s $H0 --volfile-id $V0 $M0; ## Mount NFS -TEST mount -t nfs -o vers=3,nolock,soft,intr $H0:/$V0 $N0; +TEST mount_nfs $H0:/$V0 $N0 nolock; TEST $CLI volume status all TEST $CLI volume status $V0 @@ -62,5 +63,9 @@ TEST test_shd_cmds; TEST test_nfs_cmds; TEST test_brick_cmds; + +## Before killing daemon to avoid deadlocks +EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" umount_nfs $N0 + cleanup; diff --git a/tests/bugs/bug-1043886.t b/tests/bugs/bug-1043886.t index 9a125c2de2..710fcd2064 100755 --- a/tests/bugs/bug-1043886.t +++ b/tests/bugs/bug-1043886.t @@ -46,6 +46,9 @@ TEST [ "$(stat -c %u:%g $N0/other/file)" = "$uid:$gid" ]; TEST mkdir $M0/other/dir 2>/dev/null; TEST [ "$(stat -c %u:%g $N0/other/dir)" = "$uid:$gid" ]; +## Before killing daemon to avoid deadlocks +EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" umount_nfs $N0 + TEST $CLI volume stop $V0; TEST $CLI volume delete $V0; diff --git a/tests/bugs/bug-1070734.t b/tests/bugs/bug-1070734.t index fd7bbe01cf..3928983c34 100755 --- a/tests/bugs/bug-1070734.t +++ b/tests/bugs/bug-1070734.t @@ -68,4 +68,7 @@ TEST [ -f ${OTHERBRICK}/DIR/file ] EXPECT "0x00000001000000000000000000000000" dht_get_layout $HASHED/DIR ; EXPECT "0x000000010000000000000000ffffffff" dht_get_layout $OTHERBRICK/DIR; +## Before killing daemon to avoid deadlocks +EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" umount_nfs $N0 + cleanup diff --git a/tests/bugs/bug-867253.t b/tests/bugs/bug-867253.t index 6b0332959e..47c194b4b5 100644 --- a/tests/bugs/bug-867253.t +++ b/tests/bugs/bug-867253.t @@ -30,7 +30,7 @@ TEST $CLI volume start $V0 EXPECT_WITHIN $NFS_EXPORT_TIMEOUT "1" is_nfs_export_available; ## Mount nfs, with nocache option -TEST mount -o vers=3,nolock,noac -t nfs $H0:/$V0 $M0; +TEST mount_nfs $H0:/$V0 $M0 nolock,noac; touch $M0/files{1..1000}; diff --git a/tests/bugs/bug-887145.t b/tests/bugs/bug-887145.t index ee19036e0c..554e6ce95d 100755 --- a/tests/bugs/bug-887145.t +++ b/tests/bugs/bug-887145.t @@ -80,6 +80,8 @@ TEST [ $? -ne 0 ] userdel tmp_user; rm -rf /home/tmp_user; +EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" umount_nfs $N0 + TEST $CLI volume stop $V0; TEST $CLI volume delete $V0; diff --git a/tests/bugs/bug-927616.t b/tests/bugs/bug-927616.t index 58f961dc80..4525ddbb74 100755 --- a/tests/bugs/bug-927616.t +++ b/tests/bugs/bug-927616.t @@ -54,6 +54,8 @@ TEST [ $? -eq 0 ] mkdir $N0/old 2>/dev/null; TEST [ $? -eq 0 ] +EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" umount_nfs $N0 + TEST $CLI volume stop $V0; TEST $CLI volume delete $V0; diff --git a/tests/include.rc b/tests/include.rc index 78488b3797..e6648a7ad7 100644 --- a/tests/include.rc +++ b/tests/include.rc @@ -20,12 +20,21 @@ if [ ! -f ${PWD}/tests/env.rc ]; then fi . ${PWD}/tests/env.rc +H0=${H0:=`hostname`}; # hostname +MOUNT_TYPE_FUSE="fuse.glusterfs" +GREP_MOUNT_OPT_RO="grep (ro" +GREP_MOUNT_OPT_RW="grep (rw" + case $OSTYPE in Linux) H0=${H0:=`hostname --fqdn`}; # hostname ;; +NetBSD) + MOUNT_TYPE_FUSE="puffs|perfuse|fuse.glusterfs" + GREP_MOUNT_OPT_RO="grep (read-only" + GREP_MOUNT_OPT_RW="grep -v (read-only" + ;; *) - H0=${H0:=`hostname`}; # hostname ;; esac @@ -297,6 +306,13 @@ stat -c %s /dev/null > /dev/null 2>&1 || { function cleanup() { + # unmount filesystems before killing daemons to avoid deadllocks + MOUNTPOINTS=`mount | grep "$B0/" | awk '{print $3}'` + for m in $MOUNTPOINTS; + do + umount $m + done + killall -15 glusterfs glusterfsd glusterd 2>/dev/null || true; test "x`uname -s` = "xNetBSD" && pkill -15 perfused || true # allow completion of signal handlers for SIGTERM before issue SIGKILL @@ -304,12 +320,6 @@ function cleanup() killall -9 glusterfs glusterfsd glusterd 2>/dev/null || true; test "x`uname -s` = "xNetBSD" && pkill -9 perfused || true - MOUNTPOINTS=`mount | grep "$B0/" | awk '{print $3}'` - for m in $MOUNTPOINTS; - do - umount $m - done - # unregister nfs and related services from portmapper/rpcbind ## nfs rpcinfo -d 100003 3 diff --git a/tests/nfs.rc b/tests/nfs.rc index c27452395e..a2d7c14001 100644 --- a/tests/nfs.rc +++ b/tests/nfs.rc @@ -23,5 +23,49 @@ function mount_nfs () local m=$2 local opt=$3 if [ ! -z "$opt" ]; then opt=",$opt"; fi - mount -t nfs -o soft,intr,vers=3"$opt" $e $m + opt="soft,intr,vers=3$opt" + + nopt="" + for o in ${opt//,/ }; do + case $OSTYPE in + NetBSD) + test "x${nopt}" = "x" && nopt="tcp," + + case $o in + nolock|noac|actimeo=*|mountproto=udp) + continue + ;; + proto=tcp) + o="tcp" + ;; + vers=3) + o="nfsv3" + ;; + retry=*) + o=${o/retry=/-R} + ;; + timeo=*) + o=${o/timeo=/-t} + ;; + retrans=*) + o=${o/retrans=/-x} + ;; + *) + ;; + esac + ;; + *) + ;; + esac + if [ ! -z "$nopt" ]; then nopt="${nopt},"; fi + nopt="${nopt}$o" + done + + mount -t nfs -o $nopt $e $m } + +function umount_nfs { + umount -f $1 + if [ $? -eq 0 ]; then echo "Y"; else echo "N"; fi +} + -- cgit