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