Whamcloud - gitweb
LU-2040 tests: interop test failure on mds-survey
[fs/lustre-release.git] / lustre / tests / sanityn.sh
1 #!/bin/bash
2
3 set -e
4
5 ONLY=${ONLY:-"$*"}
6 # bug number for skipped test: 3192 LU-1205 15528/3811 16929 9977 15528/11549 18080
7 ALWAYS_EXCEPT="                14b  18c     19         22    28   29          35    $SANITYN_EXCEPT"
8 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
9
10 # bug number for skipped test:        12652 12652
11 grep -q 'Enterprise Server 10' /etc/SuSE-release 2> /dev/null &&
12         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 11    14" || true
13
14 # Tests that fail on uml
15 [ "$UML" = "true" ] && EXCEPT="$EXCEPT 7"
16
17 # It will be ported soon.
18 EXCEPT="$EXCEPT 22"
19
20 SRCDIR=`dirname $0`
21 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
22
23 SIZE=${SIZE:-40960}
24 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
25 MCREATE=${MCREATE:-mcreate}
26 OPENFILE=${OPENFILE:-openfile}
27 OPENUNLINK=${OPENUNLINK:-openunlink}
28 export MULTIOP=${MULTIOP:-multiop}
29 export TMP=${TMP:-/tmp}
30 MOUNT_2=${MOUNT_2:-"yes"}
31 CHECK_GRANT=${CHECK_GRANT:-"yes"}
32 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
33
34 SAVE_PWD=$PWD
35
36 export NAME=${NAME:-local}
37
38 LUSTRE=${LUSTRE:-`dirname $0`/..}
39 . $LUSTRE/tests/test-framework.sh
40 CLEANUP=${CLEANUP:-:}
41 SETUP=${SETUP:-:}
42 init_test_env $@
43 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
44 init_logging
45
46 [ "$SLOW" = "no" ] && EXCEPT_SLOW="12 23 33a"
47
48 FAIL_ON_ERROR=false
49
50 SETUP=${SETUP:-:}
51 TRACE=${TRACE:-""}
52
53 check_and_setup_lustre
54
55 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
56 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
57
58 assert_DIR
59 rm -rf $DIR1/[df][0-9]* $DIR1/lnk
60
61 SAMPLE_FILE=$TMP/$(basename $0 .sh).junk
62 dd if=/dev/urandom of=$SAMPLE_FILE bs=1M count=1
63
64 # $RUNAS_ID may get set incorrectly somewhere else
65 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
66
67 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
68
69 build_test_filter
70
71 mkdir -p $MOUNT2
72 mount_client $MOUNT2
73
74 test_1a() {
75         touch $DIR1/f1
76         [ -f $DIR2/f1 ] || error
77 }
78 run_test 1a "check create on 2 mtpt's =========================="
79
80 test_1b() {
81         chmod 777 $DIR2/f1
82         $CHECKSTAT -t file -p 0777 $DIR1/f1 || error
83         chmod a-x $DIR2/f1
84 }
85 run_test 1b "check attribute updates on 2 mtpt's ==============="
86
87 test_1c() {
88         $CHECKSTAT -t file -p 0666 $DIR1/f1 || error
89 }
90 run_test 1c "check after remount attribute updates on 2 mtpt's ="
91
92 test_1d() {
93         rm $DIR2/f1
94         $CHECKSTAT -a $DIR1/f1 || error
95 }
96 run_test 1d "unlink on one mountpoint removes file on other ===="
97
98 test_2a() {
99         touch $DIR1/f2a
100         ls -l $DIR2/f2a
101         chmod 777 $DIR2/f2a
102         $CHECKSTAT -t file -p 0777 $DIR1/f2a || error
103 }
104 run_test 2a "check cached attribute updates on 2 mtpt's ========"
105
106 test_2b() {
107         touch $DIR1/f2b
108         ls -l $DIR2/f2b
109         chmod 777 $DIR1/f2b
110         $CHECKSTAT -t file -p 0777 $DIR2/f2b || error
111 }
112 run_test 2b "check cached attribute updates on 2 mtpt's ========"
113
114 # NEED TO SAVE ROOT DIR MODE
115 test_2c() {
116         chmod 777 $DIR1
117         $CHECKSTAT -t dir -p 0777 $DIR2 || error
118 }
119 run_test 2c "check cached attribute updates on 2 mtpt's root ==="
120
121 test_2d() {
122         chmod 755 $DIR1
123         $CHECKSTAT -t dir -p 0755 $DIR2 || error
124 }
125 run_test 2d "check cached attribute updates on 2 mtpt's root ==="
126
127 test_2e() {
128         chmod 755 $DIR1
129         ls -l $DIR1
130         ls -l $DIR2
131         chmod 777 $DIR1
132         $RUNAS dd if=/dev/zero of=$DIR2/$tfile count=1 || error
133 }
134 run_test 2e "check chmod on root is propagated to others"
135
136 test_3() {
137         local target="this/is/good"
138         ln -s $target $DIR1/$tfile || error "ln -s $target $DIR1/$tfile failed"
139         [ "$(ls -l $DIR2/$tfile | sed -e 's/.* -> //')" = "$target" ] ||
140                 error "link $DIR2/$tfile not as expected"
141 }
142 run_test 3 "symlink on one mtpt, readlink on another ==========="
143
144 test_4() {
145         multifstat $DIR1/f4 $DIR2/f4
146 }
147 run_test 4 "fstat validation on multiple mount points =========="
148
149 test_5() {
150         mcreate $DIR1/f5
151         $TRUNCATE $DIR2/f5 100
152         $CHECKSTAT -t file -s 100 $DIR1/f5 || error
153         rm $DIR1/f5
154 }
155 run_test 5 "create a file on one mount, truncate it on the other"
156
157 test_6() {
158         openunlink $DIR1/$tfile $DIR2/$tfile || \
159                 error "openunlink $DIR1/$tfile $DIR2/$tfile"
160 }
161 run_test 6 "remove of open file on other node =================="
162
163 test_7() {
164         local dir=d7
165         opendirunlink $DIR1/$dir $DIR2/$dir || \
166                 error "opendirunlink $DIR1/$dir $DIR2/$dir"
167 }
168 run_test 7 "remove of open directory on other node ============="
169
170 test_8() {
171         opendevunlink $DIR1/$tfile $DIR2/$tfile || \
172                 error "opendevunlink $DIR1/$tfile $DIR2/$tfile"
173 }
174 run_test 8 "remove of open special file on other node =========="
175
176 test_9() {
177         MTPT=1
178         local dir
179         > $DIR2/f9
180         for C in a b c d e f g h i j k l; do
181                 dir=`eval echo \\$DIR$MTPT`
182                 echo -n $C >> $dir/f9
183                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
184         done
185         [ "`cat $DIR1/f9`" = "abcdefghijkl" ] || \
186                 error "`od -a $DIR1/f9` != abcdefghijkl"
187 }
188 run_test 9 "append of file with sub-page size on multiple mounts"
189
190 test_10a() {
191         MTPT=1
192         local dir
193         OFFSET=0
194         > $DIR2/f10
195         for C in a b c d e f g h i j k l; do
196                 dir=`eval echo \\$DIR$MTPT`
197                 echo -n $C | dd of=$dir/f10 bs=1 seek=$OFFSET count=1
198                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
199                 OFFSET=`expr $OFFSET + 1`
200         done
201         [ "`cat $DIR1/f10`" = "abcdefghijkl" ] || \
202                 error "`od -a $DIR1/f10` != abcdefghijkl"
203 }
204 run_test 10a "write of file with sub-page size on multiple mounts "
205
206 test_10b() {
207         # create a seed file
208         yes "R" | head -c 4000 >$TMP/f10b-seed
209         dd if=$TMP/f10b-seed of=$DIR1/f10b bs=3k count=1 || error "dd $DIR1"
210
211         $TRUNCATE $DIR1/f10b 4096 || error "truncate 4096"
212
213         dd if=$DIR2/f10b of=$TMP/f10b-lustre bs=4k count=1 || error "dd $DIR2"
214
215         # create a test file locally to compare
216         dd if=$TMP/f10b-seed of=$TMP/f10b bs=3k count=1 || error "dd random"
217         $TRUNCATE $TMP/f10b 4096 || error "truncate 4096"
218         cmp $TMP/f10b $TMP/f10b-lustre || error "file miscompare"
219         rm $TMP/f10b $TMP/f10b-lustre $TMP/f10b-seed
220 }
221 run_test 10b "write of file with sub-page size on multiple mounts "
222
223 test_11() {
224         mkdir $DIR1/d11
225         multiop_bg_pause $DIR1/d11/f O_c || return 1
226         MULTIPID=$!
227         cp -p /bin/ls $DIR1/d11/f
228         $DIR2/d11/f
229         RC=$?
230         kill -USR1 $MULTIPID
231         wait $MULTIPID || error
232         [ $RC -eq 0 ] && error || true
233 }
234 run_test 11 "execution of file opened for write should return error ===="
235
236 test_12() {
237        DIR=$DIR DIR2=$DIR2 sh lockorder.sh
238 }
239 run_test 12 "test lock ordering (link, stat, unlink) ==========="
240
241 test_13() {     # bug 2451 - directory coherency
242        mkdir $DIR1/d13 || error
243        cd $DIR1/d13 || error
244        ls
245        ( touch $DIR1/d13/f13 ) # needs to be a separate shell
246        ls
247        rm -f $DIR2/d13/f13 || error
248        ls 2>&1 | grep f13 && error "f13 shouldn't return an error (1)" || true
249        # need to run it twice
250        ( touch $DIR1/d13/f13 ) # needs to be a separate shell
251        ls
252        rm -f $DIR2/d13/f13 || error
253        ls 2>&1 | grep f13 && error "f13 shouldn't return an error (2)" || true
254 }
255 run_test 13 "test directory page revocation ===================="
256
257 test_14() {
258         mkdir -p $DIR1/$tdir
259         cp -p /bin/ls $DIR1/$tdir/$tfile
260         multiop_bg_pause $DIR1/$tdir/$tfile Ow_c || return 1
261         MULTIPID=$!
262
263         $DIR2/$tdir/$tfile && error || true
264         kill -USR1 $MULTIPID
265         wait $MULTIPID || return 2
266 }
267 run_test 14 "execution of file open for write returns -ETXTBSY ="
268
269 test_14a() {
270         mkdir -p $DIR1/d14
271         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
272         MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
273         MULTIOP_PID=$!
274         $MULTIOP $DIR2/d14/multiop Oc && error "expected error, got success"
275         kill -USR1 $MULTIOP_PID || return 2
276         wait $MULTIOP_PID || return 3
277         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
278 }
279 run_test 14a "open(RDWR) of executing file returns -ETXTBSY ===="
280
281 test_14b() { # bug 3192, 7040
282         mkdir -p $DIR1/d14
283         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
284         MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
285         MULTIOP_PID=$!
286         $TRUNCATE $DIR2/d14/multiop 0 && kill -9 $MULTIOP_PID && \
287                 error "expected truncate error, got success"
288         kill -USR1 $MULTIOP_PID || return 2
289         wait $MULTIOP_PID || return 3
290         cmp `which multiop` $DIR1/d14/multiop || error "binary changed"
291         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
292 }
293 run_test 14b "truncate of executing file returns -ETXTBSY ======"
294
295 test_14c() { # bug 3430, 7040
296         mkdir -p $DIR1/d14
297         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
298         MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
299         MULTIOP_PID=$!
300         cp /etc/hosts $DIR2/d14/multiop && error "expected error, got success"
301         kill -USR1 $MULTIOP_PID || return 2
302         wait $MULTIOP_PID || return 3
303         cmp `which multiop` $DIR1/d14/multiop || error "binary changed"
304         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
305 }
306 run_test 14c "open(O_TRUNC) of executing file return -ETXTBSY =="
307
308 test_14d() { # bug 10921
309         mkdir -p $DIR1/d14
310         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
311         MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
312         MULTIOP_PID=$!
313         log chmod
314         chmod 600 $DIR1/d14/multiop || error "chmod failed"
315         kill -USR1 $MULTIOP_PID || return 2
316         wait $MULTIOP_PID || return 3
317         cmp `which multiop` $DIR1/d14/multiop || error "binary changed"
318         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
319 }
320 run_test 14d "chmod of executing file is still possible ========"
321
322 test_15() {     # bug 974 - ENOSPC
323         echo "PATH=$PATH"
324         sh oos2.sh $MOUNT1 $MOUNT2
325         wait_delete_completed
326         grant_error=`dmesg | grep "> available"`
327         [ -z "$grant_error" ] || error "$grant_error"
328 }
329 run_test 15 "test out-of-space with multiple writers ==========="
330
331 test_16() {
332         rm -f $MOUNT1/fsxfile
333         lfs setstripe $MOUNT1/fsxfile -c -1 # b=10919
334         fsx -c 50 -p 100 -N 2500 -l $((SIZE * 256)) -S 0 $FSXOPT \
335                 $MOUNT1/fsxfile $MOUNT2/fsxfile
336 }
337 run_test 16 "2500 iterations of dual-mount fsx ================="
338
339 test_17() { # bug 3513, 3667
340         remote_ost_nodsh && skip "remote OST with nodsh" && return
341
342         lfs setstripe $DIR1/$tfile -i 0 -c 1
343         cp $SAMPLE_FILE $DIR1/$tfile
344         cancel_lru_locks osc > /dev/null
345         #define OBD_FAIL_ONCE|OBD_FAIL_LDLM_CREATE_RESOURCE    0x30a
346         do_facet ost1 lctl set_param fail_loc=0x8000030a
347         ls -ls $DIR1/$tfile | awk '{ print $1,$6 }' > $DIR1/$tfile-1 & \
348         ls -ls $DIR2/$tfile | awk '{ print $1,$6 }' > $DIR2/$tfile-2
349         wait
350         diff -u $DIR1/$tfile-1 $DIR2/$tfile-2 || error "files are different"
351 }
352 run_test 17 "resource creation/LVB creation race ==============="
353
354 test_18() {
355         # turn e.g. ALWAYS_EXCEPT="18c" into "-e 3"
356         local idx
357         local excepts=
358         for idx in {a..z}; do
359                 local ptr=EXCEPT_ALWAYS_18$idx
360                 [ x${!ptr} = xtrue ] || continue
361
362                 excepts="$excepts -e $(($(printf %d \'$idx)-96))"
363         done
364
365         $LUSTRE/tests/mmap_sanity -d $MOUNT1 -m $MOUNT2 $excepts
366         sync; sleep 1; sync
367 }
368 run_test 18 "mmap sanity check ================================="
369
370 test_19() { # bug3811
371         local node=$(facet_active_host ost1)
372
373         # check whether obdfilter is cache capable at all
374         if ! get_obdfilter_param $node '' read_cache_enable >/dev/null; then
375                 echo "not cache-capable obdfilter"
376                 return 0
377         fi
378
379         local MAX=$(get_obdfilter_param $node '' readcache_max_filesize | \
380                     head -n 1)
381         set_obdfilter_param $node '' readcache_max_filesize 4096
382         dd if=/dev/urandom of=$TMP/$tfile bs=512k count=32
383         local SUM=$(cksum $TMP/$tfile | cut -d" " -f 1,2)
384         cp $TMP/$tfile $DIR1/$tfile
385         for i in `seq 1 20`; do
386                 [ $((i % 5)) -eq 0 ] && log "$testname loop $i"
387                 cancel_lru_locks osc > /dev/null
388                 cksum $DIR1/$tfile | cut -d" " -f 1,2 > $TMP/sum1 & \
389                 cksum $DIR2/$tfile | cut -d" " -f 1,2 > $TMP/sum2
390                 wait
391                 [ "$(cat $TMP/sum1)" = "$SUM" ] || \
392                         error "$DIR1/$tfile $(cat $TMP/sum1) != $SUM"
393                 [ "$(cat $TMP/sum2)" = "$SUM" ] || \
394                         error "$DIR2/$tfile $(cat $TMP/sum2) != $SUM"
395         done
396         set_obdfilter_param $node '' readcache_max_filesize $MAX
397         rm $DIR1/$tfile
398 }
399 run_test 19 "test concurrent uncached read races ==============="
400
401 test_20() {
402         mkdir $DIR1/d20
403         cancel_lru_locks osc
404         CNT=$((`lctl get_param -n llite.*.dump_page_cache | wc -l`))
405         $MULTIOP $DIR1/f20 Ow8190c
406         $MULTIOP $DIR2/f20 Oz8194w8190c
407         $MULTIOP $DIR1/f20 Oz0r8190c
408         cancel_lru_locks osc
409         CNTD=$((`lctl get_param -n llite.*.dump_page_cache | wc -l` - $CNT))
410         [ $CNTD -gt 0 ] && \
411             error $CNTD" page left in cache after lock cancel" || true
412 }
413 run_test 20 "test extra readahead page left in cache ===="
414
415 cleanup_21() {
416         trap 0
417         umount $DIR1/d21
418 }
419
420 test_21() { # Bug 5907
421         mkdir $DIR1/d21
422         mount /etc $DIR1/d21 --bind || error "mount failed" # Poor man's mount.
423         trap cleanup_21 EXIT
424         rmdir -v $DIR1/d21 && error "Removed mounted directory"
425         rmdir -v $DIR2/d21 && echo "Removed mounted directory from another mountpoint, needs to be fixed"
426         test -d $DIR1/d21 || error "Mounted directory disappeared"
427         cleanup_21
428         test -d $DIR2/d21 || test -d $DIR1/d21 && error "Removed dir still visible after umount"
429         true
430 }
431 run_test 21 " Try to remove mountpoint on another dir ===="
432
433 test_23() { # Bug 5972
434         echo "others should see updated atime while another read" > $DIR1/f23
435         
436         # clear the lock(mode: LCK_PW) gotten from creating operation
437         cancel_lru_locks osc
438         
439         time1=`date +%s`        
440         #MAX_ATIME_DIFF 60, we update atime only if older than 60 seconds
441         sleep 61
442         
443         multiop_bg_pause $DIR1/f23 or20_c || return 1
444         # with SOM and opencache enabled, we need to close a file and cancel
445         # open lock to get atime propogated to MDS
446         kill -USR1 $!
447         cancel_lru_locks mdc
448
449         time2=`stat -c "%X" $DIR2/f23`
450
451         if (( $time2 <= $time1 )); then
452                 error "atime doesn't update among nodes"
453         fi
454
455         rm -f $DIR1/f23 || error "rm -f $DIR1/f23 failed"
456         true
457 }
458 run_test 23 " others should see updated atime while another read===="
459
460 test_24a() {
461         touch $DIR1/$tfile
462         lfs df || error "lfs df failed"
463         lfs df -ih || error "lfs df -ih failed"
464         lfs df -h $DIR1 || error "lfs df -h $DIR1 failed"
465         lfs df -i $DIR2 || error "lfs df -i $DIR2 failed"
466         lfs df $DIR1/$tfile || error "lfs df $DIR1/$tfile failed"
467         lfs df -ih $DIR2/$tfile || error "lfs df -ih $DIR2/$tfile failed"
468         
469         OSC=`lctl dl | awk '/-osc-|OSC.*MNT/ {print $4}' | head -n 1`
470 #       OSC=`lctl dl | awk '/-osc-/ {print $4}' | head -n 1`
471         lctl --device %$OSC deactivate
472         lfs df -i || error "lfs df -i with deactivated OSC failed"
473         lctl --device %$OSC activate
474         lfs df || error "lfs df with reactivated OSC failed"
475 }
476 run_test 24a "lfs df [-ih] [path] test ========================="
477
478 test_24b() {
479         touch $DIR1/$tfile
480         fsnum=`lfs df | grep -c "filesystem summary:"`
481         [ $fsnum -eq 2 ] || error "lfs df shows $fsnum != 2 filesystems."
482 }
483 run_test 24b "lfs df should show both filesystems ==============="
484
485 test_25() {
486         [ `lctl get_param -n mdc.*-mdc-*.connect_flags | grep -c acl` -lt 2 ] &&
487                 skip "must have acl, skipping" && return
488
489         mkdir -p $DIR1/$tdir
490         touch $DIR1/$tdir/f1 || error "touch $DIR1/$tdir/f1"
491         chmod 0755 $DIR1/$tdir/f1 || error "chmod 0755 $DIR1/$tdir/f1"
492
493         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #1"
494         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
495                 error "setfacl $DIR2/$tdir #1"
496         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #2"
497         setfacl -m u:$RUNAS_ID:r-x -m g:$RUNAS_GID:r-x $DIR1/$tdir ||
498                 error "setfacl $DIR2/$tdir #2"
499         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #3"
500         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
501                 error "setfacl $DIR2/$tdir #3"
502         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #4"
503         setfacl -x u:$RUNAS_ID: -x g:$RUNAS_GID: $DIR1/$tdir ||
504                 error "setfacl $DIR2/$tdir #4"
505         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #5"
506
507         rm -rf $DIR1/$tdir
508 }
509 run_test 25 "change ACL on one mountpoint be seen on another ==="
510
511 test_26a() {
512         utime $DIR1/f26a -s $DIR2/f26a || error
513 }
514 run_test 26a "allow mtime to get older"
515
516 test_26b() {
517         touch $DIR1/$tfile
518         sleep 1
519         echo "aaa" >> $DIR1/$tfile
520         sleep 1
521         chmod a+x $DIR2/$tfile
522         mt1=`stat -c %Y $DIR1/$tfile`
523         mt2=`stat -c %Y $DIR2/$tfile`
524
525         if [ x"$mt1" != x"$mt2" ]; then
526                 error "not equal mtime, client1: "$mt1", client2: "$mt2"."
527         fi
528 }
529 run_test 26b "sync mtime between ost and mds"
530
531 test_27() {
532         cancel_lru_locks osc
533         lctl clear
534         dd if=/dev/zero of=$DIR2/$tfile bs=$((4096+4))k conv=notrunc count=4 seek=3 &
535         DD2_PID=$!
536         usleep 50
537         log "dd 1 started"
538         
539         dd if=/dev/zero of=$DIR1/$tfile bs=$((16384-1024))k conv=notrunc count=1 seek=4 &
540         DD1_PID=$!
541         log "dd 2 started"
542         
543         sleep 1
544         dd if=/dev/zero of=$DIR1/$tfile bs=8k conv=notrunc count=1 seek=0
545         log "dd 3 finished"
546         lctl set_param -n ldlm.dump_namespaces ""
547         wait $DD1_PID $DD2_PID
548         [ $? -ne 0 ] && lctl dk $TMP/debug || true
549 }
550 run_test 27 "align non-overlapping extent locks from request ==="
551
552 test_28() { # bug 9977
553         ECHO_UUID="ECHO_osc1_UUID"
554         tOST=`$LCTL dl | | awk '/-osc-|OSC.*MNT/ { print $4 }' | head -1`
555
556         $LFS setstripe $DIR1/$tfile -S 1048576 -i 0 -c 2
557         tOBJID=`$LFS getstripe $DIR1/$tfile | awk '$1 == 1 {print $2}'`
558         dd if=/dev/zero of=$DIR1/$tfile bs=1024k count=2
559
560         $LCTL <<-EOF
561                 newdev
562                 attach echo_client ECHO_osc1 $ECHO_UUID
563                 setup $tOST
564         EOF
565
566         tECHOID=`$LCTL dl | grep $ECHO_UUID | awk '{ print $1 }'`
567         $LCTL --device $tECHOID destroy "${tOBJID}:0"
568
569         $LCTL <<-EOF
570                 cfg_device ECHO_osc1
571                 cleanup
572                 detach
573         EOF
574
575         # reading of 1st stripe should pass
576         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 || error
577         # reading of 2nd stripe should fail (this stripe was destroyed)
578         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 skip=1 && error
579
580         # now, recreating test file
581         dd if=/dev/zero of=$DIR1/$tfile bs=1024k count=2 || error
582         # reading of 1st stripe should pass
583         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 || error
584         # reading of 2nd stripe should pass
585         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 skip=1 || error
586 }
587 run_test 28 "read/write/truncate file with lost stripes"
588
589 test_29() { # bug 10999
590         touch $DIR1/$tfile
591         #define OBD_FAIL_LDLM_GLIMPSE  0x30f
592         lctl set_param fail_loc=0x8000030f
593         ls -l $DIR2/$tfile &
594         usleep 500
595         dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1
596         wait
597 }
598 #bug 11549 - permanently turn test off in b1_5
599 run_test 29 "lock put race between glimpse and enqueue ========="
600
601 test_30() { #bug #11110
602     mkdir -p $DIR1/$tdir
603     cp -f /bin/bash $DIR1/$tdir/bash
604     /bin/sh -c 'sleep 1; rm -f $DIR2/$tdir/bash; cp /bin/bash $DIR2/$tdir' &
605     err=$($DIR1/$tdir/bash -c 'sleep 2; openfile -f O_RDONLY /proc/$$/exe >& /dev/null; echo $?')
606     wait
607     [ $err -ne 116 ] && error_ignore 12900 "return code ($err) != -ESTALE" && return
608     true
609 }
610
611 run_test 30 "recreate file race ========="
612
613 test_31a() {
614         mkdir -p $DIR1/$tdir || error "Creating dir $DIR1/$tdir"
615         writes=`LANG=C dd if=/dev/zero of=$DIR/$tdir/$tfile count=1 2>&1 |
616                 awk 'BEGIN { FS="+" } /out/ {print $1}'`
617         #define OBD_FAIL_LDLM_CANCEL_BL_CB_RACE   0x314
618         lctl set_param fail_loc=0x314
619         reads=`LANG=C dd if=$DIR2/$tdir/$tfile of=/dev/null 2>&1 |
620                awk 'BEGIN { FS="+" } /in/ {print $1}'`
621         [ $reads -eq $writes ] || error "read" $reads "blocks, must be" $writes
622 }
623 run_test 31a "voluntary cancel / blocking ast race=============="
624
625 test_31b() {
626         remote_ost || { skip "local OST" && return 0; }
627         remote_ost_nodsh && skip "remote OST w/o dsh" && return 0
628
629         # make sure there is no local locks due to destroy
630         wait_mds_ost_sync || error "wait_mds_ost_sync()"
631         wait_delete_completed || error "wait_delete_completed()"
632
633         mkdir -p $DIR1/$tdir || error "Creating dir $DIR1/$tdir"
634         lfs setstripe $DIR/$tdir/$tfile -i 0 -c 1
635         cp /etc/hosts $DIR/$tdir/$tfile
636         #define OBD_FAIL_LDLM_CANCEL_BL_CB_RACE   0x314
637         lctl set_param fail_loc=0x314
638         #define OBD_FAIL_LDLM_OST_FAIL_RACE      0x316
639         do_facet ost1 lctl set_param fail_loc=0x316
640         # Don't crash kernel
641         cat $DIR2/$tdir/$tfile > /dev/null 2>&1
642         lctl set_param fail_loc=0
643         do_facet ost1 lctl set_param fail_loc=0
644         # cleanup: reconnect the client back
645         df $DIR2
646 }
647 run_test 31b "voluntary OST cancel / blocking ast race=============="
648
649 # enable/disable lockless truncate feature, depending on the arg 0/1
650 enable_lockless_truncate() {
651         lctl set_param -n osc.*.lockless_truncate $1
652 }
653
654 test_32a() { # bug 11270
655         local p="$TMP/sanityN-$TESTNAME.parameters"
656         save_lustre_params $HOSTNAME osc.*.lockless_truncate > $p
657         cancel_lru_locks osc
658         enable_lockless_truncate 1
659         rm -f $DIR1/$tfile
660         lfs setstripe -c -1 $DIR1/$tfile
661         dd if=/dev/zero of=$DIR1/$tfile count=$OSTCOUNT bs=$STRIPE_BYTES > \
662                 /dev/null 2>&1
663         clear_osc_stats
664
665         log "checking cached lockless truncate"
666         $TRUNCATE $DIR1/$tfile 8000000
667         $CHECKSTAT -s 8000000 $DIR2/$tfile || error "wrong file size"
668         [ $(calc_osc_stats lockless_truncate) -eq 0 ] ||
669                 error "lockless truncate doesn't use cached locks"
670
671         log "checking not cached lockless truncate"
672         $TRUNCATE $DIR2/$tfile 5000000
673         $CHECKSTAT -s 5000000 $DIR1/$tfile || error "wrong file size"
674         [ $(calc_osc_stats lockless_truncate) -ne 0 ] ||
675                 error "not cached trancate isn't lockless"
676
677         log "disabled lockless truncate"
678         enable_lockless_truncate 0
679         clear_osc_stats
680         $TRUNCATE $DIR2/$tfile 3000000
681         $CHECKSTAT -s 3000000 $DIR1/$tfile || error "wrong file size"
682         [ $(calc_osc_stats lockless_truncate) -eq 0 ] ||
683                 error "lockless truncate disabling failed"
684         rm $DIR1/$tfile
685         # restore lockless_truncate default values
686         restore_lustre_params < $p
687         rm -f $p
688 }
689 run_test 32a "lockless truncate"
690
691 test_32b() { # bug 11270
692         remote_ost_nodsh && skip "remote OST with nodsh" && return
693
694         local node
695         local p="$TMP/sanityN-$TESTNAME.parameters"
696         save_lustre_params $HOSTNAME "osc.*.contention_seconds" > $p
697         for node in $(osts_nodes); do
698                 save_lustre_params $node "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
699                 save_lustre_params $node "ldlm.namespaces.filter-*.contended_locks" >> $p
700                 save_lustre_params $node "ldlm.namespaces.filter-*.contention_seconds" >> $p
701         done
702         clear_osc_stats
703         # agressive lockless i/o settings
704         for node in $(osts_nodes); do
705                 do_node $node 'lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes 2000000; lctl set_param -n ldlm.namespaces.filter-*.contended_locks 0; lctl set_param -n ldlm.namespaces.filter-*.contention_seconds 60'
706         done
707         lctl set_param -n osc.*.contention_seconds 60
708         for i in $(seq 5); do
709                 dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
710                 dd if=/dev/zero of=$DIR2/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
711         done
712         [ $(calc_osc_stats lockless_write_bytes) -ne 0 ] || error "lockless i/o was not triggered"
713         # disable lockless i/o (it is disabled by default)
714         for node in $(osts_nodes); do
715                 do_node $node 'lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes 0; lctl set_param -n ldlm.namespaces.filter-*.contended_locks 32; lctl set_param -n ldlm.namespaces.filter-*.contention_seconds 0'
716         done
717         # set contention_seconds to 0 at client too, otherwise Lustre still
718         # remembers lock contention
719         lctl set_param -n osc.*.contention_seconds 0
720         clear_osc_stats
721         for i in $(seq 1); do
722                 dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
723                 dd if=/dev/zero of=$DIR2/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
724         done
725         [ $(calc_osc_stats lockless_write_bytes) -eq 0 ] ||
726                 error "lockless i/o works when disabled"
727         rm -f $DIR1/$tfile
728         restore_lustre_params <$p
729         rm -f $p
730 }
731 run_test 32b "lockless i/o"
732
733 print_jbd_stat () {
734     local dev
735     local mdts=$(get_facets MDS)
736     local varcvs
737     local mds
738
739     local stat=0
740     for mds in ${mdts//,/ }; do
741         varsvc=${mds}_svc
742         dev=$(basename $(do_facet $mds lctl get_param -n osd*.${!varsvc}.mntdev))
743         val=$(do_facet $mds "procfile=/proc/fs/jbd/$dev/info;
744 [ -f \\\$procfile ] || procfile=/proc/fs/jbd2/$dev/info;
745 [ -f \\\$procfile ] || procfile=/proc/fs/jbd2/${dev}\:\\\*/info;
746 cat \\\$procfile | head -1;")
747         val=${val%% *};
748         stat=$(( stat + val))
749     done
750     echo $stat
751 }
752
753 # commit on sharing tests
754 test_33a() {
755     remote_mds_nodsh && skip "remote MDS with nodsh" && return
756
757     [ -n "$CLIENTS" ] || { skip "Need two or more clients" && return 0; }
758     [ $CLIENTCOUNT -ge 2 ] || \
759         { skip "Need two or more clients, have $CLIENTCOUNT" && return 0; }
760
761     local nfiles=${TEST33_NFILES:-10000}
762     local param_file=$TMP/$tfile-params
763
764     save_lustre_params $(comma_list $(mdts_nodes)) "mdt.*.commit_on_sharing" > $param_file
765
766     local COS
767     local jbdold
768     local jbdnew
769     local jbd
770
771     for COS in 0 1; do
772         do_facet $SINGLEMDS lctl set_param mdt.*.commit_on_sharing=$COS
773         avgjbd=0
774         avgtime=0
775         for i in 1 2 3; do
776             do_nodes $CLIENT1,$CLIENT2 "mkdir -p $DIR1/$tdir-\\\$(hostname)-$i"
777
778             jbdold=$(print_jbd_stat)
779             echo "=== START createmany old: $jbdold transaction"
780             local elapsed=$(do_and_time "do_nodes $CLIENT1,$CLIENT2 createmany -o $DIR1/$tdir-\\\$(hostname)-$i/f- -r $DIR2/$tdir-\\\$(hostname)-$i/f- $nfiles > /dev/null 2>&1")
781             jbdnew=$(print_jbd_stat)
782             jbd=$(( jbdnew - jbdold ))
783             echo "=== END   createmany new: $jbdnew transaction :  $jbd transactions  nfiles $nfiles time $elapsed COS=$COS"
784             avgjbd=$(( avgjbd + jbd ))
785             avgtime=$(( avgtime + elapsed ))
786         done
787         eval cos${COS}_jbd=$((avgjbd / 3))
788         eval cos${COS}_time=$((avgtime / 3))
789     done
790
791     echo "COS=0 transactions (avg): $cos0_jbd  time (avg): $cos0_time"
792     echo "COS=1 transactions (avg): $cos1_jbd  time (avg): $cos1_time"
793     [ "$cos0_jbd" != 0 ] && echo "COS=1 vs COS=0 jbd:  $((((cos1_jbd/cos0_jbd - 1)) * 100 )) %"
794     [ "$cos0_time" != 0 ] && echo "COS=1 vs COS=0 time: $((((cos1_time/cos0_time - 1)) * 100 )) %"
795
796     restore_lustre_params < $param_file
797     rm -f $param_file
798     return 0
799 }
800 run_test 33a "commit on sharing, cross crete/delete, 2 clients, benchmark"
801
802 # End commit on sharing tests
803
804 get_ost_lock_timeouts() {
805     local nodes=${1:-$(comma_list $(osts_nodes))}
806
807     local locks=$(do_nodes $nodes \
808         "lctl get_param -n ldlm.namespaces.filter-*.lock_timeouts" | calc_sum)
809
810     echo $locks
811 }
812
813 test_34() { #16129
814         local OPER
815         local lock_in
816         local lock_out
817         for OPER in notimeout timeout ; do
818                 rm $DIR1/$tfile 2>/dev/null
819                 lock_in=$(get_ost_lock_timeouts)
820                 if [ $OPER == "timeout" ] ; then
821                         for j in `seq $OSTCOUNT`; do
822                                 #define OBD_FAIL_PTLRPC_HPREQ_TIMEOUT    0x511
823                                 do_facet ost$j lctl set_param fail_loc=0x511
824                         done
825                         echo lock should expire
826                 else
827                         for j in `seq $OSTCOUNT`; do
828                                 #define OBD_FAIL_PTLRPC_HPREQ_NOTIMEOUT  0x512
829                                 do_facet ost$j lctl set_param fail_loc=0x512
830                         done
831                         echo lock should not expire
832                 fi
833                 echo writing on client1
834                 dd if=/dev/zero of=$DIR1/$tfile count=100 conv=notrunc > /dev/null 2>&1
835                 sync &
836                 echo reading on client2
837                 dd of=/dev/null if=$DIR2/$tfile > /dev/null 2>&1
838                 # wait for a lock timeout
839                 sleep 4
840                 lock_out=$(get_ost_lock_timeouts)
841                 if [ $OPER == "timeout" ] ; then
842                         if [ $lock_in == $lock_out ]; then
843                                 error "no lock timeout happened"
844                         else
845                                 echo "success"
846                         fi
847                 else
848                         if [ $lock_in != $lock_out ]; then
849                                 error "lock timeout happened"
850                         else
851                                 echo "success"
852                         fi
853                 fi
854         done
855 }
856 run_test 34 "no lock timeout under IO"
857
858 test_35() { # bug 17645
859         local generation=[]
860         local count=0
861         for imp in /proc/fs/lustre/mdc/$FSNAME-MDT*-mdc-*; do
862             g=$(awk '/generation/{print $2}' $imp/import)
863             generation[count]=$g
864             let count=count+1
865         done
866
867         mkdir -p $MOUNT1/$tfile
868         cancel_lru_locks mdc
869
870         # Let's initiate -EINTR situation by setting fail_loc and take
871         # write lock on same file from same client. This will not cause
872         # bl_ast yet as lock is already in local cache.
873 #define OBD_FAIL_LDLM_INTR_CP_AST        0x317
874         do_facet client "lctl set_param fail_loc=0x80000317"
875         local timeout=`do_facet $SINGLEMDS lctl get_param  -n timeout`
876         let timeout=timeout*3
877         local nr=0
878         while test $nr -lt 10; do
879                 log "Race attempt $nr"
880                 local blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
881                 test "x$blk1" = "x" && blk1=0
882                 createmany -o $MOUNT2/$tfile/a 4000 &
883                 pid1=$!
884                 sleep 1
885
886                 # Let's make conflict and bl_ast
887                 ls -la $MOUNT1/$tfile > /dev/null &
888                 pid2=$!
889
890                 log "Wait for $pid1 $pid2 for $timeout sec..."
891                 sleep $timeout
892                 kill -9 $pid1 $pid2 > /dev/null 2>&1
893                 wait
894                 local blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
895                 test "x$blk2" = "x" && blk2=0
896                 test $blk2 -gt $blk1 && break
897                 rm -fr $MOUNT1/$tfile/*
898                 cancel_lru_locks mdc
899                 let nr=nr+1
900         done
901         do_facet client "lctl set_param fail_loc=0x0"
902         df -h $MOUNT1 $MOUNT2
903         count=0
904         for imp in /proc/fs/lustre/mdc/$FSNAME-MDT*-mdc-*; do
905             g=$(awk '/generation/{print $2}' $imp/import)
906             if ! test "$g" -eq "${generation[count]}"; then
907                 error "Eviction happened on import $(basename $imp)"
908             fi
909             let count=count+1
910         done
911 }
912 run_test 35 "-EINTR cp_ast vs. bl_ast race does not evict client"
913
914 test_36() { #bug 16417
915         local SIZE
916         local SIZE_B
917         local i
918
919         mkdir -p $DIR1/$tdir
920         $LFS setstripe -c -1 $DIR1/$tdir
921         i=0
922         SIZE=50
923         let SIZE_B=SIZE*1024*1024
924
925         while [ $i -le 10 ]; do
926                 lctl mark "start test"
927                 local before=$($LFS df | awk '{if ($1 ~/^filesystem/) \
928                                                {print $5; exit} }')
929                 dd if=/dev/zero of=$DIR1/$tdir/file000 bs=1M count=$SIZE
930                 sync          # sync data from client's cache
931                 sync_all_data # sync data from server's cache (delayed
932                               # allocation)
933                 sleep 1
934                 local after_dd=$($LFS df | awk '{if ($1 ~/^filesystem/) \
935                                                  {print $5; exit} }')
936                 multiop_bg_pause $DIR2/$tdir/file000 O_r${SIZE_B}c || return 3
937                 read_pid=$!
938                 rm -f $DIR1/$tdir/file000
939                 kill -USR1 $read_pid
940                 wait $read_pid
941                 wait_delete_completed
942                 local after=$($LFS df | awk '{if ($1 ~/^filesystem/) \
943                                               {print $5; exit} }')
944                 echo "*** cycle($i) *** before($before) after_dd($after_dd)" \
945                         "after($after)"
946                 # this free space! not used
947                 if [ $after_dd -ge $after ]; then
948                         error "space leaked"
949                         return 1;
950                 fi
951                 let i=i+1
952         done
953 }
954 run_test 36 "handle ESTALE/open-unlink corectly"
955
956 test_37() { # bug 18695
957         mkdir -p $DIR1/$tdir
958         multiop_bg_pause $DIR1/$tdir D_c || return 1
959         MULTIPID=$!
960         # create large directory (32kB seems enough from e2fsck, ~= 1000 files)
961         createmany -m $DIR2/$tdir/f 10000
962         # set mtime/atime backward
963         touch -t 198001010000 $DIR2/$tdir
964         kill -USR1 $MULTIPID
965         nr_files=`lfs find $DIR1/$tdir -type f | wc -l`
966         [ $nr_files -eq 10000 ] || error "$nr_files != 10000 truncated directory?"
967
968 }
969 run_test 37 "check i_size is not updated for directory on close (bug 18695) =============="
970
971 # this should be set to past
972 TEST_39_MTIME=`date -d "1 year ago" +%s`
973
974 # bug 11063
975 test_39a() {
976         local client1=${CLIENT1:-`hostname`}
977         local client2=${CLIENT2:-`hostname`}
978
979         do_node $client1 "touch $DIR1/$tfile"
980
981         do_node $client1 "touch -m -d @$TEST_39_MTIME $DIR1/$tfile"
982         local mtime1=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
983         [ "$mtime1" = $TEST_39_MTIME ] || \
984                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
985
986         local d1=`do_node $client1 date +%s`
987         do_node $client1 'echo hello >> '$DIR1/$tfile
988         local d2=`do_node $client1 date +%s`
989
990         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
991         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
992                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
993
994         do_node $client1 "mv $DIR1/$tfile $DIR1/$tfile-1"
995
996         for (( i=0; i < 2; i++ )) ; do
997                 local mtime3=`do_node $client2 "stat -c %Y $DIR1/$tfile-1"`
998                 [ "$mtime2" = "$mtime3" ] || \
999                         error "mtime ($mtime2) changed (to $mtime3) on rename"
1000
1001                 cancel_lru_locks osc
1002                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1003         done
1004 }
1005 run_test 39a "test from 11063 =================================="
1006
1007 test_39b() {
1008         local client1=${CLIENT1:-`hostname`}
1009         local client2=${CLIENT2:-`hostname`}
1010
1011         touch $DIR1/$tfile
1012
1013         local mtime1=`stat -c %Y $DIR1/$tfile`
1014         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1015
1016         sleep 1
1017         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
1018
1019         for (( i=0; i < 2; i++ )) ; do
1020                 local mtime3=`stat -c %Y $DIR1/$tfile`
1021                 local mtime4=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1022
1023                 [ "$mtime3" = "$mtime4" ] || \
1024                         error "different mtime on clients: $mtime3, $mtime4"
1025                 [ "$mtime3" = $TEST_39_MTIME ] || \
1026                         error "lost mtime: $mtime3, should be $TEST_39_MTIME"
1027
1028                 cancel_lru_locks osc
1029                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1030         done
1031 }
1032 run_test 39b "11063 problem 1 =================================="
1033
1034 test_39c() {
1035         local client1=${CLIENT1:-`hostname`}
1036         local client2=${CLIENT2:-`hostname`}
1037
1038         echo hello > $DIR1/$tfile
1039
1040         local mtime1=`stat -c %Y $DIR1/$tfile`
1041         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1042         [ "$mtime1" = "$mtime2" ] || \
1043                 error "create: different mtime on clients: $mtime1, $mtime2"
1044
1045         sleep 1
1046         $TRUNCATE $DIR1/$tfile 1
1047
1048         for (( i=0; i < 2; i++ )) ; do
1049                 local mtime3=`stat -c %Y $DIR1/$tfile`
1050                 local mtime4=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1051
1052                 [ "$mtime3" = "$mtime4" ] || \
1053                         error "different mtime on clients: $mtime3, $mtime4"
1054                 [ "$mtime3" -gt $mtime2 ] || \
1055                         error "truncate did not update mtime: $mtime2, $mtime3"
1056
1057                 cancel_lru_locks osc
1058                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1059         done
1060 }
1061 run_test 39c "check truncate mtime update ======================"
1062
1063 # check that pid exists hence second operation wasn't blocked by first one
1064 # if it is so then there is no conflict, return 0
1065 # else second operation is conflicting with first one, return 1
1066 check_pdo_conflict() {
1067         local pid=$1
1068         local conflict=0
1069         sleep 1 # to ensure OP1 is finished on client if OP2 is blocked by OP1
1070         if [[ `ps --pid $pid | wc -l` == 1 ]]; then
1071                 conflict=1
1072                 echo "Conflict"
1073         else
1074                 echo "No conflict"
1075         fi
1076         return $conflict
1077 }
1078
1079 # pdirop tests
1080 # test 40: check non-blocking operations
1081 test_40a() {
1082 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1083         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1084         mkdir $DIR1/$tfile &
1085         PID1=$!
1086         sleep 1
1087         touch $DIR2/$tfile-2
1088         check_pdo_conflict $PID1 || error "create is blocked"
1089         mkdir $DIR2/$tfile-3
1090         check_pdo_conflict $PID1 || error "mkdir is blocked"
1091         link $DIR2/$tfile-2 $DIR2/$tfile-4
1092         check_pdo_conflict $PID1 || error "link is blocked"
1093         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1094         check_pdo_conflict $PID1 || error "rename is blocked"
1095         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1096         check_pdo_conflict $PID1 || error "getattr is blocked"
1097         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1098         rmdir $DIR2/$tfile-3
1099         check_pdo_conflict $PID1 || error "unlink is blocked"
1100         # all operations above shouldn't wait the first one
1101         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1102         wait $PID1
1103         rm -r $DIR1/*
1104         return 0
1105 }
1106 run_test 40a "pdirops: create vs others =============="
1107
1108 test_40b() {
1109 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1110         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1111         touch $DIR1/$tfile &
1112         PID1=$!
1113         sleep 1
1114         # open|create
1115         touch $DIR2/$tfile-2
1116         check_pdo_conflict $PID1 || error "create is blocked"
1117         mkdir $DIR2/$tfile-3
1118         check_pdo_conflict $PID1 || error "mkdir is blocked"
1119         link $DIR2/$tfile-2 $DIR2/$tfile-4
1120         check_pdo_conflict $PID1 || error "link is blocked"
1121         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1122         check_pdo_conflict $PID1 || error "rename is blocked"
1123         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1124         check_pdo_conflict $PID1 || error "getattr is blocked"
1125         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1126         rmdir $DIR2/$tfile-3
1127         check_pdo_conflict $PID1 || error "unlink is blocked"
1128         # all operations above shouldn't wait the first one
1129         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1130         wait $PID1
1131         rm -r $DIR1/*
1132         return 0
1133 }
1134 run_test 40b "pdirops: open|create and others =============="
1135
1136 test_40c() {
1137         touch $DIR1/$tfile
1138 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1139         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1140         link $DIR1/$tfile $DIR1/$tfile-0 &
1141         PID1=$!
1142         sleep 1
1143         # open|create
1144         touch $DIR2/$tfile-2
1145         check_pdo_conflict $PID1 || error "create is blocked"
1146         mkdir $DIR2/$tfile-3
1147         check_pdo_conflict $PID1 || error "mkdir is blocked"
1148         link $DIR2/$tfile-2 $DIR2/$tfile-4
1149         check_pdo_conflict $PID1 || error "link is blocked"
1150         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1151         check_pdo_conflict $PID1 || error "rename is blocked"
1152         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1153         check_pdo_conflict $PID1 || error "getattr is blocked"
1154         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1155         rmdir $DIR2/$tfile-3
1156         check_pdo_conflict $PID1 || error "unlink is blocked"
1157         # all operations above shouldn't wait the first one
1158         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1159         wait $PID1
1160         rm -r $DIR1/*
1161         return 0
1162 }
1163 run_test 40c "pdirops: link and others =============="
1164
1165 test_40d() {
1166         touch $DIR1/$tfile
1167 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1168         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1169         rm $DIR1/$tfile &
1170         PID1=$!
1171         sleep 1
1172         # open|create
1173         touch $DIR2/$tfile-2
1174         check_pdo_conflict $PID1 || error "create is blocked"
1175         mkdir $DIR2/$tfile-3
1176         check_pdo_conflict $PID1 || error "mkdir is blocked"
1177         link $DIR2/$tfile-2 $DIR2/$tfile-4
1178         check_pdo_conflict $PID1 || error "link is blocked"
1179         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1180         check_pdo_conflict $PID1 || error "rename is blocked"
1181         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1182         check_pdo_conflict $PID1 || error "getattr is blocked"
1183         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1184         rmdir $DIR2/$tfile-3
1185         check_pdo_conflict $PID1 || error "unlink is blocked"
1186         # all operations above shouldn't wait the first one
1187         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1188         wait $PID1
1189         return 0
1190 }
1191 run_test 40d "pdirops: unlink and others =============="
1192
1193 test_40e() {
1194         touch $DIR1/$tfile
1195 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1196         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1197         mv $DIR1/$tfile $DIR1/$tfile-0 &
1198         PID1=$!
1199         sleep 1
1200         # open|create
1201         touch $DIR2/$tfile-2
1202         check_pdo_conflict $PID1 || error "create is blocked"
1203         mkdir $DIR2/$tfile-3
1204         check_pdo_conflict $PID1 || error "mkdir is blocked"
1205         link $DIR2/$tfile-2 $DIR2/$tfile-4
1206         check_pdo_conflict $PID1 || error "link is blocked"
1207         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1208         check_pdo_conflict $PID1 || error "getattr is blocked"
1209         rm $DIR2/$tfile-4 $DIR2/$tfile-2
1210         rmdir $DIR2/$tfile-3
1211         check_pdo_conflict $PID1 || error "unlink is blocked"
1212         # all operations above shouldn't wait the first one
1213         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1214         wait $PID1
1215         rm -r $DIR1/*
1216         return 0
1217 }
1218 run_test 40e "pdirops: rename and others =============="
1219
1220 # test 41: create blocking operations
1221 test_41a() {
1222 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1223         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1224         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1225         PID1=$!
1226         sleep 1
1227         mkdir $DIR2/$tfile && error "mkdir must fail"
1228         check_pdo_conflict $PID1 && { wait $PID1; echo "mkdir isn't blocked"; }
1229         rm -r $DIR1/*
1230         return 0
1231 }
1232 run_test 41a "pdirops: create vs mkdir =============="
1233
1234 test_41b() {
1235 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1236         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1237         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1238         PID1=$!
1239         sleep 1
1240         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
1241         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1242         rm -r $DIR1/*
1243         return 0
1244 }
1245 run_test 41b "pdirops: create vs create =============="
1246
1247 test_41c() {
1248         touch $DIR1/$tfile-2
1249 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1250         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1251         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1252         PID1=$!
1253         sleep 1
1254         link $DIR2/$tfile-2 $DIR2/$tfile && error "link must fail"
1255         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1256         rm -r $DIR1/*
1257         return 0
1258 }
1259 run_test 41c "pdirops: create vs link =============="
1260
1261 test_41d() {
1262 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1263         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1264         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1265         PID1=$!
1266         sleep 1
1267         rm $DIR2/$tfile || error "unlink must succeed"
1268         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1269         rm -r $DIR1/*
1270         return 0
1271 }
1272 run_test 41d "pdirops: create vs unlink =============="
1273
1274 test_41e() {
1275         touch $DIR1/$tfile-2
1276 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1277         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1278         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1279         PID1=$!
1280         sleep 1
1281         mv $DIR2/$tfile-2 $DIR2/$tfile || error "rename must succeed"
1282         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1283         rm -r $DIR1/*
1284         return 0
1285 }
1286 run_test 41e "pdirops: create and rename (tgt) =============="
1287
1288 test_41f() {
1289 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1290         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1291         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1292         PID1=$!
1293         sleep 1
1294         mv $DIR2/$tfile $DIR2/$tfile-2 || error "rename must succeed"
1295         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1296         rm -r $DIR1/*
1297         return 0
1298 }
1299 run_test 41f "pdirops: create and rename (src) =============="
1300
1301 test_41g() {
1302 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1303         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1304         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1305         PID1=$!
1306         sleep 1
1307         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
1308         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1309         rm -r $DIR1/*
1310         return 0
1311 }
1312 run_test 41g "pdirops: create vs getattr =============="
1313
1314 test_41h() {
1315 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1316         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1317         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1318         PID1=$!
1319         sleep 1
1320         ls -lia $DIR2/ > /dev/null
1321         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1322         rm -r $DIR1/*
1323         return 0
1324 }
1325 run_test 41h "pdirops: create vs readdir =============="
1326
1327 # test 42: unlink and blocking operations
1328 test_42a() {
1329 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1330         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1331         mkdir $DIR1/$tfile &
1332         PID1=$!
1333         sleep 1
1334         mkdir $DIR2/$tfile && error "mkdir must fail"
1335         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1336         rm -r $DIR1/*
1337         return 0
1338 }
1339 run_test 42a "pdirops: mkdir vs mkdir =============="
1340
1341 test_42b() {
1342 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1343         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1344         mkdir $DIR1/$tfile &
1345         PID1=$!
1346         sleep 1
1347         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
1348         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1349         rm -r $DIR1/*
1350         return 0
1351 }
1352 run_test 42b "pdirops: mkdir vs create =============="
1353
1354 test_42c() {
1355         touch $DIR1/$tfile-2
1356 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1357         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1358         mkdir $DIR1/$tfile &
1359         PID1=$!
1360         sleep 1
1361         link $DIR2/$tfile-2 $DIR2/$tfile && error "link must fail"
1362         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1363         rm -r $DIR1/*
1364         return 0
1365 }
1366 run_test 42c "pdirops: mkdir vs link =============="
1367
1368 test_42d() {
1369 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1370         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1371         mkdir $DIR1/$tfile &
1372         PID1=$!
1373         sleep 1
1374         rmdir $DIR2/$tfile || error "unlink must succeed"
1375         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1376         rm -r $DIR1/*
1377         return 0
1378 }
1379 run_test 42d "pdirops: mkdir vs unlink =============="
1380
1381 test_42e() {
1382         touch $DIR1/$tfile-2
1383 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1384         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1385         mkdir $DIR1/$tfile &
1386         PID1=$!
1387         sleep 1
1388         mv -T $DIR2/$tfile-2 $DIR2/$tfile && error "rename must fail"
1389         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1390         rm -r $DIR1/*
1391         return 0
1392 }
1393 run_test 42e "pdirops: mkdir and rename (tgt) =============="
1394
1395 test_42f() {
1396 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1397         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1398         mkdir $DIR1/$tfile &
1399         PID1=$!
1400         sleep 1
1401         mv $DIR2/$tfile $DIR2/$tfile-2 || error "rename must succeed"
1402         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1403         rm -r $DIR1/*
1404         return 0
1405 }
1406 run_test 42f "pdirops: mkdir and rename (src) =============="
1407
1408 test_42g() {
1409 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1410         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1411         mkdir $DIR1/$tfile &
1412         PID1=$!
1413         sleep 1
1414         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
1415         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1416         rm -r $DIR1/*
1417         return 0
1418 }
1419 run_test 42g "pdirops: mkdir vs getattr =============="
1420
1421 test_42h() {
1422 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1423         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1424         mkdir $DIR1/$tfile &
1425         PID1=$!
1426         sleep 1
1427         ls -lia $DIR2/ > /dev/null
1428         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1429         rm -r $DIR1/*
1430         return 0
1431 }
1432 run_test 42h "pdirops: mkdir vs readdir =============="
1433
1434 # test 43: unlink and blocking operations
1435 test_43a() {
1436         touch $DIR1/$tfile
1437 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1438         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1439         rm $DIR1/$tfile &
1440         PID1=$!
1441         sleep 1
1442         mkdir $DIR2/$tfile || error "mkdir must succeed"
1443         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1444         rm -r $DIR1/*
1445         return 0
1446 }
1447 run_test 43a "pdirops: unlink vs mkdir =============="
1448
1449 test_43b() {
1450         touch $DIR1/$tfile
1451 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1452         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1453         rm $DIR1/$tfile &
1454         PID1=$!
1455         sleep 1
1456         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c || error "create must succeed"
1457         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1458         rm -r $DIR1/*
1459         return 0
1460 }
1461 run_test 43b "pdirops: unlink vs create =============="
1462
1463 test_43c() {
1464         touch $DIR1/$tfile
1465         touch $DIR1/$tfile-2
1466 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1467         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1468         rm $DIR1/$tfile &
1469         PID1=$!
1470         sleep 1
1471         link $DIR2/$tfile-2 $DIR2/$tfile || error "link must succeed"
1472         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1473         rm -r $DIR1/*
1474         return 0
1475 }
1476 run_test 43c "pdirops: unlink vs link =============="
1477
1478 test_43d() {
1479         touch $DIR1/$tfile
1480 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1481         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1482         rm $DIR1/$tfile &
1483         PID1=$!
1484         sleep 1
1485         rm $DIR2/$tfile && error "unlink must fail"
1486         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1487         rm -r $DIR1/*
1488         return 0
1489 }
1490 run_test 43d "pdirops: unlink vs unlink =============="
1491
1492 test_43e() {
1493         touch $DIR1/$tfile
1494         touch $DIR1/$tfile-2
1495 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1496         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1497         rm $DIR1/$tfile &
1498         PID1=$!
1499         sleep 1
1500         mv -u $DIR2/$tfile-2 $DIR2/$tfile || error "rename must succeed"
1501         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1502         rm -r $DIR1/*
1503         return 0
1504 }
1505 run_test 43e "pdirops: unlink and rename (tgt) =============="
1506
1507 test_43f() {
1508         touch $DIR1/$tfile
1509 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1510         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1511         rm $DIR1/$tfile &
1512         PID1=$!
1513         sleep 1
1514         mv $DIR2/$tfile $DIR2/$tfile-2 && error "rename must fail"
1515         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1516         rm -r $DIR1/*
1517         return 0
1518 }
1519 run_test 43f "pdirops: unlink and rename (src) =============="
1520
1521 test_43g() {
1522         touch $DIR1/$tfile
1523 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1524         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1525         rm $DIR1/$tfile &
1526         PID1=$!
1527         sleep 1
1528         stat $DIR2/$tfile > /dev/null && error "stat must fail"
1529         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1530         rm -r $DIR1/*
1531         return 0
1532 }
1533 run_test 43g "pdirops: unlink vs getattr =============="
1534
1535 test_43h() {
1536         touch $DIR1/$tfile
1537 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1538         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1539         rm $DIR1/$tfile &
1540         PID1=$!
1541         sleep 1
1542         ls -lia $DIR2/ > /dev/null
1543         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1544         rm -r $DIR1/*
1545         return 0
1546 }
1547 run_test 43h "pdirops: unlink vs readdir =============="
1548
1549 # test 44: rename tgt and blocking operations
1550 test_44a() {
1551         touch $DIR1/$tfile-2
1552 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
1553         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1554         mv $DIR1/$tfile-2 $DIR1/$tfile &
1555         PID1=$!
1556         sleep 1
1557         mkdir $DIR2/$tfile && error "mkdir must fail"
1558         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1559         rm -r $DIR1/*
1560         return 0
1561 }
1562 run_test 44a "pdirops: rename tgt vs mkdir =============="
1563
1564 test_44b() {
1565         touch $DIR1/$tfile-2
1566 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1567         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1568         mv $DIR1/$tfile-2 $DIR1/$tfile &
1569         PID1=$!
1570         sleep 1
1571         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
1572         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1573         rm -r $DIR1/*
1574         return 0
1575 }
1576 run_test 44b "pdirops: rename tgt vs create =============="
1577
1578 test_44c() {
1579         touch $DIR1/$tfile-2
1580         touch $DIR1/$tfile-3
1581 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1582         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1583         mv $DIR1/$tfile-2 $DIR1/$tfile &
1584         PID1=$!
1585         sleep 1
1586         link $DIR2/$tfile-3 $DIR2/$tfile && error "link must fail"
1587         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1588         rm -r $DIR1/*
1589         return 0
1590 }
1591 run_test 44c "pdirops: rename tgt vs link =============="
1592
1593 test_44d() {
1594         touch $DIR1/$tfile-2
1595 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1596         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1597         mv $DIR1/$tfile-2 $DIR1/$tfile &
1598         PID1=$!
1599         sleep 1
1600         rm $DIR2/$tfile || error "unlink must succeed"
1601         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1602         rm -r $DIR1/*
1603         return 0
1604 }
1605 run_test 44d "pdirops: rename tgt vs unlink =============="
1606
1607 test_44e() {
1608         touch $DIR1/$tfile
1609         touch $DIR1/$tfile-2
1610         touch $DIR1/$tfile-3
1611 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1612         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1613         mv $DIR1/$tfile-2 $DIR1/$tfile &
1614         PID1=$!
1615         sleep 1
1616         mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
1617         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1618         rm -r $DIR1/*
1619         return 0
1620 }
1621 run_test 44e "pdirops: rename tgt and rename (tgt) =============="
1622
1623 test_44f() {
1624         touch $DIR1/$tfile-2
1625         touch $DIR1/$tfile-3
1626 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1627         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1628         mv $DIR1/$tfile-2 $DIR1/$tfile &
1629         PID1=$!
1630         sleep 1
1631         mv $DIR2/$tfile $DIR2/$tfile-3 || error "rename must succeed"
1632         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1633         rm -r $DIR1/*
1634         return 0
1635 }
1636 run_test 44f "pdirops: rename tgt and rename (src) =============="
1637
1638 test_44g() {
1639         touch $DIR1/$tfile-2
1640 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1641         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1642         mv $DIR1/$tfile-2 $DIR1/$tfile &
1643         PID1=$!
1644         sleep 1
1645         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
1646         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1647         rm -r $DIR1/*
1648         return 0
1649 }
1650 run_test 44g "pdirops: rename tgt vs getattr =============="
1651
1652 test_44h() {
1653         touch $DIR1/$tfile-2
1654 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1655         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1656         mv $DIR1/$tfile-2 $DIR1/$tfile &
1657         PID1=$!
1658         sleep 1
1659         ls -lia $DIR2/ > /dev/null
1660         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1661         rm -r $DIR1/*
1662         return 0
1663 }
1664 run_test 44h "pdirops: rename tgt vs readdir =============="
1665
1666 # test 45: rename src and blocking operations
1667 test_45a() {
1668         touch $DIR1/$tfile
1669 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1670         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1671         mv $DIR1/$tfile $DIR1/$tfile-2 &
1672         PID1=$!
1673         sleep 1
1674         mkdir $DIR2/$tfile || error "mkdir must succeed"
1675         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1676         rm -r $DIR1/*
1677         return 0
1678 }
1679 run_test 45a "pdirops: rename src vs mkdir =============="
1680
1681 test_45b() {
1682         touch $DIR1/$tfile
1683 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1684         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1685         mv $DIR1/$tfile $DIR1/$tfile-2 &
1686         PID1=$!
1687         sleep 1
1688         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c || error "create must succeed"
1689         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1690         rm -r $DIR1/*
1691         return 0
1692 }
1693 run_test 45b "pdirops: rename src vs create =============="
1694
1695 test_45c() {
1696         touch $DIR1/$tfile
1697         touch $DIR1/$tfile-3
1698 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1699         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1700         mv $DIR1/$tfile $DIR1/$tfile-2 &
1701         PID1=$!
1702         sleep 1
1703         link $DIR2/$tfile-3 $DIR2/$tfile || error "link must succeed"
1704         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1705         rm -r $DIR1/*
1706         return 0
1707 }
1708 run_test 45c "pdirops: rename src vs link =============="
1709
1710 test_45d() {
1711         touch $DIR1/$tfile
1712 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1713         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1714         mv $DIR1/$tfile $DIR1/$tfile-2 &
1715         PID1=$!
1716         sleep 1
1717         rm $DIR2/$tfile && error "unlink must fail"
1718         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1719         rm -r $DIR1/*
1720         return 0
1721 }
1722 run_test 45d "pdirops: rename src vs unlink =============="
1723
1724 test_45e() {
1725         touch $DIR1/$tfile
1726         touch $DIR1/$tfile-3
1727 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1728         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1729         mv $DIR1/$tfile $DIR1/$tfile-2 &
1730         PID1=$!
1731         sleep 1
1732         mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
1733         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1734         rm -r $DIR1/*
1735         return 0
1736 }
1737 run_test 45e "pdirops: rename src and rename (tgt) =============="
1738
1739 test_45f() {
1740         touch $DIR1/$tfile
1741 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1742         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1743         mv $DIR1/$tfile $DIR1/$tfile-2 &
1744         PID1=$!
1745         sleep 1
1746         mv $DIR2/$tfile $DIR2/$tfile-3 && error "rename must fail"
1747         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1748         rm -r $DIR1/*
1749         return 0
1750 }
1751 run_test 45f "pdirops: rename src and rename (src) =============="
1752
1753 test_45g() {
1754         touch $DIR1/$tfile
1755 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1756         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1757         mv $DIR1/$tfile $DIR1/$tfile-2 &
1758         PID1=$!
1759         sleep 1
1760         stat $DIR2/$tfile > /dev/null && "stat must fail"
1761         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1762         rm -r $DIR1/*
1763         return 0
1764 }
1765 run_test 45g "pdirops: rename src vs getattr =============="
1766
1767 test_45h() {
1768         touch $DIR1/$tfile
1769 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1770         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1771         mv $DIR1/$tfile $DIR1/$tfile-2 &
1772         PID1=$!
1773         sleep 1
1774         ls -lia $DIR2/ > /dev/null
1775         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1776         rm -r $DIR1/*
1777         return 0
1778 }
1779 run_test 45h "pdirops: unlink vs readdir =============="
1780
1781 # test 46: link and blocking operations
1782 test_46a() {
1783         touch $DIR1/$tfile-2
1784 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1785         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1786         link $DIR1/$tfile-2 $DIR1/$tfile &
1787         PID1=$!
1788         sleep 1
1789         mkdir $DIR2/$tfile && error "mkdir must fail"
1790         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1791         rm -r $DIR1/*
1792         return 0
1793 }
1794 run_test 46a "pdirops: link vs mkdir =============="
1795
1796 test_46b() {
1797         touch $DIR1/$tfile-2
1798 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1799         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1800         link $DIR1/$tfile-2 $DIR1/$tfile &
1801         PID1=$!
1802         sleep 1
1803         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
1804         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1805         rm -r $DIR1/*
1806         return 0
1807 }
1808 run_test 46b "pdirops: link vs create =============="
1809
1810 test_46c() {
1811         touch $DIR1/$tfile-2
1812 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1813         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1814         link $DIR1/$tfile-2 $DIR1/$tfile &
1815         PID1=$!
1816         sleep 1
1817         link $DIR2/$tfile $DIR2/$tfile && error "link must fail"
1818         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1819         rm -r $DIR1/*
1820         return 0
1821 }
1822 run_test 46c "pdirops: link vs link =============="
1823
1824 test_46d() {
1825         touch $DIR1/$tfile-2
1826 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1827         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1828         link $DIR1/$tfile-2 $DIR1/$tfile &
1829         PID1=$!
1830         sleep 1
1831         rm $DIR2/$tfile || error "unlink must succeed"
1832         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1833         rm -r $DIR1/*
1834         return 0
1835 }
1836 run_test 46d "pdirops: link vs unlink =============="
1837
1838 test_46e() {
1839         touch $DIR1/$tfile-2
1840         touch $DIR1/$tfile-3
1841 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1842         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1843         link $DIR1/$tfile-2 $DIR1/$tfile &
1844         PID1=$!
1845         sleep 1
1846         mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
1847         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1848         rm -r $DIR1/*
1849         return 0
1850 }
1851 run_test 46e "pdirops: link and rename (tgt) =============="
1852
1853 test_46f() {
1854         touch $DIR1/$tfile-2
1855         touch $DIR1/$tfile-3
1856 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1857         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1858         link $DIR1/$tfile-2 $DIR1/$tfile &
1859         PID1=$!
1860         sleep 1
1861         mv $DIR2/$tfile $DIR2/$tfile-3 || error "rename must succeed"
1862         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1863         rm -r $DIR1/*
1864         return 0
1865 }
1866 run_test 46f "pdirops: link and rename (src) =============="
1867
1868 test_46g() {
1869         touch $DIR1/$tfile-2
1870 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1871         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1872         link $DIR1/$tfile-2 $DIR1/$tfile &
1873         PID1=$!
1874         sleep 1
1875         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
1876         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1877         rm -r $DIR1/*
1878         return 0
1879 }
1880 run_test 46g "pdirops: link vs getattr =============="
1881
1882 test_46h() {
1883         touch $DIR1/$tfile-2
1884 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1885         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1886         link $DIR1/$tfile-2 $DIR1/$tfile &
1887         PID1=$!
1888         sleep 1
1889         ls -lia $DIR2/ > /dev/null
1890         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1891         rm -r $DIR1/*
1892         return 0
1893 }
1894 run_test 46h "pdirops: link vs readdir =============="
1895
1896 test_50() {
1897         trunc_size=4096
1898         dd if=/dev/zero of=$DIR1/$tfile bs=1K count=10
1899 #define OBD_FAIL_OSC_CP_ENQ_RACE         0x410
1900         do_facet client "lctl set_param fail_loc=0x410"
1901         $TRUNCATE $DIR2/$tfile $trunc_size
1902         do_facet client "lctl set_param fail_loc=0x0"
1903         sleep 3
1904         size=`stat -c %s $DIR2/$tfile`
1905         [ $size -eq $trunc_size ] || error "wrong size"
1906 }
1907 run_test 50 "osc lvb attrs: enqueue vs. CP AST =============="
1908
1909 test_60() {
1910         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
1911         { skip "Need MDS version at least 2.3.0"; return; }
1912         # Create a file
1913         mkdir -p $DIR1/$tdir
1914         file1=$DIR1/$tdir/file
1915         file2=$DIR2/$tdir/file
1916
1917         echo orig > $file2 || error "Could not create $file2"
1918         version=$($LFS data_version $file1)
1919
1920         # Append data
1921         echo append >> $file2 || error "Could not append to $file2"
1922         version2=$($LFS data_version $file1)
1923         [ "$version" != "$version2" ] ||
1924             error "append did not change data version: $version"
1925
1926         # Overwrite data
1927         echo overwrite > $file2 || error "Could not overwrite $file2"
1928         version3=$($LFS data_version $file1)
1929         [ "$version2" != "$version3" ] ||
1930             error "overwrite did not change data version: $version2"
1931
1932         # Truncate before EOF
1933         $TRUNCATE $file2 3 || error "Could not truncate $file2"
1934         version4=$($LFS data_version $file1)
1935         [ "$version3" != "$version4" ] ||
1936             error "truncate did not change data version: $version3"
1937
1938         # Truncate after EOF
1939         $TRUNCATE $file2 123456 || error "Could not truncate $file2"
1940         version5=$($LFS data_version $file1)
1941         [ "$version4" != "$version5" ] ||
1942             error "truncate did not change data version: $version4"
1943
1944         # Chmod do not change version
1945         chmod 400 $file2 || error "Could not chmod 400 $file2"
1946         version6=$($LFS data_version $file1)
1947         [ "$version5" == "$version6" ] ||
1948             error "chmod should not change data version: $version5 != $version6"
1949
1950         # Chown do not change version
1951         chown $RUNAS_ID $file2 || error "Could not chown $RUNAS_ID $file2"
1952         version7=$($LFS data_version $file1)
1953         [ "$version5" == "$version7" ] ||
1954             error "chown should not change data version: $version5 != $version7"
1955 }
1956 run_test 60 "Verify data_version behaviour"
1957
1958 log "cleanup: ======================================================"
1959
1960 [ "$(mount | grep $MOUNT2)" ] && umount $MOUNT2
1961
1962 complete $(basename $0) $SECONDS
1963 check_and_cleanup_lustre
1964 exit_status