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