Whamcloud - gitweb
LU-6570 tests: fix 40a in sanityn.sh
[fs/lustre-release.git] / lustre / tests / sanityn.sh
1 #!/bin/bash
2
3 set -e
4
5 ONLY=${ONLY:-"$*"}
6 # bug number for skipped test: 3192 LU-1205 15528/3811 9977 15528/11549 18080
7 ALWAYS_EXCEPT="                14b  18c     19         28   29          35    $SANITYN_EXCEPT"
8 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
9
10 SRCDIR=$(dirname $0)
11 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
12
13 SIZE=${SIZE:-40960}
14 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
15 OPENFILE=${OPENFILE:-openfile}
16 OPENUNLINK=${OPENUNLINK:-openunlink}
17 export MULTIOP=${MULTIOP:-multiop}
18 export TMP=${TMP:-/tmp}
19 MOUNT_2=${MOUNT_2:-"yes"}
20 CHECK_GRANT=${CHECK_GRANT:-"yes"}
21 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
22
23 SAVE_PWD=$PWD
24
25 export NAME=${NAME:-local}
26
27 LUSTRE=${LUSTRE:-`dirname $0`/..}
28 . $LUSTRE/tests/test-framework.sh
29 CLEANUP=${CLEANUP:-:}
30 SETUP=${SETUP:-:}
31 init_test_env $@
32 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
33 init_logging
34
35 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
36 # bug number for skipped test:        LU-2189 LU-2776
37         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 36      51a"
38 # LU-2829 / LU-2887 - make allowances for ZFS slowness
39         TEST33_NFILES=${TEST33_NFILES:-1000}
40 fi
41
42 [ "$SLOW" = "no" ] && EXCEPT_SLOW="33a"
43
44 FAIL_ON_ERROR=false
45
46 SETUP=${SETUP:-:}
47 TRACE=${TRACE:-""}
48
49 check_and_setup_lustre
50
51 LOVNAME=$($LCTL get_param -n llite.*.lov.common_name | tail -n 1)
52 OSTCOUNT=$($LCTL get_param -n lov.$LOVNAME.numobd)
53
54 assert_DIR
55 rm -rf $DIR1/[df][0-9]* $DIR1/lnk $DIR/[df].${TESTSUITE}*
56
57 SAMPLE_FILE=$TMP/$(basename $0 .sh).junk
58 dd if=/dev/urandom of=$SAMPLE_FILE bs=1M count=1
59
60 # $RUNAS_ID may get set incorrectly somewhere else
61 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
62
63 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
64
65 build_test_filter
66
67 mkdir -p $MOUNT2
68 mount_client $MOUNT2
69
70 test_1a() {
71         touch $DIR1/f1
72         [ -f $DIR2/f1 ] || error
73 }
74 run_test 1a "check create on 2 mtpt's =========================="
75
76 test_1b() {
77         chmod 777 $DIR2/f1
78         $CHECKSTAT -t file -p 0777 $DIR1/f1 || error
79         chmod a-x $DIR2/f1
80 }
81 run_test 1b "check attribute updates on 2 mtpt's ==============="
82
83 test_1c() {
84         $CHECKSTAT -t file -p 0666 $DIR1/f1 || error
85 }
86 run_test 1c "check after remount attribute updates on 2 mtpt's ="
87
88 test_1d() {
89         rm $DIR2/f1
90         $CHECKSTAT -a $DIR1/f1 || error
91 }
92 run_test 1d "unlink on one mountpoint removes file on other ===="
93
94 test_2a() {
95         touch $DIR1/f2a
96         ls -l $DIR2/f2a
97         chmod 777 $DIR2/f2a
98         $CHECKSTAT -t file -p 0777 $DIR1/f2a || error
99 }
100 run_test 2a "check cached attribute updates on 2 mtpt's ========"
101
102 test_2b() {
103         touch $DIR1/f2b
104         ls -l $DIR2/f2b
105         chmod 777 $DIR1/f2b
106         $CHECKSTAT -t file -p 0777 $DIR2/f2b || error
107 }
108 run_test 2b "check cached attribute updates on 2 mtpt's ========"
109
110 # NEED TO SAVE ROOT DIR MODE
111 test_2c() {
112         chmod 777 $DIR1
113         $CHECKSTAT -t dir -p 0777 $DIR2 || error
114 }
115 run_test 2c "check cached attribute updates on 2 mtpt's root ==="
116
117 test_2d() {
118         chmod 755 $DIR1
119         $CHECKSTAT -t dir -p 0755 $DIR2 || error
120 }
121 run_test 2d "check cached attribute updates on 2 mtpt's root ==="
122
123 test_2e() {
124         chmod 755 $DIR1
125         ls -l $DIR1
126         ls -l $DIR2
127         chmod 777 $DIR1
128         $RUNAS dd if=/dev/zero of=$DIR2/$tfile count=1 || error
129 }
130 run_test 2e "check chmod on root is propagated to others"
131
132 test_2f() {
133         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
134         local MDTIDX=1
135         local remote_dir=$tdir/remote_dir
136
137         mkdir -p $DIR1/$tdir
138         $LFS mkdir -i $MDTIDX $DIR1/$remote_dir ||
139                    error "Create remote directory failed"
140
141         touch $DIR1/$remote_dir/$tfile ||
142                 error "Create file under remote directory failed"
143         chmod 777 $DIR1/$remote_dir/$tfile ||
144                 error "Chmod file under remote directory failed"
145
146         $CHECKSTAT -t file -p 0777 $DIR2/$remote_dir/$tfile ||
147                 error "Check attr of file under remote directory failed"
148
149         chown $RUNAS_ID:$RUNAS_GID $DIR1/$remote_dir/$tfile ||
150                 error "Chown file under remote directory failed"
151
152         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR2/$remote_dir/$tfile ||
153                 error "Check owner of file under remote directory failed"
154
155         cd $DIR2/$remote_dir || error "enter remote dir"
156         rm -rf $DIR1/$remote_dir/$tfile ||
157                 error "Unlink remote directory failed"
158
159         $CHECKSTAT -t file $DIR2/$remote_dir/$tfile &&
160                 error "unlink file still exists!"
161
162         cd $DIR2/$tdir || error "exit remote dir"
163         rm -rf $DIR1/$tdir || error "unlink directory failed"
164 }
165 run_test 2f "check attr/owner updates on DNE with 2 mtpt's"
166
167 test_2g() {
168         dd if=/dev/zero of=$DIR1/$tfile oflag=sync bs=1M count=2
169
170         local block1=$(stat $DIR1/$tfile | awk '/Blocks/ {print $4} ')
171         cancel_lru_locks osc
172         local block2=$(stat $DIR2/$tfile | awk '/Blocks/ {print $4} ')
173         echo "$DIR1/$tfile has $block1 blocks"
174         echo "$DIR2/$tfile has $block2 blocks"
175         [ $block1 -eq $block2 ] || error
176 }
177 run_test 2g "check blocks update on sync write"
178
179 test_3() {
180         local target="this/is/good"
181         ln -s $target $DIR1/$tfile || error "ln -s $target $DIR1/$tfile failed"
182         [ "$(ls -l $DIR2/$tfile | sed -e 's/.* -> //')" = "$target" ] ||
183                 error "link $DIR2/$tfile not as expected"
184 }
185 run_test 3 "symlink on one mtpt, readlink on another ==========="
186
187 test_4() {
188         multifstat $DIR1/f4 $DIR2/f4
189 }
190 run_test 4 "fstat validation on multiple mount points =========="
191
192 test_5() {
193         mcreate $DIR1/f5
194         $TRUNCATE $DIR2/f5 100
195         $CHECKSTAT -t file -s 100 $DIR1/f5 || error
196         rm $DIR1/f5
197 }
198 run_test 5 "create a file on one mount, truncate it on the other"
199
200 test_6() {
201         openunlink $DIR1/$tfile $DIR2/$tfile || \
202                 error "openunlink $DIR1/$tfile $DIR2/$tfile"
203 }
204 run_test 6 "remove of open file on other node =================="
205
206 test_7() {
207         local dir=d7
208         opendirunlink $DIR1/$dir $DIR2/$dir || \
209                 error "opendirunlink $DIR1/$dir $DIR2/$dir"
210 }
211 run_test 7 "remove of open directory on other node ============="
212
213 test_8() {
214         opendevunlink $DIR1/$tfile $DIR2/$tfile || \
215                 error "opendevunlink $DIR1/$tfile $DIR2/$tfile"
216 }
217 run_test 8 "remove of open special file on other node =========="
218
219 test_9() {
220         MTPT=1
221         local dir
222         > $DIR2/f9
223         for C in a b c d e f g h i j k l; do
224                 dir=`eval echo \\$DIR$MTPT`
225                 echo -n $C >> $dir/f9
226                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
227         done
228         [ "`cat $DIR1/f9`" = "abcdefghijkl" ] || \
229                 error "`od -a $DIR1/f9` != abcdefghijkl"
230 }
231 run_test 9 "append of file with sub-page size on multiple mounts"
232
233 test_10a() {
234         MTPT=1
235         local dir
236         OFFSET=0
237         > $DIR2/f10
238         for C in a b c d e f g h i j k l; do
239                 dir=`eval echo \\$DIR$MTPT`
240                 echo -n $C | dd of=$dir/f10 bs=1 seek=$OFFSET count=1
241                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
242                 OFFSET=`expr $OFFSET + 1`
243         done
244         [ "`cat $DIR1/f10`" = "abcdefghijkl" ] || \
245                 error "`od -a $DIR1/f10` != abcdefghijkl"
246 }
247 run_test 10a "write of file with sub-page size on multiple mounts "
248
249 test_10b() {
250         # create a seed file
251         yes "R" | head -c 4000 >$TMP/f10b-seed
252         dd if=$TMP/f10b-seed of=$DIR1/f10b bs=3k count=1 || error "dd $DIR1"
253
254         $TRUNCATE $DIR1/f10b 4096 || error "truncate 4096"
255
256         dd if=$DIR2/f10b of=$TMP/f10b-lustre bs=4k count=1 || error "dd $DIR2"
257
258         # create a test file locally to compare
259         dd if=$TMP/f10b-seed of=$TMP/f10b bs=3k count=1 || error "dd random"
260         $TRUNCATE $TMP/f10b 4096 || error "truncate 4096"
261         cmp $TMP/f10b $TMP/f10b-lustre || error "file miscompare"
262         rm $TMP/f10b $TMP/f10b-lustre $TMP/f10b-seed
263 }
264 run_test 10b "write of file with sub-page size on multiple mounts "
265
266 test_11() {
267         test_mkdir $DIR1/d11
268         multiop_bg_pause $DIR1/d11/f O_c || return 1
269         MULTIPID=$!
270         cp -p /bin/ls $DIR1/d11/f
271         $DIR2/d11/f
272         RC=$?
273         kill -USR1 $MULTIPID
274         wait $MULTIPID || error
275         [ $RC -eq 0 ] && error || true
276 }
277 run_test 11 "execution of file opened for write should return error ===="
278
279 test_12() {
280        DIR=$DIR DIR2=$DIR2 sh lockorder.sh
281 }
282 run_test 12 "test lock ordering (link, stat, unlink) ==========="
283
284 test_13() {     # bug 2451 - directory coherency
285         test_mkdir $DIR1/d13 || error
286        cd $DIR1/d13 || error
287        ls
288        ( touch $DIR1/d13/f13 ) # needs to be a separate shell
289        ls
290        rm -f $DIR2/d13/f13 || error
291        ls 2>&1 | grep f13 && error "f13 shouldn't return an error (1)" || true
292        # need to run it twice
293        ( touch $DIR1/d13/f13 ) # needs to be a separate shell
294        ls
295        rm -f $DIR2/d13/f13 || error
296        ls 2>&1 | grep f13 && error "f13 shouldn't return an error (2)" || true
297 }
298 run_test 13 "test directory page revocation ===================="
299
300 test_14() {
301         test_mkdir -p $DIR1/$tdir
302         cp -p /bin/ls $DIR1/$tdir/$tfile
303         multiop_bg_pause $DIR1/$tdir/$tfile Ow_c || return 1
304         MULTIPID=$!
305
306         $DIR2/$tdir/$tfile && error || true
307         kill -USR1 $MULTIPID
308         wait $MULTIPID || return 2
309 }
310 run_test 14 "execution of file open for write returns -ETXTBSY ="
311
312 test_14a() {
313         test_mkdir -p $DIR1/d14
314         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
315         MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
316         MULTIOP_PID=$!
317         $MULTIOP $DIR2/d14/multiop Oc && error "expected error, got success"
318         kill -USR1 $MULTIOP_PID || return 2
319         wait $MULTIOP_PID || return 3
320         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
321 }
322 run_test 14a "open(RDWR) of executing file returns -ETXTBSY ===="
323
324 test_14b() { # bug 3192, 7040
325         test_mkdir -p $DIR1/d14
326         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
327         MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
328         MULTIOP_PID=$!
329         $TRUNCATE $DIR2/d14/multiop 0 && kill -9 $MULTIOP_PID && \
330                 error "expected truncate error, got success"
331         kill -USR1 $MULTIOP_PID || return 2
332         wait $MULTIOP_PID || return 3
333         cmp `which multiop` $DIR1/d14/multiop || error "binary changed"
334         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
335 }
336 run_test 14b "truncate of executing file returns -ETXTBSY ======"
337
338 test_14c() { # bug 3430, 7040
339         test_mkdir -p $DIR1/d14
340         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
341         MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
342         MULTIOP_PID=$!
343         cp /etc/hosts $DIR2/d14/multiop && error "expected error, got success"
344         kill -USR1 $MULTIOP_PID || return 2
345         wait $MULTIOP_PID || return 3
346         cmp `which multiop` $DIR1/d14/multiop || error "binary changed"
347         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
348 }
349 run_test 14c "open(O_TRUNC) of executing file return -ETXTBSY =="
350
351 test_14d() { # bug 10921
352         test_mkdir -p $DIR1/d14
353         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
354         MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
355         MULTIOP_PID=$!
356         log chmod
357         chmod 600 $DIR1/d14/multiop || error "chmod failed"
358         kill -USR1 $MULTIOP_PID || return 2
359         wait $MULTIOP_PID || return 3
360         cmp `which multiop` $DIR1/d14/multiop || error "binary changed"
361         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
362 }
363 run_test 14d "chmod of executing file is still possible ========"
364
365 test_15() {     # bug 974 - ENOSPC
366         echo "PATH=$PATH"
367         sh oos2.sh $MOUNT1 $MOUNT2
368         wait_delete_completed
369         grant_error=`dmesg | grep "> available"`
370         [ -z "$grant_error" ] || error "$grant_error"
371 }
372 run_test 15 "test out-of-space with multiple writers ==========="
373
374 COUNT=${COUNT:-2500}
375 # The FSXNUM reduction for ZFS is needed until ORI-487 is fixed.
376 # We don't want to skip it entirely, but ZFS is VERY slow and cannot
377 # pass a 2500 operation dual-mount run within the time limit.
378 if [ "$(facet_fstype ost1)" = "zfs" ]; then
379         FSXNUM=$((COUNT / 5))
380         FSXP=1
381 elif [ "$SLOW" = "yes" ]; then
382         FSXNUM=$((COUNT * 5))
383         FSXP=500
384 else
385         FSXNUM=$COUNT
386         FSXP=100
387 fi
388
389 test_16() {
390         local file1=$DIR1/$tfile
391         local file2=$DIR2/$tfile
392
393         # to allocate grant because it may run out due to test_15.
394         lfs setstripe -c -1 $file1
395         dd if=/dev/zero of=$file1 bs=$STRIPE_BYTES count=$OSTCOUNT oflag=sync
396         dd if=/dev/zero of=$file2 bs=$STRIPE_BYTES count=$OSTCOUNT oflag=sync
397         rm -f $file1
398
399         lfs setstripe -c -1 $file1 # b=10919
400         fsx -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -S 0 $file1 $file2
401 }
402 run_test 16 "$FSXNUM iterations of dual-mount fsx"
403
404 test_17() { # bug 3513, 3667
405         remote_ost_nodsh && skip "remote OST with nodsh" && return
406
407         lfs setstripe $DIR1/$tfile -i 0 -c 1
408         cp $SAMPLE_FILE $DIR1/$tfile
409         cancel_lru_locks osc > /dev/null
410         #define OBD_FAIL_ONCE|OBD_FAIL_LDLM_CREATE_RESOURCE    0x30a
411         do_facet ost1 lctl set_param fail_loc=0x8000030a
412         ls -ls $DIR1/$tfile | awk '{ print $1,$6 }' > $DIR1/$tfile-1 & \
413         ls -ls $DIR2/$tfile | awk '{ print $1,$6 }' > $DIR2/$tfile-2
414         wait
415         diff -u $DIR1/$tfile-1 $DIR2/$tfile-2 || error "files are different"
416 }
417 run_test 17 "resource creation/LVB creation race ==============="
418
419 test_18() {
420         # turn e.g. ALWAYS_EXCEPT="18c" into "-e 3"
421         local idx
422         local excepts=
423         for idx in {a..z}; do
424                 local ptr=EXCEPT_ALWAYS_18$idx
425                 [ x${!ptr} = xtrue ] || continue
426
427                 excepts="$excepts -e $(($(printf %d \'$idx)-96))"
428         done
429
430         $LUSTRE/tests/mmap_sanity -d $MOUNT1 -m $MOUNT2 $excepts
431         sync; sleep 1; sync
432 }
433 run_test 18 "mmap sanity check ================================="
434
435 test_19() { # bug3811
436         local node=$(facet_active_host ost1)
437
438         # check whether obdfilter is cache capable at all
439         if ! get_osd_param $node '' read_cache_enable >/dev/null; then
440                 echo "not cache-capable obdfilter"
441                 return 0
442         fi
443
444         local MAX=$(get_osd_param $node '' readcache_max_filesize | \
445                     head -n 1)
446         set_osd_param $node '' readcache_max_filesize 4096
447         dd if=/dev/urandom of=$TMP/$tfile bs=512k count=32
448         local SUM=$(cksum $TMP/$tfile | cut -d" " -f 1,2)
449         cp $TMP/$tfile $DIR1/$tfile
450         for i in `seq 1 20`; do
451                 [ $((i % 5)) -eq 0 ] && log "$testname loop $i"
452                 cancel_lru_locks osc > /dev/null
453                 cksum $DIR1/$tfile | cut -d" " -f 1,2 > $TMP/sum1 & \
454                 cksum $DIR2/$tfile | cut -d" " -f 1,2 > $TMP/sum2
455                 wait
456                 [ "$(cat $TMP/sum1)" = "$SUM" ] || \
457                         error "$DIR1/$tfile $(cat $TMP/sum1) != $SUM"
458                 [ "$(cat $TMP/sum2)" = "$SUM" ] || \
459                         error "$DIR2/$tfile $(cat $TMP/sum2) != $SUM"
460         done
461         set_osd_param $node '' readcache_max_filesize $MAX
462         rm $DIR1/$tfile
463 }
464 run_test 19 "test concurrent uncached read races ==============="
465
466 test_20() {
467         test_mkdir $DIR1/d20
468         cancel_lru_locks osc
469         CNT=$((`lctl get_param -n llite.*.dump_page_cache | wc -l`))
470         $MULTIOP $DIR1/f20 Ow8190c
471         $MULTIOP $DIR2/f20 Oz8194w8190c
472         $MULTIOP $DIR1/f20 Oz0r8190c
473         cancel_lru_locks osc
474         CNTD=$((`lctl get_param -n llite.*.dump_page_cache | wc -l` - $CNT))
475         [ $CNTD -gt 0 ] && \
476             error $CNTD" page left in cache after lock cancel" || true
477 }
478 run_test 20 "test extra readahead page left in cache ===="
479
480 cleanup_21() {
481         trap 0
482         umount $DIR1/$tdir
483 }
484
485 test_21() { # Bug 5907
486         test_mkdir $DIR1/$tdir
487         mount /etc $DIR1/$tdir --bind || error "mount failed" # Poor man's mount.
488         trap cleanup_21 EXIT
489         rmdir -v $DIR1/$tdir && error "Removed mounted directory"
490         rmdir -v $DIR2/$tdir && echo "Removed mounted directory from another mountpoint, needs to be fixed"
491         test -d $DIR1/$tdir || error "Mounted directory disappeared"
492         cleanup_21
493         test -d $DIR2/$tdir || test -d $DIR1/$tdir && error "Removed dir still visible after umount"
494         true
495 }
496 run_test 21 " Try to remove mountpoint on another dir ===="
497
498 test_23() { # Bug 5972
499         local at_diff=$(do_facet $SINGLEMDS \
500                 $LCTL get_param -n mdd.*MDT0000*.atime_diff | head -n1)
501         echo "atime should be updated while another read" > $DIR1/$tfile
502
503         # clear the lock(mode: LCK_PW) gotten from creating operation
504         cancel_lru_locks osc
505         time1=$(date +%s)
506         echo "now is $time1"
507         sleep $((at_diff + 1))
508
509         echo "starting reads"
510         multiop_bg_pause $DIR1/$tfile or20_c || return 1
511         # with SOM and opencache enabled, we need to close a file and cancel
512         # open lock to get atime propogated to MDS
513         kill -USR1 $! || return 2
514         cancel_lru_locks mdc
515
516         time2=$(stat -c "%X" $DIR/$tfile)
517         echo "new atime is $time2"
518
519         [ $time2 -gt $time1 ] || error "atime was not updated"
520         rm -f $DIR1/$tfile || error "rm -f $DIR1/$tfile failed"
521         true
522 }
523 run_test 23 " others should see updated atime while another read===="
524
525 test_24a() {
526         touch $DIR1/$tfile
527         lfs df || error "lfs df failed"
528         lfs df -ih || error "lfs df -ih failed"
529         lfs df -h $DIR1 || error "lfs df -h $DIR1 failed"
530         lfs df -i $DIR2 || error "lfs df -i $DIR2 failed"
531         lfs df $DIR1/$tfile || error "lfs df $DIR1/$tfile failed"
532         lfs df -ih $DIR2/$tfile || error "lfs df -ih $DIR2/$tfile failed"
533
534         OSC=`lctl dl | awk '/-osc-|OSC.*MNT/ {print $4}' | head -n 1`
535 #       OSC=`lctl dl | awk '/-osc-/ {print $4}' | head -n 1`
536         lctl --device %$OSC deactivate
537         lfs df -i || error "lfs df -i with deactivated OSC failed"
538         lctl --device %$OSC activate
539         lfs df || error "lfs df with reactivated OSC failed"
540 }
541 run_test 24a "lfs df [-ih] [path] test ========================="
542
543 test_24b() {
544         touch $DIR1/$tfile
545         fsnum=$(lfs_df | grep -c "summary")
546         [ $fsnum -eq 2 ] || error "lfs df shows $fsnum != 2 filesystems."
547 }
548 run_test 24b "lfs df should show both filesystems ==============="
549
550 test_25a() {
551         local acl=$(lctl get_param -n mdc.*MDT0000-mdc-*.connect_flags |
552                                                                 grep -c acl)
553         [ "$acl" -lt 1 ] && skip "must have acl, skipping" && return
554
555         mkdir -p $DIR1/$tdir
556         touch $DIR1/$tdir/f1 || error "touch $DIR1/$tdir/f1"
557         chmod 0755 $DIR1/$tdir/f1 || error "chmod 0755 $DIR1/$tdir/f1"
558
559         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #1"
560         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
561                 error "setfacl $DIR2/$tdir #1"
562         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #2"
563         setfacl -m u:$RUNAS_ID:r-x -m g:$RUNAS_GID:r-x $DIR1/$tdir ||
564                 error "setfacl $DIR2/$tdir #2"
565         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #3"
566         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
567                 error "setfacl $DIR2/$tdir #3"
568         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #4"
569         setfacl -x u:$RUNAS_ID: -x g:$RUNAS_GID: $DIR1/$tdir ||
570                 error "setfacl $DIR2/$tdir #4"
571         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #5"
572
573         rm -rf $DIR1/$tdir
574 }
575 run_test 25a "change ACL on one mountpoint be seen on another ==="
576
577 test_25b() {
578         local acl=$(lctl get_param -n mdc.*MDT0000-mdc-*.connect_flags |
579                                                         grep -c acl)
580         [ "$acl" -lt 1 ] && skip "must have acl, skipping" && return
581
582         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
583
584         rm -rf $DIR1/$tdir
585         $LFS mkdir -i 1 $DIR1/$tdir
586         touch $DIR1/$tdir/f1 || error "touch $DIR1/$tdir/f1"
587         chmod 0755 $DIR1/$tdir/f1 || error "chmod 0755 $DIR1/$tdir/f1"
588
589         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #1"
590         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
591                 error "setfacl $DIR2/$tdir #1"
592         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #2"
593         setfacl -m u:$RUNAS_ID:r-x -m g:$RUNAS_GID:r-x $DIR1/$tdir ||
594                 error "setfacl $DIR2/$tdir #2"
595         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #3"
596         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
597                 error "setfacl $DIR2/$tdir #3"
598         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #4"
599         setfacl -x u:$RUNAS_ID: -x g:$RUNAS_GID: $DIR1/$tdir ||
600                 error "setfacl $DIR2/$tdir #4"
601         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #5"
602
603         rm -rf $DIR1/$tdir
604 }
605 run_test 25b "change ACL under remote dir on one mountpoint be seen on another"
606
607 test_26a() {
608         utime $DIR1/f26a -s $DIR2/f26a || error
609 }
610 run_test 26a "allow mtime to get older"
611
612 test_26b() {
613         touch $DIR1/$tfile
614         sleep 1
615         echo "aaa" >> $DIR1/$tfile
616         sleep 1
617         chmod a+x $DIR2/$tfile
618         mt1=`stat -c %Y $DIR1/$tfile`
619         mt2=`stat -c %Y $DIR2/$tfile`
620
621         if [ x"$mt1" != x"$mt2" ]; then
622                 error "not equal mtime, client1: "$mt1", client2: "$mt2"."
623         fi
624 }
625 run_test 26b "sync mtime between ost and mds"
626
627 test_27() {
628         cancel_lru_locks osc
629         lctl clear
630         dd if=/dev/zero of=$DIR2/$tfile bs=$((4096+4))k conv=notrunc count=4 seek=3 &
631         DD2_PID=$!
632         usleep 50
633         log "dd 1 started"
634
635         dd if=/dev/zero of=$DIR1/$tfile bs=$((16384-1024))k conv=notrunc count=1 seek=4 &
636         DD1_PID=$!
637         log "dd 2 started"
638
639         sleep 1
640         dd if=/dev/zero of=$DIR1/$tfile bs=8k conv=notrunc count=1 seek=0
641         log "dd 3 finished"
642         lctl set_param -n ldlm.dump_namespaces ""
643         wait $DD1_PID $DD2_PID
644         [ $? -ne 0 ] && lctl dk $TMP/debug || true
645 }
646 run_test 27 "align non-overlapping extent locks from request ==="
647
648 test_28() { # bug 9977
649         ECHO_UUID="ECHO_osc1_UUID"
650         tOST=$($LCTL dl | awk '/-osc-|OSC.*MNT/ { print $4 }' | head -n1)
651
652         $LFS setstripe $DIR1/$tfile -S 1048576 -i 0 -c 2
653         tOBJID=`$LFS getstripe $DIR1/$tfile | awk '$1 == 1 {print $2}'`
654         dd if=/dev/zero of=$DIR1/$tfile bs=1024k count=2
655
656         $LCTL <<-EOF
657                 newdev
658                 attach echo_client ECHO_osc1 $ECHO_UUID
659                 setup $tOST
660         EOF
661
662         tECHOID=`$LCTL dl | grep $ECHO_UUID | awk '{ print $1 }'`
663         $LCTL --device $tECHOID destroy "${tOBJID}:0"
664
665         $LCTL <<-EOF
666                 cfg_device ECHO_osc1
667                 cleanup
668                 detach
669         EOF
670
671         # reading of 1st stripe should pass
672         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 || error
673         # reading of 2nd stripe should fail (this stripe was destroyed)
674         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 skip=1 && error
675
676         # now, recreating test file
677         dd if=/dev/zero of=$DIR1/$tfile bs=1024k count=2 || error
678         # reading of 1st stripe should pass
679         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 || error
680         # reading of 2nd stripe should pass
681         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 skip=1 || error
682 }
683 run_test 28 "read/write/truncate file with lost stripes"
684
685 test_29() { # bug 10999
686         touch $DIR1/$tfile
687         #define OBD_FAIL_LDLM_GLIMPSE  0x30f
688         lctl set_param fail_loc=0x8000030f
689         ls -l $DIR2/$tfile &
690         usleep 500
691         dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1
692         wait
693 }
694 #bug 11549 - permanently turn test off in b1_5
695 run_test 29 "lock put race between glimpse and enqueue ========="
696
697 test_30() { #bug #11110, LU-2523
698         test_mkdir -p $DIR1/$tdir
699         cp -f /bin/bash $DIR1/$tdir/bash
700         /bin/sh -c 'sleep 1; rm -f $DIR2/$tdir/bash;
701                     cp /bin/bash $DIR2/$tdir' &
702         $DIR1/$tdir/bash -c 'sleep 2;
703                 openfile -f O_RDONLY /proc/$$/exe >& /dev/null; echo $?'
704         wait
705         true
706 }
707
708 run_test 30 "recreate file race"
709
710 test_31a() {
711         test_mkdir -p $DIR1/$tdir || error "Creating dir $DIR1/$tdir"
712         local writes=$(LANG=C dd if=/dev/zero of=$DIR/$tdir/$tfile \
713                        count=1 2>&1 | awk 'BEGIN { FS="+" } /out/ {print $1}')
714         #define OBD_FAIL_LDLM_CANCEL_BL_CB_RACE   0x314
715         lctl set_param fail_loc=0x314
716         local reads=$(LANG=C dd if=$DIR2/$tdir/$tfile of=/dev/null 2>&1 |
717                       awk 'BEGIN { FS="+" } /in/ {print $1}')
718         [ $reads -eq $writes ] || error "read" $reads "blocks, must be" $writes
719 }
720 run_test 31a "voluntary cancel / blocking ast race=============="
721
722 test_31b() {
723         remote_ost || { skip "local OST" && return 0; }
724         remote_ost_nodsh && skip "remote OST w/o dsh" && return 0
725
726         # make sure there is no local locks due to destroy
727         wait_mds_ost_sync || error "wait_mds_ost_sync()"
728         wait_delete_completed || error "wait_delete_completed()"
729
730         test_mkdir -p $DIR1/$tdir || error "Creating dir $DIR1/$tdir"
731         lfs setstripe $DIR/$tdir/$tfile -i 0 -c 1
732         cp /etc/hosts $DIR/$tdir/$tfile
733         #define OBD_FAIL_LDLM_CANCEL_BL_CB_RACE   0x314
734         lctl set_param fail_loc=0x314
735         #define OBD_FAIL_LDLM_OST_FAIL_RACE      0x316
736         do_facet ost1 lctl set_param fail_loc=0x316
737         # Don't crash kernel
738         cat $DIR2/$tdir/$tfile > /dev/null 2>&1
739         lctl set_param fail_loc=0
740         do_facet ost1 lctl set_param fail_loc=0
741         # cleanup: reconnect the client back
742         df $DIR2
743 }
744 run_test 31b "voluntary OST cancel / blocking ast race=============="
745
746 # enable/disable lockless truncate feature, depending on the arg 0/1
747 enable_lockless_truncate() {
748         lctl set_param -n osc.*.lockless_truncate $1
749 }
750
751 test_32a() { # bug 11270
752         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
753         save_lustre_params client "osc.*.lockless_truncate" > $p
754         cancel_lru_locks osc
755         enable_lockless_truncate 1
756         rm -f $DIR1/$tfile
757         lfs setstripe -c -1 $DIR1/$tfile
758         dd if=/dev/zero of=$DIR1/$tfile count=$OSTCOUNT bs=$STRIPE_BYTES > \
759                 /dev/null 2>&1
760         clear_osc_stats
761
762         log "checking cached lockless truncate"
763         $TRUNCATE $DIR1/$tfile 8000000
764         $CHECKSTAT -s 8000000 $DIR2/$tfile || error "wrong file size"
765         [ $(calc_osc_stats lockless_truncate) -ne 0 ] ||
766                 error "cached truncate isn't lockless"
767
768         log "checking not cached lockless truncate"
769         $TRUNCATE $DIR2/$tfile 5000000
770         $CHECKSTAT -s 5000000 $DIR1/$tfile || error "wrong file size"
771         [ $(calc_osc_stats lockless_truncate) -ne 0 ] ||
772                 error "not cached truncate isn't lockless"
773
774         log "disabled lockless truncate"
775         enable_lockless_truncate 0
776         clear_osc_stats
777         $TRUNCATE $DIR2/$tfile 3000000
778         $CHECKSTAT -s 3000000 $DIR1/$tfile || error "wrong file size"
779         [ $(calc_osc_stats lockless_truncate) -eq 0 ] ||
780                 error "lockless truncate disabling failed"
781         rm $DIR1/$tfile
782         # restore lockless_truncate default values
783         restore_lustre_params < $p
784         rm -f $p
785 }
786 run_test 32a "lockless truncate"
787
788 test_32b() { # bug 11270
789         remote_ost_nodsh && skip "remote OST with nodsh" && return
790
791         local node
792         local facets=$(get_facets OST)
793         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
794
795         save_lustre_params client "osc.*.contention_seconds" > $p
796         save_lustre_params $facets \
797                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
798         save_lustre_params $facets \
799                 "ldlm.namespaces.filter-*.contended_locks" >> $p
800         save_lustre_params $facets \
801                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
802         clear_osc_stats
803
804         # agressive lockless i/o settings
805         for node in $(osts_nodes); do
806                 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'
807         done
808         lctl set_param -n osc.*.contention_seconds 60
809         for i in $(seq 5); do
810                 dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
811                 dd if=/dev/zero of=$DIR2/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
812         done
813         [ $(calc_osc_stats lockless_write_bytes) -ne 0 ] || error "lockless i/o was not triggered"
814         # disable lockless i/o (it is disabled by default)
815         for node in $(osts_nodes); do
816                 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'
817         done
818         # set contention_seconds to 0 at client too, otherwise Lustre still
819         # remembers lock contention
820         lctl set_param -n osc.*.contention_seconds 0
821         clear_osc_stats
822         for i in $(seq 1); do
823                 dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
824                 dd if=/dev/zero of=$DIR2/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
825         done
826         [ $(calc_osc_stats lockless_write_bytes) -eq 0 ] ||
827                 error "lockless i/o works when disabled"
828         rm -f $DIR1/$tfile
829         restore_lustre_params <$p
830         rm -f $p
831 }
832 run_test 32b "lockless i/o"
833
834 print_jbd_stat () {
835     local dev
836     local mdts=$(get_facets MDS)
837     local varcvs
838     local mds
839
840     local stat=0
841     for mds in ${mdts//,/ }; do
842         varsvc=${mds}_svc
843         dev=$(basename $(do_facet $mds "lctl get_param -n osd*.${!varsvc}.mntdev|\
844                 xargs readlink -f" ))
845         val=$(do_facet $mds "cat /proc/fs/jbd*/${dev}{,:*,-*}/info 2>/dev/null |
846                 head -n1")
847         val=${val%% *};
848         stat=$(( stat + val))
849     done
850     echo $stat
851 }
852
853 # commit on sharing tests
854 test_33a() {
855     remote_mds_nodsh && skip "remote MDS with nodsh" && return
856
857     [ -z "$CLIENTS" ] && skip "Need two or more clients, have $CLIENTS" && return 0
858     [ $CLIENTCOUNT -lt 2 ] &&
859         skip "Need two or more clients, have $CLIENTCOUNT" && return 0
860
861     local nfiles=${TEST33_NFILES:-10000}
862     local param_file=$TMP/$tfile-params
863     local fstype=$(facet_fstype $SINGLEMDS)
864
865         save_lustre_params $(get_facets MDS) \
866                 "mdt.*.commit_on_sharing" > $param_file
867
868     local COS
869     local jbdold="N/A"
870     local jbdnew="N/A"
871     local jbd
872
873     for COS in 0 1; do
874         do_facet $SINGLEMDS lctl set_param mdt.*.commit_on_sharing=$COS
875         avgjbd=0
876         avgtime=0
877         for i in 1 2 3; do
878             do_nodes $CLIENT1,$CLIENT2 "mkdir -p $DIR1/$tdir-\\\$(hostname)-$i"
879
880             [ $fstype = ldiskfs ] && jbdold=$(print_jbd_stat)
881             echo "=== START createmany old: $jbdold transaction"
882             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")
883             [ $fstype = ldiskfs ] && jbdnew=$(print_jbd_stat)
884             [ $fstype = ldiskfs ] && jbd=$(( jbdnew - jbdold ))
885             echo "=== END   createmany new: $jbdnew transaction :  $jbd transactions  nfiles $nfiles time $elapsed COS=$COS"
886             [ $fstype = ldiskfs ] && avgjbd=$(( avgjbd + jbd ))
887             avgtime=$(( avgtime + elapsed ))
888         done
889         eval cos${COS}_jbd=$((avgjbd / 3))
890         eval cos${COS}_time=$((avgtime / 3))
891     done
892
893     echo "COS=0 transactions (avg): $cos0_jbd  time (avg): $cos0_time"
894     echo "COS=1 transactions (avg): $cos1_jbd  time (avg): $cos1_time"
895     [ "$cos0_jbd" != 0 ] && echo "COS=1 vs COS=0 jbd:  $((((cos1_jbd/cos0_jbd - 1)) * 100 )) %"
896     [ "$cos0_time" != 0 ] && echo "COS=1 vs COS=0 time: $((((cos1_time/cos0_time - 1)) * 100 )) %"
897
898     restore_lustre_params < $param_file
899     rm -f $param_file
900     return 0
901 }
902 run_test 33a "commit on sharing, cross crete/delete, 2 clients, benchmark"
903
904 # commit on sharing tests
905 test_33b() {
906         remote_mds_nodsh && skip "remote MDS with nodsh" && return
907
908         [ -n "$CLIENTS" ] || { skip "Need two or more clients" && return 0; }
909         [ $CLIENTCOUNT -ge 2 ] ||
910                 { skip "Need two or more clients, have $CLIENTCOUNT" &&
911                                                                 return 0; }
912         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
913
914         local nfiles=${TEST33_NFILES:-10000}
915         local param_file=$TMP/$tfile-params
916
917         save_lustre_params $(get_facets MDS) \
918                 "mdt.*.commit_on_sharing" > $param_file
919
920         local COS
921         local jbdold
922         local jbdnew
923         local jbd
924         local MDTIDX=1
925
926         for COS in 0 1; do
927                 do_facet $SINGLEMDS lctl set_param mdt.*.commit_on_sharing=$COS
928                 avgjbd=0
929                 avgtime=0
930                 for i in 1 2 3; do
931                         do_node $CLIENT1 "$LFS mkdir -i $MDTIDX -p \
932                                           $DIR1/$tdir-\\\$(hostname)-$i"
933
934                         jbdold=$(print_jbd_stat)
935                         echo "=== START createmany old: $jbdold transaction"
936                         local elapsed=$(do_and_time "do_nodes $CLIENT1,$CLIENT2\
937                                 createmany -o $DIR1/$tdir-\\\$(hostname)-$i/f- \
938                                 -r $DIR2/$tdir-\\\$(hostname)-$i/f- $nfiles > \
939                                                                 /dev/null 2>&1")
940                         jbdnew=$(print_jbd_stat)
941                         jbd=$(( jbdnew - jbdold ))
942                         echo "=== END   createmany new: $jbdnew transaction : \
943                         $jbd transactions nfiles $nfiles time $elapsed COS=$COS"
944                         avgjbd=$(( avgjbd + jbd ))
945                         avgtime=$(( avgtime + elapsed ))
946                 done
947                 eval cos${COS}_jbd=$((avgjbd / 3))
948                 eval cos${COS}_time=$((avgtime / 3))
949         done
950
951         echo "COS=0 transactions (avg): $cos0_jbd  time (avg): $cos0_time"
952         echo "COS=1 transactions (avg): $cos1_jbd  time (avg): $cos1_time"
953         [ "$cos0_jbd" != 0 ] &&
954             echo "COS=1 vs COS=0 jbd: $(((cos1_jbd/cos0_jbd - 1) * 100)) %"
955         [ "$cos0_time" != 0 ] &&
956             echo "COS=1 vs COS=0 time: $(((cos1_time/cos0_time - 1) * 100)) %"
957
958         restore_lustre_params < $param_file
959         rm -f $param_file
960         return 0
961 }
962 run_test 33b "COS: cross create/delete, 2 clients, benchmark under remote dir"
963
964 # End commit on sharing tests
965
966 get_ost_lock_timeouts() {
967     local nodes=${1:-$(comma_list $(osts_nodes))}
968
969     local locks=$(do_nodes $nodes \
970         "lctl get_param -n ldlm.namespaces.filter-*.lock_timeouts" | calc_sum)
971
972     echo $locks
973 }
974
975 cleanup_34() {
976         local i
977         trap 0
978         do_nodes $(comma_list $(osts_nodes)) \
979                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
980         for i in $(seq $OSTCOUNT); do
981                 wait_osc_import_state client ost$i FULL
982         done
983 }
984
985 test_34() { #16129
986         local OPER
987         local lock_in
988         local lock_out
989         trap cleanup_34 EXIT RETURN
990         for OPER in notimeout timeout ; do
991                 rm $DIR1/$tfile 2>/dev/null
992                 lock_in=$(get_ost_lock_timeouts)
993                 if [ $OPER == "timeout" ] ; then
994                         for j in `seq $OSTCOUNT`; do
995                                 #define OBD_FAIL_PTLRPC_HPREQ_TIMEOUT    0x511
996                                 do_facet ost$j lctl set_param fail_loc=0x511
997                         done
998                         echo lock should expire
999                 else
1000                         for j in `seq $OSTCOUNT`; do
1001                                 #define OBD_FAIL_PTLRPC_HPREQ_NOTIMEOUT  0x512
1002                                 do_facet ost$j lctl set_param fail_loc=0x512
1003                         done
1004                         echo lock should not expire
1005                 fi
1006                 echo writing on client1
1007                 dd if=/dev/zero of=$DIR1/$tfile count=100 conv=notrunc > /dev/null 2>&1
1008                 sync &
1009                 echo reading on client2
1010                 dd of=/dev/null if=$DIR2/$tfile > /dev/null 2>&1
1011                 # wait for a lock timeout
1012                 sleep 4
1013                 lock_out=$(get_ost_lock_timeouts)
1014                 if [ $OPER == "timeout" ] ; then
1015                         if [ $lock_in == $lock_out ]; then
1016                                 error "no lock timeout happened"
1017                         else
1018                                 echo "success"
1019                         fi
1020                 else
1021                         if [ $lock_in != $lock_out ]; then
1022                                 error "lock timeout happened"
1023                         else
1024                                 echo "success"
1025                         fi
1026                 fi
1027         done
1028         cleanup_34
1029 }
1030 run_test 34 "no lock timeout under IO"
1031
1032 test_35() { # bug 17645
1033         local generation=[]
1034         local count=0
1035         gen=$(lctl get_param mdc.$FSNAME-MDT*-mdc-*.import | grep generation |
1036                 awk '/generation/{print $2}')
1037         for g in $gen; do
1038             generation[count]=$g
1039             let count=count+1
1040         done
1041
1042         test_mkdir -p $MOUNT1/$tfile
1043         cancel_lru_locks mdc
1044
1045         # Let's initiate -EINTR situation by setting fail_loc and take
1046         # write lock on same file from same client. This will not cause
1047         # bl_ast yet as lock is already in local cache.
1048 #define OBD_FAIL_LDLM_INTR_CP_AST        0x317
1049         do_facet client "lctl set_param fail_loc=0x80000317"
1050         local timeout=`do_facet $SINGLEMDS lctl get_param  -n timeout`
1051         let timeout=timeout*3
1052         local nr=0
1053         while test $nr -lt 10; do
1054                 log "Race attempt $nr"
1055                 local blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
1056                 test "x$blk1" = "x" && blk1=0
1057                 createmany -o $MOUNT2/$tfile/a 4000 &
1058                 pid1=$!
1059                 sleep 1
1060
1061                 # Let's make conflict and bl_ast
1062                 ls -la $MOUNT1/$tfile > /dev/null &
1063                 pid2=$!
1064
1065                 log "Wait for $pid1 $pid2 for $timeout sec..."
1066                 sleep $timeout
1067                 kill -9 $pid1 $pid2 > /dev/null 2>&1
1068                 wait
1069                 local blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
1070                 test "x$blk2" = "x" && blk2=0
1071                 test $blk2 -gt $blk1 && break
1072                 rm -fr $MOUNT1/$tfile/*
1073                 cancel_lru_locks mdc
1074                 let nr=nr+1
1075         done
1076         do_facet client "lctl set_param fail_loc=0x0"
1077         df -h $MOUNT1 $MOUNT2
1078         count=0
1079         gen=$(lctl get_param mdc.$FSNAME-MDT*-mdc-*.import | grep generation |
1080                 awk '/generation/{print $2}')
1081         for g in $gen; do
1082             if ! test "$g" -eq "${generation[count]}"; then
1083                 list=$(lctl list_param mdc.$FSNAME-MDT*-mdc-*.import)
1084                 local c = 0
1085                 for imp in $list; do
1086                         if [ $c = $count ]; then
1087                                 break
1088                         fi
1089                         c=c+1
1090                 done
1091                 imp=$(echo "$imp" | awk -F"." '{print $2}')
1092                 error "Eviction happened on import $imp"
1093             fi
1094             let count=count+1
1095         done
1096 }
1097 run_test 35 "-EINTR cp_ast vs. bl_ast race does not evict client"
1098
1099 test_36() { #bug 16417
1100         local SIZE
1101         local SIZE_B
1102         local i
1103
1104         test_mkdir -p $DIR1/$tdir
1105         $LFS setstripe -c -1 $DIR1/$tdir
1106         i=0
1107         SIZE=50
1108         let SIZE_B=SIZE*1024*1024
1109         sync; sleep 5; sync # wait for delete thread
1110
1111         while [ $i -le 10 ]; do
1112                 lctl mark "start test"
1113                 local before=$(lfs_df $MOUNT1 | awk '/^filesystem/{ print $4; exit }')
1114                 dd if=/dev/zero of=$DIR1/$tdir/$tfile bs=1M count=$SIZE ||
1115                         error "dd $DIR1/$tdir/$tfile ${SIZE}MB failed"
1116                 sync          # sync data from client cache
1117                 sync_all_data # sync data from server cache (delayed allocation)
1118                 sleep 2
1119                 local after_dd=$(lfs_df $MOUNT1 | awk '/^filesystem/{ print $4; exit }')
1120                 multiop_bg_pause $DIR2/$tdir/$tfile O_r${SIZE_B}c || return 3
1121                 read_pid=$!
1122                 rm -f $DIR1/$tdir/$tfile
1123                 kill -USR1 $read_pid
1124                 wait $read_pid
1125                 wait_delete_completed
1126                 local after=$(lfs_df $MOUNT1 | awk '/^filesystem/{ print $4; exit }')
1127                 echo "*** cycle($i) *** before($before) after_dd($after_dd)" \
1128                         "after($after)"
1129                 # this free space! not used
1130                 (( $after_dd <= $after)) ||
1131                         error "space leaked after_dd:$after_dd > after:$after"
1132                 let i=i+1
1133         done
1134 }
1135 run_test 36 "handle ESTALE/open-unlink correctly"
1136
1137 test_37() { # bug 18695
1138         test_mkdir -p $DIR1/$tdir
1139         multiop_bg_pause $DIR1/$tdir D_c || return 1
1140         MULTIPID=$!
1141         # create large directory (32kB seems enough from e2fsck, ~= 1000 files)
1142         createmany -m $DIR2/$tdir/f 10000
1143         # set mtime/atime backward
1144         touch -t 198001010000 $DIR2/$tdir
1145         kill -USR1 $MULTIPID
1146         nr_files=`lfs find $DIR1/$tdir -type f | wc -l`
1147         [ $nr_files -eq 10000 ] || error "$nr_files != 10000 truncated directory?"
1148
1149 }
1150 run_test 37 "check i_size is not updated for directory on close (bug 18695) =============="
1151
1152 # this should be set to past
1153 TEST_39_MTIME=`date -d "1 year ago" +%s`
1154
1155 # bug 11063
1156 test_39a() {
1157         local client1=${CLIENT1:-`hostname`}
1158         local client2=${CLIENT2:-`hostname`}
1159
1160         do_node $client1 "touch $DIR1/$tfile"
1161
1162         do_node $client1 "touch -m -d @$TEST_39_MTIME $DIR1/$tfile"
1163         local mtime1=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1164         [ "$mtime1" = $TEST_39_MTIME ] || \
1165                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
1166
1167         local d1=`do_node $client1 date +%s`
1168         do_node $client1 'echo hello >> '$DIR1/$tfile
1169         local d2=`do_node $client1 date +%s`
1170
1171         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1172         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
1173                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
1174
1175         do_node $client1 "mv $DIR1/$tfile $DIR1/$tfile-1"
1176
1177         for (( i=0; i < 2; i++ )) ; do
1178                 local mtime3=`do_node $client2 "stat -c %Y $DIR1/$tfile-1"`
1179                 [ "$mtime2" = "$mtime3" ] || \
1180                         error "mtime ($mtime2) changed (to $mtime3) on rename"
1181
1182                 cancel_lru_locks osc
1183                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1184         done
1185 }
1186 run_test 39a "test from 11063 =================================="
1187
1188 test_39b() {
1189         local client1=${CLIENT1:-`hostname`}
1190         local client2=${CLIENT2:-`hostname`}
1191
1192         touch $DIR1/$tfile
1193
1194         local mtime1=`stat -c %Y $DIR1/$tfile`
1195         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1196
1197         sleep 1
1198         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
1199
1200         for (( i=0; i < 2; i++ )) ; do
1201                 local mtime3=`stat -c %Y $DIR1/$tfile`
1202                 local mtime4=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1203
1204                 [ "$mtime3" = "$mtime4" ] || \
1205                         error "different mtime on clients: $mtime3, $mtime4"
1206                 [ "$mtime3" = $TEST_39_MTIME ] || \
1207                         error "lost mtime: $mtime3, should be $TEST_39_MTIME"
1208
1209                 cancel_lru_locks osc
1210                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1211         done
1212 }
1213 run_test 39b "11063 problem 1 =================================="
1214
1215 test_39c() {
1216         local client1=${CLIENT1:-`hostname`}
1217         local client2=${CLIENT2:-`hostname`}
1218
1219         echo hello > $DIR1/$tfile
1220
1221         local mtime1=`stat -c %Y $DIR1/$tfile`
1222         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1223         [ "$mtime1" = "$mtime2" ] || \
1224                 error "create: different mtime on clients: $mtime1, $mtime2"
1225
1226         sleep 1
1227         $TRUNCATE $DIR1/$tfile 1
1228
1229         for (( i=0; i < 2; i++ )) ; do
1230                 local mtime3=`stat -c %Y $DIR1/$tfile`
1231                 local mtime4=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1232
1233                 [ "$mtime3" = "$mtime4" ] || \
1234                         error "different mtime on clients: $mtime3, $mtime4"
1235                 [ "$mtime3" -gt $mtime2 ] || \
1236                         error "truncate did not update mtime: $mtime2, $mtime3"
1237
1238                 cancel_lru_locks osc
1239                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1240         done
1241 }
1242 run_test 39c "check truncate mtime update ======================"
1243
1244 # check that pid exists hence second operation wasn't blocked by first one
1245 # if it is so then there is no conflict, return 0
1246 # else second operation is conflicting with first one, return 1
1247 check_pdo_conflict() {
1248         local pid=$1
1249         local conflict=0
1250         sleep 1 # to ensure OP1 is finished on client if OP2 is blocked by OP1
1251         if [[ `ps --pid $pid | wc -l` == 1 ]]; then
1252                 conflict=1
1253                 echo "Conflict"
1254         else
1255                 echo "No conflict"
1256         fi
1257         return $conflict
1258 }
1259
1260 # pdirop tests
1261 # test 40: check non-blocking operations
1262 test_40a() {
1263 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1264         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1265         touch $DIR2
1266         mkdir $DIR1/$tfile &
1267         PID1=$!
1268         sleep 1
1269         touch $DIR2/$tfile-2
1270         check_pdo_conflict $PID1 || error "create is blocked"
1271         mkdir $DIR2/$tfile-3
1272         check_pdo_conflict $PID1 || error "mkdir is blocked"
1273         link $DIR2/$tfile-2 $DIR2/$tfile-4
1274         check_pdo_conflict $PID1 || error "link is blocked"
1275         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1276         check_pdo_conflict $PID1 || error "rename is blocked"
1277         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1278         check_pdo_conflict $PID1 || error "getattr is blocked"
1279         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1280         rmdir $DIR2/$tfile-3
1281         check_pdo_conflict $PID1 || error "unlink is blocked"
1282
1283         # all operations above shouldn't wait the first one
1284         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1285         wait $PID1
1286         rm -r $DIR1/*
1287         return 0
1288 }
1289 run_test 40a "pdirops: create vs others =============="
1290
1291 test_40b() {
1292 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1293         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1294         touch $DIR1/$tfile &
1295         PID1=$!
1296         sleep 1
1297         # open|create
1298         touch $DIR2/$tfile-2
1299         check_pdo_conflict $PID1 || error "create is blocked"
1300         mkdir $DIR2/$tfile-3
1301         check_pdo_conflict $PID1 || error "mkdir is blocked"
1302         link $DIR2/$tfile-2 $DIR2/$tfile-4
1303         check_pdo_conflict $PID1 || error "link is blocked"
1304         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1305         check_pdo_conflict $PID1 || error "rename is blocked"
1306         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1307         check_pdo_conflict $PID1 || error "getattr is blocked"
1308         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1309         rmdir $DIR2/$tfile-3
1310         check_pdo_conflict $PID1 || error "unlink is blocked"
1311         # all operations above shouldn't wait the first one
1312
1313         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1314         wait $PID1
1315         rm -r $DIR1/*
1316         return 0
1317 }
1318 run_test 40b "pdirops: open|create and others =============="
1319
1320 test_40c() {
1321         touch $DIR1/$tfile
1322 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1323         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1324         link $DIR1/$tfile $DIR1/$tfile-0 &
1325         PID1=$!
1326         sleep 1
1327         # open|create
1328         touch $DIR2/$tfile-2
1329         check_pdo_conflict $PID1 || error "create is blocked"
1330         mkdir $DIR2/$tfile-3
1331         check_pdo_conflict $PID1 || error "mkdir is blocked"
1332         link $DIR2/$tfile-2 $DIR2/$tfile-4
1333         check_pdo_conflict $PID1 || error "link is blocked"
1334         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1335         check_pdo_conflict $PID1 || error "rename is blocked"
1336         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1337         check_pdo_conflict $PID1 || error "getattr is blocked"
1338         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1339         rmdir $DIR2/$tfile-3
1340         check_pdo_conflict $PID1 || error "unlink is blocked"
1341
1342         # all operations above shouldn't wait the first one
1343         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1344         wait $PID1
1345         rm -r $DIR1/*
1346         return 0
1347 }
1348 run_test 40c "pdirops: link and others =============="
1349
1350 test_40d() {
1351         touch $DIR1/$tfile
1352 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1353         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1354         rm $DIR1/$tfile &
1355         PID1=$!
1356         sleep 1
1357         # open|create
1358         touch $DIR2/$tfile-2
1359         check_pdo_conflict $PID1 || error "create is blocked"
1360         mkdir $DIR2/$tfile-3
1361         check_pdo_conflict $PID1 || error "mkdir is blocked"
1362         link $DIR2/$tfile-2 $DIR2/$tfile-4
1363         check_pdo_conflict $PID1 || error "link is blocked"
1364         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1365         check_pdo_conflict $PID1 || error "rename is blocked"
1366         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1367         check_pdo_conflict $PID1 || error "getattr is blocked"
1368         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1369         rmdir $DIR2/$tfile-3
1370         check_pdo_conflict $PID1 || error "unlink is blocked"
1371
1372         # all operations above shouldn't wait the first one
1373         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1374         wait $PID1
1375         return 0
1376 }
1377 run_test 40d "pdirops: unlink and others =============="
1378
1379 test_40e() {
1380         touch $DIR1/$tfile
1381 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1382         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1383         mv $DIR1/$tfile $DIR1/$tfile-0 &
1384         PID1=$!
1385         sleep 1
1386         # open|create
1387         touch $DIR2/$tfile-2
1388         check_pdo_conflict $PID1 || error "create is blocked"
1389         mkdir $DIR2/$tfile-3
1390         check_pdo_conflict $PID1 || error "mkdir is blocked"
1391         link $DIR2/$tfile-2 $DIR2/$tfile-4
1392         check_pdo_conflict $PID1 || error "link is blocked"
1393         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1394         check_pdo_conflict $PID1 || error "getattr is blocked"
1395         rm $DIR2/$tfile-4 $DIR2/$tfile-2
1396         rmdir $DIR2/$tfile-3
1397         check_pdo_conflict $PID1 || error "unlink is blocked"
1398
1399        # all operations above shouldn't wait the first one
1400         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1401         wait $PID1
1402         rm -r $DIR1/*
1403         return 0
1404 }
1405 run_test 40e "pdirops: rename and others =============="
1406
1407 # test 41: create blocking operations
1408 test_41a() {
1409 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1410         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1411         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1412         PID1=$!
1413         sleep 1
1414         mkdir $DIR2/$tfile && error "mkdir must fail"
1415         check_pdo_conflict $PID1 && { wait $PID1; echo "mkdir isn't blocked"; }
1416         rm -r $DIR1/*
1417         return 0
1418 }
1419 run_test 41a "pdirops: create vs mkdir =============="
1420
1421 test_41b() {
1422 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1423         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1424         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1425         PID1=$!
1426         sleep 1
1427         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
1428         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1429         rm -r $DIR1/*
1430         return 0
1431 }
1432 run_test 41b "pdirops: create vs create =============="
1433
1434 test_41c() {
1435         touch $DIR1/$tfile-2
1436 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1437         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1438         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1439         PID1=$!
1440         sleep 1
1441         link $DIR2/$tfile-2 $DIR2/$tfile && error "link must fail"
1442         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1443         rm -r $DIR1/*
1444         return 0
1445 }
1446 run_test 41c "pdirops: create vs link =============="
1447
1448 test_41d() {
1449 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1450         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1451         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1452         PID1=$!
1453         sleep 1
1454         rm $DIR2/$tfile || error "unlink must succeed"
1455         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1456         rm -r $DIR1/*
1457         return 0
1458 }
1459 run_test 41d "pdirops: create vs unlink =============="
1460
1461 test_41e() {
1462         touch $DIR1/$tfile-2
1463 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1464         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1465         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1466         PID1=$!
1467         sleep 1
1468         mv $DIR2/$tfile-2 $DIR2/$tfile || error "rename must succeed"
1469         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1470         rm -r $DIR1/*
1471         return 0
1472 }
1473 run_test 41e "pdirops: create and rename (tgt) =============="
1474
1475 test_41f() {
1476 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1477         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1478         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1479         PID1=$!
1480         sleep 1
1481         mv $DIR2/$tfile $DIR2/$tfile-2 || error "rename must succeed"
1482         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1483         rm -r $DIR1/*
1484         return 0
1485 }
1486 run_test 41f "pdirops: create and rename (src) =============="
1487
1488 test_41g() {
1489 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1490         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1491         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1492         PID1=$!
1493         sleep 1
1494         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
1495         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1496         rm -r $DIR1/*
1497         return 0
1498 }
1499 run_test 41g "pdirops: create vs getattr =============="
1500
1501 test_41h() {
1502 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1503         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1504         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1505         PID1=$!
1506         sleep 1
1507         ls -lia $DIR2/ > /dev/null
1508         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1509         rm -r $DIR1/*
1510         return 0
1511 }
1512 run_test 41h "pdirops: create vs readdir =============="
1513
1514 # test 42: unlink and blocking operations
1515 test_42a() {
1516 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1517         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1518         mkdir $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 42a "pdirops: mkdir vs mkdir =============="
1527
1528 test_42b() {
1529 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1530         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1531         mkdir $DIR1/$tfile &
1532         PID1=$!
1533         sleep 1
1534         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
1535         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1536         rm -r $DIR1/*
1537         return 0
1538 }
1539 run_test 42b "pdirops: mkdir vs create =============="
1540
1541 test_42c() {
1542         touch $DIR1/$tfile-2
1543 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1544         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1545         mkdir $DIR1/$tfile &
1546         PID1=$!
1547         sleep 1
1548         link $DIR2/$tfile-2 $DIR2/$tfile && error "link must fail"
1549         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1550         rm -r $DIR1/*
1551         return 0
1552 }
1553 run_test 42c "pdirops: mkdir vs link =============="
1554
1555 test_42d() {
1556 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1557         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1558         mkdir $DIR1/$tfile &
1559         PID1=$!
1560         sleep 1
1561         rmdir $DIR2/$tfile || error "unlink must succeed"
1562         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1563         rm -r $DIR1/*
1564         return 0
1565 }
1566 run_test 42d "pdirops: mkdir vs unlink =============="
1567
1568 test_42e() {
1569         touch $DIR1/$tfile-2
1570 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1571         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1572         mkdir $DIR1/$tfile &
1573         PID1=$!
1574         sleep 1
1575         mv -T $DIR2/$tfile-2 $DIR2/$tfile && error "rename must fail"
1576         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1577         rm -r $DIR1/*
1578         return 0
1579 }
1580 run_test 42e "pdirops: mkdir and rename (tgt) =============="
1581
1582 test_42f() {
1583 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1584         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1585         mkdir $DIR1/$tfile &
1586         PID1=$!
1587         sleep 1
1588         mv $DIR2/$tfile $DIR2/$tfile-2 || 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 42f "pdirops: mkdir and rename (src) =============="
1594
1595 test_42g() {
1596 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1597         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1598         mkdir $DIR1/$tfile &
1599         PID1=$!
1600         sleep 1
1601         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
1602         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1603         rm -r $DIR1/*
1604         return 0
1605 }
1606 run_test 42g "pdirops: mkdir vs getattr =============="
1607
1608 test_42h() {
1609 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1610         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1611         mkdir $DIR1/$tfile &
1612         PID1=$!
1613         sleep 1
1614         ls -lia $DIR2/ > /dev/null
1615         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1616         rm -r $DIR1/*
1617         return 0
1618 }
1619 run_test 42h "pdirops: mkdir vs readdir =============="
1620
1621 # test 43: unlink and blocking operations
1622 test_43a() {
1623         touch $DIR1/$tfile
1624 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1625         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1626         rm $DIR1/$tfile &
1627         PID1=$!
1628         sleep 1
1629         mkdir $DIR2/$tfile || error "mkdir must succeed"
1630         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1631         rm -r $DIR1/*
1632         return 0
1633 }
1634 run_test 43a "pdirops: unlink vs mkdir =============="
1635
1636 test_43b() {
1637         touch $DIR1/$tfile
1638 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1639         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1640         rm $DIR1/$tfile &
1641         PID1=$!
1642         sleep 1
1643         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c || error "create must succeed"
1644         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1645         rm -r $DIR1/*
1646         return 0
1647 }
1648 run_test 43b "pdirops: unlink vs create =============="
1649
1650 test_43c() {
1651         touch $DIR1/$tfile
1652         touch $DIR1/$tfile-2
1653 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1654         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1655         rm $DIR1/$tfile &
1656         PID1=$!
1657         sleep 1
1658         link $DIR2/$tfile-2 $DIR2/$tfile || error "link must succeed"
1659         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1660         rm -r $DIR1/*
1661         return 0
1662 }
1663 run_test 43c "pdirops: unlink vs link =============="
1664
1665 test_43d() {
1666         touch $DIR1/$tfile
1667 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1668         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1669         rm $DIR1/$tfile &
1670         PID1=$!
1671         sleep 1
1672         rm $DIR2/$tfile && error "unlink must fail"
1673         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1674         rm -r $DIR1/*
1675         return 0
1676 }
1677 run_test 43d "pdirops: unlink vs unlink =============="
1678
1679 test_43e() {
1680         touch $DIR1/$tfile
1681         touch $DIR1/$tfile-2
1682 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1683         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1684         rm $DIR1/$tfile &
1685         PID1=$!
1686         sleep 1
1687         mv -u $DIR2/$tfile-2 $DIR2/$tfile || error "rename must succeed"
1688         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1689         rm -r $DIR1/*
1690         return 0
1691 }
1692 run_test 43e "pdirops: unlink and rename (tgt) =============="
1693
1694 test_43f() {
1695         touch $DIR1/$tfile
1696 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1697         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1698         rm $DIR1/$tfile &
1699         PID1=$!
1700         sleep 1
1701         mv $DIR2/$tfile $DIR2/$tfile-2 && error "rename must fail"
1702         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1703         rm -r $DIR1/*
1704         return 0
1705 }
1706 run_test 43f "pdirops: unlink and rename (src) =============="
1707
1708 test_43g() {
1709         touch $DIR1/$tfile
1710 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1711         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1712         rm $DIR1/$tfile &
1713         PID1=$!
1714         sleep 1
1715         stat $DIR2/$tfile > /dev/null && error "stat must fail"
1716         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1717         rm -r $DIR1/*
1718         return 0
1719 }
1720 run_test 43g "pdirops: unlink vs getattr =============="
1721
1722 test_43h() {
1723         touch $DIR1/$tfile
1724 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1725         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1726         rm $DIR1/$tfile &
1727         PID1=$!
1728         sleep 1
1729         ls -lia $DIR2/ > /dev/null
1730         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1731         rm -r $DIR1/*
1732         return 0
1733 }
1734 run_test 43h "pdirops: unlink vs readdir =============="
1735
1736 test_43i() {
1737         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1738         touch $DIR1/$tfile
1739 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1740         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1741         rm $DIR1/$tfile &
1742         PID1=$!
1743         sleep 1
1744         $LFS mkdir -i 1 $DIR2/$tfile || error "remote mkdir must succeed"
1745         check_pdo_conflict $PID1 &&
1746                 { wait $PID1; error "remote mkdir isn't blocked"; }
1747         rm -r $DIR1/*
1748         return 0
1749 }
1750 run_test 43i "pdirops: unlink vs remote mkdir"
1751
1752 # test 44: rename tgt and blocking operations
1753 test_44a() {
1754         touch $DIR1/$tfile-2
1755 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
1756         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1757         mv $DIR1/$tfile-2 $DIR1/$tfile &
1758         PID1=$!
1759         sleep 1
1760         mkdir $DIR2/$tfile && error "mkdir must fail"
1761         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1762         rm -r $DIR1/*
1763         return 0
1764 }
1765 run_test 44a "pdirops: rename tgt vs mkdir =============="
1766
1767 test_44b() {
1768         touch $DIR1/$tfile-2
1769 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1770         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1771         mv $DIR1/$tfile-2 $DIR1/$tfile &
1772         PID1=$!
1773         sleep 1
1774         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
1775         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1776         rm -r $DIR1/*
1777         return 0
1778 }
1779 run_test 44b "pdirops: rename tgt vs create =============="
1780
1781 test_44c() {
1782         touch $DIR1/$tfile-2
1783         touch $DIR1/$tfile-3
1784 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1785         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1786         mv $DIR1/$tfile-2 $DIR1/$tfile &
1787         PID1=$!
1788         sleep 1
1789         link $DIR2/$tfile-3 $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 44c "pdirops: rename tgt vs link =============="
1795
1796 test_44d() {
1797         touch $DIR1/$tfile-2
1798 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1799         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1800         mv $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 44d "pdirops: rename tgt vs unlink =============="
1809
1810 test_44e() {
1811         touch $DIR1/$tfile
1812         touch $DIR1/$tfile-2
1813         touch $DIR1/$tfile-3
1814 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1815         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1816         mv $DIR1/$tfile-2 $DIR1/$tfile &
1817         PID1=$!
1818         sleep 1
1819         mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
1820         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1821         rm -r $DIR1/*
1822         return 0
1823 }
1824 run_test 44e "pdirops: rename tgt and rename (tgt) =============="
1825
1826 test_44f() {
1827         touch $DIR1/$tfile-2
1828         touch $DIR1/$tfile-3
1829 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1830         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1831         mv $DIR1/$tfile-2 $DIR1/$tfile &
1832         PID1=$!
1833         sleep 1
1834         mv $DIR2/$tfile $DIR2/$tfile-3 || error "rename must succeed"
1835         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1836         rm -r $DIR1/*
1837         return 0
1838 }
1839 run_test 44f "pdirops: rename tgt and rename (src) =============="
1840
1841 test_44g() {
1842         touch $DIR1/$tfile-2
1843 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1844         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1845         mv $DIR1/$tfile-2 $DIR1/$tfile &
1846         PID1=$!
1847         sleep 1
1848         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
1849         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1850         rm -r $DIR1/*
1851         return 0
1852 }
1853 run_test 44g "pdirops: rename tgt vs getattr =============="
1854
1855 test_44h() {
1856         touch $DIR1/$tfile-2
1857 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1858         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1859         mv $DIR1/$tfile-2 $DIR1/$tfile &
1860         PID1=$!
1861         sleep 1
1862         ls -lia $DIR2/ > /dev/null
1863         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1864         rm -r $DIR1/*
1865         return 0
1866 }
1867 run_test 44h "pdirops: rename tgt vs readdir =============="
1868
1869 # test 44: rename tgt and blocking operations
1870 test_44i() {
1871         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1872         touch $DIR1/$tfile-2
1873 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
1874         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1875         mv $DIR1/$tfile-2 $DIR1/$tfile &
1876         PID1=$!
1877         sleep 1
1878         $LFS mkdir -i 1 $DIR2/$tfile && error "remote mkdir must fail"
1879         check_pdo_conflict $PID1 && { wait $PID1;
1880                                 error "remote mkdir isn't blocked"; }
1881         rm -r $DIR1/*
1882         return 0
1883 }
1884 run_test 44i "pdirops: rename tgt vs remote mkdir"
1885
1886 # test 45: rename src and blocking operations
1887 test_45a() {
1888         touch $DIR1/$tfile
1889 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1890         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1891         mv $DIR1/$tfile $DIR1/$tfile-2 &
1892         PID1=$!
1893         sleep 1
1894         mkdir $DIR2/$tfile || error "mkdir must succeed"
1895         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1896         rm -r $DIR1/*
1897         return 0
1898 }
1899 run_test 45a "pdirops: rename src vs mkdir =============="
1900
1901 test_45b() {
1902         touch $DIR1/$tfile
1903 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1904         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1905         mv $DIR1/$tfile $DIR1/$tfile-2 &
1906         PID1=$!
1907         sleep 1
1908         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c || error "create must succeed"
1909         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1910         rm -r $DIR1/*
1911         return 0
1912 }
1913 run_test 45b "pdirops: rename src vs create =============="
1914
1915 test_45c() {
1916         touch $DIR1/$tfile
1917         touch $DIR1/$tfile-3
1918 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1919         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1920         mv $DIR1/$tfile $DIR1/$tfile-2 &
1921         PID1=$!
1922         sleep 1
1923         link $DIR2/$tfile-3 $DIR2/$tfile || error "link must succeed"
1924         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1925         rm -r $DIR1/*
1926         return 0
1927 }
1928 run_test 45c "pdirops: rename src vs link =============="
1929
1930 test_45d() {
1931         touch $DIR1/$tfile
1932 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1933         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1934         mv $DIR1/$tfile $DIR1/$tfile-2 &
1935         PID1=$!
1936         sleep 1
1937         rm $DIR2/$tfile && error "unlink must fail"
1938         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1939         rm -r $DIR1/*
1940         return 0
1941 }
1942 run_test 45d "pdirops: rename src vs unlink =============="
1943
1944 test_45e() {
1945         touch $DIR1/$tfile
1946         touch $DIR1/$tfile-3
1947 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1948         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1949         mv $DIR1/$tfile $DIR1/$tfile-2 &
1950         PID1=$!
1951         sleep 1
1952         mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
1953         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1954         rm -r $DIR1/*
1955         return 0
1956 }
1957 run_test 45e "pdirops: rename src and rename (tgt) =============="
1958
1959 test_45f() {
1960         touch $DIR1/$tfile
1961 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1962         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1963         mv $DIR1/$tfile $DIR1/$tfile-2 &
1964         PID1=$!
1965         sleep 1
1966         mv $DIR2/$tfile $DIR2/$tfile-3 && error "rename must fail"
1967         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1968         rm -r $DIR1/*
1969         return 0
1970 }
1971 run_test 45f "pdirops: rename src and rename (src) =============="
1972
1973 test_45g() {
1974         touch $DIR1/$tfile
1975 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1976         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1977         mv $DIR1/$tfile $DIR1/$tfile-2 &
1978         PID1=$!
1979         sleep 1
1980         stat $DIR2/$tfile > /dev/null && error "stat must fail"
1981         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1982         rm -r $DIR1/*
1983         return 0
1984 }
1985 run_test 45g "pdirops: rename src vs getattr =============="
1986
1987 test_45h() {
1988         touch $DIR1/$tfile
1989 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1990         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1991         mv $DIR1/$tfile $DIR1/$tfile-2 &
1992         PID1=$!
1993         sleep 1
1994         ls -lia $DIR2/ > /dev/null
1995         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1996         rm -r $DIR1/*
1997         return 0
1998 }
1999 run_test 45h "pdirops: unlink vs readdir =============="
2000
2001 test_45i() {
2002         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2003         touch $DIR1/$tfile
2004 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2005         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2006         mv $DIR1/$tfile $DIR1/$tfile-2 &
2007         PID1=$!
2008         sleep 1
2009         $LFS mkdir -i 1 $DIR2/$tfile || error "create remote dir must succeed"
2010         check_pdo_conflict $PID1 && { wait $PID1;
2011                                 error "create remote dir isn't blocked"; }
2012         rm -r $DIR1/*
2013         return 0
2014 }
2015 run_test 45i "pdirops: rename src vs remote mkdir"
2016
2017 # test 46: link and blocking operations
2018 test_46a() {
2019         touch $DIR1/$tfile-2
2020 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2021         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2022         link $DIR1/$tfile-2 $DIR1/$tfile &
2023         PID1=$!
2024         sleep 1
2025         mkdir $DIR2/$tfile && error "mkdir must fail"
2026         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
2027         rm -r $DIR1/*
2028         return 0
2029 }
2030 run_test 46a "pdirops: link vs mkdir =============="
2031
2032 test_46b() {
2033         touch $DIR1/$tfile-2
2034 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2035         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2036         link $DIR1/$tfile-2 $DIR1/$tfile &
2037         PID1=$!
2038         sleep 1
2039         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
2040         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
2041         rm -r $DIR1/*
2042         return 0
2043 }
2044 run_test 46b "pdirops: link vs create =============="
2045
2046 test_46c() {
2047         touch $DIR1/$tfile-2
2048 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2049         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2050         link $DIR1/$tfile-2 $DIR1/$tfile &
2051         PID1=$!
2052         sleep 1
2053         link $DIR2/$tfile $DIR2/$tfile && error "link must fail"
2054         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2055         rm -r $DIR1/*
2056         return 0
2057 }
2058 run_test 46c "pdirops: link vs link =============="
2059
2060 test_46d() {
2061         touch $DIR1/$tfile-2
2062 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2063         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2064         link $DIR1/$tfile-2 $DIR1/$tfile &
2065         PID1=$!
2066         sleep 1
2067         rm $DIR2/$tfile || error "unlink must succeed"
2068         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
2069         rm -r $DIR1/*
2070         return 0
2071 }
2072 run_test 46d "pdirops: link vs unlink =============="
2073
2074 test_46e() {
2075         touch $DIR1/$tfile-2
2076         touch $DIR1/$tfile-3
2077 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2078         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2079         link $DIR1/$tfile-2 $DIR1/$tfile &
2080         PID1=$!
2081         sleep 1
2082         mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
2083         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2084         rm -r $DIR1/*
2085         return 0
2086 }
2087 run_test 46e "pdirops: link and rename (tgt) =============="
2088
2089 test_46f() {
2090         touch $DIR1/$tfile-2
2091         touch $DIR1/$tfile-3
2092 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2093         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2094         link $DIR1/$tfile-2 $DIR1/$tfile &
2095         PID1=$!
2096         sleep 1
2097         mv $DIR2/$tfile $DIR2/$tfile-3 || error "rename must succeed"
2098         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2099         rm -r $DIR1/*
2100         return 0
2101 }
2102 run_test 46f "pdirops: link and rename (src) =============="
2103
2104 test_46g() {
2105         touch $DIR1/$tfile-2
2106 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2107         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2108         link $DIR1/$tfile-2 $DIR1/$tfile &
2109         PID1=$!
2110         sleep 1
2111         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
2112         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
2113         rm -r $DIR1/*
2114         return 0
2115 }
2116 run_test 46g "pdirops: link vs getattr =============="
2117
2118 test_46h() {
2119         touch $DIR1/$tfile-2
2120 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2121         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2122         link $DIR1/$tfile-2 $DIR1/$tfile &
2123         PID1=$!
2124         sleep 1
2125         ls -lia $DIR2/ > /dev/null
2126         check_pdo_conflict $PID1 && { wait $PID1;
2127                         error "readdir isn't blocked"; }
2128         rm -r $DIR1/*
2129         return 0
2130 }
2131 run_test 46h "pdirops: link vs readdir =============="
2132
2133 test_46i() {
2134         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2135         touch $DIR1/$tfile-2
2136 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2137         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2138         link $DIR1/$tfile-2 $DIR1/$tfile &
2139         PID1=$!
2140         sleep 1
2141         $LFS mkdir -i 1 $DIR2/$tfile && error "remote mkdir must fail"
2142         check_pdo_conflict $PID1 && { wait $PID1;
2143                                 error "remote mkdir isn't blocked"; }
2144         rm -r $DIR1/*
2145         return 0
2146 }
2147 run_test 46i "pdirops: link vs remote mkdir"
2148
2149 # test 47: remote mkdir and blocking operations
2150 test_47a() {
2151 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2152         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2153         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2154         $LFS mkdir -i 1 $DIR1/$tfile &
2155         PID1=$!
2156         sleep 1
2157         mkdir $DIR2/$tfile && error "mkdir must fail"
2158         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
2159         rm -r $DIR1/*
2160         return 0
2161 }
2162 run_test 47a "pdirops: remote mkdir vs mkdir"
2163
2164 test_47b() {
2165 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2166         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2167         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2168         $LFS mkdir -i 1 $DIR1/$tfile &
2169         PID1=$!
2170         sleep 1
2171         multiop $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
2172         check_pdo_conflict $PID1 && { wait $PID1;
2173                                         error "create isn't blocked"; }
2174         rm -r $DIR1/*
2175         return 0
2176 }
2177 run_test 47b "pdirops: remote mkdir vs create"
2178
2179 test_47c() {
2180         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2181         touch $DIR1/$tfile-2
2182 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2183         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2184         $LFS mkdir -i 1 $DIR1/$tfile &
2185         PID1=$!
2186         sleep 1
2187         link $DIR2/$tfile-2 $DIR2/$tfile && error "link must fail"
2188         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2189         rm -r $DIR1/*
2190         return 0
2191 }
2192 run_test 47c "pdirops: remote mkdir vs link"
2193
2194 test_47d() {
2195         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2196 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2197         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2198         $LFS mkdir -i 1 $DIR1/$tfile &
2199         PID1=$!
2200         sleep 1
2201         rmdir $DIR2/$tfile || error "unlink must succeed"
2202         check_pdo_conflict $PID1 && { wait $PID1;
2203                                         error "unlink isn't blocked"; }
2204         rm -r $DIR1/*
2205         return 0
2206 }
2207 run_test 47d "pdirops: remote mkdir vs unlink"
2208
2209 test_47e() {
2210         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2211         touch $DIR1/$tfile-2
2212 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2213         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2214         $LFS mkdir -i 1 $DIR1/$tfile &
2215         PID1=$!
2216         sleep 1
2217         mv -T $DIR2/$tfile-2 $DIR2/$tfile && error "rename must fail"
2218         check_pdo_conflict $PID1 && { wait $PID1;
2219                                         error "rename isn't blocked"; }
2220         rm -r $DIR1/*
2221         return 0
2222 }
2223 run_test 47e "pdirops: remote mkdir and rename (tgt)"
2224
2225 test_47f() {
2226         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2227 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2228         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2229         $LFS mkdir -i 1 $DIR1/$tfile &
2230         PID1=$!
2231         sleep 1
2232         mv $DIR2/$tfile $DIR2/$tfile-2 || error "rename must succeed"
2233         check_pdo_conflict $PID1 && { wait $PID1;
2234                                         error "rename isn't blocked"; }
2235         rm -r $DIR1/*
2236         return 0
2237 }
2238 run_test 47f "pdirops: remote mkdir and rename (src)"
2239
2240 test_47g() {
2241         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2242 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2243         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2244         $LFS mkdir -i 1 $DIR1/$tfile &
2245         PID1=$!
2246         sleep 1
2247         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
2248         check_pdo_conflict $PID1 && { wait $PID1;
2249                                         error "getattr isn't blocked"; }
2250         rm -r $DIR1/*
2251         return 0
2252 }
2253 run_test 47g "pdirops: remote mkdir vs getattr"
2254
2255 test_50() {
2256         trunc_size=4096
2257         dd if=/dev/zero of=$DIR1/$tfile bs=1K count=10
2258 #define OBD_FAIL_OSC_CP_ENQ_RACE         0x410
2259         do_facet client "lctl set_param fail_loc=0x410"
2260         $TRUNCATE $DIR2/$tfile $trunc_size
2261         do_facet client "lctl set_param fail_loc=0x0"
2262         sleep 3
2263         size=`stat -c %s $DIR2/$tfile`
2264         [ $size -eq $trunc_size ] || error "wrong size"
2265 }
2266 run_test 50 "osc lvb attrs: enqueue vs. CP AST =============="
2267
2268 test_51a() {
2269         local filesize
2270         local origfile=/etc/hosts
2271
2272         filesize=`stat -c %s $origfile`
2273
2274         # create an empty file
2275         $MCREATE $DIR1/$tfile
2276         # cache layout lock on both mount point
2277         stat $DIR1/$tfile > /dev/null
2278         stat $DIR2/$tfile > /dev/null
2279
2280         # open and sleep 2 seconds then read
2281         $MULTIOP $DIR2/$tfile o_2r${filesize}c &
2282         local pid=$!
2283         sleep 1
2284
2285         # create the layout of testing file
2286         dd if=$origfile of=$DIR1/$tfile conv=notrunc > /dev/null
2287
2288         # MULTIOP proc should be able to read enough bytes and exit
2289         sleep 2
2290         kill -0 $pid && error "multiop is still there"
2291         cmp $origfile $DIR2/$tfile || error "$MCREATE and $DIR2/$tfile differs"
2292
2293         rm -f $DIR1/$tfile
2294 }
2295 run_test 51a "layout lock: refresh layout should work"
2296
2297 test_51b() {
2298         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.59) ]] ||
2299                 { skip "Need MDS version at least 2.3.59"; return 0; }
2300
2301         local tmpfile=`mktemp`
2302
2303         # create an empty file
2304         $MCREATE $DIR1/$tfile
2305
2306         # delay glimpse so that layout has changed when glimpse finish
2307 #define OBD_FAIL_GLIMPSE_DELAY 0x1404
2308         $LCTL set_param fail_loc=0x1404
2309         stat -c %s $DIR2/$tfile |tee $tmpfile &
2310         local pid=$!
2311         sleep 1
2312
2313         # create layout of testing file
2314         dd if=/dev/zero of=$DIR1/$tfile bs=1k count=1 conv=notrunc > /dev/null
2315
2316         wait $pid
2317         local fsize=`cat $tmpfile`
2318
2319         [ x$fsize = x1024 ] || error "file size is $fsize, should be 1024"
2320
2321         rm -f $DIR1/$tfile $tmpfile
2322 }
2323 run_test 51b "layout lock: glimpse should be able to restart if layout changed"
2324
2325 test_51c() {
2326         [ $OSTCOUNT -ge 2 ] || { skip "need at least 2 osts"; return; }
2327
2328         # set default layout to have 1 stripe
2329         mkdir -p $DIR1/$tdir
2330         $LFS setstripe -c 1 $DIR1/$tdir
2331
2332         # create a file with empty layout
2333         $MCREATE $DIR1/$tdir/$tfile
2334
2335 #define OBD_FAIL_MDS_LL_BLOCK 0x172
2336         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x172
2337
2338         # change the layout of testing file
2339         echo "Setting layout to have $OSTCOUNT stripes ..."
2340         $LFS setstripe -c $OSTCOUNT $DIR1/$tdir/$tfile &
2341         pid=$!
2342         sleep 1
2343
2344         # write something to the file, it should be blocked on fetching layout
2345         dd if=/dev/zero of=$DIR2/$tdir/$tfile bs=1k count=1 conv=notrunc
2346         local cnt=$($LFS getstripe -c $DIR2/$tdir/$tfile)
2347         [ $cnt -eq $OSTCOUNT ] || error "have $cnt stripes, expected $OSTCOUNT"
2348
2349         rm -fr $DIR1/$tdir
2350 }
2351 run_test 51c "layout lock: IT_LAYOUT blocked and correct layout can be returned"
2352
2353 test_51d() {
2354         dd if=/dev/zero of=/$DIR1/$tfile bs=1M count=1
2355         cancel_lru_locks mdc
2356
2357         # open should grant LAYOUT lock, mmap and read will install pages
2358         $MULTIOP $DIR1/$tfile oO_RDWR:SMR_Uc &
2359         local PID=$!
2360         sleep 1
2361
2362         # rss before revoking
2363         local br=$(grep -A 10 $tfile /proc/$PID/smaps | awk '/^Rss/{print $2}')
2364         echo "Before revoking layout lock: $br KB mapped"
2365
2366         # delete the file will revoke layout lock
2367         rm -f $DIR2/$tfile
2368
2369         # rss after revoking
2370         local ar=$(grep -A 10 $tfile /proc/$PID/smaps | awk '/^Rss/{print $2}')
2371
2372         kill -USR1 $PID
2373         wait $PID || error
2374
2375         [ $ar -eq 0 ] || error "rss before: $br, after $ar, some pages remained"
2376 }
2377 run_test 51d "layout lock: losing layout lock should clean up memory map region"
2378
2379 test_54_part1()
2380 {
2381         echo "==> rename vs getattr vs setxattr should not deadlock"
2382         mkdir -p $DIR/d1/d2/d3 || error "(1) mkdir failed"
2383
2384         do_facet mds $LCTL set_param fail_loc=$1
2385
2386         mv -T $DIR/d1/d2/d3 $DIR/d1/d3 &
2387         PID1=$!
2388         sleep 1
2389
2390         stat $DIR/d1/d2 &
2391         PID2=$!
2392         sleep 1
2393
2394         setfattr -n user.attr1 -v value1 $DIR2/d1 || error "(2) setfattr failed"
2395         wait $PID1 || error "(3) mv failed"
2396         wait $PID2 || error "(4) stat failed"
2397         echo
2398
2399         rm -rf $DIR/d1
2400 }
2401
2402 test_54_part2() {
2403         echo "==> rename vs getattr vs open vs getattr should not deadlock"
2404         mkdir -p $DIR/d1/d2/d3 || error "(1) mkdir failed"
2405
2406         do_facet mds $LCTL set_param fail_loc=$1
2407
2408         mv -T $DIR/d1/d2/d3 $DIR/d1/d3 &
2409         PID1=$!
2410         sleep 1
2411
2412         stat $DIR/d1/d2 &
2413         PID2=$!
2414         sleep 1
2415
2416         $MULTIOP $DIR2/d1/d2 Oc &
2417         PID3=$!
2418         sleep 1
2419
2420         stat $DIR/d1 || error "(2) stat failed"
2421
2422         wait $PID1 || error "(3) mv failed"
2423         wait $PID2 || error "(4) stat failed"
2424         wait $PID3 && error "(5) multiop failed"
2425         echo
2426         rm -rf $DIR/d1
2427 }
2428
2429 test_54() {
2430         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
2431         save_lustre_params client "llite.*.xattr_cache" > $p
2432         lctl set_param llite.*.xattr_cache 1 ||
2433                 { skip "xattr cache is not supported"; return 0; }
2434
2435 #define OBD_FAIL_MDS_RENAME              0x153
2436 #define OBD_FAIL_MDS_RENAME2             0x154
2437         test_54_part1 0x80000153 || error 10
2438         test_54_part1 0x80000154 || error 11
2439         test_54_part2 0x80000153 || error 12
2440         test_54_part2 0x80000154 || error 13
2441
2442         restore_lustre_params < $p
2443         rm -f $p
2444 }
2445 run_test 54 "rename locking"
2446
2447 test_55a() {
2448         mkdir -p $DIR/d1/d2 $DIR/d3 || error "(1) mkdir failed"
2449
2450 #define OBD_FAIL_MDS_RENAME4              0x156
2451         do_facet mds $LCTL set_param fail_loc=0x80000156
2452
2453         mv -T $DIR/d1/d2 $DIR/d3/d2 &
2454         PID1=$!
2455         sleep 1
2456
2457         rm -r $DIR2/d3
2458         wait $PID1 && error "(2) mv succeeded"
2459
2460         rm -rf $DIR/d1
2461 }
2462 run_test 55a "rename vs unlink target dir"
2463
2464 test_55b()
2465 {
2466         mkdir -p $DIR/d1/d2 $DIR/d3 || error "(1) mkdir failed"
2467
2468 #define OBD_FAIL_MDS_RENAME4             0x156
2469         do_facet mds $LCTL set_param fail_loc=0x80000156
2470
2471         mv -T $DIR/d1/d2 $DIR/d3/d2 &
2472         PID1=$!
2473         sleep 1
2474
2475         rm -r $DIR2/d1
2476         wait $PID1 && error "(2) mv succeeded"
2477
2478         rm -rf $DIR/d3
2479 }
2480 run_test 55b "rename vs unlink source dir"
2481
2482 test_55c()
2483 {
2484         mkdir -p $DIR/d1/d2 $DIR/d3 || error "(1) mkdir failed"
2485
2486 #define OBD_FAIL_MDS_RENAME4              0x156
2487         do_facet mds $LCTL set_param fail_loc=0x156
2488
2489         mv -T $DIR/d1/d2 $DIR/d3/d2 &
2490         PID1=$!
2491         sleep 1
2492
2493         # while rename is sleeping, open and remove d3
2494         $MULTIOP $DIR2/d3 D_c &
2495         PID2=$!
2496         sleep 1
2497         rm -rf $DIR2/d3
2498         sleep 5
2499
2500         # while rename is sleeping 2nd time, close d3
2501         kill -USR1 $PID2
2502         wait $PID2 || error "(3) multiop failed"
2503
2504         wait $PID1 && error "(2) mv succeeded"
2505
2506         rm -rf $DIR/d1
2507 }
2508 run_test 55c "rename vs unlink orphan target dir"
2509
2510 test_55d()
2511 {
2512         touch $DIR/f1
2513
2514 #define OBD_FAIL_MDS_RENAME3              0x155
2515         do_facet mds $LCTL set_param fail_loc=0x155
2516         mv $DIR/f1 $DIR/$tdir &
2517         PID1=$!
2518         sleep 2
2519
2520         # while rename is sleeping, create $tdir, but as a directory
2521         mkdir -p $DIR2/$tdir || error "(1) mkdir failed"
2522
2523         # link in reverse locking order
2524         ln $DIR2/f1 $DIR2/$tdir/
2525
2526         wait $PID1 && error "(2) mv succeeded"
2527         rm -rf $DIR/f1
2528 }
2529 run_test 55d "rename file vs link"
2530
2531 test_60() {
2532         local MDSVER=$(lustre_build_version $SINGLEMDS)
2533         [ $(version_code $MDSVER) -lt $(version_code 2.3.0) ] &&
2534                 skip "MDS version $MDSVER must be >= 2.3.0" && return 0
2535
2536         # Create a file
2537         test_mkdir -p $DIR1/$tdir
2538         file1=$DIR1/$tdir/file
2539         file2=$DIR2/$tdir/file
2540
2541         echo orig > $file2 || error "Could not create $file2"
2542         version=$($LFS data_version $file1)
2543
2544         # Append data
2545         echo append >> $file2 || error "Could not append to $file2"
2546         version2=$($LFS data_version $file1)
2547         [ "$version" != "$version2" ] ||
2548             error "append did not change data version: $version"
2549
2550         # Overwrite data
2551         echo overwrite > $file2 || error "Could not overwrite $file2"
2552         version3=$($LFS data_version $file1)
2553         [ "$version2" != "$version3" ] ||
2554             error "overwrite did not change data version: $version2"
2555
2556         # Truncate before EOF
2557         $TRUNCATE $file2 3 || error "Could not truncate $file2"
2558         version4=$($LFS data_version $file1)
2559         [ "$version3" != "$version4" ] ||
2560             error "truncate did not change data version: $version3"
2561
2562         # Truncate after EOF
2563         $TRUNCATE $file2 123456 || error "Could not truncate $file2"
2564         version5=$($LFS data_version $file1)
2565         [ "$version4" != "$version5" ] ||
2566             error "truncate did not change data version: $version4"
2567
2568         # Chmod do not change version
2569         chmod 400 $file2 || error "Could not chmod 400 $file2"
2570         version6=$($LFS data_version $file1)
2571         [ "$version5" == "$version6" ] ||
2572             error "chmod should not change data version: $version5 != $version6"
2573
2574         # Chown do not change version
2575         chown $RUNAS_ID $file2 || error "Could not chown $RUNAS_ID $file2"
2576         version7=$($LFS data_version $file1)
2577         [ "$version5" == "$version7" ] ||
2578             error "chown should not change data version: $version5 != $version7"
2579 }
2580 run_test 60 "Verify data_version behaviour"
2581
2582 test_70a() {
2583         local test_dir=$tdir/test_dir
2584
2585         mkdir -p $DIR1/$tdir
2586         if [ $MDSCOUNT -ge 2 ]; then
2587                 local MDTIDX=1
2588                 $LFS mkdir -i $MDTIDX $DIR1/$test_dir ||
2589                         error "Create remote directory failed"
2590         else
2591                 mkdir -p $DIR1/$test_dir
2592         fi
2593         cd $DIR2/$test_dir || error "cd directory failed"
2594         rm -rf $DIR1/$test_dir || error "unlink directory failed"
2595
2596         cd $DIR2/$tdir || error "exit directory"
2597 }
2598 run_test 70a "cd directory && rm directory"
2599
2600 test_70b() { # LU-2781
2601         local i
2602         mkdir -p $DIR1/$tdir
2603
2604         touch $DIR1/$tdir/file
2605         for ((i = 0; i < 32; i++)); do
2606             $LFS rm_entry $DIR1/$tdir/non_existent_dir &>/dev/null
2607         done
2608         rm $DIR1/$tdir/file || error "cannot remove file after rm_entry"
2609
2610         touch $DIR1/$tdir/file
2611         $LFS mkdir -i0 $DIR1/$tdir/test_dir
2612         $LFS rm_entry $DIR1/$tdir/test_dir &>/dev/null
2613         rm -rf $DIR1/$tdir/test_dir ||
2614                 error "cannot remove directory after rm_entry"
2615         rm $DIR1/$tdir/file || error "cannot remove file after rm_entry"
2616 }
2617 run_test 70b "remove files after calling rm_entry"
2618
2619 test_71() {
2620         local server_version=$(lustre_version_code $SINGLEMDS)
2621
2622         [[ $server_version -lt $(version_code 2.1.6) ]] &&
2623                 skip "Need MDS version at least 2.1.6" && return
2624
2625         # Patch not applied to 2.2 and 2.3 branches
2626         [[ $server_version -ge $(version_code 2.2.0) ]] &&
2627         [[ $server_version -lt $(version_code 2.4.0) ]] &&
2628                 skip "Need MDS version at least 2.4.0" && return
2629
2630         checkfiemap --test ||
2631                 { skip "checkfiemap not runnable: $?" && return; }
2632         # write data this way: hole - data - hole - data
2633         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=1 count=1
2634         [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR1/$tfile) + 1)))" = \
2635                 "zfs" ] &&
2636                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return 0
2637         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=3 count=1
2638         GET_STAT="lctl get_param -n ldlm.services.ldlm_cbd.stats"
2639         stat $DIR2/$tfile
2640         local can1=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
2641         echo $can1
2642         checkfiemap $DIR2/$tfile 81920 ||
2643                 error "data is not flushed from client"
2644         local can2=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
2645         echo $can2
2646
2647         # common case of "create file, copy file" on a single node
2648         # should not flush data from ost
2649         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=1 count=1
2650         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=3 count=1
2651         stat $DIR1/$tfile
2652         local can3=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
2653         echo $can3
2654         checkfiemap $DIR1/$tfile 81920 ||
2655         error 4
2656         local can4=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
2657         echo $can2
2658         [ $can3 -eq $can4 ] || error $((can2-can1)) "cancel RPC occured."
2659 }
2660 run_test 71 "correct file map just after write operation is finished"
2661
2662 test_72() {
2663         local p="$TMP/sanityN-$TESTNAME.parameters"
2664         local tlink1
2665         local tlink2
2666         save_lustre_params client "llite.*.xattr_cache" > $p
2667         lctl set_param llite.*.xattr_cache 1 ||
2668                 { skip "xattr cache is not supported"; return 0; }
2669
2670         touch $DIR1/$tfile
2671         setfattr -n user.attr1 -v value1 $DIR1/$tfile ||
2672                 error "setfattr1 failed"
2673         getfattr -n user.attr1 $DIR2/$tfile | grep value1 ||
2674                 error "getfattr1 failed"
2675         setfattr -n user.attr1 -v value2 $DIR2/$tfile ||
2676                 error "setfattr2 failed"
2677         getfattr -n user.attr1 $DIR1/$tfile | grep value2 ||
2678                 error "getfattr2 failed"
2679
2680         # check that trusted.link is consistent
2681         tlink1=$(getfattr -n trusted.link $DIR1/$tfile | md5sum)
2682         ln $DIR2/$tfile $DIR2/$tfile-2 || error "failed to link"
2683         tlink2=$(getfattr -n trusted.link $DIR1/$tfile | md5sum)
2684         echo "$tlink1 $tlink2"
2685         [ "$tlink1" = "$tlink2" ] && error "trusted.link should have changed!"
2686
2687         rm -f $DIR2/$tfile
2688
2689         restore_lustre_params < $p
2690         rm -f $p
2691 }
2692 run_test 72 "getxattr/setxattr cache should be consistent between nodes"
2693
2694 test_73() {
2695         local p="$TMP/sanityN-$TESTNAME.parameters"
2696         save_lustre_params client "llite.*.xattr_cache" > $p
2697         lctl set_param llite.*.xattr_cache 1 ||
2698                 { skip "xattr cache is not supported"; return 0; }
2699
2700         touch $DIR1/$tfile
2701         setfattr -n user.attr1 -v value1 $DIR1/$tfile ||
2702                 error "setfattr1 failed"
2703         getfattr -n user.attr1 $DIR2/$tfile || error "getfattr1 failed"
2704         getfattr -n user.attr1 $DIR1/$tfile || error "getfattr2 failed"
2705         clear_llite_stats
2706         # PR lock should be cached by now on both clients
2707         getfattr -n user.attr1 $DIR1/$tfile || error "getfattr3 failed"
2708         # 2 hits for getfattr(0)+getfattr(size)
2709         [ $(calc_llite_stats getxattr_hits) -eq 2 ] || error "not cached in $DIR1"
2710         getfattr -n user.attr1 $DIR2/$tfile || error "getfattr4 failed"
2711         # 4 hits for more getfattr(0)+getfattr(size)
2712         [ $(calc_llite_stats getxattr_hits) -eq 4 ] || error "not cached in $DIR2"
2713         rm -f $DIR2/$tfile
2714
2715         restore_lustre_params < $p
2716         rm -f $p
2717 }
2718 run_test 73 "getxattr should not cause xattr lock cancellation"
2719
2720 test_74() {
2721         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.93) ] &&
2722                 skip "Need MDS version at least 2.4.93" && return
2723
2724         dd if=/dev/zero of=$DIR1/$tfile-1 bs=1K count=1
2725         dd if=/dev/zero of=$DIR1/$tfile-2 bs=1K count=1
2726         flocks_test 4 $DIR1/$tfile-1 $DIR2/$tfile-2
2727 }
2728 run_test 74 "flock deadlock: different mounts =============="
2729
2730 # LU-3889
2731 test_75() {
2732         $LFS setstripe -c 2 -S 1m -i 0 $DIR1/$tfile
2733         dd if=/dev/zero of=$DIR1/$tfile bs=1M count=2
2734         cancel_lru_locks osc
2735
2736         dd of=$DIR1/$tfile if=/dev/zero bs=1M count=1 seek=1 conv=notrunc
2737         sync
2738
2739         # define OBD_FAIL_LDLM_ENQUEUE_HANG 0x31d
2740         $LCTL set_param fail_loc=0x31d
2741         stat -c %s $DIR1/$tfile &
2742         local pid=$!
2743         sleep 1
2744         kill -9 $pid
2745
2746         # For bad lock error handler we should ASSERT and got kernel panic here
2747         sleep 4
2748         $LCTL set_param fail_loc=0
2749 }
2750 run_test 75 "osc: upcall after unuse lock==================="
2751
2752 test_76() { #LU-946
2753         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
2754                 skip "Need MDS version at least 2.5.53" && return
2755
2756         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2757         local fcount=2048
2758         declare -a fd_list
2759         declare -a fid_list
2760
2761         if remote_mds; then
2762                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
2763         else
2764                 nid="0@lo"
2765         fi
2766
2767         rm -rf $DIR/$tdir
2768         test_mkdir -p $DIR/$tdir
2769
2770         # drop all open locks and close any cached "open" files on the client
2771         cancel_lru_locks mdc
2772
2773         echo -n "open files "
2774         ulimit -n 8096
2775         for ((i = 0; i < $fcount; i++)); do
2776                 touch $DIR/$tdir/f_$i
2777                 local fd=$(free_fd)
2778                 local cmd="exec $fd<$DIR/$tdir/f_$i"
2779                 eval $cmd
2780                 fd_list[i]=$fd
2781                 echo -n "."
2782         done
2783         echo
2784
2785         local get_open_fids="$LCTL get_param -n mdt.*.exports.'$nid'.open_files"
2786         local fid_list=($(do_nodes $(comma_list $(mdts_nodes)) $get_open_fids))
2787
2788         # Possible errors in openfiles FID list.
2789         # 1. Missing FIDs. Check 1
2790         # 2. Extra FIDs. Check 1
2791         # 3. Duplicated FID. Check 2
2792         # 4. Invalid FIDs. Check 2
2793         # 5. Valid FID, points to some other file. Check 3
2794
2795         # Check 1
2796         [ ${#fid_list[@]} -ne $fcount ] &&
2797                 error "${#fid_list[@]} != $fcount open files"
2798
2799         for (( i = 0; i < $fcount; i++ )) ; do
2800                 cmd="exec ${fd_list[i]}</dev/null"
2801                 eval $cmd
2802                 filename=$($LFS fid2path $DIR2 ${fid_list[i]})
2803
2804                 # Check 2
2805                 rm --interactive=no $filename
2806                 [ $? -ne 0 ] &&
2807                         error "Nonexisting fid ${fid_list[i]} listed."
2808         done
2809
2810         # Check 3
2811         ls_op=$(ls $DIR2/$tdir | wc -l)
2812         [ $ls_op -ne 0 ] &&
2813                 error "Some openfiles are missing in lproc output"
2814
2815         rm -rf $DIR/$tdir
2816 }
2817 run_test 76 "Verify open file for 2048 files"
2818
2819 nrs_write_read() {
2820         local n=16
2821         local dir=$DIR/$tdir
2822
2823         mkdir $dir || error "mkdir $dir failed"
2824         $LFS setstripe -c $OSTCOUNT $dir || error "setstripe to $dir failed"
2825
2826         do_nodes $CLIENTS dd if=/dev/zero of="$dir/nrs_r_$HOSTNAME"\
2827                 bs=1M count=$n > /dev/null 2>&1
2828
2829         for ((i = 0; i < $n; i++)); do
2830                 do_nodes $CLIENTS dd if=/dev/zero of="$dir/nrs_w_$HOSTNAME"\
2831                         bs=1M seek=$i count=1 > /dev/null 2>&1 &
2832                 local pids_w[$i]=$!
2833         done
2834         do_nodes $CLIENTS sync;
2835         cancel_lru_locks osc
2836
2837         for ((i = 0; i < $n; i++)); do
2838                 do_nodes $CLIENTS dd if="$dir/nrs_w_$HOSTNAME" of=/dev/zero\
2839                         bs=1M seek=$i count=1 > /dev/null 2>&1 &
2840                 local pids_r[$i]=$!
2841         done
2842         cancel_lru_locks osc
2843
2844         for ((i = 0; i < $n; i++)); do
2845                 wait ${pids_w[$i]}
2846                 wait ${pids_r[$i]}
2847         done
2848         rm -rf $dir || error "rm -rf $dir failed"
2849 }
2850
2851 test_77a() { #LU-3266
2852         do_facet $SINGLEMDS lctl set_param ost.OSS.*.nrs_policies="fifo"
2853         nrs_write_read
2854
2855         return 0
2856 }
2857 run_test 77a "check FIFO NRS policy"
2858
2859
2860 test_77b() { #LU-3266
2861         do_facet $SINGLEMDS lctl set_param ost.OSS.*.nrs_policies="crrn"
2862         do_facet $SINGLEMDS lctl set_param ost.OSS.*.nrs_crrn_quantum=1
2863
2864         echo "policy: crr-n, crrn_quantum 1"
2865         nrs_write_read
2866
2867         do_facet $SINGLEMDS lctl set_param ost.OSS.*.nrs_crrn_quantum=64
2868
2869         echo "policy: crr-n, crrn_quantum 64"
2870         nrs_write_read
2871
2872         return 0
2873 }
2874 run_test 77b "check CRR-N NRS policy"
2875
2876 orr_trr() {
2877         local policy=$1
2878
2879         for i in $(seq 1 $OSTCOUNT)
2880         do
2881                 do_facet ost"$i" lctl set_param \
2882                         ost.OSS.ost_io.nrs_policies=$policy
2883                 do_facet ost"$i" lctl set_param \
2884                         ost.OSS.*.nrs_"$policy"_quantum=1
2885                 do_facet ost"$i" lctl set_param \
2886                         ost.OSS.*.nrs_"$policy"_offset_type="physical"
2887                 do_facet ost"$i" lctl set_param \
2888                         ost.OSS.*.nrs_"$policy"_supported="reads"
2889         done
2890
2891         echo "policy: $policy, ${policy}_quantum 1, ${policy}_offset_type \
2892                                 physical, ${policy}_supported reads"
2893         nrs_write_read
2894
2895         for i in $(seq 1 $OSTCOUNT)
2896         do
2897                 do_facet ost"$i" lctl set_param \
2898                         ost.OSS.*.nrs_${policy}_supported="writes"
2899                 do_facet ost"$i" lctl set_param \
2900                         ost.OSS.*.nrs_${policy}_quantum=64
2901         done
2902         echo "policy: $policy, ${policy}_quantum 64, \
2903                 ${policy}_offset_type physical, ${policy}_supported writes"
2904         nrs_write_read
2905
2906         for i in $(seq 1 $OSTCOUNT)
2907         do
2908                 do_facet ost"$i" lctl set_param \
2909                         ost.OSS.*.nrs_${policy}_supported="reads_and_writes"
2910                 do_facet ost"$i" lctl set_param \
2911                         ost.OSS.*.nrs_${policy}_offset_type="logical"
2912         done
2913         echo "policy: $policy, ${policy}_quantum 64, \
2914                 ${policy}_offset_type logical, ${policy}_supported reads_and_writes"
2915         nrs_write_read
2916
2917         return 0
2918 }
2919
2920 test_77c() { #LU-3266
2921         orr_trr "orr"
2922         return 0
2923 }
2924 run_test 77c "check ORR NRS policy"
2925
2926 test_77d() { #LU-3266
2927         orr_trr "trr"
2928         return 0
2929 }
2930 run_test 77d "check TRR nrs policy"
2931
2932 test_80() {
2933         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2934         local MDTIDX=1
2935         local mdt_index
2936         local i
2937         local file
2938         local pid
2939
2940         mkdir -p $DIR1/$tdir/dir
2941         createmany -o $DIR1/$tdir/dir/f 10 ||
2942                 error "create files under remote dir failed $i"
2943
2944         cp /etc/passwd $DIR1/$tdir/$tfile
2945
2946         #migrate open file should fails
2947         multiop_bg_pause $DIR2/$tdir/$tfile O_c || error "open $file failed"
2948         pid=$!
2949         # give multiop a chance to open
2950         sleep 1
2951
2952         $LFS mv -M $MDTIDX $DIR1/$tdir &&
2953                 error "migrate open files should failed with open files"
2954
2955         kill -USR1 $pid
2956
2957         $LFS mv -M $MDTIDX $DIR1/$tdir ||
2958                         error "migrate remote dir error"
2959
2960         echo "Finish migration, then checking.."
2961         for file in $(find $DIR1/$tdir); do
2962                 mdt_index=$($LFS getstripe -M $file)
2963                 [ $mdt_index == $MDTIDX ] ||
2964                         error "$file is not on MDT${MDTIDX}"
2965         done
2966
2967         diff /etc/passwd $DIR1/$tdir/$tfile ||
2968                 error "file different after migration"
2969
2970         rm -rf $DIR1/$tdir || error "rm dir failed after migration"
2971 }
2972 run_test 80 "migrate directory when some children is being opened"
2973
2974 test_81() {
2975         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2976
2977         rm -rf $DIR1/$tdir
2978
2979         mkdir -p $DIR1/$tdir
2980
2981         $LFS setdirstripe -i0 -c$MDSCOUNT  $DIR1/$tdir/d0
2982         $LFS setdirstripe -i0 -c$MDSCOUNT  $DIR1/$tdir/d1
2983
2984         cd $DIR1/$tdir
2985         touch d0/0      || error "create 0 failed"
2986         mv d0/0 d1/0    || error "rename d0/0 d1/0 failed"
2987         stat d0/0       && error "stat mv filed succeed"
2988         mv $DIR2/$tdir/d1/0 $DIR2/$tdir/d0/0 || "rename d1/0 d0/0 failed"
2989         stat d0/0       || error "stat failed"
2990
2991         local t=$(ls -ai $DIR1/$tdir/d0 | sort -u | wc -l)
2992
2993         if [ $t -ne 3 ]; then
2994                 ls -ai $DIR1/$tdir/d0
2995                 error "expect 3 get $t"
2996         fi
2997
2998         return 0
2999 }
3000 run_test 81 "rename and stat under striped directory"
3001
3002 test_82() {
3003         [[ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.6.91) ]] ||
3004                 { skip "Need MDS version at least 2.6.92"; return 0; }
3005
3006         # Client 1 creates a file.
3007         multiop_bg_pause $DIR1/$tfile O_ac || error "multiop_bg_pause 1"
3008         pid1=$!
3009         # Client 2 opens the file.
3010         multiop_bg_pause $DIR2/$tfile o_Ac || error "multiop_bg_pause 2"
3011         pid2=$!
3012         # Client 1 makes the file an orphan.
3013         rm $DIR1/$tfile || error "rm"
3014         # Client 2 sets EA "user.multiop".
3015         kill -s USR1 $pid2
3016         wait $pid2 || error "multiop 2"
3017         # Client 1 gets EA "user.multiop".  This used to fail because the EA
3018         # cache refill would get "trusted.link" from mdd_xattr_list() but
3019         # -ENOENT when trying to get "trusted.link"'s value.  See also sanity
3020         # 102q.
3021         kill -s USR1 $pid1
3022         wait $pid1 || error "multiop 1"
3023 }
3024 run_test 82 "fsetxattr and fgetxattr on orphan files"
3025
3026 log "cleanup: ======================================================"
3027
3028 [ "$(mount | grep $MOUNT2)" ] && umount $MOUNT2
3029
3030 complete $SECONDS
3031 rm -f $SAMPLE_FILE
3032 check_and_cleanup_lustre
3033 exit_status