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