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