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 on open and write ops after server re-boots; \
31 # recovery verified by read op, expect OK
32 # b: Verify client recovers on open and write ops after nfsd dies and \
33 # and restarts; recovery verified by read op, expect OK
34 #
35
36 . ${STF_SUITE}/include/nfsgen.kshlib
37
38 NAME=$(basename $0)
39
40 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] \
41 && set -x
42
43 DIR=$(dirname $0)
44 prog=$STF_SUITE/bin/file_operator
45
46 export RECOVERY_EXECUTE_PATH=$DIR
47 export RECOVERY_STAT_PATH=$STF_SUITE/bin/
48
49 TESTFILE="openfile.$$"
50
51 if [[ ! -x $prog ]]; then
52 echo "$NAME: the executible program '$prog' not found."
53 echo "\t Test UNINITIATED"
54 return $STF_UNINITIATED
55 fi
56
57 # First check this test is not started before previous tests
58 # grace period ends.
59 echo "xxx" > $MNTDIR/wait_for_grace
60 if [[ $? -ne 0 ]]
61 then
62 echo "cannot create file: $MNTDIR/wait_for_grace"
63 touch $MNTDIR/wait_for_grace
64 ls $MNTDIR
65 exit $STF_FAIL
66 fi
67 rm -rf $MNTDIR/wait_for_grace > /dev/null 2>&1
68
69 # Start test
70 # --------------------------------------------------------------------
71 function assertion_func
72 {
73 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
74 actionType=$1
75
76 # start a process to open and write data info a file
77 # it also read those data back for check after server reboot or
78 # nfsd restart on server
79 $prog -W -o 4 -e $RANDOM -B "32768 1024 1024" $MNTDIR/$TESTFILE > \
80 $STF_TMPDIR/$NAME.out.$$ 2>&1 &
81 pid=$!
82
83 # wait untill prog wrote all data into the file
84 wait_now 200 "grep \"I am ready\" $STF_TMPDIR/$NAME.out.$$" \
85 > /dev/null 2>&1
86 if (( $? != 0 )); then
87 echo "$NAME: client failed to write 32MB data into $STF_TMPDIR/$NAME.out.$$ \
88 in 200 seconds"
89 cat $STF_TMPDIR/$NAME.out.$$
90 kill $pid
91 rm -f $MNTDIR/$TESTFILE* $STF_TMPDIR/$NAME.*
92 echo "\t Test FAIL"
93 return $STF_FAIL
94 fi
95
96 # reboot server or restart nfsd on server
97 $DIR/isserverup $actionType > $STF_TMPDIR/$NAME.reboot.$$ 2>&1
98 if (( $? != 0 )); then
99 echo "$NAME: failed to reboot $SERVER"
100 cat $STF_TMPDIR/$NAME.reboot.$$
101 kill $pid
102 rm -f $MNTDIR/$TESTFILE* $STF_TMPDIR/$NAME.*
103 echo "\t Test FAIL"
104 return $STF_FAIL
105 fi
106
107 # signal the test program to read data back
108 kill -16 $pid
109
110 wait $pid
111 if (( $? != 0 )); then
112 echo "wait the process with pid=$pid failed"
113 echo "\t Test FAIL"
114 kill $pid
115 rm -f $MNTDIR/$TESTFILE* $STF_TMPDIR/$NAME.*
116 return $STF_FAIL
117 fi
118
119 rm -f $MNTDIR/$TESTFILE* $STF_TMPDIR/$NAME.*
120 echo "\tTest PASS"
121 return $STF_PASS
122 }
123
124 # Start main program here:
125 # ----------------------------------------------------------------------
126 ASSERTION_a="Verify client recovers on open and write after \
127 server reboots; recovery verified by read op, expect sucess"
128 ASSERTION_b="Verify client recovers on open and write ops after nfsd \
129 dies and re-starts; recovery verified by read op, expect sucess"
130
131 echo "$NAME{a}: $ASSERTION"
132 assertion_func "reboot"
133 retcode=$?
134
135 echo "$NAME{b}: $ASSERTION"
136 assertion_func "reset-nfsd"
137 retcode=$(($retcode+$?))
138
139 (( $retcode == $STF_PASS )) && cleanup $STF_PASS || cleanup $STF_FAIL