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 named attribute files.
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:* ]] \
38 && set -x
39
40 DIR=$(dirname $0)
41 PATH=/usr/bin:.:$PATH
42
43 echo "xxx" > $MNTDIR/wait_for_grace
44 if (( $? != 0 )); then
45 echo "cannot create file: $MNTDIR/wait_for_grace"
46 exit $STF_FAIL
47 fi
48
49 export RECOVERY_EXECUTE_PATH=$DIR
50 export RECOVERY_STAT_PATH=$STF_SUITE/bin/
51 prog=$STF_SUITE/bin/holdopenat
52 if [[ ! -x $prog ]]; then
53 echo "$NAME: test program '$prog' not found or not exexutable"
54 echo "\t Test UNINITIATED"
55 exit $STF_UNINITIATED
56 fi
57
58 # make sure the server is not in the GRACE period due to previous test
59 SRVNDIR=$MNTDIR/$NOTICEDIR
60 echo "ckgrace" > $SRVNDIR/ckgrace 2> $STF_TMPDIR/$NAME.ckgrace.$$
61 if (( $? != 0 )); then
62 echo "$NAME: test setup - ckgrace failed"
63 echo "\t Test UNINITIATED"
64 cat $STF_TMPDIR/$NAME.ckgrace.$$
65 rm -f $STF_TMPDIR/$NAME.ckgrace.$$
66 exit $STF_UNINITIATED
67 fi
68 rm -f $SRVNDIR/* $STF_TMPDIR/$NAME.ckgrace.$$
69
70
71 # Start test
72 # --------------------------------------------------------------------
73 # a: Client open/write to a named_attr file, server reboot, and verfiy
74 # client is able to read back the data and close the file.
75 function assertion_a
76 {
77 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
78 As="Client open/write to a named_attr file, server reboot; \n"
79 As="$As \t verify client is able read back and close the file, expect OK"
80 echo "$NAME{a}: $As"
81
82 # call the program with reboot flag
83 $prog -f $MNTDIR/${NAME}_a.$$ -u $SRVNDIR/DONE_reboot > \
84 $STF_TMPDIR/$NAME.out.$$ 2>&1 &
85 sleep 2
86
87 # signal server to reboot; then wait
88 touch $SRVNDIR/reboot
89 wait
90 grep "GOOD" $STF_TMPDIR/$NAME.out.$$ | grep "successful" > /dev/null 2>&1
91 if (( $? != 0 )); then
92 echo "\t Test FAIL: $prog did not exit with <successful>"
93 cat $STF_TMPDIR/$NAME.out.$$
94 return $STF_FAIL
95 fi
96
97 echo "\tTest PASS"
98 return $STF_PASS
99 }
100
101
102 # --------------------------------------------------------------------
103 # b: Client open/write to a named_attr file, server restart-nfsd, verfiy
104 # client is able to read back the data and close the file.
105 function assertion_b
106 {
107 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
108 Bs="Client open/write to a named_attr file, server restart-nfsd; \n"
109 Bs="$Bs \t verify client is able read back and close the file, expect OK"
110 echo "$NAME{b}: $Bs"
111
112 # make sure the server is not in the GRACE period due
113 # to previous test
114 echo "xxx" > $MNTDIR/wait_for_grace
115 rm -rf $MNTDIR/wait_for_grace > /dev/null 2>&1
116
117 # call the program with reset (nfsd) flag
118 $prog -f $MNTDIR/${NAME}_b.$$ -u $SRVNDIR/DONE_reset > \
119 $STF_TMPDIR/$NAME.out.$$ 2>&1 &
120 sleep 2
121
122 # signal server to restart nfsd; then wait
123 touch $SRVNDIR/reset-nfsd
124 wait
125 grep "GOOD" $STF_TMPDIR/$NAME.out.$$ | grep "successful" > /dev/null 2>&1
126 if (( $? != 0 )); then
127 echo "\t Test FAIL: $prog did not exit with <successful>"
128 cat $STF_TMPDIR/$NAME.out.$$
129 return $STF_FAIL
130 fi
131
132 echo "\tTest PASS"
133 return $STF_PASS
134 }
135
136 # Start main program here:
137 # ----------------------------------------------------------------------
138
139 assertion_a
140 retcode=$?
141
142 assertion_b
143 retcode=$(($retcode+$?))
144
145 (( $retcode == $STF_PASS )) \
146 && cleanup $STF_PASS "" "$STF_TMPDIR/${NAME}*.$$ \
147 $SRVNDIR/ckgrace $SRVNDIR/DONE_*" \
148 || cleanup $STF_FAIL "" "$STF_TMPDIR/${NAME}*.$$ \
149 $SRVNDIR/ckgrace $SRVNDIR/DONE_*"
150