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