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 client recovers it's lock after server re-boots, expect OK
31 # b: Verify client recovers it's lock after nfsd dies and re-starts, expect OK
32 #
33
34 . ${STF_SUITE}/include/nfsgen.kshlib
35
36 NAME=$(basename $0)
37
38 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
39
40 DIR=$(dirname $0)
41
42 . ${STF_SUITE}/include/nfsgen.kshlib
43
44 prog=$STF_SUITE/bin/file_operator
45
46 TESTFILE="openfile.$$"
47
48 if [[ ! -x $prog ]]; then
49 echo "$NAME: the executible program '$prog' not found."
50 echo "\t Test FAIL"
51 return $STF_FAIL
52 fi
53
54 # First check this test is not started before previous tests
55 # grace period ends.
56 echo "xxx" > $MNTDIR/wait_for_grace
57 rm -rf $MNTDIR/wait_for_grace > /dev/null 2>&1
58
59 # Start test
60 # --------------------------------------------------------------------
61 function assertion_func
62 {
63 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
64
65 typeset actionType=$1
66 typeset -i timer=REBOOTIMER/60
67
68 # Invoke open and hold lock
69 $prog -W -c -o 4 -s $(expr $REBOOTIMER + 60) -L "1 0 0 0" -B "0 0 0" $MNTDIR/$TESTFILE > \
70 $STF_TMPDIR/$NAME.out.$$ 2>&1 &
71 pid1=$!
72
73 wait_now 200 "grep \"got exclusive lock\" $STF_TMPDIR/$NAME.out.$$" > /dev/null 2>&1
74 if (( $? != 0 )); then
75 echo "$NAME: client failed to got exclusive lock in 200 seconds"
76 cat $STF_TMPDIR/$NAME.out.$$
77 kill $pid1
78 rm -f $MNTDIR/$TESTFILE* $STF_TMPDIR/$NAME.*
79 echo "\t Test FAIL"
80 return $STF_FAIL
81 fi
82
83 # Now, reboot SERVER or restart nfsd on server
84 ${DIR}/isserverup $actionType > $STF_TMPDIR/$NAME.srv.$$ 2>&1
85 if (( $? != 0 )); then
86 echo "$NAME: reboot SERVER or restart nfsd on SERVER failed in $timer minutes"
87 kill $pid1
88 cat $STF_TMPDIR/$NAME.srv.$$
89 rm -f $MNTDIR/$TESTFILE* $STF_TMPDIR/$NAME.*
90 return $STF_FAIL
91 fi
92
93 # Check lock recovery by 2nd process attempting to acquire the lock
94 $prog -W -c -u -o 4 -s 30 -L "1 0 0 0" -B "0 0 -1" $MNTDIR/$TESTFILE > \
95 $STF_TMPDIR/$NAME.out2.$$ 2>&1
96
97 # Now cleanup process locks
98 kill $pid1 > /dev/null 2>&1
99
100 sleep 10
101
102 grep "unavailable" $STF_TMPDIR/$NAME.out2.$$ > /dev/null 2>&1
103 if (( $? != 0 )); then
104 echo "$NAME: 2nd process was able to get the lock \
105 after $SERVER reboot or nfsd restarted on server."
106 cat $STF_TMPDIR/$NAME.out2.$$
107 rm -f $MNTDIR/$TESTFILE* $STF_TMPDIR/$NAME.*
108 echo "\t Test FAIL"
109 return $STF_FAIL
110 fi
111
112 # cleanup test file
113 rm $MNTDIR/$TESTFILE* 2>&1
114
115 # cleanup tmp files
116 rm $STF_TMPDIR/$NAME.* 2>&1
117
118 echo "\tTest PASS"
119 return $STF_PASS
120 }
121
122
123 # Start main program here:
124 # ----------------------------------------------------------------------
125 ASSERTION_a="Verify client recovers it's lock after server re-boots, expect sucess"
126 ASSERTION_b="Verify client recovers it's lock after nfsd dies, expect sucess"
127
128 echo "$NAME{a}: $ASSERTION"
129 assertion_func "reboot"
130 retcode=$?
131
132 echo "$NAME{b}: $ASSERTION"
133 assertion_func "reset-nfsd"
134 retcode=$(($retcode+$?))
135
136 (( $retcode == $STF_PASS )) && cleanup $STF_PASS || cleanup $STF_FAIL