Whamcloud - gitweb
b=1844
[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 "$*" 2> /dev/null || 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 "test_$1: $?"
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         log "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 -rf $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 # NEED TO SAVE ROOT DIR MODE
149 test_2c() {
150         chmod 777 $DIR1
151         $CHECKSTAT -t dir -p 0777 $DIR2 || error
152 }
153 run_test 2c "check cached attribute updates on 2 mtpt's root ==="
154
155 test_2d() {
156         chmod 755 $DIR1
157         $CHECKSTAT -t dir -p 0755 $DIR2 || error
158 }
159 run_test 2c "check cached attribute updates on 2 mtpt's root ==="
160
161 test_3() {
162         ( cd $DIR1 ; ln -s this/is/good lnk )
163         [ "this/is/good" = "`perl -e 'print readlink("'$DIR2/lnk'");'`" ] || \
164                 error
165 }
166 run_test 3 "symlink on one mtpt, readlink on another ==========="
167
168 test_4() {
169         ./multifstat $DIR1/f4 $DIR2/f4
170 }
171 run_test 4 "fstat validation on multiple mount points =========="
172
173 test_5() {
174         mcreate $DIR1/f5
175         truncate $DIR2/f5 100
176         rm $DIR1/f5
177 }
178 run_test 5 "create a file on one mount, truncate it on the other"
179
180 test_6() {
181         ./openunlink $DIR1/f6 $DIR2/f6 || error
182 }
183 run_test 6 "remove of open file on other node =================="
184
185 test_7() {
186         ./opendirunlink $DIR1/d7 $DIR2/d7 || error
187 }
188 run_test 7 "remove of open directory on other node ============="
189
190 test_8() {
191         ./opendevunlink $DIR1/dev8 $DIR2/dev8 || error
192 }
193 run_test 8 "remove of open special file on other node =========="
194
195 test_9() {
196         MTPT=1
197         > $DIR2/f9
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 >> $DIR/f9
201                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
202         done
203         [ "`cat $DIR1/f9`" = "abcdefghijkl" ] || error
204 }
205 run_test 9 "append of file with sub-page size on multiple mounts"
206
207 test_10() {
208         MTPT=1
209         OFFSET=0
210         > $DIR2/f10
211         for C in a b c d e f g h i j k l; do
212                 DIR=`eval echo \\$DIR$MTPT`
213                 echo -n $C | dd of=$DIR/f10 bs=1 seek=$OFFSET count=1
214                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
215                 OFFSET=`expr $OFFSET + 1`
216         done
217         [ "`cat $DIR1/f10`" = "abcdefghijkl" ] || error
218 }
219 run_test 10 "write of file with sub-page size on multiple mounts "
220
221 test_11() {
222         mkdir $DIR1/d11
223         multiop $DIR1/d11/f O_c &
224         MULTIPID=$!
225         cp -p /bin/ls $DIR1/d11/f
226         $DIR2/d11/f
227         RC=$?
228         kill -USR1 $MULTIPID
229         wait $MULTIPID || error
230         [ $RC -eq 0 ] && error || true
231 }
232 run_test 11 "execution of file opened for write should return error ===="
233
234 test_12() {
235        sh lockorder.sh
236 }
237 run_test 12 "test lock ordering (link, stat, unlink) ==========="
238
239 log "cleanup: ======================================================"
240 rm -rf $DIR1/[df][0-9]* $DIR1/lnk || true
241 echo '=========================== finished ==============================='