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