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