Whamcloud - gitweb
LU-5473 tests: sanity/51b Account for ZFS inode size
[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
2417         # cache layout lock on both mount point
2418         stat $DIR1/$tfile > /dev/null
2419         stat $DIR2/$tfile > /dev/null
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
2429         # MULTIOP proc should be able to read enough bytes and exit
2430         sleep 2
2431         kill -0 $pid && error "multiop is still there"
2432         cmp $origfile $DIR2/$tfile || error "$MCREATE and $DIR2/$tfile differs"
2433
2434         rm -f $DIR1/$tfile
2435 }
2436 run_test 51a "layout lock: refresh layout should work"
2437
2438 test_51b() {
2439         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.59) ]] ||
2440                 { skip "Need MDS version at least 2.3.59"; return 0; }
2441
2442         local tmpfile=`mktemp`
2443
2444         # create an empty file
2445         $MCREATE $DIR1/$tfile
2446
2447         # delay glimpse so that layout has changed when glimpse finish
2448 #define OBD_FAIL_GLIMPSE_DELAY 0x1404
2449         $LCTL set_param fail_loc=0x1404
2450         stat -c %s $DIR2/$tfile |tee $tmpfile &
2451         local pid=$!
2452         sleep 1
2453
2454         # create layout of testing file
2455         dd if=/dev/zero of=$DIR1/$tfile bs=1k count=1 conv=notrunc > /dev/null
2456
2457         wait $pid
2458         local fsize=`cat $tmpfile`
2459
2460         [ x$fsize = x1024 ] || error "file size is $fsize, should be 1024"
2461
2462         rm -f $DIR1/$tfile $tmpfile
2463 }
2464 run_test 51b "layout lock: glimpse should be able to restart if layout changed"
2465
2466 test_51c() {
2467         [ $OSTCOUNT -ge 2 ] || { skip "need at least 2 osts"; return; }
2468
2469         # set default layout to have 1 stripe
2470         mkdir -p $DIR1/$tdir
2471         $LFS setstripe -c 1 $DIR1/$tdir
2472
2473         # create a file with empty layout
2474         $MCREATE $DIR1/$tdir/$tfile
2475
2476 #define OBD_FAIL_MDS_LL_BLOCK 0x172
2477         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x172
2478
2479         # change the layout of testing file
2480         echo "Setting layout to have $OSTCOUNT stripes ..."
2481         $LFS setstripe -c $OSTCOUNT $DIR1/$tdir/$tfile &
2482         pid=$!
2483         sleep 1
2484
2485         # write something to the file, it should be blocked on fetching layout
2486         dd if=/dev/zero of=$DIR2/$tdir/$tfile bs=1k count=1 conv=notrunc
2487         local cnt=$($LFS getstripe -c $DIR2/$tdir/$tfile)
2488         [ $cnt -eq $OSTCOUNT ] || error "have $cnt stripes, expected $OSTCOUNT"
2489
2490         rm -fr $DIR1/$tdir
2491 }
2492 run_test 51c "layout lock: IT_LAYOUT blocked and correct layout can be returned"
2493
2494 test_51d() {
2495         dd if=/dev/zero of=/$DIR1/$tfile bs=1M count=1
2496         cancel_lru_locks mdc
2497
2498         # open should grant LAYOUT lock, mmap and read will install pages
2499         $MULTIOP $DIR1/$tfile oO_RDWR:SMR_Uc &
2500         local PID=$!
2501         sleep 1
2502
2503         # rss before revoking
2504         local br=$(grep -A 10 $tfile /proc/$PID/smaps | awk '/^Rss/{print $2}')
2505         echo "Before revoking layout lock: $br KB mapped"
2506
2507         # delete the file will revoke layout lock
2508         rm -f $DIR2/$tfile
2509
2510         # rss after revoking
2511         local ar=$(grep -A 10 $tfile /proc/$PID/smaps | awk '/^Rss/{print $2}')
2512
2513         kill -USR1 $PID
2514         wait $PID || error
2515
2516         [ $ar -eq 0 ] || error "rss before: $br, after $ar, some pages remained"
2517 }
2518 run_test 51d "layout lock: losing layout lock should clean up memory map region"
2519
2520 test_54_part1()
2521 {
2522         echo "==> rename vs getattr vs setxattr should not deadlock"
2523         mkdir -p $DIR/d1/d2/d3 || error "(1) mkdir failed"
2524
2525         do_facet mds $LCTL set_param fail_loc=$1
2526
2527         mv -T $DIR/d1/d2/d3 $DIR/d1/d3 &
2528         PID1=$!
2529         sleep 1
2530
2531         stat $DIR/d1/d2 &
2532         PID2=$!
2533         sleep 1
2534
2535         setfattr -n user.attr1 -v value1 $DIR2/d1 || error "(2) setfattr failed"
2536         wait $PID1 || error "(3) mv failed"
2537         wait $PID2 || error "(4) stat failed"
2538         echo
2539
2540         rm -rf $DIR/d1
2541 }
2542
2543 test_54_part2() {
2544         echo "==> rename vs getattr vs open vs getattr should not deadlock"
2545         mkdir -p $DIR/d1/d2/d3 || error "(1) mkdir failed"
2546
2547         do_facet mds $LCTL set_param fail_loc=$1
2548
2549         mv -T $DIR/d1/d2/d3 $DIR/d1/d3 &
2550         PID1=$!
2551         sleep 1
2552
2553         stat $DIR/d1/d2 &
2554         PID2=$!
2555         sleep 1
2556
2557         $MULTIOP $DIR2/d1/d2 Oc &
2558         PID3=$!
2559         sleep 1
2560
2561         stat $DIR/d1 || error "(2) stat failed"
2562
2563         wait $PID1 || error "(3) mv failed"
2564         wait $PID2 || error "(4) stat failed"
2565         wait $PID3 && error "(5) multiop failed"
2566         echo
2567         rm -rf $DIR/d1
2568 }
2569
2570 test_54() {
2571         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
2572         save_lustre_params client "llite.*.xattr_cache" > $p
2573         lctl set_param llite.*.xattr_cache 1 ||
2574                 { skip "xattr cache is not supported"; return 0; }
2575
2576 #define OBD_FAIL_MDS_RENAME              0x153
2577 #define OBD_FAIL_MDS_RENAME2             0x154
2578         test_54_part1 0x80000153 || error 10
2579         test_54_part1 0x80000154 || error 11
2580         test_54_part2 0x80000153 || error 12
2581         test_54_part2 0x80000154 || error 13
2582
2583         restore_lustre_params < $p
2584         rm -f $p
2585 }
2586 run_test 54 "rename locking"
2587
2588 test_55a() {
2589         mkdir -p $DIR/d1/d2 $DIR/d3 || error "(1) mkdir failed"
2590
2591 #define OBD_FAIL_MDS_RENAME4              0x156
2592         do_facet mds $LCTL set_param fail_loc=0x80000156
2593
2594         mv -T $DIR/d1/d2 $DIR/d3/d2 &
2595         PID1=$!
2596         sleep 1
2597
2598         rm -r $DIR2/d3
2599         wait $PID1 && error "(2) mv succeeded"
2600
2601         rm -rf $DIR/d1
2602 }
2603 run_test 55a "rename vs unlink target dir"
2604
2605 test_55b()
2606 {
2607         mkdir -p $DIR/d1/d2 $DIR/d3 || error "(1) mkdir failed"
2608
2609 #define OBD_FAIL_MDS_RENAME4             0x156
2610         do_facet mds $LCTL set_param fail_loc=0x80000156
2611
2612         mv -T $DIR/d1/d2 $DIR/d3/d2 &
2613         PID1=$!
2614         sleep 1
2615
2616         rm -r $DIR2/d1
2617         wait $PID1 && error "(2) mv succeeded"
2618
2619         rm -rf $DIR/d3
2620 }
2621 run_test 55b "rename vs unlink source dir"
2622
2623 test_55c()
2624 {
2625         mkdir -p $DIR/d1/d2 $DIR/d3 || error "(1) mkdir failed"
2626
2627 #define OBD_FAIL_MDS_RENAME4              0x156
2628         do_facet mds $LCTL set_param fail_loc=0x156
2629
2630         mv -T $DIR/d1/d2 $DIR/d3/d2 &
2631         PID1=$!
2632         sleep 1
2633
2634         # while rename is sleeping, open and remove d3
2635         $MULTIOP $DIR2/d3 D_c &
2636         PID2=$!
2637         sleep 1
2638         rm -rf $DIR2/d3
2639         sleep 5
2640
2641         # while rename is sleeping 2nd time, close d3
2642         kill -USR1 $PID2
2643         wait $PID2 || error "(3) multiop failed"
2644
2645         wait $PID1 && error "(2) mv succeeded"
2646
2647         rm -rf $DIR/d1
2648 }
2649 run_test 55c "rename vs unlink orphan target dir"
2650
2651 test_55d()
2652 {
2653         touch $DIR/f1
2654
2655 #define OBD_FAIL_MDS_RENAME3              0x155
2656         do_facet mds $LCTL set_param fail_loc=0x155
2657         mv $DIR/f1 $DIR/$tdir &
2658         PID1=$!
2659         sleep 2
2660
2661         # while rename is sleeping, create $tdir, but as a directory
2662         mkdir -p $DIR2/$tdir || error "(1) mkdir failed"
2663
2664         # link in reverse locking order
2665         ln $DIR2/f1 $DIR2/$tdir/
2666
2667         wait $PID1 && error "(2) mv succeeded"
2668         rm -rf $DIR/f1
2669 }
2670 run_test 55d "rename file vs link"
2671
2672 test_60() {
2673         local MDSVER=$(lustre_build_version $SINGLEMDS)
2674         [ $(version_code $MDSVER) -lt $(version_code 2.3.0) ] &&
2675                 skip "MDS version $MDSVER must be >= 2.3.0" && return 0
2676
2677         # Create a file
2678         test_mkdir -p $DIR1/$tdir
2679         file1=$DIR1/$tdir/file
2680         file2=$DIR2/$tdir/file
2681
2682         echo orig > $file2 || error "Could not create $file2"
2683         version=$($LFS data_version $file1)
2684
2685         # Append data
2686         echo append >> $file2 || error "Could not append to $file2"
2687         version2=$($LFS data_version $file1)
2688         [ "$version" != "$version2" ] ||
2689             error "append did not change data version: $version"
2690
2691         # Overwrite data
2692         echo overwrite > $file2 || error "Could not overwrite $file2"
2693         version3=$($LFS data_version $file1)
2694         [ "$version2" != "$version3" ] ||
2695             error "overwrite did not change data version: $version2"
2696
2697         # Truncate before EOF
2698         $TRUNCATE $file2 3 || error "Could not truncate $file2"
2699         version4=$($LFS data_version $file1)
2700         [ "$version3" != "$version4" ] ||
2701             error "truncate did not change data version: $version3"
2702
2703         # Truncate after EOF
2704         $TRUNCATE $file2 123456 || error "Could not truncate $file2"
2705         version5=$($LFS data_version $file1)
2706         [ "$version4" != "$version5" ] ||
2707             error "truncate did not change data version: $version4"
2708
2709         # Chmod do not change version
2710         chmod 400 $file2 || error "Could not chmod 400 $file2"
2711         version6=$($LFS data_version $file1)
2712         [ "$version5" == "$version6" ] ||
2713             error "chmod should not change data version: $version5 != $version6"
2714
2715         # Chown do not change version
2716         chown $RUNAS_ID $file2 || error "Could not chown $RUNAS_ID $file2"
2717         version7=$($LFS data_version $file1)
2718         [ "$version5" == "$version7" ] ||
2719             error "chown should not change data version: $version5 != $version7"
2720 }
2721 run_test 60 "Verify data_version behaviour"
2722
2723 test_70a() {
2724         local test_dir=$tdir/test_dir
2725
2726         mkdir -p $DIR1/$tdir
2727         if [ $MDSCOUNT -ge 2 ]; then
2728                 local MDTIDX=1
2729                 $LFS mkdir -i $MDTIDX $DIR1/$test_dir ||
2730                         error "Create remote directory failed"
2731         else
2732                 mkdir -p $DIR1/$test_dir
2733         fi
2734         cd $DIR2/$test_dir || error "cd directory failed"
2735         rm -rf $DIR1/$test_dir || error "unlink directory failed"
2736
2737         cd $DIR2/$tdir || error "exit directory"
2738 }
2739 run_test 70a "cd directory && rm directory"
2740
2741 test_70b() { # LU-2781
2742         local i
2743         mkdir -p $DIR1/$tdir
2744
2745         touch $DIR1/$tdir/file
2746         for ((i = 0; i < 32; i++)); do
2747             $LFS rm_entry $DIR1/$tdir/non_existent_dir &>/dev/null
2748         done
2749         rm $DIR1/$tdir/file || error "cannot remove file after rm_entry"
2750
2751         touch $DIR1/$tdir/file
2752         $LFS mkdir -i0 $DIR1/$tdir/test_dir
2753         $LFS rm_entry $DIR1/$tdir/test_dir &>/dev/null
2754         rm -rf $DIR1/$tdir/test_dir ||
2755                 error "cannot remove directory after rm_entry"
2756         rm $DIR1/$tdir/file || error "cannot remove file after rm_entry"
2757 }
2758 run_test 70b "remove files after calling rm_entry"
2759
2760 test_71() {
2761         local server_version=$(lustre_version_code $SINGLEMDS)
2762
2763         [[ $server_version -lt $(version_code 2.1.6) ]] &&
2764                 skip "Need MDS version at least 2.1.6" && return
2765
2766         # Patch not applied to 2.2 and 2.3 branches
2767         [[ $server_version -ge $(version_code 2.2.0) ]] &&
2768         [[ $server_version -lt $(version_code 2.4.0) ]] &&
2769                 skip "Need MDS version at least 2.4.0" && return
2770
2771         checkfiemap --test ||
2772                 { skip "checkfiemap not runnable: $?" && return; }
2773         # write data this way: hole - data - hole - data
2774         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=1 count=1
2775         [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR1/$tfile) + 1)))" = \
2776                 "zfs" ] &&
2777                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return 0
2778         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=3 count=1
2779         GET_STAT="lctl get_param -n ldlm.services.ldlm_cbd.stats"
2780         stat $DIR2/$tfile
2781         local can1=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
2782         echo $can1
2783         checkfiemap $DIR2/$tfile 81920 ||
2784                 error "data is not flushed from client"
2785         local can2=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
2786         echo $can2
2787
2788         # common case of "create file, copy file" on a single node
2789         # should not flush data from ost
2790         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=1 count=1
2791         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=3 count=1
2792         stat $DIR1/$tfile
2793         local can3=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
2794         echo $can3
2795         checkfiemap $DIR1/$tfile 81920 ||
2796         error 4
2797         local can4=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
2798         echo $can2
2799         [ $can3 -eq $can4 ] || error $((can2-can1)) "cancel RPC occured."
2800 }
2801 run_test 71 "correct file map just after write operation is finished"
2802
2803 test_72() {
2804         local p="$TMP/sanityN-$TESTNAME.parameters"
2805         local tlink1
2806         local tlink2
2807         save_lustre_params client "llite.*.xattr_cache" > $p
2808         lctl set_param llite.*.xattr_cache 1 ||
2809                 { skip "xattr cache is not supported"; return 0; }
2810
2811         touch $DIR1/$tfile
2812         setfattr -n user.attr1 -v value1 $DIR1/$tfile ||
2813                 error "setfattr1 failed"
2814         getfattr -n user.attr1 $DIR2/$tfile | grep value1 ||
2815                 error "getfattr1 failed"
2816         setfattr -n user.attr1 -v value2 $DIR2/$tfile ||
2817                 error "setfattr2 failed"
2818         getfattr -n user.attr1 $DIR1/$tfile | grep value2 ||
2819                 error "getfattr2 failed"
2820
2821         # check that trusted.link is consistent
2822         tlink1=$(getfattr -n trusted.link $DIR1/$tfile | md5sum)
2823         ln $DIR2/$tfile $DIR2/$tfile-2 || error "failed to link"
2824         tlink2=$(getfattr -n trusted.link $DIR1/$tfile | md5sum)
2825         echo "$tlink1 $tlink2"
2826         [ "$tlink1" = "$tlink2" ] && error "trusted.link should have changed!"
2827
2828         rm -f $DIR2/$tfile
2829
2830         restore_lustre_params < $p
2831         rm -f $p
2832 }
2833 run_test 72 "getxattr/setxattr cache should be consistent between nodes"
2834
2835 test_73() {
2836         local p="$TMP/sanityN-$TESTNAME.parameters"
2837         save_lustre_params client "llite.*.xattr_cache" > $p
2838         lctl set_param llite.*.xattr_cache 1 ||
2839                 { skip "xattr cache is not supported"; return 0; }
2840
2841         touch $DIR1/$tfile
2842         setfattr -n user.attr1 -v value1 $DIR1/$tfile ||
2843                 error "setfattr1 failed"
2844         getfattr -n user.attr1 $DIR2/$tfile || error "getfattr1 failed"
2845         getfattr -n user.attr1 $DIR1/$tfile || error "getfattr2 failed"
2846         clear_llite_stats
2847         # PR lock should be cached by now on both clients
2848         getfattr -n user.attr1 $DIR1/$tfile || error "getfattr3 failed"
2849         # 2 hits for getfattr(0)+getfattr(size)
2850         [ $(calc_llite_stats getxattr_hits) -eq 2 ] || error "not cached in $DIR1"
2851         getfattr -n user.attr1 $DIR2/$tfile || error "getfattr4 failed"
2852         # 4 hits for more getfattr(0)+getfattr(size)
2853         [ $(calc_llite_stats getxattr_hits) -eq 4 ] || error "not cached in $DIR2"
2854         rm -f $DIR2/$tfile
2855
2856         restore_lustre_params < $p
2857         rm -f $p
2858 }
2859 run_test 73 "getxattr should not cause xattr lock cancellation"
2860
2861 test_74() {
2862         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.93) ] &&
2863                 skip "Need MDS version at least 2.4.93" && return
2864
2865         dd if=/dev/zero of=$DIR1/$tfile-1 bs=1K count=1
2866         dd if=/dev/zero of=$DIR1/$tfile-2 bs=1K count=1
2867         flocks_test 4 $DIR1/$tfile-1 $DIR2/$tfile-2
2868 }
2869 run_test 74 "flock deadlock: different mounts =============="
2870
2871 # LU-3889
2872 test_75() {
2873         $LFS setstripe -c 2 -S 1m -i 0 $DIR1/$tfile
2874         dd if=/dev/zero of=$DIR1/$tfile bs=1M count=2
2875         cancel_lru_locks osc
2876
2877         dd of=$DIR1/$tfile if=/dev/zero bs=1M count=1 seek=1 conv=notrunc
2878         sync
2879
2880         # define OBD_FAIL_LDLM_ENQUEUE_HANG 0x31d
2881         $LCTL set_param fail_loc=0x31d
2882         stat -c %s $DIR1/$tfile &
2883         local pid=$!
2884         sleep 1
2885         kill -9 $pid
2886
2887         # For bad lock error handler we should ASSERT and got kernel panic here
2888         sleep 4
2889         $LCTL set_param fail_loc=0
2890 }
2891 run_test 75 "osc: upcall after unuse lock==================="
2892
2893 test_76() { #LU-946
2894         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
2895                 skip "Need MDS version at least 2.5.53" && return
2896
2897         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2898         local fcount=2048
2899         declare -a fd_list
2900         declare -a fid_list
2901
2902         if remote_mds; then
2903                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
2904         else
2905                 nid="0@lo"
2906         fi
2907
2908         rm -rf $DIR/$tdir
2909         test_mkdir -p $DIR/$tdir
2910
2911         # drop all open locks and close any cached "open" files on the client
2912         cancel_lru_locks mdc
2913
2914         echo -n "open files "
2915         ulimit -n 8096
2916         for ((i = 0; i < $fcount; i++)); do
2917                 touch $DIR/$tdir/f_$i
2918                 local fd=$(free_fd)
2919                 local cmd="exec $fd<$DIR/$tdir/f_$i"
2920                 eval $cmd
2921                 fd_list[i]=$fd
2922                 echo -n "."
2923         done
2924         echo
2925
2926         local get_open_fids="$LCTL get_param -n mdt.*.exports.'$nid'.open_files"
2927         local fid_list=($(do_nodes $(comma_list $(mdts_nodes)) $get_open_fids))
2928
2929         # Possible errors in openfiles FID list.
2930         # 1. Missing FIDs. Check 1
2931         # 2. Extra FIDs. Check 1
2932         # 3. Duplicated FID. Check 2
2933         # 4. Invalid FIDs. Check 2
2934         # 5. Valid FID, points to some other file. Check 3
2935
2936         # Check 1
2937         [ ${#fid_list[@]} -ne $fcount ] &&
2938                 error "${#fid_list[@]} != $fcount open files"
2939
2940         for (( i = 0; i < $fcount; i++ )) ; do
2941                 cmd="exec ${fd_list[i]}</dev/null"
2942                 eval $cmd
2943                 filename=$($LFS fid2path $DIR2 ${fid_list[i]})
2944
2945                 # Check 2
2946                 rm --interactive=no $filename
2947                 [ $? -ne 0 ] &&
2948                         error "Nonexisting fid ${fid_list[i]} listed."
2949         done
2950
2951         # Check 3
2952         ls_op=$(ls $DIR2/$tdir | wc -l)
2953         [ $ls_op -ne 0 ] &&
2954                 error "Some openfiles are missing in lproc output"
2955
2956         rm -rf $DIR/$tdir
2957 }
2958 run_test 76 "Verify open file for 2048 files"
2959
2960 nrs_write_read() {
2961         local n=16
2962         local dir=$DIR/$tdir
2963         local myRUNAS="$1"
2964
2965         mkdir $dir || error "mkdir $dir failed"
2966         $LFS setstripe -c $OSTCOUNT $dir || error "setstripe to $dir failed"
2967         chmod 777 $dir
2968
2969         do_nodes $CLIENTS $myRUNAS dd if=/dev/zero of="$dir/nrs_r_$HOSTNAME"\
2970                 bs=1M count=$n > /dev/null 2>&1 || error "dd on client failed"
2971
2972         for ((i = 0; i < $n; i++)); do
2973                 do_nodes $CLIENTS $myRUNAS dd if=/dev/zero\
2974                         of="$dir/nrs_w_$HOSTNAME" bs=1M seek=$i count=1\
2975                          > /dev/null 2>&1 || error "dd on client failed" &
2976                 local pids_w[$i]=$!
2977         done
2978         do_nodes $CLIENTS sync;
2979         cancel_lru_locks osc
2980
2981         for ((i = 0; i < $n; i++)); do
2982                 do_nodes $CLIENTS $myRUNAS dd if="$dir/nrs_w_$HOSTNAME"\
2983                         of=/dev/zero bs=1M seek=$i count=1 > /dev/null 2>&1 ||
2984                         error "dd on client failed"
2985                 local pids_r[$i]=$!
2986         done
2987         cancel_lru_locks osc
2988
2989         for ((i = 0; i < $n; i++)); do
2990                 wait ${pids_w[$i]}
2991                 wait ${pids_r[$i]}
2992         done
2993         rm -rf $dir || error "rm -rf $dir failed"
2994 }
2995
2996 test_77a() { #LU-3266
2997         oss=$(comma_list $(osts_nodes))
2998         do_nodes $oss lctl set_param ost.OSS.*.nrs_policies="fifo"
2999         nrs_write_read
3000
3001         return 0
3002 }
3003 run_test 77a "check FIFO NRS policy"
3004
3005 test_77b() { #LU-3266
3006         oss=$(comma_list $(osts_nodes))
3007
3008         do_nodes $oss lctl set_param ost.OSS.*.nrs_policies="crrn" \
3009                            ost.OSS.*.nrs_crrn_quantum=1
3010
3011         echo "policy: crr-n, crrn_quantum 1"
3012         nrs_write_read
3013
3014         do_nodes $oss lctl set_param ost.OSS.*.nrs_crrn_quantum=64
3015
3016         echo "policy: crr-n, crrn_quantum 64"
3017         nrs_write_read
3018
3019         # cleanup
3020         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3021         return 0
3022 }
3023 run_test 77b "check CRR-N NRS policy"
3024
3025 orr_trr() {
3026         local policy=$1
3027
3028         oss=$(comma_list $(osts_nodes))
3029
3030         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies=$policy \
3031                                      ost.OSS.*.nrs_"$policy"_quantum=1 \
3032                                      ost.OSS.*.nrs_"$policy"_offset_type="physical" \
3033                                      ost.OSS.*.nrs_"$policy"_supported="reads"
3034
3035         echo "policy: $policy, ${policy}_quantum 1, ${policy}_offset_type physical, ${policy}_supported reads"
3036         nrs_write_read
3037
3038         do_nodes $oss lctl set_param ost.OSS.*.nrs_${policy}_supported="writes" \
3039                                      ost.OSS.*.nrs_${policy}_quantum=64
3040
3041         echo "policy: $policy, ${policy}_quantum 64, ${policy}_offset_type physical, ${policy}_supported writes"
3042         nrs_write_read
3043
3044         do_nodes $oss lctl set_param ost.OSS.*.nrs_${policy}_supported="reads_and_writes" \
3045                                      ost.OSS.*.nrs_${policy}_offset_type="logical"
3046         echo "policy: $policy, ${policy}_quantum 64, ${policy}_offset_type logical, ${policy}_supported reads_and_writes"
3047         nrs_write_read
3048
3049         # cleanup
3050         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3051         return 0
3052 }
3053
3054 test_77c() { #LU-3266
3055         orr_trr "orr"
3056         return 0
3057 }
3058 run_test 77c "check ORR NRS policy"
3059
3060 test_77d() { #LU-3266
3061         orr_trr "trr"
3062         return 0
3063 }
3064 run_test 77d "check TRR nrs policy"
3065
3066 tbf_rule_operate()
3067 {
3068         local facet=$1
3069         shift 1
3070
3071         do_facet $facet lctl set_param \
3072                 ost.OSS.ost_io.nrs_tbf_rule="$*"
3073         [ $? -ne 0 ] &&
3074                 error "failed to run operate '$*' on TBF rules"
3075 }
3076
3077 test_77e() {
3078         local server_version=$(lustre_version_code ost1)
3079         [[ $server_version -ge $(version_code 2.7.58) ]] ||
3080                 { skip "Need server version newer than 2.7.57"; return 0; }
3081
3082         oss=$(comma_list $(osts_nodes))
3083
3084         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ nid"
3085         [ $? -ne 0 ] && error "failed to set TBF policy"
3086
3087         local idis
3088         local rateis
3089         if [ $(lustre_version_code ost1) -ge $(version_code 2.8.54) ]; then
3090                 idis="nid="
3091                 rateis="rate="
3092         fi
3093
3094         # Only operate rules on ost1 since OSTs might run on the same OSS
3095         # Add some rules
3096         tbf_rule_operate ost1 "start\ localhost\ ${idis}{0@lo}\ ${rateis}1000"
3097         local address=$(comma_list "$(host_nids_address $CLIENTS $NETTYPE)")
3098         local client_nids=$(nids_list $address "\\")
3099         tbf_rule_operate ost1 "start\ clients\ ${idis}{$client_nids}\ ${rateis}100"
3100         tbf_rule_operate ost1 "start\ others\ ${idis}{*.*.*.*@$NETTYPE}\ ${rateis}50"
3101         nrs_write_read
3102
3103         # Change the rules
3104         tbf_rule_operate ost1 "change\ localhost\ ${rateis}1001"
3105         tbf_rule_operate ost1 "change\ clients\ ${rateis}101"
3106         tbf_rule_operate ost1 "change\ others\ ${rateis}51"
3107         nrs_write_read
3108
3109         # Stop the rules
3110         tbf_rule_operate ost1 "stop\ localhost"
3111         tbf_rule_operate ost1 "stop\ clients"
3112         tbf_rule_operate ost1 "stop\ others"
3113         nrs_write_read
3114
3115         # Cleanup the TBF policy
3116         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3117         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3118         nrs_write_read
3119         return 0
3120 }
3121 run_test 77e "check TBF NID nrs policy"
3122
3123 test_77f() {
3124         local server_version=$(lustre_version_code ost1)
3125         [[ $server_version -ge $(version_code 2.7.58) ]] ||
3126                 { skip "Need server version newer than 2.7.57"; return 0; }
3127
3128         oss=$(comma_list $(osts_nodes))
3129
3130         # Configure jobid_var
3131         local saved_jobid_var=$($LCTL get_param -n jobid_var)
3132         if [ $saved_jobid_var != procname_uid ]; then
3133                 set_conf_param_and_check client                 \
3134                         "$LCTL get_param -n jobid_var"          \
3135                         "$FSNAME.sys.jobid_var" procname_uid
3136         fi
3137
3138         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ jobid"
3139         [ $? -ne 0 ] && error "failed to set TBF policy"
3140
3141         local idis
3142         local rateis
3143         if [ $(lustre_version_code ost1) -ge $(version_code 2.8.54) ]; then
3144                 idis="jobid="
3145                 rateis="rate="
3146         fi
3147
3148         # Only operate rules on ost1 since OSTs might run on the same OSS
3149         # Add some rules
3150         tbf_rule_operate ost1 "start\ runas\ ${idis}{iozone.$RUNAS_ID\ dd.$RUNAS_ID\ tiotest.$RUNAS_ID}\ ${rateis}1000"
3151         tbf_rule_operate ost1 "start\ iozone_runas\ ${idis}{iozone.$RUNAS_ID}\ ${rateis}100"
3152         tbf_rule_operate ost1 "start\ dd_runas\ ${idis}{dd.$RUNAS_ID}\ ${rateis}50"
3153         nrs_write_read "$RUNAS"
3154
3155         # Change the rules
3156         tbf_rule_operate ost1 "change\ runas\ ${rateis}1001"
3157         tbf_rule_operate ost1 "change\ iozone_runas\ ${rateis}101"
3158         tbf_rule_operate ost1 "change\ dd_runas\ ${rateis}51"
3159         nrs_write_read "$RUNAS"
3160
3161         # Stop the rules
3162         tbf_rule_operate ost1 "stop\ runas"
3163         tbf_rule_operate ost1 "stop\ iozone_runas"
3164         tbf_rule_operate ost1 "stop\ dd_runas"
3165         nrs_write_read "$RUNAS"
3166
3167         # Cleanup the TBF policy
3168         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3169         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3170         nrs_write_read "$RUNAS"
3171
3172         local current_jobid_var=$($LCTL get_param -n jobid_var)
3173         if [ $saved_jobid_var != $current_jobid_var ]; then
3174                 set_conf_param_and_check client                 \
3175                         "$LCTL get_param -n jobid_var"          \
3176                         "$FSNAME.sys.jobid_var" $saved_jobid_var
3177         fi
3178         return 0
3179 }
3180 run_test 77f "check TBF JobID nrs policy"
3181
3182 test_77g() {
3183         local server_version=$(lustre_version_code ost1)
3184         [[ $server_version -ge $(version_code 2.7.58) ]] ||
3185                 { skip "Need server version newer than 2.7.57"; return 0; }
3186
3187         oss=$(comma_list $(osts_nodes))
3188
3189         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ nid"
3190         [ $? -ne 0 ] && error "failed to set TBF policy"
3191
3192         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ jobid"
3193         [ $? -ne 0 ] && error "failed to set TBF policy"
3194
3195         local idis
3196         local rateis
3197         if [ $(lustre_version_code ost1) -ge $(version_code 2.8.54) ]; then
3198                 idis="jobid="
3199                 rateis="rate="
3200         fi
3201
3202         # Add a rule that only valid for Jobid TBF. If direct change between
3203         # TBF types is not supported, this operation will fail.
3204         tbf_rule_operate ost1 "start\ dd_runas\ ${idis}{dd.$RUNAS_ID}\ ${rateis}50"
3205
3206         # Cleanup the TBF policy
3207         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3208         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3209         return 0
3210 }
3211 run_test 77g "Change TBF type directly"
3212
3213 test_77h() {
3214         [ $(lustre_version_code ost1) -ge $(version_code 2.8.55) ] ||
3215                 { skip "Need OST version at least 2.8.55"; return 0; }
3216
3217         local old_policy=$(do_facet ost1 \
3218                 lctl get_param ost.OSS.ost_io.nrs_policies)
3219         local new_policy
3220
3221         do_facet ost1 lctl set_param \
3222                 ost.OSS.ost_io.nrs_policies="abc"
3223         [ $? -eq 0 ] && error "should return error"
3224
3225         do_facet ost1 lctl set_param \
3226                 ost.OSS.ost_io.nrs_policies="tbf\ abc"
3227         [ $? -eq 0 ] && error "should return error"
3228
3229         do_facet ost1 lctl set_param \
3230                 ost.OSS.ost_io.nrs_policies="tbf\ reg"
3231         [ $? -eq 0 ] && error "should return error"
3232
3233         do_facet ost1 lctl set_param \
3234                 ost.OSS.ost_io.nrs_policies="tbf\ reg\ abc"
3235         [ $? -eq 0 ] && error "should return error"
3236
3237         do_facet ost1 lctl set_param \
3238                 ost.OSS.ost_io.nrs_policies="tbf\ abc\ efg"
3239         [ $? -eq 0 ] && error "should return error"
3240
3241         new_policy=$(do_facet ost1 lctl get_param ost.OSS.ost_io.nrs_policies)
3242         [ $? -eq 0 ] || error "shouldn't LBUG"
3243
3244         [ "$old_policy" = "$new_policy" ] || error "NRS policy should be same"
3245
3246         return 0
3247 }
3248 run_test 77h "Wrong policy name should report error, not LBUG"
3249
3250 tbf_rule_check()
3251 {
3252         local facet=$1
3253         local expected=$2
3254         local error_message=$3
3255         local rule_number=0
3256         for rule in $expected; do
3257                 rule_number=$((rule_number + 1))
3258         done
3259         local stop_line=$(($rule_number + 3))
3260         local awk_command="awk 'NR >= 4 && NR <= $stop_line {print \$1}'"
3261
3262         local output=$(do_facet $facet lctl get_param \
3263                 ost.OSS.ost_io.nrs_tbf_rule |
3264                 eval $awk_command |
3265                 tr "\n" " " |
3266                 sed 's/[ ]*$//')
3267         if [ "$output" != "$expected" ]; then
3268                 error "$error_message, expected '$expected', got '$output'"
3269         fi
3270 }
3271
3272 test_77i() {
3273     [ $(lustre_version_code ost1) -ge $(version_code 2.8.55) ] ||
3274                 { skip "Need OST version at least 2.8.55"; return 0; }
3275
3276         for i in $(seq 1 $OSTCOUNT)
3277         do
3278                 do_facet ost"$i" lctl set_param \
3279                         ost.OSS.ost_io.nrs_policies="tbf\ jobid"
3280                 [ $? -ne 0 ] &&
3281                         error "failed to set TBF policy"
3282         done
3283
3284         tbf_rule_check ost1 "default" "error before inserting any rule"
3285
3286         tbf_rule_operate ost1 "start\ before\ jobid={jobid}\ rate=1000"
3287         tbf_rule_check ost1 "before default" \
3288                 "error when inserting rule 'before'"
3289
3290         tbf_rule_operate ost1 "start\ after\ jobid={jobid}\ rate=1000\ rank=default"
3291         tbf_rule_check ost1 "before after default" \
3292                 "error when inserting rule 'after'"
3293
3294         tbf_rule_operate ost1 "start\ target\ jobid={jobid}\ rate=1000\ rank=after"
3295         tbf_rule_check ost1 "before target after default" \
3296                 "error when inserting rule 'target'"
3297
3298         echo "Move before itself"
3299         tbf_rule_operate ost1 "change\ target\ rank=target"
3300         tbf_rule_check ost1 "before target after default" \
3301                 "error when moving before itself"
3302
3303         echo "Move to higher rank"
3304         tbf_rule_operate ost1 "change\ target\ rank=before"
3305         tbf_rule_check ost1 "target before after default" \
3306                 "error when moving to higher rank"
3307
3308         echo "Move to lower rank"
3309         tbf_rule_operate ost1 "change\ target\ rank=after"
3310         tbf_rule_check ost1 "before target after default" \
3311                 "error when moving to lower rank"
3312
3313         echo "Move before default"
3314         tbf_rule_operate ost1 "change\ target\ rank=default"
3315         tbf_rule_check ost1 "before after target default" \
3316                 error "error when moving before default"
3317
3318         # Cleanup the TBF policy
3319         do_nodes $(comma_list $(osts_nodes)) \
3320                 $LCTL set_param ost.OSS.ost_io.nrs_policies=fifo
3321         return 0
3322 }
3323 run_test 77i "Change rank of TBF rule"
3324
3325 test_78() { #LU-6673
3326         local rc
3327
3328         oss=$(comma_list $(osts_nodes))
3329         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="orr" &
3330         do_nodes $oss lctl set_param ost.OSS.*.nrs_orr_quantum=1
3331         rc=$?
3332         # Valid return codes are:
3333         # 0: Tuning succeeded
3334         # ENODEV: Policy is still stopped
3335         # EAGAIN: Policy is being initialized
3336         [ $rc -eq 0 -o $rc -eq 19 -o $rc -eq 11 ] ||
3337                 error "Expected set_param to return 0|ENODEV|EAGAIN"
3338
3339         # Cleanup the ORR policy
3340         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3341         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3342         return 0
3343 }
3344 run_test 78 "Enable policy and specify tunings right away"
3345
3346 test_79() {
3347         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3348         test_mkdir -p $DIR/$tdir
3349
3350         # Prevent interference from layout intent RPCs due to
3351         # asynchronous writeback. These will be tested in 130c below.
3352         do_nodes ${CLIENTS:-$HOSTNAME} sync
3353
3354         setfattr -n trusted.name1 -v value1 $DIR/$tdir ||
3355                 error "setfattr -n trusted.name1=value1 $DIR/$tdir failed"
3356
3357 #define OBD_FAIL_MDS_INTENT_DELAY               0x160
3358         local mdtidx=$($LFS getstripe -M $DIR/$tdir)
3359         local facet=mds$((mdtidx + 1))
3360         stat $DIR/$tdir
3361         set_nodes_failloc $(facet_active_host $facet) 0x80000160
3362         getfattr -n trusted.name1 $DIR/$tdir 2> /dev/null  &
3363         local pid=$!
3364         sleep 2
3365
3366 #define OBD_FAIL_MDS_GETXATTR_PACK       0x131
3367         set_nodes_failloc $(facet_active_host $facet) 0x80000131
3368
3369         wait $pid
3370         return 0
3371 }
3372 run_test 79 "xattr: intent error"
3373
3374 test_80a() {
3375         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3376         local MDTIDX=1
3377         local mdt_index
3378         local i
3379         local file
3380         local pid
3381
3382         mkdir -p $DIR1/$tdir/dir
3383         createmany -o $DIR1/$tdir/dir/f 10 ||
3384                 error "create files under remote dir failed $i"
3385
3386         cp /etc/passwd $DIR1/$tdir/$tfile
3387
3388         #migrate open file should fails
3389         multiop_bg_pause $DIR2/$tdir/$tfile O_c || error "open $file failed"
3390         pid=$!
3391         # give multiop a chance to open
3392         sleep 1
3393
3394         $LFS migrate -m $MDTIDX $DIR1/$tdir &&
3395                 error "migrate open files should failed with open files"
3396
3397         kill -USR1 $pid
3398
3399         $LFS migrate -m $MDTIDX $DIR1/$tdir ||
3400                         error "migrate remote dir error"
3401
3402         echo "Finish migration, then checking.."
3403         for file in $(find $DIR1/$tdir); do
3404                 mdt_index=$($LFS getstripe -M $file)
3405                 [ $mdt_index == $MDTIDX ] ||
3406                         error "$file is not on MDT${MDTIDX}"
3407         done
3408
3409         diff /etc/passwd $DIR1/$tdir/$tfile ||
3410                 error "file different after migration"
3411
3412         rm -rf $DIR1/$tdir || error "rm dir failed after migration"
3413 }
3414 run_test 80a "migrate directory when some children is being opened"
3415
3416 cleanup_80b() {
3417         trap 0
3418         kill -9 $migrate_pid
3419 }
3420
3421 test_80b() {
3422         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3423         local migrate_dir1=$DIR1/$tdir/migrate_dir
3424         local migrate_dir2=$DIR2/$tdir/migrate_dir
3425         local migrate_run=$LUSTRE/tests/migrate.sh
3426         local start_time
3427         local end_time
3428         local show_time=1
3429         local mdt_idx
3430         local rc=0
3431         local rc1=0
3432
3433         trap cleanup_80b EXIT
3434         #prepare migrate directory
3435         mkdir -p $migrate_dir1
3436         for F in {1,2,3,4,5}; do
3437                 echo "$F$F$F$F$F" > $migrate_dir1/file$F
3438                 echo "$F$F$F$F$F" > $DIR/$tdir/file$F
3439         done
3440
3441         #migrate the directories among MDTs
3442         (
3443                 while true; do
3444                         mdt_idx=$((RANDOM % MDSCOUNT))
3445                         $LFS migrate -m $mdt_idx $migrate_dir1 2&>/dev/null ||
3446                                 rc=$?
3447                         [ $rc -ne 0 -o $rc -ne 16 ] || break
3448                 done
3449         ) &
3450         migrate_pid=$!
3451
3452         echo "start migration thread $migrate_pid"
3453         #Access the files at the same time
3454         start_time=$(date +%s)
3455         echo "accessing the migrating directory for 5 minutes..."
3456         while true; do
3457                 ls $migrate_dir2 > /dev/null || {
3458                         echo "read dir fails"
3459                         break
3460                 }
3461                 diff -u $DIR2/$tdir/file1 $migrate_dir2/file1 || {
3462                         echo "access file1 fails"
3463                         break
3464                 }
3465
3466                 cat $migrate_dir2/file2 > $migrate_dir2/file3 || {
3467                         echo "access file2/3 fails"
3468                         break
3469                 }
3470
3471                 echo "aaaaa" > $migrate_dir2/file4 > /dev/null || {
3472                         echo "access file4 fails"
3473                         break
3474                 }
3475
3476                 stat $migrate_dir2/file5 > /dev/null || {
3477                         echo "stat file5 fails"
3478                         break
3479                 }
3480
3481                 touch $migrate_dir2/source_file > /dev/null || rc1=$?
3482                 [ $rc1 -ne 0 -o $rc1 -ne 1 ] || {
3483                         echo "touch file failed with $rc1"
3484                         break;
3485                 }
3486
3487                 if [ -e $migrate_dir2/source_file ]; then
3488                         ln $migrate_dir2/source_file $migrate_dir2/link_file \
3489                                         2&>/dev/null || rc1=$?
3490                         if [ -e $migrate_dir2/link_file ]; then
3491                                 rm -rf $migrate_dir2/link_file
3492                         fi
3493
3494                         mrename $migrate_dir2/source_file \
3495                                 $migrate_dir2/target_file 2&>/dev/null || rc1=$?
3496                         [ $rc1 -ne 0 -o $rc1 -ne 1 ] || {
3497                                 echo "rename failed with $rc1"
3498                                 break
3499                         }
3500
3501                         if [ -e $migrate_dir2/target_file ]; then
3502                                 rm -rf $migrate_dir2/target_file 2&>/dev/null ||
3503                                                                 rc1=$?
3504                         else
3505                                 rm -rf $migrate_dir2/source_file 2&>/dev/null ||
3506                                                                 rc1=$?
3507                         fi
3508                         [ $rc1 -ne 0 -o $rc1 -ne 1 ] || {
3509                                 echo "unlink failed with $rc1"
3510                                 break
3511                         }
3512                 fi
3513
3514                 end_time=$(date +%s)
3515                 duration=$((end_time - start_time))
3516                 if [ $((duration % 10)) -eq 0 ]; then
3517                         if [ $show_time -eq 1 ]; then
3518                                 echo "...$duration seconds"
3519                                 show_time=0
3520                         fi
3521                 else
3522                         show_time=1
3523                 fi
3524
3525                 kill -0 $migrate_pid || {
3526                         echo "migration stopped 1"
3527                         break
3528                 }
3529
3530                 [ $duration -ge 300 ] && break
3531         done
3532
3533         #check migration are still there
3534         kill -0 $migrate_pid || error "migration stopped 2"
3535         cleanup_80b
3536 }
3537 run_test 80b "Accessing directory during migration"
3538
3539 test_81() {
3540         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3541
3542         rm -rf $DIR1/$tdir
3543
3544         mkdir -p $DIR1/$tdir
3545
3546         $LFS setdirstripe -i0 -c$MDSCOUNT  $DIR1/$tdir/d0
3547         $LFS setdirstripe -i0 -c$MDSCOUNT  $DIR1/$tdir/d1
3548
3549         cd $DIR1/$tdir
3550         touch d0/0      || error "create 0 failed"
3551         mv d0/0 d1/0    || error "rename d0/0 d1/0 failed"
3552         stat d0/0       && error "stat mv filed succeed"
3553         mv $DIR2/$tdir/d1/0 $DIR2/$tdir/d0/0 || error "rename d1/0 d0/0 failed"
3554         stat d0/0       || error "stat failed"
3555
3556         local t=$(ls -ai $DIR1/$tdir/d0 | sort -u | wc -l)
3557
3558         if [ $t -ne 3 ]; then
3559                 ls -ai $DIR1/$tdir/d0
3560                 error "expect 3 get $t"
3561         fi
3562
3563         return 0
3564 }
3565 run_test 81 "rename and stat under striped directory"
3566
3567 test_82() {
3568         [[ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.6.91) ]] ||
3569                 { skip "Need MDS version at least 2.6.92"; return 0; }
3570
3571         # Client 1 creates a file.
3572         multiop_bg_pause $DIR1/$tfile O_ac || error "multiop_bg_pause 1"
3573         pid1=$!
3574         # Client 2 opens the file.
3575         multiop_bg_pause $DIR2/$tfile o_Ac || error "multiop_bg_pause 2"
3576         pid2=$!
3577         # Client 1 makes the file an orphan.
3578         rm $DIR1/$tfile || error "rm"
3579         # Client 2 sets EA "user.multiop".
3580         kill -s USR1 $pid2
3581         wait $pid2 || error "multiop 2"
3582         # Client 1 gets EA "user.multiop".  This used to fail because the EA
3583         # cache refill would get "trusted.link" from mdd_xattr_list() but
3584         # -ENOENT when trying to get "trusted.link"'s value.  See also sanity
3585         # 102q.
3586         kill -s USR1 $pid1
3587         wait $pid1 || error "multiop 1"
3588 }
3589 run_test 82 "fsetxattr and fgetxattr on orphan files"
3590
3591 test_83() {
3592         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3593         local pid1
3594         local pid2
3595
3596         (
3597                 cd $DIR1
3598                 while true; do
3599                         $LFS mkdir -i1 -c2 $tdir
3600                         rmdir $tdir
3601                 done
3602         ) &
3603         pid1=$!
3604         echo "start pid $pid1 to create/unlink striped directory"
3605
3606         # Access the directory at the same time
3607         (
3608                 cd $DIR2
3609                 while true; do
3610                         stat $tdir > /dev/null 2>&1
3611                 done
3612         ) &
3613         pid2=$!
3614         echo "start pid $pid2 to stat striped directory"
3615
3616         sleep 120
3617         kill $pid1 $pid2
3618         wait $pid1 $pid2
3619
3620         return 0
3621 }
3622 run_test 83 "access striped directory while it is being created/unlinked"
3623
3624 test_90() {
3625         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3626         local pid1
3627         local pid2
3628         local duration=180
3629
3630         [ "$SLOW" = "yes" ] && duration=600
3631         # Open/Create under striped directory
3632         (
3633                 cd $DIR1
3634                 while true; do
3635                         $LFS mkdir -c$MDSCOUNT $tdir > /dev/null 2>&1
3636                         touch $tdir/f{0..3} > /dev/null 2>&1
3637                 done
3638         ) &
3639         pid1=$!
3640         echo "start pid $pid1 to open/create under striped directory"
3641
3642         # unlink the striped directory at the same time
3643         (
3644                 cd $DIR2
3645                 while true; do
3646                         rm -rf $tdir > /dev/null 2>&1
3647                 done
3648         ) &
3649         pid2=$!
3650         echo "start pid $pid2 to unlink striped directory"
3651
3652         sleep $duration
3653
3654         kill $pid1 $pid2
3655         wait $pid1 $pid2
3656
3657         return 0
3658 }
3659 run_test 90 "open/create and unlink striped directory"
3660
3661 test_91() {
3662         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3663         local pid1
3664         local pid2
3665         local duration=180
3666
3667         [ "$SLOW" = "yes" ] && duration=600
3668         # chmod striped directory
3669         (
3670                 cd $DIR1
3671                 while true; do
3672                         $LFS mkdir -c$MDSCOUNT $tdir > /dev/null 2>&1
3673                         chmod go+w $tdir > /dev/null 2>&1
3674                 done
3675         ) &
3676         pid1=$!
3677         echo "start pid $pid1 to chmod striped directory"
3678
3679         # unlink the striped directory at the same time
3680         (
3681                 cd $DIR2
3682                 while true; do
3683                         rm -rf $tdir > /dev/null 2>&1
3684                 done
3685         ) &
3686         pid2=$!
3687         echo "start pid $pid2 to unlink striped directory"
3688
3689         sleep $duration
3690
3691         kill $pid1 $pid2
3692         wait $pid1 $pid2
3693
3694         return 0
3695 }
3696 run_test 91 "chmod and unlink striped directory"
3697
3698 test_92() {
3699         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3700
3701         local fd=$(free_fd)
3702         local cmd="exec $fd<$DIR1/$tdir"
3703         $LFS setdirstripe -c$MDSCOUNT $DIR1/$tdir || error "mkdir $tdir fails"
3704         eval $cmd
3705         cmd="exec $fd<&-"
3706         trap "eval $cmd" EXIT
3707         cd $DIR1/$tdir || error "cd $DIR1/$tdir fails"
3708         rmdir ../$tdir || error "rmdir ../$tdir fails"
3709
3710         #define OBD_FAIL_LLITE_NO_CHECK_DEAD  0x1408
3711         $LCTL set_param fail_loc=0x1408
3712         mkdir $DIR2/$tdir/dir && error "create dir succeeds"
3713         $LFS setdirstripe -i1 $DIR2/$tdir/remote_dir &&
3714                 error "create remote dir succeeds"
3715         $LCTL set_param fail_loc=0
3716         eval $cmd
3717         return 0
3718 }
3719 run_test 92 "create remote directory under orphan directory"
3720
3721 log "cleanup: ======================================================"
3722
3723 # kill and wait in each test only guarentee script finish, but command in script
3724 # like 'rm' 'chmod' may still be running, wait for all commands to finish
3725 # otherwise umount below will fail
3726 wait_update $HOSTNAME "fuser -m $MOUNT2" "" || true
3727
3728 [ "$(mount | grep $MOUNT2)" ] && umount $MOUNT2
3729
3730 complete $SECONDS
3731 rm -f $SAMPLE_FILE
3732 check_and_cleanup_lustre
3733 exit_status