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