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