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 # NFSv4 client recovery:
30 # a: Verify multiple clients lock on multiple files and server reboots,
31 # expect OK
32 # b: Verify multiple clients lock on multiple files after nfsd dies and
33 # restarts, expect OK
34 #
35
36 . ${STF_SUITE}/include/nfsgen.kshlib
37
38 NAME=$(basename $0)
39
40 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
41
42 DIR=$(dirname $0)
43 PATH=/usr/bin:$PATH
44
45 prog=$STF_SUITE/bin/file_operator
46
47 TESTFILE="openfile.$$"
48 TESTFILE2="openfile2.$$"
49 TESTFILE3="openfile3.$$"
50
51 # proc to check result and print out failure messages
52 if [[ ! -x $prog ]]; then
53 echo "$NAME: the executible program '$prog' not found."
54 echo "\t Test FAIL"
55 return $STF_FAIL
56 fi
57
58
59 # First check this test is not started before previous tests
60 # grace period ends.
61 echo "xxx" > $MNTDIR/wait_for_grace
62 rm -rf $MNTDIR/wait_for_grace > /dev/null 2>&1
63
64 # Start test
65 # --------------------------------------------------------------------
66 function assertion_func
67 {
68 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
69
70 typeset actionType=$1
71 typeset -i timer=REBOOTIMER/60
72 typeset -i tmpcode=0
73
74 # the localhost locks offset 0 and length 20 bytes:
75 $prog -W -c -u -o 4 -s $(expr $REBOOTIMER + 300) -L "1 0 0 20" -B "0 0 0" \
76 $MNTDIR/$TESTFILE > $STF_TMPDIR/$NAME.out.$$ 2>&1 &
77 pid1=$!
78
79 # Now 2nd client instance locks a different file with offset 0 \
80 # and length 20 bytes:
81 $prog -W -c -u -o 4 -s $(expr $REBOOTIMER + 300) -L "1 0 0 20" -B "0 0 0" \
82 $MNTDIR/$TESTFILE2 > $STF_TMPDIR/$NAME.out2.$$ 2>&1 &
83 pid2=$!
84
85 # Now a third client instance locks offset 0 and length 20 bytes on \
86 # a different file:
87 $prog -W -c -u -o 4 -s $(expr $REBOOTIMER + 300) -L "1 0 0 20" -B "0 0 0" \
88 $MNTDIR/$TESTFILE3 > $STF_TMPDIR/$NAME.out3.$$ 2>&1 &
89 pid3=$!
90
91 # check process[1|2|3] already locked the files
92 wait_now 200 "grep \"got exclusive lock\" $STF_TMPDIR/$NAME.out.$$" > /dev/null 2>&1
93 tmpcode=$?
94 wait_now 200 "grep \"got exclusive lock\" $STF_TMPDIR/$NAME.out2.$$" > /dev/null 2>&1
95 tmpcode=$(($tmpcode+$?))
96 wait_now 200 "grep \"got exclusive lock\" $STF_TMPDIR/$NAME.out3.$$" > /dev/null 2>&1
97 tmpcode=$(($tmpcode+$?))
98 if (( $tmpcode != 0 )); then
99 echo "$NAME: process[1|2|3] did not have 0-(20-1) bytes locked?"
100 cat $STF_TMPDIR/$NAME.out.$$
101 cat $STF_TMPDIR/$NAME.out2.$$
102 cat $STF_TMPDIR/$NAME.out3.$$
103 kill $pid1 > /dev/null 2>&1
104 kill $pid2 > /dev/null 2>&1
105 kill $pid3 > /dev/null 2>&1
106 rm -f $MNTDIR/$TESTFILE* $STF_TMPDIR/$NAME.*
107 echo "\t Test FAIL"
108 return $STF_FAIL
109 fi
110
111 ${DIR}/isserverup $actionType > $STF_TMPDIR/$NAME.srv.$$ 2>&1
112 if (( $? != 0 )); then
113 echo "$NAME: $actionType on $SERVER failed within $timer minutes"
114 echo "\t Test FAIL"
115 cat $STF_TMPDIR/$NAME.out.$$
116 return $STF_FAIL
117 fi
118
119 # Check that first process still has the lock after server reboot
120 $prog -W -c -u -o 4 -s 30 -L "1 0 0 20" -B "0 0 -1" $MNTDIR/$TESTFILE \
121 > $STF_TMPDIR/$NAME.out.2.$$ 2>&1
122
123 # Check that 2nd client instance still has the lock after server reboot
124 $prog -W -c -u -o 4 -s 30 -L "1 0 0 20" -B "0 0 -1" $MNTDIR/$TESTFILE2 \
125 > $STF_TMPDIR/$NAME.out2.2.$$ 2>&1
126
127 #Check that 3rd client instance still has the lock after server reboot
128 $prog -W -c -u -o 4 -s 30 -L "1 0 0 20" -B "0 0 -1" $MNTDIR/$TESTFILE3 \
129 > $STF_TMPDIR/$NAME.out3.2.$$ 2>&1
130
131 # kill the lock processes
132 kill $pid1 > /dev/null 2>&1
133 kill $pid2 > /dev/null 2>&1
134 kill $pid3 > /dev/null 2>&1
135
136 grep "unavailable" $STF_TMPDIR/$NAME.out.2.$$ > /dev/null 2>&1
137 if (( $? != 0 )); then
138 echo "$NAME: 1rst client instance did not have \
139 0-(20-1) bytes locked?"
140 cat $STF_TMPDIR/$NAME.out.$$
141 rm -f $STF_TMPDIR/$NAME* $MNTDIR/$TESTFILE*
142 echo "\t Test FAIL"
143 return $STF_FAIL
144 fi
145
146 grep "unavailable" $STF_TMPDIR/$NAME.out2.2.$$ > /dev/null 2>&1
147 if (( $? != 0 )); then
148 echo "$NAME: 2nd client instance did not have \
149 0-(20-1) bytes locked?"
150 cat $STF_TMPDIR/$NAME.out2.2.$$
151 rm -f $STF_TMPDIR/$NAME* $MNTDIR/$TESTFILE*
152 echo "\t Test FAIL"
153 return $STF_FAIL
154 fi
155
156 grep "unavailable" $STF_TMPDIR/$NAME.out3.2.$$ > /dev/null 2>&1
157 if (( $? != 0 )); then
158 echo "$NAME: 3rd client instance did not have 0-(20-1) bytes locked?"
159 cat $STF_TMPDIR/$NAME.out3.$$
160 rm -f $STF_TMPDIR/$NAME* $MNTDIR/$TESTFILE*
161 echo "\t Test FAIL"
162 return $STF_FAIL
163 fi
164
165 # cleanup test file
166 rm -f $MNTDIR/$TESTFILE* > /dev/null 2>&1
167
168 # cleanup tmp files
169 rm -f $STF_TMPDIR/$NAME.* > /dev/null 2>&1
170
171 echo "\tTest PASS"
172 return $STF_PASS
173 }
174
175
176 # Start main program here:
177 # ----------------------------------------------------------------------
178 ASSERTION_a="Verify client recovery from multiple client instances \
179 lock on multiple files and server reboots, expect sucess"
180 ASSERTION_b="Verify client recovery multiple client instances lock \
181 on multiple files after nfsd dies and resets, expect sucess"
182
183 echo "$NAME{a}: $ASSERTION_a"
184 assertion_func "reboot"
185 retcode=$?
186
187 echo "$NAME{b}: $ASSERTION_b"
188 assertion_func "reset-nfsd"
189 retcode=$(($retcode+$?))
190
191 (( $retcode == $STF_PASS )) && cleanup $STF_PASS || cleanup $STF_FAIL