1 #! /usr/bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 #
29 # Client recovery with a file with a long path name
30 #
31
32 . ${STF_SUITE}/include/nfsgen.kshlib
33
34 NAME=$(basename $0)
35
36 # Turn on debugging if DEBUG variable is set.
37 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
38
39 DIR=$(dirname $0)
40 PATH=/usr/bin:.:$PATH
41
42 export RECOVERY_EXECUTE_PATH=$DIR
43 export RECOVERY_STAT_PATH=$STF_SUITE/bin/
44 prog=$STF_SUITE/bin/file_operator
45 if [[ ! -x $prog ]]; then
46 echo "$NAME: test program '$prog' not found or not exexutable"
47 echo "\t Test UNINITIATED"
48 return $STF_UNINITIATED
49 fi
50
51 function internalCleanup
52 {
53 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
54 rc=$1
55 Nmnt=$2
56 rm -fr $Nmnt/d
57 umount -f $Nmnt
58 (( $rc == 0 )) && rm -f $STF_TMPDIR/${NAME}*.$$
59 rmdir $Nmnt
60 exit $rc
61 }
62
63 # First check this test is not started before previous tests
64 # grace period ends.
65 echo "xxx" > $MNTDIR/wait_for_grace
66 if (( $? != 0 )); then
67 echo "cannot create file: $MNTDIR/wait_for_grace"
68 touch $MNTDIR/wait_for_grace
69 ls $MNTDIR
70 exit $STF_FAIL
71 fi
72 rm -rf $MNTDIR/wait_for_grace > /dev/null 2>&1
73
74 # Start test
75 # --------------------------------------------------------------------
76 function assertion_func
77 {
78 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
79
80 typeset longfile=$1
81 typeset Nmnt=$2
82 typeset actionType=$3
83
84 $prog -W -c -u -o 4 -s 800 -L "1 1 0 0" -B "32768 1024 1024" $longfile \
85 > $STF_TMPDIR/$NAME.lck.$$ 2>&1 &
86 pid1=$!
87 wait_now 200 "grep \"got exclusive lock\" $STF_TMPDIR/$NAME.lck.$$" \
88 > /dev/null 2>&1
89 if (( $? != 0 )); then
90 echo "\t Test FAIL: failed to make 1st write lock within 200 seconds"
91 cat $STF_TMPDIR/$NAME.lck.$$
92 kill $pid1 > /dev/null 2>&1
93 internalCleanup $STF_FAIL $Nmnt
94 fi
95
96 # now signal server to reboot
97 $DIR/isserverup $actionType > $STF_TMPDIR/$NAME.reboot.$$ 2>&1
98 if (( $? != 0 )); then
99 echo "\t Test UNRESOLVED: failed to $actionType on $SERVER"
100 cat $STF_TMPDIR/$NAME.reboot.$$
101 kill $pid1 > /dev/null 2>&1
102 internalCleanup $STF_UNRESOLVED $Nmnt
103 fi
104
105 sleep 5
106 # verify the lock still valid in the file
107 $prog -W -c -o 4 -L "1 0 0 0" -B "0 0 -1" $longfile > $STF_TMPDIR/$NAME.lck2.$$ 2>&1
108 wait_now 200 "grep \"unavailable\" $STF_TMPDIR/$NAME.lck2.$$" > /dev/null 2>&1
109 if (( $? != 0 )); then
110 echo "\t Test FAIL: second lock did not fail"
111 cat $STF_TMPDIR/$NAME.lck2.$$
112 kill $pid1 > /dev/null 2>&1
113 internalCleanup $STF_FAIL $Nmnt
114 fi
115
116 kill $pid1 > /dev/null 2>&1
117 rm $longfile
118
119 echo "\tTest PASS"
120 return $STF_PASS
121 }
122
123
124 # Start main program here:
125 # ----------------------------------------------------------------------
126 # Get the system maxpathlen and build the path
127 MLEN=$(grep -w MAXPATHLEN /usr/include/sys/param.h | \
128 grep '^\#define' | awk '{print $3}')
129 NCH=$(echo "$ZONE_PATH/a" | wc -c) # the mntptr '$ZONE_PATH/a' and NULL
130 (( NCH = NCH + 2 )) # the file '/f'
131 Nlen=$(($MLEN - $NCH))
132 (( $Nlen % 2 == 0 )) && Nmnt="$ZONE_PATH/a" || Nmnt="$ZONE_PATH/az"
133 Mdir="$Nmnt"
134 i=1
135 while (( $i < $Nlen )); do
136 Mdir="$Mdir/d"
137 i=$(($i + 2))
138 done
139
140 # Now mount the test directory to '/a"
141 [ ! -d $Nmnt ] && mkdir -m 0777 -p $Nmnt
142 umount $Nmnt > /dev/null 2>&1
143 mount -F nfs -o ${MNTOPT} ${SERVER}:${SHRDIR} $Nmnt \
144 > $STF_TMPDIR/$NAME.mnt.$$ 2>&1
145 if (( $? != 0 )); then
146 echo "$NAME: test setup"
147 echo "\t Test UNINITIATED: failed to mount [${SERVER}:${SHRDIR}]"
148 cat $STF_TMPDIR/${NAME}.mnt.$$
149 internalCleanup $STF_UNINITIATED $Nmnt
150 fi
151
152 mkdir -p $Mdir
153 Lfile="$Mdir/f"
154
155 #----------------------------------
156 As_a="Client locks a maxpathlen file, then server reboot;\n\t"
157 As_a="$As verify the lock still valid, expect OK"
158 As_b="Client locks a maxpathlen file, then server restart-nfsd;\n\t"
159 As_b="$Bs verify the lock still valid, expect OK"
160
161 echo "$NAME{a}: $As_a"
162 assertion_func $Lfile $Nmnt "reboot"
163 retcode=$?
164
165 echo "$NAME{a}: $As_b"
166 assertion_func $Lfile $Nmnt "reset-nfsd"
167 retcode=$(($retcode+$?))
168
169 (( $retcode == $STF_PASS )) && internalCleanup $STF_PASS $Nmnt || internalCleanup $STF_FAIL $Nmnt