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