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