Whamcloud - gitweb
d59d426a5ce7be4403f17f1ad024175a79852cf9
[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 pdo_sched() {
1464         # how long 40-47 take with specific delay
1465         # sleep 0.1 # 78s
1466         sleep 0.2 # 103s
1467         # sleep 0.3 # 124s
1468         # sleep 0.5 # 164s
1469 }
1470
1471 # check that pid exists hence second operation wasn't blocked by first one
1472 # if it is so then there is no conflict, return 0
1473 # else second operation is conflicting with first one, return 1
1474 check_pdo_conflict() {
1475         local pid=$1
1476         local conflict=0
1477         pdo_sched # to ensure OP1 is finished on client if OP2 is blocked by OP1
1478         if [[ `ps --pid $pid | wc -l` == 1 ]]; then
1479                 conflict=1
1480                 echo "Conflict"
1481         else
1482                 echo "No conflict"
1483         fi
1484         return $conflict
1485 }
1486
1487 # pdirop tests
1488 # test 40: check non-blocking operations
1489 test_40a() {
1490         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1491         cancel_lru_locks mdc
1492 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1493         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1494         touch $DIR2
1495         mkdir $DIR1/$tfile &
1496         PID1=$!; pdo_sched
1497         touch $DIR2/$tfile-2
1498         check_pdo_conflict $PID1 || error "create is blocked"
1499         mkdir $DIR2/$tfile-3
1500         check_pdo_conflict $PID1 || error "mkdir is blocked"
1501         link $DIR2/$tfile-2 $DIR2/$tfile-4
1502         check_pdo_conflict $PID1 || error "link is blocked"
1503         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1504         check_pdo_conflict $PID1 || error "rename is blocked"
1505         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1506         check_pdo_conflict $PID1 || error "getattr is blocked"
1507         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1508         rmdir $DIR2/$tfile-3
1509         check_pdo_conflict $PID1 || error "unlink is blocked"
1510
1511         #  all operations above shouldn't wait the first one
1512         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1513         do_facet $SINGLEMDS lctl set_param fail_loc=0
1514         wait $PID1
1515         rm -rf $DIR/$tfile*
1516         return 0
1517 }
1518 run_test 40a "pdirops: create vs others =============="
1519
1520 test_40b() {
1521         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1522         cancel_lru_locks mdc
1523 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1524         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1525         touch $DIR1/$tfile &
1526         PID1=$!; pdo_sched
1527         # open|create
1528         touch $DIR2/$tfile-2
1529         check_pdo_conflict $PID1 || error "create is blocked"
1530         mkdir $DIR2/$tfile-3
1531         check_pdo_conflict $PID1 || error "mkdir is blocked"
1532         link $DIR2/$tfile-2 $DIR2/$tfile-4
1533         check_pdo_conflict $PID1 || error "link is blocked"
1534         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1535         check_pdo_conflict $PID1 || error "rename is blocked"
1536         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1537         check_pdo_conflict $PID1 || error "getattr is blocked"
1538         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1539         rmdir $DIR2/$tfile-3
1540         check_pdo_conflict $PID1 || error "unlink is blocked"
1541         # all operations above shouldn't wait the first one
1542
1543         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1544         do_facet $SINGLEMDS lctl set_param fail_loc=0
1545         wait $PID1
1546         rm -rf $DIR/$tfile*
1547         return 0
1548 }
1549 run_test 40b "pdirops: open|create and others =============="
1550
1551 test_40c() {
1552         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1553         cancel_lru_locks mdc
1554         touch $DIR1/$tfile
1555 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1556         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1557         link $DIR1/$tfile $DIR1/$tfile-0 &
1558         PID1=$!; pdo_sched
1559         # open|create
1560         touch $DIR2/$tfile-2
1561         check_pdo_conflict $PID1 || error "create is blocked"
1562         mkdir $DIR2/$tfile-3
1563         check_pdo_conflict $PID1 || error "mkdir is blocked"
1564         link $DIR2/$tfile-2 $DIR2/$tfile-4
1565         check_pdo_conflict $PID1 || error "link is blocked"
1566         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1567         check_pdo_conflict $PID1 || error "rename is blocked"
1568         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1569         check_pdo_conflict $PID1 || error "getattr is blocked"
1570         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1571         rmdir $DIR2/$tfile-3
1572         check_pdo_conflict $PID1 || error "unlink is blocked"
1573
1574         # all operations above shouldn't wait the first one
1575         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1576         do_facet $SINGLEMDS lctl set_param fail_loc=0
1577         wait $PID1
1578         rm -rf $DIR/$tfile*
1579         return 0
1580 }
1581 run_test 40c "pdirops: link and others =============="
1582
1583 test_40d() {
1584         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1585         cancel_lru_locks mdc
1586         touch $DIR1/$tfile
1587 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1588         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1589         rm $DIR1/$tfile &
1590         PID1=$!; pdo_sched
1591         # open|create
1592         touch $DIR2/$tfile-2
1593         check_pdo_conflict $PID1 || error "create is blocked"
1594         mkdir $DIR2/$tfile-3
1595         check_pdo_conflict $PID1 || error "mkdir is blocked"
1596         link $DIR2/$tfile-2 $DIR2/$tfile-4
1597         check_pdo_conflict $PID1 || error "link is blocked"
1598         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1599         check_pdo_conflict $PID1 || error "rename is blocked"
1600         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1601         check_pdo_conflict $PID1 || error "getattr is blocked"
1602         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1603         rmdir $DIR2/$tfile-3
1604         check_pdo_conflict $PID1 || error "unlink is blocked"
1605
1606         # all operations above shouldn't wait the first one
1607         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1608         do_facet $SINGLEMDS lctl set_param fail_loc=0
1609         wait $PID1
1610         return 0
1611 }
1612 run_test 40d "pdirops: unlink and others =============="
1613
1614 test_40e() {
1615         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1616         cancel_lru_locks mdc
1617         touch $DIR1/$tfile
1618 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1619         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1620         mv $DIR1/$tfile $DIR1/$tfile-0 &
1621         PID1=$!; pdo_sched
1622         # open|create
1623         touch $DIR2/$tfile-2
1624         check_pdo_conflict $PID1 || error "create is blocked"
1625         mkdir $DIR2/$tfile-3
1626         check_pdo_conflict $PID1 || error "mkdir is blocked"
1627         link $DIR2/$tfile-2 $DIR2/$tfile-4
1628         check_pdo_conflict $PID1 || error "link is blocked"
1629         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1630         check_pdo_conflict $PID1 || error "getattr is blocked"
1631         rm $DIR2/$tfile-4 $DIR2/$tfile-2
1632         rmdir $DIR2/$tfile-3
1633         check_pdo_conflict $PID1 || error "unlink is blocked"
1634
1635        # all operations above shouldn't wait the first one
1636         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1637         do_facet $SINGLEMDS lctl set_param fail_loc=0
1638         wait $PID1
1639         rm -rf $DIR/$tfile*
1640         return 0
1641 }
1642 run_test 40e "pdirops: rename and others =============="
1643
1644 # test 41: create blocking operations
1645 test_41a() {
1646         cancel_lru_locks mdc
1647 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1648         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1649         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1650         PID1=$! ; pdo_sched
1651         mkdir $DIR2/$tfile &
1652         PID2=$! ; pdo_sched
1653         do_facet $SINGLEMDS lctl set_param fail_loc=0
1654         check_pdo_conflict $PID1 && { wait $PID1; echo "mkdir isn't blocked"; }
1655         wait $PID2 ; [ $? -ne 0 ] || error "mkdir must fail"
1656         rm -rf $DIR/$tfile*
1657         return 0
1658 }
1659 run_test 41a "pdirops: create vs mkdir =============="
1660
1661 test_41b() {
1662         cancel_lru_locks mdc
1663 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1664         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1665         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1666         PID1=$! ; pdo_sched
1667         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
1668         PID2=$! ; pdo_sched
1669         do_facet $SINGLEMDS lctl set_param fail_loc=0
1670         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1671         wait $PID2 ; [ $? -ne 0 ] || error "create must fail"
1672         rm -rf $DIR/$tfile*
1673         return 0
1674 }
1675 run_test 41b "pdirops: create vs create =============="
1676
1677 test_41c() {
1678         cancel_lru_locks mdc
1679         touch $DIR1/$tfile-2
1680 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1681         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1682         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1683         PID1=$! ; pdo_sched
1684         link $DIR2/$tfile-2 $DIR2/$tfile &
1685         PID2=$! ; pdo_sched
1686         do_facet $SINGLEMDS lctl set_param fail_loc=0
1687         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1688         wait $PID2 ; [ $? -ne 0 ] || error "link must fail"
1689         rm -rf $DIR/$tfile*
1690         return 0
1691 }
1692 run_test 41c "pdirops: create vs link =============="
1693
1694 test_41d() {
1695         cancel_lru_locks mdc
1696 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1697         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1698         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1699         PID1=$! ; pdo_sched
1700         rm $DIR2/$tfile &
1701         PID2=$! ; pdo_sched
1702         do_facet $SINGLEMDS lctl set_param fail_loc=0
1703         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1704         wait $PID2 ; [ $? -eq 0 ] || error "unlink must succeed"
1705         rm -rf $DIR/$tfile*
1706         return 0
1707 }
1708 run_test 41d "pdirops: create vs unlink =============="
1709
1710 test_41e() {
1711         cancel_lru_locks mdc
1712         touch $DIR1/$tfile-2
1713 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1714         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1715         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1716         PID1=$! ; pdo_sched
1717         mv $DIR2/$tfile-2 $DIR2/$tfile &
1718         PID2=$! ; pdo_sched
1719         do_facet $SINGLEMDS lctl set_param fail_loc=0
1720         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1721         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
1722         rm -rf $DIR/$tfile*
1723         return 0
1724 }
1725 run_test 41e "pdirops: create and rename (tgt) =============="
1726
1727 test_41f() {
1728         cancel_lru_locks mdc
1729 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1730         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1731         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1732         PID1=$! ; pdo_sched
1733         mv $DIR2/$tfile $DIR2/$tfile-2 &
1734         PID2=$! ; pdo_sched
1735         do_facet $SINGLEMDS lctl set_param fail_loc=0
1736         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1737         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
1738         rm -rf $DIR/$tfile*
1739         return 0
1740 }
1741 run_test 41f "pdirops: create and rename (src) =============="
1742
1743 test_41g() {
1744         cancel_lru_locks mdc
1745 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1746         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1747         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1748         PID1=$! ; pdo_sched
1749         stat $DIR2/$tfile > /dev/null &
1750         PID2=$! ; pdo_sched
1751         do_facet $SINGLEMDS lctl set_param fail_loc=0
1752         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1753         wait $PID2 ; [ $? -eq 0 ] || error "stat must succeed"
1754         rm -rf $DIR/$tfile*
1755         return 0
1756 }
1757 run_test 41g "pdirops: create vs getattr =============="
1758
1759 test_41h() {
1760         cancel_lru_locks mdc
1761 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1762         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1763         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1764         PID1=$! ; pdo_sched
1765         ls -lia $DIR2/ > /dev/null &
1766         PID2=$! ; pdo_sched
1767         do_facet $SINGLEMDS lctl set_param fail_loc=0
1768         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1769         wait $PID2
1770         rm -rf $DIR/$tfile*
1771         return 0
1772 }
1773 run_test 41h "pdirops: create vs readdir =============="
1774
1775 # test 42: unlink and blocking operations
1776 test_42a() {
1777         cancel_lru_locks mdc
1778 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1779         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1780         mkdir $DIR1/$tfile &
1781         PID1=$! ; pdo_sched
1782         mkdir $DIR2/$tfile &
1783         PID2=$! ; pdo_sched
1784         do_facet $SINGLEMDS lctl set_param fail_loc=0
1785         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1786         wait $PID2 ; [ $? -ne 0 ] || error "mkdir must fail"
1787         rm -rf $DIR/$tfile*
1788         return 0
1789 }
1790 run_test 42a "pdirops: mkdir vs mkdir =============="
1791
1792 test_42b() {
1793         cancel_lru_locks mdc
1794 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1795         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1796         mkdir $DIR1/$tfile &
1797         PID1=$! ; pdo_sched
1798         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
1799         PID2=$! ; pdo_sched
1800         do_facet $SINGLEMDS lctl set_param fail_loc=0
1801         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1802         wait $PID2 ; [ $? -ne 0 ] || error "create must fail"
1803         rm -rf $DIR/$tfile*
1804         return 0
1805 }
1806 run_test 42b "pdirops: mkdir vs create =============="
1807
1808 test_42c() {
1809         cancel_lru_locks mdc
1810         touch $DIR1/$tfile-2
1811 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1812         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1813         mkdir $DIR1/$tfile &
1814         PID1=$! ; pdo_sched
1815         link $DIR2/$tfile-2 $DIR2/$tfile &
1816         PID2=$! ; pdo_sched
1817         do_facet $SINGLEMDS lctl set_param fail_loc=0
1818         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1819         wait $PID2 ; [ $? -ne 0 ] || error "link must fail"
1820         rm -rf $DIR/$tfile*
1821         return 0
1822 }
1823 run_test 42c "pdirops: mkdir vs link =============="
1824
1825 test_42d() {
1826         cancel_lru_locks mdc
1827 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1828         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1829         mkdir $DIR1/$tfile &
1830         PID1=$! ; pdo_sched
1831         rmdir $DIR2/$tfile &
1832         PID2=$! ; pdo_sched
1833         do_facet $SINGLEMDS lctl set_param fail_loc=0
1834         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1835         wait $PID2 ; [ $? -eq 0 ] || error "unlink must succeed"
1836         rm -rf $DIR/$tfile*
1837         return 0
1838 }
1839 run_test 42d "pdirops: mkdir vs unlink =============="
1840
1841 test_42e() {
1842         cancel_lru_locks mdc
1843         touch $DIR1/$tfile-2
1844 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1845         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1846         mkdir $DIR1/$tfile &
1847         PID1=$! ; pdo_sched
1848         mv -T $DIR2/$tfile-2 $DIR2/$tfile &
1849         PID2=$! ; pdo_sched
1850         do_facet $SINGLEMDS lctl set_param fail_loc=0
1851         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1852         wait $PID2 ; [ $? -ne 0 ] || error "rename must fail"
1853         rm -rf $DIR/$tfile*
1854         return 0
1855 }
1856 run_test 42e "pdirops: mkdir and rename (tgt) =============="
1857
1858 test_42f() {
1859         cancel_lru_locks mdc
1860 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1861         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1862         mkdir $DIR1/$tfile &
1863         PID1=$! ; pdo_sched
1864         mv $DIR2/$tfile $DIR2/$tfile-2 &
1865         PID2=$! ; pdo_sched
1866         do_facet $SINGLEMDS lctl set_param fail_loc=0
1867         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1868         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
1869         rm -rf $DIR/$tfile*
1870         return 0
1871 }
1872 run_test 42f "pdirops: mkdir and rename (src) =============="
1873
1874 test_42g() {
1875         cancel_lru_locks mdc
1876 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1877         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1878         mkdir $DIR1/$tfile &
1879         PID1=$! ; pdo_sched
1880         stat $DIR2/$tfile > /dev/null &
1881         PID2=$! ; pdo_sched
1882         do_facet $SINGLEMDS lctl set_param fail_loc=0
1883         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1884         wait $PID2 ; [ $? -eq 0 ] || error "stat must succeed"
1885         rm -rf $DIR/$tfile*
1886         return 0
1887 }
1888 run_test 42g "pdirops: mkdir vs getattr =============="
1889
1890 test_42h() {
1891         cancel_lru_locks mdc
1892 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1893         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1894         mkdir $DIR1/$tfile &
1895         PID1=$! ; pdo_sched
1896         ls -lia $DIR2/ > /dev/null &
1897         PID2=$! ; pdo_sched
1898         do_facet $SINGLEMDS lctl set_param fail_loc=0
1899         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1900         wait $PID2
1901         rm -rf $DIR/$tfile*
1902         return 0
1903 }
1904 run_test 42h "pdirops: mkdir vs readdir =============="
1905
1906 # test 43: unlink and blocking operations
1907 test_43a() {
1908         cancel_lru_locks mdc
1909         touch $DIR1/$tfile
1910 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1911         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1912         rm $DIR1/$tfile &
1913         PID1=$! ; pdo_sched
1914         mkdir $DIR2/$tfile &
1915         PID2=$! ; pdo_sched
1916         do_facet $SINGLEMDS lctl set_param fail_loc=0
1917         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1918         wait $PID2 ; [ $? -eq 0 ] || error "mkdir must succeed"
1919         rm -rf $DIR/$tfile*
1920         return 0
1921 }
1922 run_test 43a "pdirops: unlink vs mkdir =============="
1923
1924 test_43b() {
1925         cancel_lru_locks mdc
1926         touch $DIR1/$tfile
1927 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1928         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1929         rm $DIR1/$tfile &
1930         PID1=$! ; pdo_sched
1931         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
1932         PID2=$! ; pdo_sched
1933         do_facet $SINGLEMDS lctl set_param fail_loc=0
1934         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1935         wait $PID2 ; [ $? -eq 0 ] || error "create must succeed"
1936         rm -rf $DIR/$tfile*
1937         return 0
1938 }
1939 run_test 43b "pdirops: unlink vs create =============="
1940
1941 test_43c() {
1942         cancel_lru_locks mdc
1943         touch $DIR1/$tfile
1944         touch $DIR1/$tfile-2
1945 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1946         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1947         rm $DIR1/$tfile &
1948         PID1=$! ; pdo_sched
1949         link $DIR2/$tfile-2 $DIR2/$tfile &
1950         PID2=$! ; pdo_sched
1951         do_facet $SINGLEMDS lctl set_param fail_loc=0
1952         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1953         wait $PID2 ; [ $? -eq 0 ] || error "link must succeed"
1954         rm -rf $DIR/$tfile*
1955         return 0
1956 }
1957 run_test 43c "pdirops: unlink vs link =============="
1958
1959 test_43d() {
1960         cancel_lru_locks mdc
1961         touch $DIR1/$tfile
1962 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1963         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1964         rm $DIR1/$tfile &
1965         PID1=$! ; pdo_sched
1966         rm $DIR2/$tfile &
1967         PID2=$! ; pdo_sched
1968         do_facet $SINGLEMDS lctl set_param fail_loc=0
1969         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1970         wait $PID2 ; [ $? -ne 0 ] || error "unlink must fail"
1971         rm -rf $DIR/$tfile*
1972         return 0
1973 }
1974 run_test 43d "pdirops: unlink vs unlink =============="
1975
1976 test_43e() {
1977         cancel_lru_locks mdc
1978         touch $DIR1/$tfile
1979         touch $DIR1/$tfile-2
1980 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1981         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1982         rm $DIR1/$tfile &
1983         PID1=$! ; pdo_sched
1984         mv -u $DIR2/$tfile-2 $DIR2/$tfile &
1985         PID2=$! ; pdo_sched
1986         do_facet $SINGLEMDS lctl set_param fail_loc=0
1987         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1988         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
1989         rm -rf $DIR/$tfile*
1990         return 0
1991 }
1992 run_test 43e "pdirops: unlink and rename (tgt) =============="
1993
1994 test_43f() {
1995         cancel_lru_locks mdc
1996         touch $DIR1/$tfile
1997 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1998         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1999         rm $DIR1/$tfile &
2000         PID1=$! ; pdo_sched
2001         mv $DIR2/$tfile $DIR2/$tfile-2 &
2002         PID2=$! ; pdo_sched
2003         do_facet $SINGLEMDS lctl set_param fail_loc=0
2004         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2005         wait $PID2 ; [ $? -ne 0 ] || error "rename must fail"
2006         rm -rf $DIR/$tfile*
2007         return 0
2008 }
2009 run_test 43f "pdirops: unlink and rename (src) =============="
2010
2011 test_43g() {
2012         cancel_lru_locks mdc
2013         touch $DIR1/$tfile
2014 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2015         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2016         rm $DIR1/$tfile &
2017         PID1=$! ; pdo_sched
2018         stat $DIR2/$tfile > /dev/null &
2019         PID2=$! ; pdo_sched
2020         do_facet $SINGLEMDS lctl set_param fail_loc=0
2021         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
2022         wait $PID2 ; [ $? -ne 0 ] || error "stat must fail"
2023         rm -rf $DIR/$tfile*
2024         return 0
2025 }
2026 run_test 43g "pdirops: unlink vs getattr =============="
2027
2028 test_43h() {
2029         cancel_lru_locks mdc
2030         touch $DIR1/$tfile
2031 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2032         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2033         rm $DIR1/$tfile &
2034         PID1=$! ; pdo_sched
2035         ls -lia $DIR2/ > /dev/null &
2036         PID2=$! ; pdo_sched
2037         do_facet $SINGLEMDS lctl set_param fail_loc=0
2038         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
2039         wait $PID2
2040         rm -rf $DIR/$tfile*
2041         return 0
2042 }
2043 run_test 43h "pdirops: unlink vs readdir =============="
2044
2045 test_43i() {
2046         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2047         cancel_lru_locks mdc
2048         touch $DIR1/$tfile
2049 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2050         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2051         rm $DIR1/$tfile &
2052         PID1=$! ; pdo_sched
2053         $LFS mkdir -i 1 $DIR2/$tfile &
2054         PID2=$! ; pdo_sched
2055         do_facet $SINGLEMDS lctl set_param fail_loc=0
2056         check_pdo_conflict $PID1 &&
2057                 { wait $PID1; error "remote mkdir isn't blocked"; }
2058         wait $PID2 ; [ $? -eq 0 ] || error "remote mkdir must succeed"
2059         rm -rf $DIR/$tfile*
2060         return 0
2061 }
2062 run_test 43i "pdirops: unlink vs remote mkdir"
2063
2064 # test 44: rename tgt and blocking operations
2065 test_44a() {
2066         cancel_lru_locks mdc
2067         touch $DIR1/$tfile-2
2068 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
2069         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2070         mv $DIR1/$tfile-2 $DIR1/$tfile &
2071         PID1=$! ; pdo_sched
2072         mkdir $DIR2/$tfile &
2073         PID2=$! ; pdo_sched
2074         do_facet $SINGLEMDS lctl set_param fail_loc=0
2075         check_pdo_conflict $PID1 && { wait $PID1; date;error "mkdir isn't blocked"; }
2076         wait $PID2 ; [ $? -ne 0 ] || error "mkdir must fail"
2077         date
2078         rm -rf $DIR/$tfile*
2079         return 0
2080 }
2081 run_test 44a "pdirops: rename tgt vs mkdir =============="
2082
2083 test_44b() {
2084         cancel_lru_locks mdc
2085         touch $DIR1/$tfile-2
2086 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2087         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2088         mv $DIR1/$tfile-2 $DIR1/$tfile &
2089         PID1=$! ; pdo_sched
2090         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
2091         PID2=$! ; pdo_sched
2092         do_facet $SINGLEMDS lctl set_param fail_loc=0
2093         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
2094         wait $PID2 ; [ $? -ne 0 ] || error "create must fail"
2095         rm -rf $DIR/$tfile*
2096         return 0
2097 }
2098 run_test 44b "pdirops: rename tgt vs create =============="
2099
2100 test_44c() {
2101         cancel_lru_locks mdc
2102         touch $DIR1/$tfile-2
2103         touch $DIR1/$tfile-3
2104 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2105         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2106         mv $DIR1/$tfile-2 $DIR1/$tfile &
2107         PID1=$! ; pdo_sched
2108         link $DIR2/$tfile-3 $DIR2/$tfile &
2109         PID2=$! ; pdo_sched
2110         do_facet $SINGLEMDS lctl set_param fail_loc=0
2111         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2112         wait $PID2 ; [ $? -ne 0 ] || error "link must fail"
2113         rm -rf $DIR/$tfile*
2114         return 0
2115 }
2116 run_test 44c "pdirops: rename tgt vs link =============="
2117
2118 test_44d() {
2119         cancel_lru_locks mdc
2120         touch $DIR1/$tfile-2
2121 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2122         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2123         mv $DIR1/$tfile-2 $DIR1/$tfile &
2124         PID1=$! ; pdo_sched
2125         rm $DIR2/$tfile &
2126         PID2=$! ; pdo_sched
2127         do_facet $SINGLEMDS lctl set_param fail_loc=0
2128         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
2129         wait $PID2 ; [ $? -eq 0 ] || error "unlink must succeed"
2130         rm -rf $DIR/$tfile*
2131         return 0
2132 }
2133 run_test 44d "pdirops: rename tgt vs unlink =============="
2134
2135 test_44e() {
2136         cancel_lru_locks mdc
2137         touch $DIR1/$tfile
2138         touch $DIR1/$tfile-2
2139         touch $DIR1/$tfile-3
2140 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2141         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2142         mv $DIR1/$tfile-2 $DIR1/$tfile &
2143         PID1=$! ; pdo_sched
2144         mv $DIR2/$tfile-3 $DIR2/$tfile &
2145         PID2=$! ; pdo_sched
2146         do_facet $SINGLEMDS lctl set_param fail_loc=0
2147         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2148         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
2149         rm -rf $DIR/$tfile*
2150         return 0
2151 }
2152 run_test 44e "pdirops: rename tgt and rename (tgt) =============="
2153
2154 test_44f() {
2155         cancel_lru_locks mdc
2156         touch $DIR1/$tfile-2
2157         touch $DIR1/$tfile-3
2158 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2159         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2160         mv $DIR1/$tfile-2 $DIR1/$tfile &
2161         PID1=$! ; pdo_sched
2162         mv $DIR2/$tfile $DIR2/$tfile-3 &
2163         PID2=$! ; pdo_sched
2164         do_facet $SINGLEMDS lctl set_param fail_loc=0
2165         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2166         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
2167         rm -rf $DIR/$tfile*
2168         return 0
2169 }
2170 run_test 44f "pdirops: rename tgt and rename (src) =============="
2171
2172 test_44g() {
2173         cancel_lru_locks mdc
2174         touch $DIR1/$tfile-2
2175 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2176         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2177         mv $DIR1/$tfile-2 $DIR1/$tfile &
2178         PID1=$! ; pdo_sched
2179         stat $DIR2/$tfile > /dev/null &
2180         PID2=$! ; pdo_sched
2181         do_facet $SINGLEMDS lctl set_param fail_loc=0
2182         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
2183         wait $PID2 ; [ $? -eq 0 ] || error "stat must succeed"
2184         rm -rf $DIR/$tfile*
2185         return 0
2186 }
2187 run_test 44g "pdirops: rename tgt vs getattr =============="
2188
2189 test_44h() {
2190         cancel_lru_locks mdc
2191         touch $DIR1/$tfile-2
2192 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2193         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2194         mv $DIR1/$tfile-2 $DIR1/$tfile &
2195         PID1=$! ; pdo_sched
2196         ls -lia $DIR2/ > /dev/null &
2197         PID2=$! ; pdo_sched
2198         do_facet $SINGLEMDS lctl set_param fail_loc=0
2199         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
2200         wait $PID2
2201         rm -rf $DIR/$tfile*
2202         return 0
2203 }
2204 run_test 44h "pdirops: rename tgt vs readdir =============="
2205
2206 # test 44: rename tgt and blocking operations
2207 test_44i() {
2208         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2209         cancel_lru_locks mdc
2210         touch $DIR1/$tfile-2
2211 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
2212         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2213         mv $DIR1/$tfile-2 $DIR1/$tfile &
2214         PID1=$! ; pdo_sched
2215         $LFS mkdir -i 1 $DIR2/$tfile &
2216         PID2=$! ; pdo_sched
2217         do_facet $SINGLEMDS lctl set_param fail_loc=0
2218         check_pdo_conflict $PID1 && { wait $PID1;
2219                                 error "remote mkdir isn't blocked"; }
2220         wait $PID2 ; [ $? -ne 0 ] || error "remote mkdir must fail"
2221         rm -rf $DIR/$tfile*
2222         return 0
2223 }
2224 run_test 44i "pdirops: rename tgt vs remote mkdir"
2225
2226 # test 45: rename src and blocking operations
2227 test_45a() {
2228         cancel_lru_locks mdc
2229         touch $DIR1/$tfile
2230 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2231         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2232         mv $DIR1/$tfile $DIR1/$tfile-2 &
2233         PID1=$! ; pdo_sched
2234         mkdir $DIR2/$tfile &
2235         PID2=$! ; pdo_sched
2236         do_facet $SINGLEMDS lctl set_param fail_loc=0
2237         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
2238         wait $PID2 ; [ $? -eq 0 ] || error "mkdir must succeed"
2239         rm -rf $DIR/$tfile*
2240         return 0
2241 }
2242 run_test 45a "pdirops: rename src vs mkdir =============="
2243
2244 test_45b() {
2245         cancel_lru_locks mdc
2246         touch $DIR1/$tfile
2247 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2248         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2249         mv $DIR1/$tfile $DIR1/$tfile-2 &
2250         PID1=$! ; pdo_sched
2251         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
2252         PID2=$! ; pdo_sched
2253         do_facet $SINGLEMDS lctl set_param fail_loc=0
2254         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
2255         wait $PID2 ; [ $? -eq 0 ] || error "create must succeed"
2256         rm -rf $DIR/$tfile*
2257         return 0
2258 }
2259 run_test 45b "pdirops: rename src vs create =============="
2260
2261 test_45c() {
2262         cancel_lru_locks mdc
2263         touch $DIR1/$tfile
2264         touch $DIR1/$tfile-3
2265 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2266         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2267         mv $DIR1/$tfile $DIR1/$tfile-2 &
2268         PID1=$! ; pdo_sched
2269         link $DIR2/$tfile-3 $DIR2/$tfile &
2270         PID2=$! ; pdo_sched
2271         do_facet $SINGLEMDS lctl set_param fail_loc=0
2272         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2273         wait $PID2 ; [ $? -eq 0 ] || error "link must succeed"
2274         rm -rf $DIR/$tfile*
2275         return 0
2276 }
2277 run_test 45c "pdirops: rename src vs link =============="
2278
2279 test_45d() {
2280         cancel_lru_locks mdc
2281         touch $DIR1/$tfile
2282 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2283         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2284         mv $DIR1/$tfile $DIR1/$tfile-2 &
2285         PID1=$! ; pdo_sched
2286         rm $DIR2/$tfile &
2287         PID2=$! ; pdo_sched
2288         do_facet $SINGLEMDS lctl set_param fail_loc=0
2289         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
2290         wait $PID2 ; [ $? -ne 0 ] || error "unlink must fail"
2291         rm -rf $DIR/$tfile*
2292         return 0
2293 }
2294 run_test 45d "pdirops: rename src vs unlink =============="
2295
2296 test_45e() {
2297         cancel_lru_locks mdc
2298         touch $DIR1/$tfile
2299         touch $DIR1/$tfile-3
2300 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2301         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2302         mv $DIR1/$tfile $DIR1/$tfile-2 &
2303         PID1=$! ; pdo_sched
2304         mv $DIR2/$tfile-3 $DIR2/$tfile &
2305         PID2=$! ; pdo_sched
2306         do_facet $SINGLEMDS lctl set_param fail_loc=0
2307         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2308         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
2309         rm -rf $DIR/$tfile*
2310         return 0
2311 }
2312 run_test 45e "pdirops: rename src and rename (tgt) =============="
2313
2314 test_45f() {
2315         cancel_lru_locks mdc
2316         touch $DIR1/$tfile
2317 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2318         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2319         mv $DIR1/$tfile $DIR1/$tfile-2 &
2320         PID1=$! ; pdo_sched
2321         mv $DIR2/$tfile $DIR2/$tfile-3 &
2322         PID2=$! ; pdo_sched
2323         do_facet $SINGLEMDS lctl set_param fail_loc=0
2324         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2325         wait $PID2 ; [ $? -ne 0 ] || error "rename must fail"
2326         rm -rf $DIR/$tfile*
2327         return 0
2328 }
2329 run_test 45f "pdirops: rename src and rename (src) =============="
2330
2331 test_45g() {
2332         cancel_lru_locks mdc
2333         touch $DIR1/$tfile
2334 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2335         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2336         mv $DIR1/$tfile $DIR1/$tfile-2 &
2337         PID1=$! ; pdo_sched
2338         stat $DIR2/$tfile > /dev/null &
2339         PID2=$! ; pdo_sched
2340         do_facet $SINGLEMDS lctl set_param fail_loc=0
2341         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
2342         wait $PID2 ; [ $? -ne 0 ] || error "stat must fail"
2343         rm -rf $DIR/$tfile*
2344         return 0
2345 }
2346 run_test 45g "pdirops: rename src vs getattr =============="
2347
2348 test_45h() {
2349         cancel_lru_locks mdc
2350         touch $DIR1/$tfile
2351 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2352         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2353         mv $DIR1/$tfile $DIR1/$tfile-2 &
2354         PID1=$! ; pdo_sched
2355         ls -lia $DIR2/ > /dev/null &
2356         do_facet $SINGLEMDS lctl set_param fail_loc=0
2357         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
2358         wait $PID2
2359         rm -rf $DIR/$tfile*
2360         return 0
2361 }
2362 run_test 45h "pdirops: unlink vs readdir =============="
2363
2364 test_45i() {
2365         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2366         cancel_lru_locks mdc
2367         touch $DIR1/$tfile
2368 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2369         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2370         mv $DIR1/$tfile $DIR1/$tfile-2 &
2371         PID1=$! ; pdo_sched
2372         $LFS mkdir -i 1 $DIR2/$tfile &
2373         PID2=$! ; pdo_sched
2374         do_facet $SINGLEMDS lctl set_param fail_loc=0
2375         check_pdo_conflict $PID1 && { wait $PID1;
2376                                 error "create remote dir isn't blocked"; }
2377         wait $PID2 ; [ $? -eq 0 ] || error "create remote dir must succeed"
2378         rm -rf $DIR/$tfile*
2379         return 0
2380 }
2381 run_test 45i "pdirops: rename src vs remote mkdir"
2382
2383 # test 46: link and blocking operations
2384 test_46a() {
2385         cancel_lru_locks mdc
2386         touch $DIR1/$tfile-2
2387 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2388         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2389         link $DIR1/$tfile-2 $DIR1/$tfile &
2390         PID1=$! ; pdo_sched
2391         mkdir $DIR2/$tfile &
2392         PID2=$! ; pdo_sched
2393         do_facet $SINGLEMDS lctl set_param fail_loc=0
2394         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
2395         wait $PID2 ; [ $? -ne 0 ] || error "mkdir must fail"
2396         rm -rf $DIR/$tfile*
2397         return 0
2398 }
2399 run_test 46a "pdirops: link vs mkdir =============="
2400
2401 test_46b() {
2402         cancel_lru_locks mdc
2403         touch $DIR1/$tfile-2
2404 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2405         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2406         link $DIR1/$tfile-2 $DIR1/$tfile &
2407         PID1=$! ; pdo_sched
2408         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
2409         PID2=$! ; pdo_sched
2410         do_facet $SINGLEMDS lctl set_param fail_loc=0
2411         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
2412         wait $PID2 ; [ $? -ne 0 ] || error "create must fail"
2413         rm -rf $DIR/$tfile*
2414         return 0
2415 }
2416 run_test 46b "pdirops: link vs create =============="
2417
2418 test_46c() {
2419         cancel_lru_locks mdc
2420         touch $DIR1/$tfile-2
2421 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2422         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2423         link $DIR1/$tfile-2 $DIR1/$tfile &
2424         PID1=$! ; pdo_sched
2425         link $DIR2/$tfile $DIR2/$tfile &
2426         PID2=$! ; pdo_sched
2427         do_facet $SINGLEMDS lctl set_param fail_loc=0
2428         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2429         wait $PID2 ; [ $? -ne 0 ] || error "link must fail"
2430         rm -rf $DIR/$tfile*
2431         return 0
2432 }
2433 run_test 46c "pdirops: link vs link =============="
2434
2435 test_46d() {
2436         cancel_lru_locks mdc
2437         touch $DIR1/$tfile-2
2438 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2439         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2440         link $DIR1/$tfile-2 $DIR1/$tfile &
2441         PID1=$! ; pdo_sched
2442         rm $DIR2/$tfile &
2443         PID2=$! ; pdo_sched
2444         do_facet $SINGLEMDS lctl set_param fail_loc=0
2445         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
2446         wait $PID2 ; [ $? -eq 0 ] || error "unlink must succeed"
2447         rm -rf $DIR/$tfile*
2448         return 0
2449 }
2450 run_test 46d "pdirops: link vs unlink =============="
2451
2452 test_46e() {
2453         cancel_lru_locks mdc
2454         touch $DIR1/$tfile-2
2455         touch $DIR1/$tfile-3
2456 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2457         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2458         link $DIR1/$tfile-2 $DIR1/$tfile &
2459         PID1=$! ; pdo_sched
2460         mv $DIR2/$tfile-3 $DIR2/$tfile &
2461         PID2=$! ; pdo_sched
2462         do_facet $SINGLEMDS lctl set_param fail_loc=0
2463         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2464         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
2465         rm -rf $DIR/$tfile*
2466         return 0
2467 }
2468 run_test 46e "pdirops: link and rename (tgt) =============="
2469
2470 test_46f() {
2471         cancel_lru_locks mdc
2472         touch $DIR1/$tfile-2
2473         touch $DIR1/$tfile-3
2474 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2475         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2476         link $DIR1/$tfile-2 $DIR1/$tfile &
2477         PID1=$! ; pdo_sched
2478         mv $DIR2/$tfile $DIR2/$tfile-3 &
2479         PID2=$! ; pdo_sched
2480         do_facet $SINGLEMDS lctl set_param fail_loc=0
2481         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2482         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
2483         rm -rf $DIR/$tfile*
2484         return 0
2485 }
2486 run_test 46f "pdirops: link and rename (src) =============="
2487
2488 test_46g() {
2489         cancel_lru_locks mdc
2490         touch $DIR1/$tfile-2
2491 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2492         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2493         link $DIR1/$tfile-2 $DIR1/$tfile &
2494         PID1=$! ; pdo_sched
2495         stat $DIR2/$tfile > /dev/null &
2496         PID2=$! ; pdo_sched
2497         do_facet $SINGLEMDS lctl set_param fail_loc=0
2498         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
2499         wait $PID2 ; [ $? -eq 0 ] || error "stat must succeed"
2500         rm -rf $DIR/$tfile*
2501         return 0
2502 }
2503 run_test 46g "pdirops: link vs getattr =============="
2504
2505 test_46h() {
2506         cancel_lru_locks mdc
2507         touch $DIR1/$tfile-2
2508 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2509         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2510         link $DIR1/$tfile-2 $DIR1/$tfile &
2511         PID1=$! ; pdo_sched
2512         ls -lia $DIR2/ > /dev/null &
2513         PID2=$! ; pdo_sched
2514         do_facet $SINGLEMDS lctl set_param fail_loc=0
2515         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
2516         wait $PID2
2517         rm -rf $DIR/$tfile*
2518         return 0
2519 }
2520 run_test 46h "pdirops: link vs readdir =============="
2521
2522 test_46i() {
2523         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2524         cancel_lru_locks mdc
2525         touch $DIR1/$tfile-2
2526 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2527         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2528         link $DIR1/$tfile-2 $DIR1/$tfile &
2529         PID1=$! ; pdo_sched
2530         $LFS mkdir -i 1 $DIR2/$tfile &
2531         PID2=$! ; pdo_sched
2532         do_facet $SINGLEMDS lctl set_param fail_loc=0
2533         check_pdo_conflict $PID1 && { wait $PID1;
2534                                 error "remote mkdir isn't blocked"; }
2535         wait $PID2 ; [ $? -ne 0 ] || error "remote mkdir must fail"
2536         rm -rf $DIR/$tfile*
2537         return 0
2538 }
2539 run_test 46i "pdirops: link vs remote mkdir"
2540
2541 # test 47: remote mkdir and blocking operations
2542 test_47a() {
2543         cancel_lru_locks mdc
2544 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2545         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2546         cancel_lru_locks mdc
2547         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2548         $LFS mkdir -i 1 $DIR1/$tfile &
2549         PID1=$! ; pdo_sched
2550         mkdir $DIR2/$tfile &
2551         PID2=$! ; pdo_sched
2552         do_facet $SINGLEMDS lctl set_param fail_loc=0
2553         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
2554         wait $PID2 ; [ $? -ne 0 ] || error "mkdir must fail"
2555         rm -rf $DIR/$tfile*
2556         return 0
2557 }
2558 run_test 47a "pdirops: remote mkdir vs mkdir"
2559
2560 test_47b() {
2561 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2562         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2563         cancel_lru_locks mdc
2564         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2565         $LFS mkdir -i 1 $DIR1/$tfile &
2566         PID1=$! ; pdo_sched
2567         multiop $DIR2/$tfile oO_CREAT:O_EXCL:c &
2568         PID2=$! ; pdo_sched
2569         do_facet $SINGLEMDS lctl set_param fail_loc=0
2570         check_pdo_conflict $PID1 && { wait $PID1;
2571                                         error "create isn't blocked"; }
2572         wait $PID2 ; [ $? -ne 0 ] || error "create must fail"
2573         rm -rf $DIR/$tfile*
2574         return 0
2575 }
2576 run_test 47b "pdirops: remote mkdir vs create"
2577
2578 test_47c() {
2579         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2580         cancel_lru_locks mdc
2581         touch $DIR1/$tfile-2
2582 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2583         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2584         $LFS mkdir -i 1 $DIR1/$tfile &
2585         PID1=$! ; pdo_sched
2586         link $DIR2/$tfile-2 $DIR2/$tfile &
2587         PID2=$! ; pdo_sched
2588         do_facet $SINGLEMDS lctl set_param fail_loc=0
2589         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2590         wait $PID2 ; [ $? -ne 0 ] || error "link must fail"
2591         rm -rf $DIR/$tfile*
2592         return 0
2593 }
2594 run_test 47c "pdirops: remote mkdir vs link"
2595
2596 test_47d() {
2597         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2598         cancel_lru_locks mdc
2599 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2600         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2601         $LFS mkdir -i 1 $DIR1/$tfile &
2602         PID1=$! ; pdo_sched
2603         rmdir $DIR2/$tfile &
2604         PID2=$! ; pdo_sched
2605         do_facet $SINGLEMDS lctl set_param fail_loc=0
2606         check_pdo_conflict $PID1 && { wait $PID1;
2607                                         error "unlink isn't blocked"; }
2608         wait $PID2 ; [ $? -eq 0 ] || error "rmdir must succeed"
2609         rm -rf $DIR/$tfile*
2610         return 0
2611 }
2612 run_test 47d "pdirops: remote mkdir vs unlink"
2613
2614 test_47e() {
2615         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2616         cancel_lru_locks mdc
2617         touch $DIR1/$tfile-2
2618 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2619         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2620         $LFS mkdir -i 1 $DIR1/$tfile &
2621         PID1=$! ; pdo_sched
2622         mv -T $DIR2/$tfile-2 $DIR2/$tfile &
2623         PID2=$! ; pdo_sched
2624         do_facet $SINGLEMDS lctl set_param fail_loc=0
2625         check_pdo_conflict $PID1 && { wait $PID1;
2626                                         error "rename isn't blocked"; }
2627         wait $PID2 ; [ $? -ne 0 ] || error "rename must fail"
2628         rm -rf $DIR/$tfile*
2629         return 0
2630 }
2631 run_test 47e "pdirops: remote mkdir and rename (tgt)"
2632
2633 test_47f() {
2634         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2635         cancel_lru_locks mdc
2636 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2637         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2638         $LFS mkdir -i 1 $DIR1/$tfile &
2639         PID1=$! ; pdo_sched
2640         mv $DIR2/$tfile $DIR2/$tfile-2 &
2641         PID2=$! ; pdo_sched
2642         do_facet $SINGLEMDS lctl set_param fail_loc=0
2643         check_pdo_conflict $PID1 && { wait $PID1;
2644                                         error "rename isn't blocked"; }
2645         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
2646         rm -rf $DIR/$tfile*
2647         return 0
2648 }
2649 run_test 47f "pdirops: remote mkdir and rename (src)"
2650
2651 test_47g() {
2652         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2653         sync
2654         sync_all_data
2655         cancel_lru_locks mdc
2656 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2657         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2658         $LFS mkdir -i 1 $DIR1/$tfile &
2659         PID1=$! ; pdo_sched
2660         stat $DIR2/$tfile > /dev/null &
2661         PID2=$! ; pdo_sched
2662         do_facet $SINGLEMDS lctl set_param fail_loc=0
2663         check_pdo_conflict $PID1 && { wait $PID1;
2664                                         error "getattr isn't blocked"; }
2665         wait $PID2 ; [ $? -eq 0 ] || error "stat must succeed"
2666         rm -rf $DIR/$tfile*
2667         return 0
2668 }
2669 run_test 47g "pdirops: remote mkdir vs getattr"
2670
2671 test_50() {
2672         trunc_size=4096
2673         dd if=/dev/zero of=$DIR1/$tfile bs=1K count=10
2674 #define OBD_FAIL_OSC_CP_ENQ_RACE         0x410
2675         do_facet client "lctl set_param fail_loc=0x410"
2676         $TRUNCATE $DIR2/$tfile $trunc_size
2677         do_facet client "lctl set_param fail_loc=0x0"
2678         sleep 3
2679         size=`stat -c %s $DIR2/$tfile`
2680         [ $size -eq $trunc_size ] || error "wrong size"
2681 }
2682 run_test 50 "osc lvb attrs: enqueue vs. CP AST =============="
2683
2684 test_51a() {
2685         local filesize
2686         local origfile=/etc/hosts
2687
2688         filesize=$(stat -c %s $origfile)
2689
2690         # create an empty file
2691         $MCREATE $DIR1/$tfile || error "can't create $DIR1/$tfile"
2692         # cache layout lock on both mount point
2693         stat $DIR1/$tfile > /dev/null || error "stat $DIR1/$tfile failed"
2694         stat $DIR2/$tfile > /dev/null || error "stat $DIR2/$tfile failed"
2695
2696         # open and sleep 2 seconds then read
2697         $MULTIOP $DIR2/$tfile o_2r${filesize}c &
2698         local pid=$!
2699         sleep 1
2700
2701         # create the layout of testing file
2702         dd if=$origfile of=$DIR1/$tfile conv=notrunc > /dev/null ||
2703                 error "dd $DIR1/$tfile failed"
2704
2705         # MULTIOP proc should be able to read enough bytes and exit
2706         for ((i = 0; i < 6; i++)); do
2707                 sleep 1
2708                 kill -0 $pid || break
2709         done
2710         kill -0 $pid 2> /dev/null && error "multiop is still there"
2711         cmp $origfile $DIR2/$tfile || error "$origfile and $DIR2/$tfile differs"
2712
2713         rm -f $DIR1/$tfile
2714 }
2715 run_test 51a "layout lock: refresh layout should work"
2716
2717 test_51b() {
2718         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.59) ]] ||
2719                 { skip "Need MDS version at least 2.3.59"; return 0; }
2720
2721         local tmpfile=`mktemp`
2722
2723         # create an empty file
2724         $MCREATE $DIR1/$tfile || error "mcreate $DIR1/$tfile failed"
2725
2726         # delay glimpse so that layout has changed when glimpse finish
2727 #define OBD_FAIL_GLIMPSE_DELAY 0x1404
2728         $LCTL set_param fail_loc=0x1404
2729         stat -c %s $DIR2/$tfile |tee $tmpfile &
2730         local pid=$!
2731         sleep 1
2732
2733         # create layout of testing file
2734         dd if=/dev/zero of=$DIR1/$tfile bs=1k count=1 conv=notrunc >/dev/null ||
2735                 error "dd $DIR1/$tfile failed"
2736
2737         wait $pid
2738         local fsize=$(cat $tmpfile)
2739
2740         [ x$fsize = x1024 ] || error "file size is $fsize, should be 1024"
2741
2742         rm -f $DIR1/$tfile $tmpfile
2743 }
2744 run_test 51b "layout lock: glimpse should be able to restart if layout changed"
2745
2746 test_51c() {
2747         [ $OSTCOUNT -ge 2 ] || { skip "needs >= 2 osts"; return; }
2748
2749         # set default layout to have 1 stripe
2750         mkdir $DIR1/$tdir
2751         $LFS setstripe -c 1 $DIR1/$tdir
2752
2753         # create a file with empty layout
2754         $MCREATE $DIR1/$tdir/$tfile ||
2755                 error "$MCREATE $DIR1/$tdir/$tfile failed"
2756
2757 #define OBD_FAIL_MDS_LL_BLOCK 0x172
2758         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x172
2759
2760         # change the layout of testing file
2761         echo "Setting layout to have $OSTCOUNT stripes ..."
2762         $LFS setstripe -c $OSTCOUNT $DIR1/$tdir/$tfile &
2763         pid=$!
2764         sleep 1
2765
2766         # write something to the file, it should be blocked on fetching layout
2767         dd if=/dev/zero of=$DIR2/$tdir/$tfile bs=1k count=1 conv=notrunc
2768         local stripe_count=$($LFS getstripe -c $DIR2/$tdir/$tfile)
2769         wait $pid
2770
2771         # lod_qos.c::min_stripe_count() allows setstripe with a default stripe
2772         # count to succeed with only 3/4 of the number of stripes (rounded up),
2773         # so creating striped files does not fail if an OST is offline or full
2774         [ $stripe_count -ge $((OSTCOUNT - $OSTCOUNT / 4)) ] ||
2775                 error "bad layout: getstripe -c $stripe_count < $OSTCOUNT * 3/4"
2776
2777         rm -fr $DIR1/$tdir
2778 }
2779 run_test 51c "layout lock: IT_LAYOUT blocked and correct layout can be returned"
2780
2781 test_51d() {
2782         dd if=/dev/zero of=/$DIR1/$tfile bs=1M count=1
2783         cancel_lru_locks mdc
2784
2785         # open should grant LAYOUT lock, mmap and read will install pages
2786         $MULTIOP $DIR1/$tfile oO_RDWR:SMR_Uc &
2787         local PID=$!
2788         sleep 1
2789
2790         # rss before revoking
2791         local br=$(grep -A 10 $tfile /proc/$PID/smaps | awk '/^Rss/{print $2}')
2792         echo "Before revoking layout lock: $br KB mapped"
2793
2794         # cancel layout lock manually
2795         cancel_lru_locks mdc
2796
2797         # rss after revoking
2798         local ar=$(grep -A 10 $tfile /proc/$PID/smaps | awk '/^Rss/{print $2}')
2799
2800         kill -USR1 $PID
2801         wait $PID || error "wait PID $PID failed"
2802
2803         [ $ar -eq 0 ] || error "rss before: $br, after $ar, some pages remained"
2804 }
2805 run_test 51d "layout lock: losing layout lock should clean up memory map region"
2806
2807 test_54_part1()
2808 {
2809         echo "==> rename vs getattr vs setxattr should not deadlock"
2810         mkdir -p $DIR/d1/d2/d3 || error "(1) mkdir failed"
2811
2812         do_facet mds1 $LCTL set_param fail_loc=$1
2813
2814         mv -T $DIR/d1/d2/d3 $DIR/d1/d3 &
2815         PID1=$!
2816         sleep 1
2817
2818         stat $DIR/d1/d2 &
2819         PID2=$!
2820         sleep 1
2821
2822         setfattr -n user.attr1 -v value1 $DIR2/d1 || error "(2) setfattr failed"
2823         wait $PID1 || error "(3) mv failed"
2824         wait $PID2 || error "(4) stat failed"
2825         echo
2826
2827         rm -rf $DIR/d1
2828 }
2829
2830 test_54_part2() {
2831         echo "==> rename vs getattr vs open vs getattr should not deadlock"
2832         mkdir -p $DIR/d1/d2/d3 || error "(1) mkdir failed"
2833
2834         do_facet mds1 $LCTL set_param fail_loc=$1
2835
2836         mv -T $DIR/d1/d2/d3 $DIR/d1/d3 &
2837         PID1=$!
2838         sleep 1
2839
2840         stat $DIR/d1/d2 &
2841         PID2=$!
2842         sleep 1
2843
2844         $MULTIOP $DIR2/d1/d2 Oc &
2845         PID3=$!
2846         sleep 1
2847
2848         stat $DIR/d1 || error "(2) stat failed"
2849
2850         wait $PID1 || error "(3) mv failed"
2851         wait $PID2 || error "(4) stat failed"
2852         wait $PID3 && error "(5) multiop failed"
2853         echo
2854         rm -rf $DIR/d1
2855 }
2856
2857 test_54() {
2858         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
2859         save_lustre_params client "llite.*.xattr_cache" > $p
2860         lctl set_param llite.*.xattr_cache 1 ||
2861                 { skip "xattr cache is not supported"; return 0; }
2862
2863 #define OBD_FAIL_MDS_RENAME              0x153
2864 #define OBD_FAIL_MDS_RENAME2             0x154
2865         test_54_part1 0x80000153 || error 10
2866         test_54_part1 0x80000154 || error 11
2867         test_54_part2 0x80000153 || error 12
2868         test_54_part2 0x80000154 || error 13
2869
2870         restore_lustre_params < $p
2871         rm -f $p
2872 }
2873 run_test 54 "rename locking"
2874
2875 test_55a() {
2876         mkdir -p $DIR/d1/d2 $DIR/d3 || error "(1) mkdir failed"
2877
2878 #define OBD_FAIL_MDS_RENAME4              0x156
2879         do_facet mds1 $LCTL set_param fail_loc=0x80000156
2880
2881         mv -T $DIR/d1/d2 $DIR/d3/d2 &
2882         PID1=$!
2883         sleep 1
2884
2885         rm -r $DIR2/d3
2886         wait $PID1 && error "(2) mv succeeded"
2887
2888         rm -rf $DIR/d1
2889 }
2890 run_test 55a "rename vs unlink target dir"
2891
2892 test_55b()
2893 {
2894         mkdir -p $DIR/d1/d2 $DIR/d3 || error "(1) mkdir failed"
2895
2896 #define OBD_FAIL_MDS_RENAME4             0x156
2897         do_facet mds1 $LCTL set_param fail_loc=0x80000156
2898
2899         mv -T $DIR/d1/d2 $DIR/d3/d2 &
2900         PID1=$!
2901         sleep 1
2902
2903         rm -r $DIR2/d1
2904         wait $PID1 && error "(2) mv succeeded"
2905
2906         rm -rf $DIR/d3
2907 }
2908 run_test 55b "rename vs unlink source dir"
2909
2910 test_55c()
2911 {
2912         mkdir -p $DIR/d1/d2 $DIR/d3 || error "(1) mkdir failed"
2913
2914 #define OBD_FAIL_MDS_RENAME4              0x156
2915         do_facet mds1 $LCTL set_param fail_loc=0x156
2916
2917         mv -T $DIR/d1/d2 $DIR/d3/d2 &
2918         PID1=$!
2919         sleep 1
2920
2921         # while rename is sleeping, open and remove d3
2922         $MULTIOP $DIR2/d3 D_c &
2923         PID2=$!
2924         sleep 1
2925         rm -rf $DIR2/d3
2926         sleep 5
2927
2928         # while rename is sleeping 2nd time, close d3
2929         kill -USR1 $PID2
2930         wait $PID2 || error "(3) multiop failed"
2931
2932         wait $PID1 && error "(2) mv succeeded"
2933
2934         rm -rf $DIR/d1
2935 }
2936 run_test 55c "rename vs unlink orphan target dir"
2937
2938 test_55d()
2939 {
2940         touch $DIR/f1
2941
2942 #define OBD_FAIL_MDS_RENAME3              0x155
2943         do_facet mds1 $LCTL set_param fail_loc=0x155
2944         mv $DIR/f1 $DIR/$tdir &
2945         PID1=$!
2946         sleep 2
2947
2948         # while rename is sleeping, create $tdir, but as a directory
2949         mkdir -p $DIR2/$tdir || error "(1) mkdir failed"
2950
2951         # link in reverse locking order
2952         ln $DIR2/f1 $DIR2/$tdir/
2953
2954         wait $PID1 && error "(2) mv succeeded"
2955         rm -rf $DIR/f1
2956 }
2957 run_test 55d "rename file vs link"
2958
2959 test_60() {
2960         local MDSVER=$(lustre_build_version $SINGLEMDS)
2961         [ $(version_code $MDSVER) -lt $(version_code 2.3.0) ] &&
2962                 skip "MDS version $MDSVER must be >= 2.3.0" && return 0
2963
2964         # Create a file
2965         test_mkdir $DIR1/$tdir
2966         file1=$DIR1/$tdir/file
2967         file2=$DIR2/$tdir/file
2968
2969         echo orig > $file2 || error "Could not create $file2"
2970         version=$($LFS data_version $file1)
2971
2972         # Append data
2973         echo append >> $file2 || error "Could not append to $file2"
2974         version2=$($LFS data_version $file1)
2975         [ "$version" != "$version2" ] ||
2976             error "append did not change data version: $version"
2977
2978         # Overwrite data
2979         echo overwrite > $file2 || error "Could not overwrite $file2"
2980         version3=$($LFS data_version $file1)
2981         [ "$version2" != "$version3" ] ||
2982             error "overwrite did not change data version: $version2"
2983
2984         # Truncate before EOF
2985         $TRUNCATE $file2 3 || error "Could not truncate $file2"
2986         version4=$($LFS data_version $file1)
2987         [ "$version3" != "$version4" ] ||
2988             error "truncate did not change data version: $version3"
2989
2990         # Truncate after EOF
2991         $TRUNCATE $file2 123456 || error "Could not truncate $file2"
2992         version5=$($LFS data_version $file1)
2993         [ "$version4" != "$version5" ] ||
2994             error "truncate did not change data version: $version4"
2995
2996         # Chmod do not change version
2997         chmod 400 $file2 || error "Could not chmod 400 $file2"
2998         version6=$($LFS data_version $file1)
2999         [ "$version5" == "$version6" ] ||
3000             error "chmod should not change data version: $version5 != $version6"
3001
3002         # Chown do not change version
3003         chown $RUNAS_ID $file2 || error "Could not chown $RUNAS_ID $file2"
3004         version7=$($LFS data_version $file1)
3005         [ "$version5" == "$version7" ] ||
3006             error "chown should not change data version: $version5 != $version7"
3007 }
3008 run_test 60 "Verify data_version behaviour"
3009
3010 test_70a() {
3011         local test_dir=$tdir/test_dir
3012
3013         mkdir -p $DIR1/$tdir
3014         if [ $MDSCOUNT -ge 2 ]; then
3015                 local MDTIDX=1
3016                 $LFS mkdir -i $MDTIDX $DIR1/$test_dir ||
3017                         error "Create remote directory failed"
3018         else
3019                 mkdir -p $DIR1/$test_dir
3020         fi
3021         cd $DIR2/$test_dir || error "cd directory failed"
3022         rm -rf $DIR1/$test_dir || error "unlink directory failed"
3023
3024         cd $DIR2/$tdir || error "exit directory"
3025 }
3026 run_test 70a "cd directory && rm directory"
3027
3028 test_70b() { # LU-2781
3029         local i
3030         mkdir -p $DIR1/$tdir
3031
3032         touch $DIR1/$tdir/file
3033         for ((i = 0; i < 32; i++)); do
3034             $LFS rm_entry $DIR1/$tdir/non_existent_dir &>/dev/null
3035         done
3036         rm $DIR1/$tdir/file || error "cannot remove file after rm_entry"
3037
3038         touch $DIR1/$tdir/file
3039         $LFS mkdir -i0 $DIR1/$tdir/test_dir
3040         $LFS rm_entry $DIR1/$tdir/test_dir &>/dev/null
3041         rm -rf $DIR1/$tdir/test_dir ||
3042                 error "cannot remove directory after rm_entry"
3043         rm $DIR1/$tdir/file || error "cannot remove file after rm_entry"
3044 }
3045 run_test 70b "remove files after calling rm_entry"
3046
3047 test_71a() {
3048         local server_version=$(lustre_version_code $SINGLEMDS)
3049
3050         [[ $server_version -lt $(version_code 2.1.6) ]] &&
3051                 skip "Need MDS version at least 2.1.6" && return
3052
3053         # Patch not applied to 2.2 and 2.3 branches
3054         [[ $server_version -ge $(version_code 2.2.0) ]] &&
3055         [[ $server_version -lt $(version_code 2.4.0) ]] &&
3056                 skip "Need MDS version earlier than 2.2.0 or at least 2.4.0" &&
3057                         return
3058
3059         checkfiemap --test ||
3060                 { skip "checkfiemap not runnable: $?" && return; }
3061         # write data this way: hole - data - hole - data
3062         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=1 count=1
3063         [ "$(facet_fstype ost$(($($LFS getstripe -i $DIR1/$tfile) + 1)))" = \
3064                 "zfs" ] &&
3065                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return 0
3066         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=3 count=1
3067         GET_STAT="lctl get_param -n ldlm.services.ldlm_cbd.stats"
3068         stat $DIR2/$tfile
3069         local can1=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
3070         echo $can1
3071         checkfiemap $DIR2/$tfile 81920 ||
3072                 error "data is not flushed from client"
3073         local can2=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
3074         echo $can2
3075
3076         # common case of "create file, copy file" on a single node
3077         # should not flush data from ost
3078         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=1 count=1
3079         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=3 count=1
3080         stat $DIR1/$tfile
3081         local can3=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
3082         echo $can3
3083         checkfiemap $DIR1/$tfile 81920 ||
3084         error 4
3085         local can4=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
3086         echo $can2
3087         [ $can3 -eq $can4 ] || error $((can2-can1)) "cancel RPC occured."
3088 }
3089 run_test 71a "correct file map just after write operation is finished"
3090
3091 test_71b() {
3092         local server_version=$(lustre_version_code $SINGLEMDS)
3093
3094         [[ $server_version -lt $(version_code 2.1.6) ]] &&
3095                 skip "Need MDS version at least 2.1.6" && return
3096
3097         # Patch not applied to 2.2 and 2.3 branches
3098         [[ $server_version -ge $(version_code 2.2.0) ]] &&
3099         [[ $server_version -lt $(version_code 2.4.0) ]] &&
3100                 skip "Need MDS version earlier than 2.2.0 or at least 2.4.0" &&
3101                         return
3102         [[ $OSTCOUNT -ge 2 ]] || { skip "needs >= 2 OSTs"; return; }
3103
3104         checkfiemap --test ||
3105                 { skip "error $?: checkfiemap failed" && return; }
3106
3107         mkdir -p $DIR1/$tdir
3108
3109         $LFS setstripe -c -1 $DIR1/$tdir || error "setstripe failed"
3110         dd if=/dev/urandom of=$DIR1/$tdir/$tfile bs=40K count=1
3111         [ "$(facet_fstype ost$(($($LFS getstripe -i $DIR1/$tdir/$tfile) + 1)))" = \
3112                 "zfs" ] &&
3113                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return 0
3114         checkfiemap $DIR1/$tdir/$tfile 40960 || error "checkfiemap failed"
3115 }
3116 run_test 71b "check fiemap support for stripecount > 1"
3117
3118 test_72() {
3119         local p="$TMP/sanityN-$TESTNAME.parameters"
3120         local tlink1
3121         local tlink2
3122         save_lustre_params client "llite.*.xattr_cache" > $p
3123         lctl set_param llite.*.xattr_cache 1 ||
3124                 { skip "xattr cache is not supported"; return 0; }
3125
3126         touch $DIR1/$tfile
3127         setfattr -n user.attr1 -v value1 $DIR1/$tfile ||
3128                 error "setfattr1 failed"
3129         getfattr -n user.attr1 $DIR2/$tfile | grep value1 ||
3130                 error "getfattr1 failed"
3131         setfattr -n user.attr1 -v value2 $DIR2/$tfile ||
3132                 error "setfattr2 failed"
3133         getfattr -n user.attr1 $DIR1/$tfile | grep value2 ||
3134                 error "getfattr2 failed"
3135
3136         # check that trusted.link is consistent
3137         tlink1=$(getfattr -n trusted.link $DIR1/$tfile | md5sum)
3138         ln $DIR2/$tfile $DIR2/$tfile-2 || error "failed to link"
3139         tlink2=$(getfattr -n trusted.link $DIR1/$tfile | md5sum)
3140         echo "$tlink1 $tlink2"
3141         [ "$tlink1" = "$tlink2" ] && error "trusted.link should have changed!"
3142
3143         rm -f $DIR2/$tfile
3144
3145         restore_lustre_params < $p
3146         rm -f $p
3147 }
3148 run_test 72 "getxattr/setxattr cache should be consistent between nodes"
3149
3150 test_73() {
3151         local p="$TMP/sanityN-$TESTNAME.parameters"
3152         save_lustre_params client "llite.*.xattr_cache" > $p
3153         lctl set_param llite.*.xattr_cache 1 ||
3154                 { skip "xattr cache is not supported"; return 0; }
3155
3156         touch $DIR1/$tfile
3157         setfattr -n user.attr1 -v value1 $DIR1/$tfile ||
3158                 error "setfattr1 failed"
3159         getfattr -n user.attr1 $DIR2/$tfile || error "getfattr1 failed"
3160         getfattr -n user.attr1 $DIR1/$tfile || error "getfattr2 failed"
3161         clear_stats llite.*.stats
3162         # PR lock should be cached by now on both clients
3163         getfattr -n user.attr1 $DIR1/$tfile || error "getfattr3 failed"
3164         # 2 hits for getfattr(0)+getfattr(size)
3165         [ $(calc_stats llite.*.stats getxattr_hits) -eq 2 ] ||
3166                 error "not cached in $DIR1"
3167         getfattr -n user.attr1 $DIR2/$tfile || error "getfattr4 failed"
3168         # 4 hits for more getfattr(0)+getfattr(size)
3169         [ $(calc_stats llite.*.stats getxattr_hits) -eq 4 ] ||
3170                 error "not cached in $DIR2"
3171         rm -f $DIR2/$tfile
3172
3173         restore_lustre_params < $p
3174         rm -f $p
3175 }
3176 run_test 73 "getxattr should not cause xattr lock cancellation"
3177
3178 test_74() {
3179         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.93) ] &&
3180                 skip "Need MDS version at least 2.4.93" && return
3181
3182         dd if=/dev/zero of=$DIR1/$tfile-1 bs=1K count=1
3183         dd if=/dev/zero of=$DIR1/$tfile-2 bs=1K count=1
3184         flocks_test 4 $DIR1/$tfile-1 $DIR2/$tfile-2
3185 }
3186 run_test 74 "flock deadlock: different mounts =============="
3187
3188 # LU-3889
3189 test_75() {
3190         $LFS setstripe -c 2 -S 1m -i 0 $DIR1/$tfile
3191         dd if=/dev/zero of=$DIR1/$tfile bs=1M count=2
3192         cancel_lru_locks osc
3193
3194         dd of=$DIR1/$tfile if=/dev/zero bs=1M count=1 seek=1 conv=notrunc
3195         sync
3196
3197         # define OBD_FAIL_LDLM_ENQUEUE_HANG 0x31d
3198         $LCTL set_param fail_loc=0x31d
3199         stat -c %s $DIR1/$tfile &
3200         local pid=$!
3201         sleep 1
3202         kill -9 $pid
3203
3204         # For bad lock error handler we should ASSERT and got kernel panic here
3205         sleep 4
3206         $LCTL set_param fail_loc=0
3207 }
3208 run_test 75 "osc: upcall after unuse lock==================="
3209
3210 test_76() { #LU-946
3211         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
3212                 skip "Need MDS version at least 2.5.53" && return
3213
3214         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3215         local fcount=$((MDSCOUNT * 256))
3216         declare -a fd_list
3217         declare -a fid_list
3218
3219         if remote_mds; then
3220                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
3221         else
3222                 nid="0@lo"
3223         fi
3224
3225         rm -rf $DIR/$tdir
3226         test_mkdir $DIR/$tdir
3227
3228         # drop all open locks and close any cached "open" files on the client
3229         cancel_lru_locks mdc
3230
3231         local open_fids_cmd="$LCTL get_param -n mdt.*.exports.'$nid'.open_files"
3232         local fid_list=($(do_nodes $(comma_list $(mdts_nodes)) $open_fids_cmd))
3233         local already=${#fid_list[@]}
3234         for (( i = 0; i < $already; i++ )) ; do
3235                 log "already open[$i]: $($LFS fid2path $DIR2 ${fid_list[i]})"
3236         done
3237
3238         echo -n "opening files: "
3239         ulimit -n $((fcount + 50))
3240         for ((i = 0; i < $fcount; i++)); do
3241                 touch $DIR/$tdir/f_$i
3242                 local fd=$(free_fd ${fd_list[i]})
3243                 local open_cmd="exec $fd<$DIR/$tdir/f_$i"
3244                 eval $open_cmd
3245
3246                 fd_list[i]=$fd
3247
3248                 (( $i % 32 == 0 )) && echo -n "."
3249         done
3250         echo
3251
3252         fid_list=($(do_nodes $(comma_list $(mdts_nodes)) $open_fids_cmd))
3253
3254         # Possible errors in openfiles FID list.
3255         # 1. Missing FIDs. Check 1
3256         # 2. Extra FIDs. Check 1
3257         # 3. Duplicated FID. Check 2
3258         # 4. Invalid FIDs. Check 2
3259         # 5. Valid FID, points to some other file. Check 3
3260
3261         # Check 1
3262         [ ${#fid_list[@]} -ne $((fcount + already)) ] &&
3263                 error "${#fid_list[@]} != $fcount (+$already old) open files"
3264
3265         echo -n "closing files: "
3266         for (( fd = 0, fid = 0; fd < $fcount; fd++, fid++ )) ; do
3267                 local close_cmd="exec ${fd_list[fd]}<&-"
3268                 eval $close_cmd
3269                 filename=$($LFS fid2path $DIR2 ${fid_list[fid]})
3270
3271                 while [[ ! "$filename" =~ "$DIR2/$tdir/f_" ]]; do
3272                         echo "skip old open file $filename"
3273                         ((fid++))
3274                         filename=$($LFS fid2path $DIR2 ${fid_list[fid]})
3275                 done
3276
3277                 # Check 2
3278                 rm --interactive=no $filename
3279                 [ $? -ne 0 ] &&
3280                         error "Nonexisting fid ${fid_list[fid]} listed."
3281                 (( $fd % 32 == 0 )) && echo -n "."
3282         done
3283         echo
3284
3285         # Check 3
3286         ls_op=$(ls $DIR2/$tdir | wc -l)
3287         [ $ls_op -ne 0 ] &&
3288                 error "Some openfiles are missing in lproc output"
3289
3290         rm -rf $DIR/$tdir
3291 }
3292 run_test 76 "Verify MDT open_files listing"
3293
3294 nrs_write_read() {
3295         local n=16
3296         local dir=$DIR/$tdir
3297         local myRUNAS="$1"
3298
3299         mkdir $dir || error "mkdir $dir failed"
3300         $LFS setstripe -c $OSTCOUNT $dir || error "setstripe to $dir failed"
3301         chmod 777 $dir
3302
3303         do_nodes $CLIENTS $myRUNAS \
3304                 dd if=/dev/zero of="$dir/nrs_r_\$HOSTNAME" bs=1M count=$n ||
3305                 error "dd at 0 on client failed (1)"
3306
3307         do_nodes $CLIENTS $myRUNAS \
3308                 "declare -a pids_w;
3309                 for ((i = 0; i < $n; i++)); do
3310                         dd if=/dev/zero of=$dir/nrs_w_\$HOSTNAME bs=1M \
3311 seek=\\\$i count=1 conv=notrunc &
3312                         pids_w[\\\$i]=\\\$!;
3313                 done;
3314                 rc_w=0;
3315                 for ((i = 0; i < $n; i++)); do
3316                         wait \\\${pids_w[\\\$i]};
3317                         newrc=\\\$?;
3318                         [ \\\$newrc -gt \\\$rc_w ] && rc_w=\\\$newrc;
3319                 done;
3320                 exit \\\$rc_w" &
3321         local pid_w=$!
3322         do_nodes $CLIENTS sync;
3323         cancel_lru_locks osc
3324
3325         do_nodes $CLIENTS $myRUNAS \
3326                 "declare -a pids_r;
3327                 for ((i = 0; i < $n; i++)); do
3328                         dd if=$dir/nrs_r_\$HOSTNAME bs=1M of=/dev/null \
3329 seek=\\\$i count=1 &
3330                         pids_r[\\\$i]=\\\$!;
3331                 done;
3332                 rc_r=0;
3333                 for ((i = 0; i < $n; i++)); do
3334                         wait \\\${pids_r[\\\$i]};
3335                         newrc=\\\$?;
3336                         [ \\\$newrc -gt \\\$rc_r ] && rc_r=\\\$newrc;
3337                 done;
3338                 exit \\\$rc_r" &
3339         local pid_r=$!
3340         cancel_lru_locks osc
3341
3342         wait $pid_w || error "dd (write) failed (2)"
3343         wait $pid_r || error "dd (read) failed (3)"
3344         rm -rvf $dir || error "rm -rf $dir failed"
3345 }
3346
3347 test_77a() { #LU-3266
3348         local rc
3349
3350         oss=$(comma_list $(osts_nodes))
3351         do_nodes $oss lctl set_param ost.OSS.*.nrs_policies="fifo" ||
3352                 rc=$?
3353         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3354         [[ $rc -ne 0 ]] && error "failed to set fifo policy"
3355         nrs_write_read
3356
3357         return 0
3358 }
3359 run_test 77a "check FIFO NRS policy"
3360
3361 test_77b() { #LU-3266
3362         local rc
3363
3364         oss=$(comma_list $(osts_nodes))
3365
3366         do_nodes $oss lctl set_param ost.OSS.*.nrs_policies="crrn" \
3367                 ost.OSS.*.nrs_crrn_quantum=1 || rc=$?
3368         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3369         [[ $rc -ne 0 ]] && error "failed to set crrn_quantum to 1"
3370
3371         echo "policy: crr-n, crrn_quantum 1"
3372         nrs_write_read
3373
3374         do_nodes $oss lctl set_param \
3375                 ost.OSS.*.nrs_crrn_quantum=64 || rc=$?
3376         [[ $rc -ne 0 ]] && error "failed to set crrn_quantum to 64"
3377
3378         echo "policy: crr-n, crrn_quantum 64"
3379         nrs_write_read
3380
3381         # cleanup
3382         do_nodes $oss lctl set_param \
3383                 ost.OSS.ost_io.nrs_policies="fifo" || rc=$?
3384         [[ $rc -ne 0 ]] && error "failed to set fifo policy"
3385         return 0
3386 }
3387 run_test 77b "check CRR-N NRS policy"
3388
3389 orr_trr() {
3390         local policy=$1
3391
3392         oss=$(comma_list $(osts_nodes))
3393
3394         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies=$policy \
3395                 ost.OSS.*.nrs_"$policy"_quantum=1 \
3396                 ost.OSS.*.nrs_"$policy"_offset_type="physical" \
3397                 ost.OSS.*.nrs_"$policy"_supported="reads" || return $?
3398
3399         echo "policy: $policy, ${policy}_quantum 1, ${policy}_offset_type " \
3400                 "physical, ${policy}_supported reads"
3401         nrs_write_read
3402
3403         do_nodes $oss lctl set_param \
3404                 ost.OSS.*.nrs_${policy}_supported="writes" \
3405                 ost.OSS.*.nrs_${policy}_quantum=64 || return $?
3406
3407         echo "policy: $policy, ${policy}_quantum 64, ${policy}_offset_type " \
3408                 "physical, ${policy}_supported writes"
3409         nrs_write_read
3410
3411         do_nodes $oss lctl set_param \
3412                 ost.OSS.*.nrs_${policy}_supported="reads_and_writes" \
3413                 ost.OSS.*.nrs_${policy}_offset_type="logical" || return $?
3414         echo "policy: $policy, ${policy}_quantum 64, ${policy}_offset_type " \
3415                 "logical, ${policy}_supported reads_and_writes"
3416         nrs_write_read
3417
3418         # cleanup
3419         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo" ||
3420                 return $?
3421         return 0
3422 }
3423
3424 test_77c() { #LU-3266
3425         local rc
3426         orr_trr "orr" || rc=$?
3427         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3428         [[ $rc -ne 0 ]] && error "orr_trr failed rc:$rc"
3429         return 0
3430 }
3431 run_test 77c "check ORR NRS policy"
3432
3433 test_77d() { #LU-3266
3434         local rc
3435         orr_trr "trr" || rc=$?
3436         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3437         [[ $rc -ne 0 ]] && error "orr_trr failed rc:$rc"
3438         return 0
3439 }
3440 run_test 77d "check TRR nrs policy"
3441
3442 tbf_rule_operate()
3443 {
3444         local facet=$1
3445         shift 1
3446
3447         do_facet $facet lctl set_param \
3448                 ost.OSS.ost_io.nrs_tbf_rule="$*"
3449         [ $? -ne 0 ] &&
3450                 error "failed to run operate '$*' on TBF rules"
3451 }
3452
3453 cleanup_tbf_verify()
3454 {
3455         local rc=0
3456         trap 0
3457         echo "cleanup_tbf $DIR/$tdir"
3458         rm -rf $DIR/$tdir
3459         rc=$?
3460         wait_delete_completed
3461         return $rc
3462 }
3463
3464 tbf_verify() {
3465         local dir=$DIR/$tdir
3466         local client1=${CLIENT1:-$(hostname)}
3467         local myRUNAS="$3"
3468
3469         local np=$(check_cpt_number ost1)
3470         [ $np -gt 0 ] || error "CPU partitions should not be $np."
3471         echo "cpu_npartitions on ost1 is $np"
3472
3473         mkdir $dir || error "mkdir $dir failed"
3474         $LFS setstripe -c 1 -i 0 $dir || error "setstripe to $dir failed"
3475         chmod 777 $dir
3476
3477         trap cleanup_tbf_verify EXIT
3478         echo "Limited write rate: $1, read rate: $2"
3479         echo "Verify the write rate is under TBF control"
3480         local start=$SECONDS
3481         do_node $client1 $myRUNAS dd if=/dev/zero of=$dir/tbf \
3482                 bs=1M count=100 oflag=direct 2>&1
3483         local runtime=$((SECONDS - start + 1))
3484         local rate=$(bc <<< "scale=6; 100 / $runtime")
3485         echo "Write runtime is $runtime s, speed is $rate IOPS"
3486
3487         # verify the write rate does not exceed TBF rate limit
3488         [ $(bc <<< "$rate < 1.1 * $np * $1") -eq 1 ] ||
3489                 error "The write rate ($rate) exceeds 110% of rate limit ($1 * $np)"
3490
3491         cancel_lru_locks osc
3492
3493         echo "Verify the read rate is under TBF control"
3494         start=$SECONDS
3495         do_node $client1 $myRUNAS dd if=$dir/tbf of=/dev/null \
3496                 bs=1M count=100 iflag=direct 2>&1
3497         runtime=$((SECONDS - start + 1))
3498         rate=$(bc <<< "scale=6; 100 / $runtime")
3499         echo "Read runtime is $runtime s, speed is $rate IOPS"
3500
3501         # verify the read rate does not exceed TBF rate limit
3502         [ $(bc <<< "$rate < 1.1 * $np * $2") -eq 1 ] ||
3503                 error "The read rate ($rate) exceeds 110% of rate limit ($2 * $np)"
3504
3505         cancel_lru_locks osc
3506         cleanup_tbf_verify || error "rm -rf $dir failed"
3507 }
3508
3509 test_77e() {
3510         local rc
3511
3512         oss=$(comma_list $(osts_nodes))
3513
3514         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ nid" ||
3515                 rc=$?
3516         [[ $rc -eq 3 ]] && skip "no NRS TBF exists" && return
3517         [[ $rc -ne 0 ]] && error "failed to set TBF NID policy"
3518
3519         local idis
3520         local rateis
3521         if [ $(lustre_version_code ost1) -ge $(version_code 2.8.54) ]; then
3522                 idis="nid="
3523                 rateis="rate="
3524         fi
3525
3526         # Only operate rules on ost1 since OSTs might run on the same OSS
3527         # Add some rules
3528         tbf_rule_operate ost1 "start\ localhost\ ${idis}{0@lo}\ ${rateis}1000"
3529         local address=$(comma_list "$(host_nids_address $CLIENTS $NETTYPE)")
3530         local client_nids=$(nids_list $address "\\")
3531         tbf_rule_operate ost1 "start\ clients\ ${idis}{$client_nids}\ ${rateis}100"
3532         tbf_rule_operate ost1 "start\ others\ ${idis}{*.*.*.*@$NETTYPE}\ ${rateis}50"
3533         nrs_write_read
3534
3535         # Change the rules
3536         tbf_rule_operate ost1 "change\ localhost\ ${rateis}1001"
3537         tbf_rule_operate ost1 "change\ clients\ ${rateis}101"
3538         tbf_rule_operate ost1 "change\ others\ ${rateis}51"
3539         nrs_write_read
3540
3541         # Stop the rules
3542         tbf_rule_operate ost1 "stop\ localhost"
3543         tbf_rule_operate ost1 "stop\ clients"
3544         tbf_rule_operate ost1 "stop\ others"
3545         nrs_write_read
3546
3547         # Cleanup the TBF policy
3548         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3549         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3550         nrs_write_read
3551         return 0
3552 }
3553 run_test 77e "check TBF NID nrs policy"
3554
3555 test_77f() {
3556         local rc
3557
3558         oss=$(comma_list $(osts_nodes))
3559
3560         do_nodes $oss $LCTL set_param \
3561                 ost.OSS.ost_io.nrs_policies="tbf\ jobid" || rc=$?
3562         [[ $rc -eq 3 ]] && skip "no NRS TBF exists" && return
3563         [[ $rc -ne 0 ]] && error "failed to set TBF JOBID policy"
3564
3565         # Configure jobid_var
3566         local saved_jobid_var=$($LCTL get_param -n jobid_var)
3567         rc=$?
3568         [[ $rc -eq 3 ]] && skip "jobid_var not found" && return
3569         [[ $rc -ne 0 ]] && error "failed to get param jobid_var"
3570         if [ $saved_jobid_var != procname_uid ]; then
3571                 set_persistent_param_and_check client \
3572                         "jobid_var" "$FSNAME.sys.jobid_var" procname_uid
3573         fi
3574
3575         local idis
3576         local rateis
3577         if [ $(lustre_version_code ost1) -ge $(version_code 2.8.54) ]; then
3578                 idis="jobid="
3579                 rateis="rate="
3580         fi
3581
3582         # Only operate rules on ost1 since OSTs might run on the same OSS
3583         # Add some rules
3584         tbf_rule_operate ost1 "start\ runas\ ${idis}{iozone.$RUNAS_ID\ dd.$RUNAS_ID\ tiotest.$RUNAS_ID}\ ${rateis}1000"
3585         tbf_rule_operate ost1 "start\ iozone_runas\ ${idis}{iozone.$RUNAS_ID}\ ${rateis}100"
3586         tbf_rule_operate ost1 "start\ dd_runas\ ${idis}{dd.$RUNAS_ID}\ ${rateis}50"
3587         nrs_write_read "$RUNAS"
3588
3589         # Change the rules
3590         tbf_rule_operate ost1 "change\ runas\ ${rateis}1001"
3591         tbf_rule_operate ost1 "change\ iozone_runas\ ${rateis}101"
3592         tbf_rule_operate ost1 "change\ dd_runas\ ${rateis}51"
3593         nrs_write_read "$RUNAS"
3594
3595         # Stop the rules
3596         tbf_rule_operate ost1 "stop\ runas"
3597         tbf_rule_operate ost1 "stop\ iozone_runas"
3598         tbf_rule_operate ost1 "stop\ dd_runas"
3599         nrs_write_read "$RUNAS"
3600
3601         # Cleanup the TBF policy
3602         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3603         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3604         nrs_write_read "$RUNAS"
3605
3606         local current_jobid_var=$($LCTL get_param -n jobid_var)
3607         [[ $? -ne 0 ]] && error "failed to get param jobid_var"
3608         if [ $saved_jobid_var != $current_jobid_var ]; then
3609                 set_persistent_param_and_check client \
3610                         "jobid_var" "$FSNAME.sys.jobid_var" $saved_jobid_var
3611         fi
3612         return 0
3613 }
3614 run_test 77f "check TBF JobID nrs policy"
3615
3616 test_77g() {
3617         local rc=0
3618
3619         oss=$(comma_list $(osts_nodes))
3620
3621         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ nid" ||
3622                 rc=$?
3623         [[ $rc -eq 3 ]] && skip "no NRS TBF exists" && return
3624         [[ $rc -ne 0 ]] && error "failed to set TBF NID policy"
3625
3626         do_nodes $oss lctl set_param \
3627                 ost.OSS.ost_io.nrs_policies="tbf\ jobid" || rc=$?
3628         [[ $rc -ne 0 ]] && error "failed to set TBF JOBID policy"
3629
3630         local idis
3631         local rateis
3632         if [ $(lustre_version_code ost1) -ge $(version_code 2.8.54) ]; then
3633                 idis="jobid="
3634                 rateis="rate="
3635         fi
3636
3637         # Add a rule that only valid for Jobid TBF. If direct change between
3638         # TBF types is not supported, this operation will fail.
3639         tbf_rule_operate ost1 "start\ dd_runas\ ${idis}{dd.$RUNAS_ID}\ ${rateis}50"
3640
3641         # Cleanup the TBF policy
3642         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3643         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3644         return 0
3645 }
3646 run_test 77g "Change TBF type directly"
3647
3648 test_77h() {
3649         [ $(lustre_version_code ost1) -ge $(version_code 2.8.55) ] ||
3650                 { skip "Need OST version at least 2.8.55"; return 0; }
3651
3652         local old_policy=$(do_facet ost1 \
3653                 lctl get_param ost.OSS.ost_io.nrs_policies)
3654         local new_policy
3655
3656         do_facet ost1 lctl set_param \
3657                 ost.OSS.ost_io.nrs_policies="abc"
3658         [ $? -eq 0 ] && error "should return error"
3659
3660         do_facet ost1 lctl set_param \
3661                 ost.OSS.ost_io.nrs_policies="tbf\ abc"
3662         [ $? -eq 0 ] && error "should return error"
3663
3664         do_facet ost1 lctl set_param \
3665                 ost.OSS.ost_io.nrs_policies="tbf\ reg\ abc"
3666         [ $? -eq 0 ] && error "should return error"
3667
3668         do_facet ost1 lctl set_param \
3669                 ost.OSS.ost_io.nrs_policies="tbf\ abc\ efg"
3670         [ $? -eq 0 ] && error "should return error"
3671
3672         new_policy=$(do_facet ost1 lctl get_param ost.OSS.ost_io.nrs_policies)
3673         [ $? -eq 0 ] || error "shouldn't LBUG"
3674
3675         [ "$old_policy" = "$new_policy" ] || error "NRS policy should be same"
3676
3677         return 0
3678 }
3679 run_test 77h "Wrong policy name should report error, not LBUG"
3680
3681 tbf_rule_check()
3682 {
3683         local facet=$1
3684         local expected=$2
3685         local error_message=$3
3686         local rule_number=0
3687         for rule in $expected; do
3688                 rule_number=$((rule_number + 1))
3689         done
3690         local stop_line=$(($rule_number + 3))
3691         local awk_command="awk 'NR >= 4 && NR <= $stop_line {print \$1}'"
3692
3693         local output=$(do_facet $facet lctl get_param \
3694                 ost.OSS.ost_io.nrs_tbf_rule |
3695                 eval $awk_command |
3696                 tr "\n" " " |
3697                 sed 's/[ ]*$//')
3698         if [ "$output" != "$expected" ]; then
3699                 error "$error_message, expected '$expected', got '$output'"
3700         fi
3701 }
3702
3703 test_77i() {
3704         [ $(lustre_version_code ost1) -ge $(version_code 2.8.55) ] ||
3705                 { skip "Need OST version at least 2.8.55"; return 0; }
3706
3707         for i in $(seq 1 $OSTCOUNT)
3708         do
3709                 do_facet ost"$i" lctl set_param \
3710                         ost.OSS.ost_io.nrs_policies="tbf\ jobid"
3711                 [ $? -ne 0 ] &&
3712                         error "failed to set TBF policy"
3713         done
3714
3715         tbf_rule_check ost1 "default" "error before inserting any rule"
3716
3717         tbf_rule_operate ost1 "start\ before\ jobid={jobid}\ rate=1000"
3718         tbf_rule_check ost1 "before default" \
3719                 "error when inserting rule 'before'"
3720
3721         tbf_rule_operate ost1 "start\ after\ jobid={jobid}\ rate=1000\ rank=default"
3722         tbf_rule_check ost1 "before after default" \
3723                 "error when inserting rule 'after'"
3724
3725         tbf_rule_operate ost1 "start\ target\ jobid={jobid}\ rate=1000\ rank=after"
3726         tbf_rule_check ost1 "before target after default" \
3727                 "error when inserting rule 'target'"
3728
3729         echo "Move before itself"
3730         tbf_rule_operate ost1 "change\ target\ rank=target"
3731         tbf_rule_check ost1 "before target after default" \
3732                 "error when moving before itself"
3733
3734         echo "Move to higher rank"
3735         tbf_rule_operate ost1 "change\ target\ rank=before"
3736         tbf_rule_check ost1 "target before after default" \
3737                 "error when moving to higher rank"
3738
3739         echo "Move to lower rank"
3740         tbf_rule_operate ost1 "change\ target\ rank=after"
3741         tbf_rule_check ost1 "before target after default" \
3742                 "error when moving to lower rank"
3743
3744         echo "Move before default"
3745         tbf_rule_operate ost1 "change\ target\ rank=default"
3746         tbf_rule_check ost1 "before after target default" \
3747                 error "error when moving before default"
3748
3749         # Cleanup the TBF policy
3750         do_nodes $(comma_list $(osts_nodes)) \
3751                 $LCTL set_param ost.OSS.ost_io.nrs_policies=fifo
3752         return 0
3753 }
3754 run_test 77i "Change rank of TBF rule"
3755
3756 test_77j() {
3757         local idis
3758         local rateis
3759         local ost_version=$(lustre_version_code ost1)
3760
3761         [ $ost_version -ge $(version_code 2.9.53) ] ||
3762                 { skip "Need OST version at least 2.9.53"; return 0; }
3763         if [ $ost_version -ge $(version_code 2.8.60) ]; then
3764                 idis="opcode="
3765                 rateis="rate="
3766         fi
3767
3768         do_nodes $(comma_list $(osts_nodes)) \
3769                 lctl set_param jobid_var=procname_uid \
3770                         ost.OSS.ost_io.nrs_policies="tbf\ opcode" \
3771                         ost.OSS.ost_io.nrs_tbf_rule="start\ ost_r\ ${idis}{ost_read}\ ${rateis}5" \
3772                         ost.OSS.ost_io.nrs_tbf_rule="start\ ost_w\ ${idis}{ost_write}\ ${rateis}20"
3773         [ $? -ne 0 ] && error "failed to set TBF OPCode policy"
3774
3775         nrs_write_read
3776         tbf_verify 20 5
3777
3778         do_nodes $(comma_list $(osts_nodes)) \
3779                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ost_r" \
3780                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ost_w" \
3781                         ost.OSS.ost_io.nrs_policies="fifo"
3782
3783         # sleep 3 seconds to wait the tbf policy stop completely,
3784         # or the next test case is possible get -EAGAIN when
3785         # setting the tbf policy
3786         sleep 3
3787 }
3788 run_test 77j "check TBF-OPCode NRS policy"
3789
3790 test_id() {
3791         local idstr="${1}id"
3792         local policy="${idstr}={$2}"
3793         local rate="rate=$3"
3794
3795         do_nodes $(comma_list $(osts_nodes)) \
3796                 lctl set_param jobid_var=procname_uid \
3797                         ost.OSS.ost_io.nrs_policies="tbf\ ${idstr}" \
3798                         ost.OSS.ost_io.nrs_tbf_rule="start\ ost_${idstr}\ ${policy}\ ${rate}"
3799         [ $? -ne 0 ] && error "failed to set tbf ${idstr} policy"
3800
3801         nrs_write_read "runas $4"
3802         tbf_verify $3 $3 "runas $4"
3803
3804         do_nodes $(comma_list $(osts_nodes)) \
3805                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ost_${idstr}" \
3806                         ost.OSS.ost_io.nrs_policies="fifo"
3807
3808         # sleep 3 seconds to wait the tbf policy stop completely,
3809         # or the next test case is possible get -eagain when
3810         # setting the tbf policy
3811         sleep 3
3812 }
3813
3814 test_77ja(){
3815         if [ $(lustre_version_code ost1) -lt $(version_code 2.11.50) ]; then
3816                 skip "Need OST version at least 2.11.50"
3817                 return 0
3818         fi
3819         test_id "u" "500" "5" "-u 500"
3820         test_id "g" "500" "5" "-u 500 -g 500"
3821 }
3822 run_test 77ja "check TBF-UID/GID NRS policy"
3823
3824 cleanup_77k()
3825 {
3826         local rule_lists=$1
3827         local old_nrs=$2
3828
3829         trap 0
3830         for rule in $rule_lists; do
3831                 do_nodes $(comma_list $(osts_nodes)) \
3832                         lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ $rule"
3833         done
3834
3835         do_nodes $(comma_list $(osts_nodes)) \
3836                 lctl set_param ost.OSS.ost_io.nrs_policies="$old_nrs"
3837
3838         sleep 3
3839 }
3840
3841 test_77k() {
3842         [[ $(lustre_version_code ost1) -ge $(version_code 2.9.53) ]] ||
3843                 { skip "Need OST version at least 2.9.53"; return 0; }
3844
3845         do_nodes $(comma_list $(osts_nodes)) \
3846                 lctl set_param ost.OSS.ost_io.nrs_policies="tbf" \
3847                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_w\ jobid={dd.$RUNAS_ID}\&opcode={ost_write}\ rate=20" \
3848                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_r\ jobid={dd.$RUNAS_ID}\&opcode={ost_read}\ rate=10"
3849
3850         nrs_write_read "$RUNAS"
3851         tbf_verify 20 10 "$RUNAS"
3852
3853         local address=$(comma_list "$(host_nids_address $CLIENTS $NETTYPE)")
3854         local client_nids=$(nids_list $address "\\")
3855         do_nodes $(comma_list $(osts_nodes)) \
3856                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_w" \
3857                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_r" \
3858                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_w\ nid={0@lo\ $client_nids}\&opcode={ost_write}\ rate=20" \
3859                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_r\ nid={0@lo\ $client_nids}\&opcode={ost_read}\ rate=10"
3860
3861         nrs_write_read
3862         tbf_verify 20 10
3863
3864         do_nodes $(comma_list $(osts_nodes)) \
3865                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_w" \
3866                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_r" \
3867                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext\ nid={0@lo\ $client_nids}\&jobid={dd.$RUNAS_ID}\ rate=20"
3868
3869         nrs_write_read "$RUNAS"
3870         tbf_verify 20 20 "$RUNAS"
3871
3872         do_nodes $(comma_list $(osts_nodes)) \
3873                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext" \
3874                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_a\ jobid={dd.$RUNAS_ID},opcode={ost_write}\ rate=20" \
3875                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_b\ jobid={dd.$RUNAS_ID},opcode={ost_read}\ rate=10"
3876
3877         nrs_write_read "$RUNAS"
3878         # with parameter "RUNAS", it will match the latest rule
3879         # "ext_b" first, so the limited write rate is 10.
3880         tbf_verify 10 10 "$RUNAS"
3881         tbf_verify 20 10
3882
3883         trap "cleanup_77k \"ext_a ext_b\" \"fifo\"" EXIT
3884
3885         [[ $(lustre_version_code ost1) -ge $(version_code 2.10.58) ]] ||
3886                 { skip "Need OST version at least 2.10.58"; return 0; }
3887
3888         do_nodes $(comma_list $(osts_nodes)) \
3889                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_a" \
3890                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_b" \
3891                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_ug\ uid={500}\&gid={1000}\ rate=5"
3892         nrs_write_read "runas -u 500 -g 1000"
3893         tbf_verify 5 5 "runas -u 500 -g 1000"
3894
3895         do_nodes $(comma_list $(osts_nodes)) \
3896                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_ug" \
3897                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_uw\ uid={500}\&opcode={ost_write}\ rate=20" \
3898                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_ur\ uid={500}\&opcode={ost_read}\ rate=10"
3899
3900         nrs_write_read "runas -u 500"
3901         tbf_verify 20 10 "runas -u 500"
3902
3903         do_nodes $(comma_list $(osts_nodes)) \
3904                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_uw" \
3905                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_ur" \
3906                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_a\ uid={500},opcode={ost_write}\ rate=20" \
3907                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_b\ uid={500},opcode={ost_read}\ rate=10"
3908         nrs_write_read "runas -u 500"
3909         tbf_verify 10 10 "runas -u 500"
3910         tbf_verify 20 10 "runas -u 500"
3911         cleanup_77k "ext_a ext_b" "fifo"
3912 }
3913 run_test 77k "check TBF policy with NID/JobID/OPCode expression"
3914
3915 test_77l() {
3916         [[ $(lustre_version_code ost1) -ge $(version_code 2.10.56) ]] ||
3917                 { skip "Need OST version at least 2.10.56"; return 0; }
3918
3919         do_facet ost1 lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ nid"
3920         do_facet ost1 lctl set_param ost.OSS.ost_io.nrs_policies="tbf"
3921
3922         local output=$(do_facet ost1 lctl get_param \
3923                         ost.OSS.ost_io.nrs_policies | \
3924                         awk '/name: tbf/ {print;exit}' | \
3925                         awk -F ': ' '{print $2}')
3926
3927         if [ "$output" != "tbf" ]; then
3928                 error "The generic TBF output is '$output', not 'tbf'"
3929         fi
3930
3931         do_facet ost1 lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3932 }
3933 run_test 77l "check the output of NRS policies for generic TBF"
3934
3935 test_77m() {
3936         if [ $(lustre_version_code ost1) -lt $(version_code 2.9.54) ]; then
3937                 skip "Need OST version at least 2.9.54"
3938                 return 0
3939         fi
3940
3941         local dir=$DIR/$tdir
3942
3943         mkdir $dir || error "mkdir $dir failed"
3944         $LFS setstripe -c $OSTCOUNT $dir || error "setstripe to $dir failed"
3945         chmod 777 $dir
3946
3947         local nodes=$(comma_list $(osts_nodes))
3948         do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies=delay \
3949                                        ost.OSS.ost_io.nrs_delay_min=4 \
3950                                        ost.OSS.ost_io.nrs_delay_max=4 \
3951                                        ost.OSS.ost_io.nrs_delay_pct=100
3952         [ $? -ne 0 ] && error "Failed to set delay policy"
3953
3954         local start=$SECONDS
3955         do_nodes "${SINGLECLIENT:-$HOSTNAME}" "$RUNAS" \
3956                  dd if=/dev/zero of="$dir/nrs_delay_$HOSTNAME" bs=1M count=1 \
3957                    oflag=direct conv=fdatasync ||
3958                 { do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo";
3959                   error "dd on client failed (1)"; }
3960         local elapsed=$((SECONDS - start))
3961
3962         # NRS delay doesn't do sub-second timing, so a request enqueued at
3963         # 0.9 seconds can be dequeued at 4.0
3964         [ $elapsed -lt 3 ] &&
3965                 { do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo";
3966                   error "Single 1M write should take at least 3 seconds"; }
3967
3968         start=$SECONDS
3969         do_nodes "${SINGLECLIENT:-$HOSTNAME}" "$RUNAS" \
3970                  dd if=/dev/zero of="$dir/nrs_delay_$HOSTNAME" bs=1M count=10 \
3971                    oflag=direct conv=fdatasync ||
3972                 { do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo";
3973                   error "dd on client failed (2)"; }
3974         elapsed=$((SECONDS - start))
3975
3976         [ $elapsed -lt 30 ] &&
3977                 { do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo";
3978                   error "Ten 1M writes should take at least 30 seconds"; }
3979
3980         do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3981         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3982
3983         return 0
3984 }
3985 run_test 77m "check NRS Delay slows write RPC processing"
3986
3987 test_77n() { #LU-10802
3988         if [ $(lustre_version_code ost1) -lt $(version_code 2.10.58) ]; then
3989                 skip "Need OST version at least 2.10.58"
3990                 return 0
3991         fi
3992
3993         # Configure jobid_var
3994         local saved_jobid_var=$($LCTL get_param -n jobid_var)
3995         if [ $saved_jobid_var != procname_uid ]; then
3996                 set_persistent_param_and_check client \
3997                         "jobid_var" "$FSNAME.sys.jobid_var" procname_uid
3998         fi
3999
4000         do_nodes $(comma_list $(osts_nodes)) \
4001                 lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ jobid" \
4002                         ost.OSS.ost_io.nrs_tbf_rule="stop\ dd_runas" \
4003                         ost.OSS.ost_io.nrs_tbf_rule="start\ dd_runas\ jobid={*.$RUNAS_ID}\ rate=20"
4004
4005         nrs_write_read
4006         tbf_verify 20 20 "$RUNAS"
4007
4008         do_nodes $(comma_list $(osts_nodes)) \
4009                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ dd_runas" \
4010                         ost.OSS.ost_io.nrs_tbf_rule="start\ dd_runas\ jobid={dd.*}\ rate=20"
4011
4012         nrs_write_read
4013         tbf_verify 20 20
4014
4015         do_nodes $(comma_list $(osts_nodes)) \
4016                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ dd_runas" \
4017                         ost.OSS.ost_io.nrs_policies="fifo"
4018
4019         sleep 3
4020
4021         local current_jobid_var=$($LCTL get_param -n jobid_var)
4022         if [ $saved_jobid_var != $current_jobid_var ]; then
4023                 set_persistent_param_and_check client \
4024                         "jobid_var" "$FSNAME.sys.jobid_var" $saved_jobid_var
4025         fi
4026 }
4027 run_test 77n "check wildcard support for TBF JobID NRS policy"
4028
4029 test_78() { #LU-6673
4030         local rc
4031
4032         oss=$(comma_list $(osts_nodes))
4033         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="orr" &
4034         do_nodes $oss lctl set_param ost.OSS.*.nrs_orr_quantum=1
4035         rc=$?
4036         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
4037         # Valid return codes are:
4038         # 0: Tuning succeeded
4039         # ENODEV: Policy is still stopped
4040         # EAGAIN: Policy is being initialized
4041         [ $rc -eq 0 -o $rc -eq 19 -o $rc -eq 11 ] ||
4042                 error "Expected set_param to return 0|ENODEV|EAGAIN"
4043
4044         # Cleanup the ORR policy
4045         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
4046         [ $? -ne 0 ] && error "failed to set policy back to fifo"
4047         return 0
4048 }
4049 run_test 78 "Enable policy and specify tunings right away"
4050
4051 test_79() {
4052         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4053         test_mkdir $DIR/$tdir
4054
4055         # Prevent interference from layout intent RPCs due to
4056         # asynchronous writeback. These will be tested in 130c below.
4057         do_nodes ${CLIENTS:-$HOSTNAME} sync
4058
4059         setfattr -n trusted.name1 -v value1 $DIR/$tdir ||
4060                 error "setfattr -n trusted.name1=value1 $DIR/$tdir failed"
4061
4062 #define OBD_FAIL_MDS_INTENT_DELAY               0x160
4063         local mdtidx=$($LFS getstripe -m $DIR/$tdir)
4064         local facet=mds$((mdtidx + 1))
4065         stat $DIR/$tdir
4066         set_nodes_failloc $(facet_active_host $facet) 0x80000160
4067         getfattr -n trusted.name1 $DIR/$tdir 2> /dev/null  &
4068         local pid=$!
4069         sleep 2
4070
4071 #define OBD_FAIL_MDS_GETXATTR_PACK       0x131
4072         set_nodes_failloc $(facet_active_host $facet) 0x80000131
4073
4074         wait $pid
4075         return 0
4076 }
4077 run_test 79 "xattr: intent error"
4078
4079 test_80a() {
4080         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4081         local MDTIDX=1
4082         local mdt_index
4083         local i
4084         local file
4085         local pid
4086
4087         mkdir -p $DIR1/$tdir/dir
4088         createmany -o $DIR1/$tdir/dir/f 10 ||
4089                 error "create files under remote dir failed $i"
4090
4091         cp /etc/passwd $DIR1/$tdir/$tfile
4092
4093         #migrate open file should fails
4094         multiop_bg_pause $DIR2/$tdir/$tfile O_c || error "open $file failed"
4095         pid=$!
4096         # give multiop a chance to open
4097         sleep 1
4098
4099         $LFS migrate -m $MDTIDX $DIR1/$tdir &&
4100                 error "migrate open files should failed with open files"
4101
4102         kill -USR1 $pid
4103
4104         $LFS migrate -m $MDTIDX $DIR1/$tdir ||
4105                         error "migrate remote dir error"
4106
4107         echo "Finish migration, then checking.."
4108         for file in $(find $DIR1/$tdir); do
4109                 mdt_index=$($LFS getstripe -m $file)
4110                 [ $mdt_index == $MDTIDX ] ||
4111                         error "$file is not on MDT${MDTIDX}"
4112         done
4113
4114         diff /etc/passwd $DIR1/$tdir/$tfile ||
4115                 error "file different after migration"
4116
4117         rm -rf $DIR1/$tdir || error "rm dir failed after migration"
4118 }
4119 run_test 80a "migrate directory when some children is being opened"
4120
4121 cleanup_80b() {
4122         trap 0
4123         kill -9 $migrate_pid
4124 }
4125
4126 test_80b() {
4127         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4128         local migrate_dir1=$DIR1/$tdir/migrate_dir
4129         local migrate_dir2=$DIR2/$tdir/migrate_dir
4130         local migrate_run=$LUSTRE/tests/migrate.sh
4131         local start_time
4132         local end_time
4133         local show_time=1
4134         local mdt_idx
4135         local rc=0
4136         local rc1=0
4137
4138         trap cleanup_80b EXIT
4139         #prepare migrate directory
4140         mkdir -p $migrate_dir1
4141         for F in {1,2,3,4,5}; do
4142                 echo "$F$F$F$F$F" > $migrate_dir1/file$F
4143                 echo "$F$F$F$F$F" > $DIR/$tdir/file$F
4144         done
4145
4146         #migrate the directories among MDTs
4147         (
4148                 while true; do
4149                         mdt_idx=$((RANDOM % MDSCOUNT))
4150                         $LFS migrate -m $mdt_idx $migrate_dir1 &>/dev/null ||
4151                                 rc=$?
4152                         [ $rc -ne 0 -o $rc -ne 16 ] || break
4153                 done
4154         ) &
4155         migrate_pid=$!
4156
4157         echo "start migration thread $migrate_pid"
4158         #Access the files at the same time
4159         start_time=$(date +%s)
4160         echo "accessing the migrating directory for 5 minutes..."
4161         while true; do
4162                 ls $migrate_dir2 > /dev/null || {
4163                         echo "read dir fails"
4164                         break
4165                 }
4166                 diff -u $DIR2/$tdir/file1 $migrate_dir2/file1 || {
4167                         echo "access file1 fails"
4168                         break
4169                 }
4170
4171                 cat $migrate_dir2/file2 > $migrate_dir2/file3 || {
4172                         echo "access file2/3 fails"
4173                         break
4174                 }
4175
4176                 echo "aaaaa" > $migrate_dir2/file4 > /dev/null || {
4177                         echo "access file4 fails"
4178                         break
4179                 }
4180
4181                 stat $migrate_dir2/file5 > /dev/null || {
4182                         echo "stat file5 fails"
4183                         break
4184                 }
4185
4186                 touch $migrate_dir2/source_file > /dev/null || rc1=$?
4187                 [ $rc1 -ne 0 -o $rc1 -ne 1 ] || {
4188                         echo "touch file failed with $rc1"
4189                         break;
4190                 }
4191
4192                 if [ -e $migrate_dir2/source_file ]; then
4193                         ln $migrate_dir2/source_file $migrate_dir2/link_file \
4194                                         &>/dev/null || rc1=$?
4195                         if [ -e $migrate_dir2/link_file ]; then
4196                                 rm -rf $migrate_dir2/link_file
4197                         fi
4198
4199                         mrename $migrate_dir2/source_file \
4200                                 $migrate_dir2/target_file &>/dev/null || rc1=$?
4201                         [ $rc1 -ne 0 -o $rc1 -ne 1 ] || {
4202                                 echo "rename failed with $rc1"
4203                                 break
4204                         }
4205
4206                         if [ -e $migrate_dir2/target_file ]; then
4207                                 rm -rf $migrate_dir2/target_file &>/dev/null ||
4208                                                                 rc1=$?
4209                         else
4210                                 rm -rf $migrate_dir2/source_file &>/dev/null ||
4211                                                                 rc1=$?
4212                         fi
4213                         [ $rc1 -ne 0 -o $rc1 -ne 1 ] || {
4214                                 echo "unlink failed with $rc1"
4215                                 break
4216                         }
4217                 fi
4218
4219                 end_time=$(date +%s)
4220                 duration=$((end_time - start_time))
4221                 if [ $((duration % 10)) -eq 0 ]; then
4222                         if [ $show_time -eq 1 ]; then
4223                                 echo "...$duration seconds"
4224                                 show_time=0
4225                         fi
4226                 else
4227                         show_time=1
4228                 fi
4229
4230                 kill -0 $migrate_pid || {
4231                         echo "migration stopped 1"
4232                         break
4233                 }
4234
4235                 [ $duration -ge 300 ] && break
4236         done
4237
4238         #check migration are still there
4239         kill -0 $migrate_pid || error "migration stopped 2"
4240         cleanup_80b
4241 }
4242 run_test 80b "Accessing directory during migration"
4243
4244 test_81a() {
4245         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4246
4247         rm -rf $DIR1/$tdir
4248
4249         mkdir -p $DIR1/$tdir
4250
4251         $LFS setdirstripe -i0 -c$MDSCOUNT  $DIR1/$tdir/d0
4252         $LFS setdirstripe -i0 -c$MDSCOUNT  $DIR1/$tdir/d1
4253
4254         cd $DIR1/$tdir
4255         touch d0/0      || error "create 0 failed"
4256         mv d0/0 d1/0    || error "rename d0/0 d1/0 failed"
4257         stat d0/0       && error "stat mv filed succeed"
4258         mv $DIR2/$tdir/d1/0 $DIR2/$tdir/d0/0 || error "rename d1/0 d0/0 failed"
4259         stat d0/0       || error "stat failed"
4260
4261         local t=$(ls -ai $DIR1/$tdir/d0 | sort -u | wc -l)
4262
4263         if [ $t -ne 3 ]; then
4264                 ls -ai $DIR1/$tdir/d0
4265                 error "expect 3 get $t"
4266         fi
4267
4268         return 0
4269 }
4270 run_test 81a "rename and stat under striped directory"
4271
4272 test_81b() {
4273         [ $MDSCOUNT -lt 2 ] &&
4274                 skip "We need at least 2 MDTs for this test"
4275
4276         local total
4277         local setattr_pid
4278
4279         total=1000
4280
4281         $LFS mkdir -c $MDSCOUNT $DIR1/$tdir || error "$LFS mkdir"
4282         createmany -o $DIR1/$tdir/$tfile. $total || error "createmany"
4283
4284         (
4285                 while true; do
4286                         touch $DIR1/$tdir
4287                 done
4288         ) &
4289         setattr_pid=$!
4290
4291         for i in $(seq $total); do
4292                 mrename $DIR2/$tdir/$tfile.$i $DIR2/$tdir/$tfile-new.$i \
4293                         > /dev/null
4294         done
4295
4296         kill -9 $setattr_pid
4297 }
4298 run_test 81b "rename under striped directory doesn't deadlock"
4299
4300 test_82() {
4301         [[ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.6.91) ]] ||
4302                 { skip "Need MDS version at least 2.6.92"; return 0; }
4303
4304         # Client 1 creates a file.
4305         multiop_bg_pause $DIR1/$tfile O_ac || error "multiop_bg_pause 1"
4306         pid1=$!
4307         # Client 2 opens the file.
4308         multiop_bg_pause $DIR2/$tfile o_Ac || error "multiop_bg_pause 2"
4309         pid2=$!
4310         # Client 1 makes the file an orphan.
4311         rm $DIR1/$tfile || error "rm"
4312         # Client 2 sets EA "user.multiop".
4313         kill -s USR1 $pid2
4314         wait $pid2 || error "multiop 2"
4315         # Client 1 gets EA "user.multiop".  This used to fail because the EA
4316         # cache refill would get "trusted.link" from mdd_xattr_list() but
4317         # -ENOENT when trying to get "trusted.link"'s value.  See also sanity
4318         # 102q.
4319         kill -s USR1 $pid1
4320         wait $pid1 || error "multiop 1"
4321 }
4322 run_test 82 "fsetxattr and fgetxattr on orphan files"
4323
4324 test_83() {
4325         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4326         local pid1
4327         local pid2
4328
4329         (
4330                 cd $DIR1
4331                 while true; do
4332                         $LFS mkdir -i1 -c2 $tdir
4333                         rmdir $tdir
4334                 done
4335         ) &
4336         pid1=$!
4337         echo "start pid $pid1 to create/unlink striped directory"
4338
4339         # Access the directory at the same time
4340         (
4341                 cd $DIR2
4342                 while true; do
4343                         stat $tdir > /dev/null 2>&1
4344                 done
4345         ) &
4346         pid2=$!
4347         echo "start pid $pid2 to stat striped directory"
4348
4349         sleep 120
4350         kill $pid1 $pid2
4351         wait $pid1 $pid2
4352
4353         return 0
4354 }
4355 run_test 83 "access striped directory while it is being created/unlinked"
4356
4357 test_90() {
4358         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4359         local pid1
4360         local pid2
4361         local duration=180
4362
4363         [ "$SLOW" = "yes" ] && duration=600
4364         # Open/Create under striped directory
4365         (
4366                 cd $DIR1
4367                 while true; do
4368                         $LFS mkdir -c$MDSCOUNT $tdir > /dev/null 2>&1
4369                         touch $tdir/f{0..3} > /dev/null 2>&1
4370                 done
4371         ) &
4372         pid1=$!
4373         echo "start pid $pid1 to open/create under striped directory"
4374
4375         # unlink the striped directory at the same time
4376         (
4377                 cd $DIR2
4378                 while true; do
4379                         rm -rf $tdir > /dev/null 2>&1
4380                 done
4381         ) &
4382         pid2=$!
4383         echo "start pid $pid2 to unlink striped directory"
4384
4385         sleep $duration
4386
4387         kill $pid1 $pid2
4388         wait $pid1 $pid2
4389
4390         return 0
4391 }
4392 run_test 90 "open/create and unlink striped directory"
4393
4394 test_91() {
4395         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4396         local pid1
4397         local pid2
4398         local duration=180
4399
4400         [ "$SLOW" = "yes" ] && duration=600
4401         # chmod striped directory
4402         (
4403                 cd $DIR1
4404                 while true; do
4405                         $LFS mkdir -c$MDSCOUNT $tdir > /dev/null 2>&1
4406                         chmod go+w $tdir > /dev/null 2>&1
4407                 done
4408         ) &
4409         pid1=$!
4410         echo "start pid $pid1 to chmod striped directory"
4411
4412         # unlink the striped directory at the same time
4413         (
4414                 cd $DIR2
4415                 while true; do
4416                         rm -rf $tdir > /dev/null 2>&1
4417                 done
4418         ) &
4419         pid2=$!
4420         echo "start pid $pid2 to unlink striped directory"
4421
4422         sleep $duration
4423
4424         kill $pid1 $pid2
4425         wait $pid1 $pid2
4426
4427         return 0
4428 }
4429 run_test 91 "chmod and unlink striped directory"
4430
4431 test_92() {
4432         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4433
4434         local fd=$(free_fd)
4435         local cmd="exec $fd<$DIR1/$tdir"
4436         $LFS setdirstripe -c$MDSCOUNT $DIR1/$tdir || error "mkdir $tdir fails"
4437         eval $cmd
4438         cmd="exec $fd<&-"
4439         trap "eval $cmd" EXIT
4440         cd $DIR1/$tdir || error "cd $DIR1/$tdir fails"
4441         rmdir ../$tdir || error "rmdir ../$tdir fails"
4442
4443         #define OBD_FAIL_LLITE_NO_CHECK_DEAD  0x1408
4444         $LCTL set_param fail_loc=0x1408
4445         mkdir $DIR2/$tdir/dir && error "create dir succeeds"
4446         $LFS setdirstripe -i1 $DIR2/$tdir/remote_dir &&
4447                 error "create remote dir succeeds"
4448         $LCTL set_param fail_loc=0
4449         eval $cmd
4450         return 0
4451 }
4452 run_test 92 "create remote directory under orphan directory"
4453
4454 test_93() {
4455         local rc1=0
4456         local rc2=0
4457         local old_rr
4458
4459         mkdir -p $DIR1/$tfile-1/
4460         mkdir -p $DIR2/$tfile-2/
4461         local old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
4462                 'lod.lustre-MDT*/qos_threshold_rr' | sed -e 's/%//')
4463         do_facet $SINGLEMDS lctl set_param -n \
4464                 'lod.lustre-MDT*/qos_threshold_rr' 100
4465         #define OBD_FAIL_MDS_LOV_CREATE_RACE     0x163
4466         do_facet $SINGLEMDS "lctl set_param fail_loc=0x00000163"
4467
4468         $LFS setstripe -c -1 $DIR1/$tfile-1/file1 &
4469         local PID1=$!
4470         sleep 1
4471         $LFS setstripe -c -1 $DIR2/$tfile-2/file2 &
4472         local PID2=$!
4473         wait $PID2
4474         wait $PID1
4475         do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
4476         do_facet $SINGLEMDS "lctl set_param -n \
4477                 'lod.lustre-MDT*/qos_threshold_rr' $old_rr"
4478
4479         $LFS getstripe $DIR1/$tfile-1/file1
4480         rc1=$($LFS getstripe -q $DIR1/$tfile-1/file1 |
4481                 awk '{if (/[0-9]/) print $1 }' | sort | uniq -d | wc -l)
4482         $LFS getstripe $DIR2/$tfile-2/file2
4483         rc2=$($LFS getstripe -q $DIR2/$tfile-2/file2 |
4484                 awk '{if (/[0-9]/) print $1 }' | sort | uniq -d | wc -l)
4485         echo "rc1=$rc1 and rc2=$rc2 "
4486         [ $rc1 -eq 0 ] && [ $rc2 -eq 0 ] ||
4487                 error "object allocate on same ost detected"
4488 }
4489 run_test 93 "alloc_rr should not allocate on same ost"
4490
4491 # Data-on-MDT tests
4492 test_100a() {
4493         skip "Reserved for glimpse-ahead" && return
4494         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4495                 skip "Need MDS version at least 2.10.55" && return
4496
4497         mkdir -p $DIR/$tdir
4498
4499         $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
4500
4501         lctl set_param -n mdc.*.stats=clear
4502         dd if=/dev/zero of=$DIR2/$tdir/dom bs=4096 count=1 || return 1
4503
4504         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #1"
4505         # first stat from server should return size data and save glimpse
4506         local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
4507         [ $gls -eq 0 ] || error "Unexpected $gls glimpse RPCs"
4508         # second stat to check size is NOT cached on client without IO lock
4509         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #2"
4510
4511         local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
4512         [ $gls -ge 1 ] || error "Expect glimpse RPCs but none"
4513         rm -f $dom
4514 }
4515 run_test 100a "DoM: glimpse RPCs for stat without IO lock (DoM only file)"
4516
4517 test_100b() {
4518         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4519                 skip "Need MDS version at least 2.10.55" && return
4520
4521         mkdir -p $DIR/$tdir
4522
4523         $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
4524
4525         lctl set_param -n mdc.*.stats=clear
4526         dd if=/dev/zero of=$DIR2/$tdir/dom bs=4096 count=1 || return 1
4527         cancel_lru_locks mdc
4528         # first stat data from server should have size
4529         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #1"
4530         # second stat to check size is cached on client
4531         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #2"
4532
4533         local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
4534         # both stats should cause no glimpse requests
4535         [ $gls == 0 ] || error "Unexpected $gls glimpse RPCs"
4536         rm -f $dom
4537 }
4538 run_test 100b "DoM: no glimpse RPC for stat with IO lock (DoM only file)"
4539
4540 test_100c() {
4541         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4542                 skip "Need MDS version at least 2.10.55" && return
4543
4544         mkdir -p $DIR/$tdir
4545
4546         $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
4547
4548         lctl set_param -n mdc.*.stats=clear
4549         lctl set_param -n osc.*.stats=clear
4550         dd if=/dev/zero of=$DIR2/$tdir/dom bs=2048K count=1 || return 1
4551
4552         # check that size is merged from MDT and OST correctly
4553         $CHECKSTAT -t file -s 2097152 $DIR/$tdir/dom ||
4554                 error "Wrong size from stat #1"
4555
4556         local gls=$(lctl get_param -n osc.*.stats | grep -c ldlm_glimpse)
4557         [ $gls -eq 0 ] && error "Expect OST glimpse RPCs but got none"
4558
4559         rm -f $dom
4560 }
4561 run_test 100c "DoM: write vs stat without IO lock (combined file)"
4562
4563 test_100d() {
4564         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4565                 skip "Need MDS version at least 2.10.55" && return
4566
4567         mkdir -p $DIR/$tdir
4568
4569         $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
4570
4571
4572         dd if=/dev/zero of=$DIR2/$tdir/dom bs=2048K count=1 || return 1
4573         lctl set_param -n mdc.*.stats=clear
4574         $TRUNCATE $DIR2/$tdir/dom 4096
4575
4576         # check that reported size is valid after file grows to OST and
4577         # is truncated back to MDT stripe size
4578         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom ||
4579                 error "Wrong size from stat #1"
4580
4581         local gls=$(lctl get_param -n osc.*.stats | grep -c ldlm_glimpse)
4582         [ $gls -eq 0 ] && error "Expect OST glimpse but got none"
4583
4584         rm -f $dom
4585 }
4586 run_test 100d "DoM: write+truncate vs stat without IO lock (combined file)"
4587
4588 test_101a() {
4589         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4590                 skip "Need MDS version at least 2.10.55" && return
4591
4592         $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
4593         # to get layout
4594         $CHECKSTAT -t file $DIR1/$tfile
4595
4596         local old_wb=$(sysctl -n vm.dirty_writeback_centisecs)
4597         sysctl -wq vm.dirty_writeback_centisecs=0
4598
4599         trap "sysctl -wq vm.dirty_writeback_centisecs=$old_wb" EXIT
4600
4601         # open + IO lock
4602         dd if=/dev/zero of=$DIR1/$tfile bs=4096 count=1 ||
4603                 error_noexit "Write fails"
4604         # must discard pages
4605         lctl set_param -n mdc.*.stats=clear
4606         rm $DIR2/$tfile || error "Unlink fails"
4607
4608         local writes=$(lctl get_param -n mdc.*.stats | grep -c ost_write)
4609         [ $writes -eq 0 ] || error "Found WRITE RPC but expect none"
4610 }
4611 run_test 101a "Discard DoM data on unlink"
4612
4613 test_101b() {
4614         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4615                 skip "Need MDS version at least 2.10.55" && return
4616
4617         $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
4618         touch $DIR1/${tfile}_2
4619         # to get layout
4620         $CHECKSTAT -t file $DIR1/$tfile
4621
4622         local old_wb=$(sysctl -n vm.dirty_writeback_centisecs)
4623         sysctl -wq vm.dirty_writeback_centisecs=0
4624
4625         trap "sysctl -wq vm.dirty_writeback_centisecs=$old_wb" EXIT
4626
4627         # open + IO lock
4628         dd if=/dev/zero of=$DIR1/$tfile bs=4096 count=1 || error "Write fails"
4629         # must discard pages
4630         lctl set_param -n mdc.*.stats=clear
4631         mv $DIR2/${tfile}_2 $DIR2/$tfile || error "Rename fails"
4632
4633         local writes=$(lctl get_param -n mdc.*.stats | grep -c ost_write)
4634         [ $writes -eq 0 ] || error "Found WRITE RPC but expect none"
4635 }
4636 run_test 101b "Discard DoM data on rename"
4637
4638 test_101c() {
4639         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4640                 skip "Need MDS version at least 2.10.55" && return
4641
4642         $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
4643         # to get layout
4644         $CHECKSTAT -t file $DIR1/$tfile
4645
4646         local old_wb=$(sysctl -n vm.dirty_writeback_centisecs)
4647         sysctl -wq vm.dirty_writeback_centisecs=0
4648
4649         trap "sysctl -wq vm.dirty_writeback_centisecs=$old_wb" EXIT
4650
4651         # open + IO lock
4652         dd if=/dev/zero of=$DIR1/$tfile bs=4096 count=1 || error "Write fails"
4653         $MULTIOP $DIR1/$tfile O_c &
4654         MULTIOP_PID=$!
4655         sleep 1
4656         lctl set_param -n mdc.*.stats=clear
4657         rm $DIR2/$tfile > /dev/null || error "Unlink fails for opened file"
4658         kill -USR1 $MULTIOP_PID && wait $MULTIOP_PID || error "multiop failure"
4659
4660         local writes=$(lctl get_param -n mdc.*.stats | grep -c ost_write)
4661         [ $writes -eq 0 ] || error "Found WRITE RPC but expect none"
4662 }
4663 run_test 101c "Discard DoM data on close-unlink"
4664
4665 # test to verify file handle related system calls
4666 # (name_to_handle_at/open_by_handle_at)
4667 # The new system calls are supported in glibc >= 2.14.
4668
4669 # test to verify we can open by handle an unlinked file from > 1 client
4670 # This test opens the file normally on $DIR1, which is on one mount, and then
4671 # opens it by handle on $DIR2, which is on a different mount.
4672 test_102() {
4673         [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
4674                 skip "Needs MDS version 2.11.57 or later"
4675
4676         echo "Test file_handle syscalls" > $DIR/$tfile ||
4677                 error "write failed"
4678         check_fhandle_syscalls $DIR/$tfile $DIR2 ||
4679                 error "check_fhandle_syscalls failed"
4680         rm -f $DIR2/$tfile
4681 }
4682 run_test 102 "Test open by handle of unlinked file"
4683
4684 log "cleanup: ======================================================"
4685
4686 # kill and wait in each test only guarentee script finish, but command in script
4687 # like 'rm' 'chmod' may still be running, wait for all commands to finish
4688 # otherwise umount below will fail
4689 [ "$(mount | grep $MOUNT2)" ] && wait_update $HOSTNAME "fuser -m $MOUNT2" "" ||
4690         true
4691
4692 complete $SECONDS
4693 rm -f $SAMPLE_FILE
4694 check_and_cleanup_lustre
4695 exit_status