Whamcloud - gitweb
merge b_devel into HEAD, which will become 0.7.3
[fs/lustre-release.git] / lustre / tests / sanityN.sh
1 #!/bin/bash
2
3 set -e
4
5 ONLY=${ONLY:-"$*"}
6 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-"8"} # bug 1557
7
8 SRCDIR=`dirname $0`
9 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
10
11 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
12 CREATETEST=${CREATETEST:-createtest}
13 LFIND=${LFIND:-lfind}
14 LSTRIPE=${LSTRIPE:-lstripe}
15 LCTL=${LCTL:-lctl}
16 MCREATE=${MCREATE:-mcreate}
17 OPENFILE=${OPENFILE:-openfile}
18 OPENUNLINK=${OPENUNLINK:-openunlink}
19 TOEXCL=${TOEXCL:-toexcl}
20 TRUNCATE=${TRUNCATE:-truncate}
21
22 if [ $UID -ne 0 ]; then
23         RUNAS_ID="$UID"
24         RUNAS=""
25 else
26         RUNAS_ID=${RUNAS_ID:-500}
27         RUNAS=${RUNAS:-"runas -u $RUNAS_ID"}
28 fi
29
30 export NAME=${NAME:-mount2}
31
32 SAVE_PWD=$PWD
33
34 clean() {
35         echo -n "cln.."
36         sh llmountcleanup.sh > /dev/null || exit 20
37 }
38 CLEAN=${CLEAN:-clean}
39
40 start() {
41         echo -n "mnt.."
42         sh llrmount.sh > /dev/null || exit 10
43         echo "done"
44 }
45 START=${START:-start}
46
47 log() {
48         echo "$*"
49         lctl mark "$*" || true
50 }
51
52 run_one() {
53         if ! mount | grep -q $DIR1; then
54                 $START
55         fi
56         log "== test $1: $2"
57         test_$1 || error
58         pass
59         cd $SAVE_PWD
60         $CLEAN
61 }
62
63 run_test() {
64         for O in $ONLY; do
65                 if [ "`echo $1 | grep '\<'$O'[a-z]*\>'`" ]; then
66                         echo ""
67                         run_one $1 "$2"
68                         return $?
69                 else
70                         echo -n "."
71                 fi
72         done
73         for X in $EXCEPT $ALWAYS_EXCEPT; do
74                 if [ "`echo $1 | grep '\<'$X'[a-z]*\>'`" ]; then
75                         echo "skipping excluded test $1"
76                         return 0
77                 fi
78         done
79         if [ -z "$ONLY" ]; then
80                 run_one $1 "$2"
81                 return $?
82         fi
83 }
84
85 error () {
86         echo "FAIL: $@"
87         exit 1
88 }
89
90 pass() {
91         echo PASS
92 }
93
94 MOUNT1=`mount| awk '/^'$NAME' .* lustre_lite / { print $3 }'| head -1`
95 MOUNT2=`mount| awk '/^'$NAME' .* lustre_lite / { print $3 }'| tail -1`
96 [ -z "$MOUNT1" ] && error "NAME=$NAME not mounted once"
97 [ "$MOUNT1" = "$MOUNT2" ] && error "NAME=$NAME not mounted twice"
98 [ `mount| awk '/^'$NAME' .* lustre_lite / { print $3 }'| wc -l` -ne 2 ] && \
99         error "NAME=$NAME mounted more than twice"
100
101 DIR1=${DIR1:-$MOUNT1}
102 DIR2=${DIR2:-$MOUNT2}
103 [ -z "`echo $DIR1 | grep $MOUNT1`" ] && echo "$DIR1 not in $MOUNT1" && exit 96
104 [ -z "`echo $DIR2 | grep $MOUNT2`" ] && echo "$DIR2 not in $MOUNT2" && exit 95
105
106 rm -f $DIR1/[df][0-9]* $DIR1/lnk
107
108 test_1a() {
109         touch $DIR1/f1
110         [ -f $DIR2/f1 ] || error
111 }
112 run_test 1a "check create on 2 mtpt's =========================="
113
114 test_1b() {
115         chmod 777 $DIR2/f1
116         $CHECKSTAT -t file -p 0777 $DIR1/f1 || error
117         chmod a-x $DIR2/f1
118 }
119 run_test 1b "check attribute updates on 2 mtpt's ==============="
120
121 test_1c() {
122         $CHECKSTAT -t file -p 0666 $DIR1/f1 || error
123 }
124 run_test 1c "check after remount attribute updates on 2 mtpt's ="
125
126 test_1d() {
127         rm $DIR2/f1
128         $CHECKSTAT -a $DIR1/f1 || error
129 }
130 run_test 1d "unlink on one mountpoint removes file on other ===="
131
132 test_2a() {
133         touch $DIR1/f2a
134         ls -l $DIR2/f2a
135         chmod 777 $DIR2/f2a
136         $CHECKSTAT -t file -p 0777 $DIR1/f2a || error
137 }
138 run_test 2a "check cached attribute updates on 2 mtpt's ========"
139
140 test_2b() {
141         touch $DIR1/f2b
142         ls -l $DIR2/f2b
143         chmod 777 $DIR1/f2b
144         $CHECKSTAT -t file -p 0777 $DIR2/f2b || error
145 }
146 run_test 2b "check cached attribute updates on 2 mtpt's ========"
147
148 test_3() {
149         ( cd $DIR1 ; ln -s this/is/good lnk )
150         [ "this/is/good" = "`perl -e 'print readlink("'$DIR2/lnk'");'`" ] || \
151                 error
152 }
153 run_test 3 "symlink on one mtpt, readlink on another ==========="
154
155 test_4() {
156         ./multifstat $DIR1/f6 $DIR2/f6
157 }
158 run_test 4 "fstat validation on multiple mount points =========="
159
160 test_5() {
161         mcreate $DIR1/f5
162         truncate $DIR2/f5 100
163         rm $DIR1/f5
164 }
165 run_test 5 "create a file on one mount, truncate it on the other"
166
167 test_6() {
168         ./openunlink $DIR1/f6 $DIR2/f6 || error
169 }
170 run_test 6 "remove of open file on other node =================="
171
172 test_7() {
173         ./opendirunlink $DIR1/d7 $DIR2/d7 || error
174 }
175 run_test 7 "remove of open directory on other node ============="
176
177 test_8() {
178         ./opendevunlink $DIR1/dev8 $DIR2/dev8 || error
179 }
180 run_test 8 "remove of open special file on other node =========="
181
182 test_9() {
183         MTPT=1
184         > $DIR2/f9
185         for C in a b c d e f g h i j k l; do
186                 DIR=`eval echo \\$DIR$MTPT`
187                 echo -n $C >> $DIR/f9
188                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
189         done
190         [ "`cat $DIR1/f9`" = "abcdefghijkl" ] || error
191 }
192 run_test 9 "append of file with sub-page size on multiple mounts"
193
194 test_10() {
195         MTPT=1
196         OFFSET=0
197         > $DIR2/f10
198         for C in a b c d e f g h i j k l; do
199                 DIR=`eval echo \\$DIR$MTPT`
200                 echo -n $C | dd of=$DIR/f10 bs=1 seek=$OFFSET count=1
201                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
202                 OFFSET=`expr $OFFSET + 1`
203         done
204         [ "`cat $DIR1/f10`" = "abcdefghijkl" ] || error
205 }
206 run_test 10 "write of file with sub-page size on multiple mounts "
207
208 rm -f $DIR1/f[0-9]* $DIR1/lnk