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