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