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