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