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