Whamcloud - gitweb
- fixes in sanity tests about using mount command. cat /proc/mounts is used instead
[fs/lustre-release.git] / lustre / tests / sanity-lmv.sh
1 #!/bin/bash
2 #
3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
5 #
6 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
7 set -e
8
9 ONLY=${ONLY:-"$*"}
10 # bug number for skipped test: 2108
11 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-""}
12 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
13 #case `uname -r` in
14 #2.6.*) ALWAYS_EXCEPT="$ALWAYS_EXCEPT 54c 55" # bug 3117
15 #esac
16
17 [ "$ALWAYS_EXCEPT$EXCEPT" ] && echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
18
19 SRCDIR=`dirname $0`
20 export PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
21 export SECURITY=${SECURITY:-"null"}
22
23 TMP=${TMP:-/tmp}
24 FSTYPE=${FSTYPE:-ext3}
25
26 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
27 CREATETEST=${CREATETEST:-createtest}
28 LFS=${LFS:-lfs}
29 LSTRIPE=${LSTRIPE:-"$LFS setstripe"}
30 LFIND=${LFIND:-"$LFS find"}
31 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
32 LCTL=${LCTL:-lctl}
33 MCREATE=${MCREATE:-mcreate}
34 OPENFILE=${OPENFILE:-openfile}
35 OPENUNLINK=${OPENUNLINK:-openunlink}
36 TOEXCL=${TOEXCL:-toexcl}
37 TRUNCATE=${TRUNCATE:-truncate}
38 MUNLINK=${MUNLINK:-munlink}
39 SOCKETSERVER=${SOCKETSERVER:-socketserver}
40 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
41 IOPENTEST1=${IOPENTEST1:-iopentest1}
42 IOPENTEST2=${IOPENTEST2:-iopentest2}
43 PTLDEBUG=${PTLDEBUG:-0}
44
45 . krb5_env.sh
46
47 if [ $UID -ne 0 ]; then
48         RUNAS_ID="$UID"
49         RUNAS=""
50 else
51         RUNAS_ID=${RUNAS_ID:-500}
52         RUNAS=${RUNAS:-"runas -u $RUNAS_ID"}
53 fi
54
55 if [ `using_krb5_sec $SECURITY` == 'y' ] ; then
56     start_krb5_kdc || exit 1
57     if [ $RUNAS_ID -ne $UID ]; then
58         $RUNAS ./krb5_refresh_cache.sh || exit 2
59     fi
60 fi
61
62 export NAME=${NAME:-lmv}
63
64 SAVE_PWD=$PWD
65
66 clean() {
67         echo -n "cln.."
68         sh llmountcleanup.sh > /dev/null || exit 20
69         I_MOUNTED=no
70 }
71 CLEAN=${CLEAN:-clean}
72
73 start() {
74         echo -n "mnt.."
75         sh llrmount.sh > /dev/null || exit 10
76         I_MOUNTED=yes
77         echo "done"
78 }
79 START=${START:-start}
80
81 log() {
82         echo "$*"
83         lctl mark "$*" 2> /dev/null || true
84 }
85
86 trace() {
87         log "STARTING: $*"
88         strace -o $TMP/$1.strace -ttt $*
89         RC=$?
90         log "FINISHED: $*: rc $RC"
91         return 1
92 }
93 TRACE=${TRACE:-""}
94
95 check_kernel_version() {
96         VERSION_FILE=/proc/fs/lustre/kernel_version
97         WANT_VER=$1
98         [ ! -f $VERSION_FILE ] && echo "can't find kernel version" && return 1
99         GOT_VER=`cat $VERSION_FILE`
100         [ $GOT_VER -ge $WANT_VER ] && return 0
101         log "test needs at least kernel version $WANT_VER, running $GOT_VER"
102         return 1
103 }
104
105 run_one() {
106         if ! cat /proc/mounts | grep -q $DIR; then
107                 $START
108         fi
109         echo $PTLDEBUG >/proc/sys/portals/debug 
110         log "== test $1: $2"
111         export TESTNAME=test_$1
112         test_$1 || error "test_$1: exit with rc=$?"
113         unset TESTNAME
114         pass
115         cd $SAVE_PWD
116         $CLEAN
117 }
118
119 build_test_filter() {
120         for O in $ONLY; do
121             eval ONLY_${O}=true
122         done
123         for E in $EXCEPT $ALWAYS_EXCEPT; do
124             eval EXCEPT_${E}=true
125         done
126 }
127
128 _basetest() {
129     echo $*
130 }
131
132 basetest() {
133     IFS=abcdefghijklmnopqrstuvwxyz _basetest $1
134 }
135
136 run_test() {
137          base=`basetest $1`
138          if [ "$ONLY" ]; then
139                  testname=ONLY_$1
140                  if [ ${!testname}x != x ]; then
141                         run_one $1 "$2"
142                         return $?
143                  fi
144                  testname=ONLY_$base
145                  if [ ${!testname}x != x ]; then
146                          run_one $1 "$2"
147                          return $?
148                  fi
149                  echo -n "."
150                  return 0
151         fi
152         testname=EXCEPT_$1
153         if [ ${!testname}x != x ]; then
154                  echo "skipping excluded test $1"
155                  return 0
156         fi
157         testname=EXCEPT_$base
158         if [ ${!testname}x != x ]; then
159                  echo "skipping excluded test $1 (base $base)"
160                  return 0
161         fi
162         run_one $1 "$2"
163         return $?
164 }
165
166 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
167
168 error() { 
169         log "FAIL: $@"
170         if [ "$SANITYLOG" ]; then
171                 echo "FAIL: $TESTNAME $@" >> $SANITYLOG
172         else
173                 exit 1
174         fi
175 }
176
177 pass() { 
178         echo PASS
179 }
180
181 MOUNT="`mount | awk '/^'$NAME' .* lustre_lite / { print $3 }'`"
182 if [ -z "$MOUNT" ]; then
183         sh llmount.sh
184         MOUNT="`mount | awk '/^'$NAME' .* lustre_lite / { print $3 }'`"
185         [ -z "$MOUNT" ] && error "NAME=$NAME not mounted"
186         I_MOUNTED=yes
187 fi
188
189 [ `echo $MOUNT | wc -w` -gt 1 ] && error "NAME=$NAME mounted more than once"
190
191 DIR=${DIR:-$MOUNT}
192 [ -z "`echo $DIR | grep $MOUNT`" ] && echo "$DIR not in $MOUNT" && exit 99
193
194 #LOVNAME=`cat /proc/fs/lustre/llite/fs0/lov/common_name`
195 #OSTCOUNT=`cat /proc/fs/lustre/lov/$LOVNAME/numobd`
196 #STRIPECOUNT=`cat /proc/fs/lustre/lov/$LOVNAME/stripecount`
197 #STRIPESIZE=`cat /proc/fs/lustre/lov/$LOVNAME/stripesize`
198
199 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
200 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
201 rm -rf $DIR/[Rdfs][1-9]*
202
203 build_test_filter
204
205 echo preparing for tests involving mounts
206 EXT2_DEV=${EXT2_DEV:-/tmp/SANITY.LOOP}
207 touch $EXT2_DEV
208 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
209
210 test_1a() {
211         mkdir $DIR/1a0 || error 
212         createmany -o $DIR/1a0/f 4000
213         rmdir $DIR/1a0 && error
214         rm -rf $DIR/1a0 || error
215 }
216 run_test 1a " remove splitted dir ============================="
217
218 test_1b() {
219         mkdir $DIR/1b0 || error
220         createmany -o $DIR/1b0/f 4000
221         find $DIR/1b0 -type f | xargs rm -f
222         NUM=`ls $DIR/1b0 | wc -l`
223         if [ $NUM -ne 0 ] ; then
224                 echo "dir must be empty"
225                 error
226         fi
227         touch $DIR/1b0/file0
228         touch $DIR/1b0/file1
229         touch $DIR/1b0/file2
230
231         echo "3 files left"
232         rmdir $DIR/1b0 && error
233         rm -f $DIR/1b0/file0
234
235         echo "2 files left"
236         rmdir $DIR/1b0 && error
237         rm -f $DIR/1b0/file1
238
239         echo "1 files left"
240         rmdir $DIR/1b0 && error
241         rm -f $DIR/1b0/file2
242
243         echo "0 files left"
244         rmdir $DIR/1b0 || error
245 }
246 run_test 1b " remove splitted dir ============================="
247
248 test_1c() {
249         mkdir $DIR/1b1 || error
250         createmany -o $DIR/1b1/f 4000
251         find $DIR/1b1 -type f | xargs rm -f
252         NUM=`ls $DIR/1b1 | wc -l`
253         if [ $NUM -ne 0 ] ; then
254                 echo "dir must be empty"
255                 error
256         fi
257         touch $DIR/1b1/file0
258         touch $DIR/1b1/file1
259         touch $DIR/1b1/file2
260
261         ls $DIR/1b1/
262         log "3 files left"
263         rmdir $DIR/1b1 && error
264         rm -f $DIR/1b1/file0
265
266         ls $DIR/1b1/
267         log "2 files left"
268         rmdir $DIR/1b1 && error
269         rm -f $DIR/1b1/file1
270
271         ls $DIR/1b1/
272         log "1 files left"
273         rmdir $DIR/1b1 && error
274         rm -f $DIR/1b1/file2
275
276         ls $DIR/1b1/
277         log "0 files left"
278         rmdir $DIR/1b1 || error
279 }
280 run_test 1c " remove splitted cross-node dir ============================="
281
282 test_2a() {
283         mkdir $DIR/2a0 || error 
284         createmany -o $DIR/2a0/f 5000
285         NUM=`ls $DIR/2a0 | wc -l`
286         echo "found $NUM files"
287         if [ $NUM -ne 5000 ]; then
288                 echo "wrong number of files: $NUM"
289                 error
290         fi
291         rm -rf $DIR/2a0 || error
292 }
293 run_test 2a " list splitted dir ============================="
294
295 test_2b() {
296         mkdir $DIR/2b1 || error 
297         createmany -o $DIR/2b1/f 5000
298         $CLEAN
299         $START
300         statmany -l $DIR/2b1/f 5000 5000 || error
301         statmany -s $DIR/2b1/f 5000 5000 || error
302         rm -rf $DIR/2b1 || error
303 }
304 run_test 2b " list splitted dir after remount ============================="
305
306 test_3a() {
307         mkdir $DIR/3a0 || error
308         for i in `seq 100`; do
309                 mkdir $DIR/3a0/d${i} || error
310         done
311         createmany -o $DIR/3a0/f 5000 || error
312         rm -rf $DIR/3a0 || error
313 }
314 run_test 3a " dir splitting with cross-ref ============================="
315
316 test_3b() {
317         mkdir $DIR/3b1 || error
318         createmany -m $DIR/3b1/f 5000 || error
319         rm -rf $DIR/3b1 || error
320 }
321 run_test 3b " dir splitting via createmany -m ============================="
322
323 test_3c() {
324         mkdir $DIR/3c1 || error
325         echo "MDS nodes: $MDSCOUNT"
326         for j in `seq 3`; do
327                 for i in `seq 10`; do
328                         $LFS dirstripe $DIR/3c1/d-${j}-${i} $j || error
329                         createmany -m $DIR/3c1/d-${j}-${i}/m 200 || error
330                         createmany -o $DIR/3c1/d-${j}-${i}/o 200 || error
331                 done
332         done
333         rm -rf $DIR/3c1 || error
334 }
335
336 run_test 3c " dir splitting via lfs stripe ============================="
337
338 test_4a() {
339         let rr=0
340         while let "rr < 33000"; do
341                 if let "rr % 2000 == 0"; then
342                         echo "$rr"
343                 fi
344                 mkdir $DIR/4a1 || error
345                 rm -rf $DIR/4a1
346                 let "rr = rr + 1"
347         done
348 }
349
350 ## this test is very time-consuming, don't run it by default
351 #run_test 4a " FIDS/ nlink overflow test  ============================="
352
353
354 TMPDIR=$OLDTMPDIR
355 TMP=$OLDTMP
356 HOME=$OLDHOME
357
358 log "cleanup: ======================================================"
359 if [ "`mount | grep ^$NAME`" ]; then
360         rm -rf $DIR/[Rdfs][1-9]*
361         if [ "$I_MOUNTED" = "yes" ]; then
362                 sh llmountcleanup.sh || error
363         fi
364 fi
365
366 echo '=========================== finished ==============================='
367 [ -f "$SANITYLOG" ] && cat $SANITYLOG && exit 1 || true