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