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