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