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