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