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