Whamcloud - gitweb
LU-946 lprocfs: List open files in filesystem
[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 16929 9977 15528/11549 18080
7 ALWAYS_EXCEPT="                14b  18c     19         22    28   29          35    $SANITYN_EXCEPT"
8 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
9
10 # bug number for skipped test:        12652 12652
11 grep -q 'Enterprise Server 10' /etc/SuSE-release 2> /dev/null &&
12         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 11    14" || true
13
14 # It will be ported soon.
15 EXCEPT="$EXCEPT 22"
16
17 SRCDIR=`dirname $0`
18 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
19
20 SIZE=${SIZE:-40960}
21 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
22 MCREATE=${MCREATE:-mcreate}
23 OPENFILE=${OPENFILE:-openfile}
24 OPENUNLINK=${OPENUNLINK:-openunlink}
25 export MULTIOP=${MULTIOP:-multiop}
26 export TMP=${TMP:-/tmp}
27 MOUNT_2=${MOUNT_2:-"yes"}
28 CHECK_GRANT=${CHECK_GRANT:-"yes"}
29 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
30
31 SAVE_PWD=$PWD
32
33 export NAME=${NAME:-local}
34
35 LUSTRE=${LUSTRE:-`dirname $0`/..}
36 . $LUSTRE/tests/test-framework.sh
37 CLEANUP=${CLEANUP:-:}
38 SETUP=${SETUP:-:}
39 init_test_env $@
40 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
41 init_logging
42
43 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
44 # bug number for skipped test:        LU-2840 LU-2189 LU-2776
45         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 21      36      51a"
46 # LU-2829 / LU-2887 - make allowances for ZFS slowness
47         TEST33_NFILES=${TEST33_NFILES:-1000}
48 fi
49
50 [ "$SLOW" = "no" ] && EXCEPT_SLOW="33a"
51
52 FAIL_ON_ERROR=false
53
54 SETUP=${SETUP:-:}
55 TRACE=${TRACE:-""}
56
57 check_and_setup_lustre
58
59 LOVNAME=$($LCTL get_param -n llite.*.lov.common_name | tail -n 1)
60 OSTCOUNT=$($LCTL get_param -n lov.$LOVNAME.numobd)
61
62 assert_DIR
63 rm -rf $DIR1/[df][0-9]* $DIR1/lnk $DIR/[df].${TESTSUITE}*
64
65 SAMPLE_FILE=$TMP/$(basename $0 .sh).junk
66 dd if=/dev/urandom of=$SAMPLE_FILE bs=1M count=1
67
68 # $RUNAS_ID may get set incorrectly somewhere else
69 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
70
71 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
72
73 build_test_filter
74
75 mkdir -p $MOUNT2
76 mount_client $MOUNT2
77
78 test_1a() {
79         touch $DIR1/f1
80         [ -f $DIR2/f1 ] || error
81 }
82 run_test 1a "check create on 2 mtpt's =========================="
83
84 test_1b() {
85         chmod 777 $DIR2/f1
86         $CHECKSTAT -t file -p 0777 $DIR1/f1 || error
87         chmod a-x $DIR2/f1
88 }
89 run_test 1b "check attribute updates on 2 mtpt's ==============="
90
91 test_1c() {
92         $CHECKSTAT -t file -p 0666 $DIR1/f1 || error
93 }
94 run_test 1c "check after remount attribute updates on 2 mtpt's ="
95
96 test_1d() {
97         rm $DIR2/f1
98         $CHECKSTAT -a $DIR1/f1 || error
99 }
100 run_test 1d "unlink on one mountpoint removes file on other ===="
101
102 test_2a() {
103         touch $DIR1/f2a
104         ls -l $DIR2/f2a
105         chmod 777 $DIR2/f2a
106         $CHECKSTAT -t file -p 0777 $DIR1/f2a || error
107 }
108 run_test 2a "check cached attribute updates on 2 mtpt's ========"
109
110 test_2b() {
111         touch $DIR1/f2b
112         ls -l $DIR2/f2b
113         chmod 777 $DIR1/f2b
114         $CHECKSTAT -t file -p 0777 $DIR2/f2b || error
115 }
116 run_test 2b "check cached attribute updates on 2 mtpt's ========"
117
118 # NEED TO SAVE ROOT DIR MODE
119 test_2c() {
120         chmod 777 $DIR1
121         $CHECKSTAT -t dir -p 0777 $DIR2 || error
122 }
123 run_test 2c "check cached attribute updates on 2 mtpt's root ==="
124
125 test_2d() {
126         chmod 755 $DIR1
127         $CHECKSTAT -t dir -p 0755 $DIR2 || error
128 }
129 run_test 2d "check cached attribute updates on 2 mtpt's root ==="
130
131 test_2e() {
132         chmod 755 $DIR1
133         ls -l $DIR1
134         ls -l $DIR2
135         chmod 777 $DIR1
136         $RUNAS dd if=/dev/zero of=$DIR2/$tfile count=1 || error
137 }
138 run_test 2e "check chmod on root is propagated to others"
139
140 test_2f() {
141         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
142         local MDTIDX=1
143         local remote_dir=$tdir/remote_dir
144
145         mkdir -p $DIR1/$tdir
146         $LFS mkdir -i $MDTIDX $DIR1/$remote_dir ||
147                    error "Create remote directory failed"
148
149         touch $DIR1/$remote_dir/$tfile ||
150                 error "Create file under remote directory failed"
151         chmod 777 $DIR1/$remote_dir/$tfile ||
152                 error "Chmod file under remote directory failed"
153
154         $CHECKSTAT -t file -p 0777 $DIR2/$remote_dir/$tfile ||
155                 error "Check attr of file under remote directory failed"
156
157         chown $RUNAS_ID:$RUNAS_GID $DIR1/$remote_dir/$tfile ||
158                 error "Chown file under remote directory failed"
159
160         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR2/$remote_dir/$tfile ||
161                 error "Check owner of file under remote directory failed"
162
163         cd $DIR2/$remote_dir || error "enter remote dir"
164         rm -rf $DIR1/$remote_dir/$tfile ||
165                 error "Unlink remote directory failed"
166
167         $CHECKSTAT -t file $DIR2/$remote_dir/$tfile &&
168                 error "unlink file still exists!"
169
170         cd $DIR2/$tdir || error "exit remote dir"
171         rm -rf $DIR1/$tdir || error "unlink directory failed"
172 }
173 run_test 2f "check attr/owner updates on DNE with 2 mtpt's"
174
175 test_3() {
176         local target="this/is/good"
177         ln -s $target $DIR1/$tfile || error "ln -s $target $DIR1/$tfile failed"
178         [ "$(ls -l $DIR2/$tfile | sed -e 's/.* -> //')" = "$target" ] ||
179                 error "link $DIR2/$tfile not as expected"
180 }
181 run_test 3 "symlink on one mtpt, readlink on another ==========="
182
183 test_4() {
184         multifstat $DIR1/f4 $DIR2/f4
185 }
186 run_test 4 "fstat validation on multiple mount points =========="
187
188 test_5() {
189         mcreate $DIR1/f5
190         $TRUNCATE $DIR2/f5 100
191         $CHECKSTAT -t file -s 100 $DIR1/f5 || error
192         rm $DIR1/f5
193 }
194 run_test 5 "create a file on one mount, truncate it on the other"
195
196 test_6() {
197         openunlink $DIR1/$tfile $DIR2/$tfile || \
198                 error "openunlink $DIR1/$tfile $DIR2/$tfile"
199 }
200 run_test 6 "remove of open file on other node =================="
201
202 test_7() {
203         local dir=d7
204         opendirunlink $DIR1/$dir $DIR2/$dir || \
205                 error "opendirunlink $DIR1/$dir $DIR2/$dir"
206 }
207 run_test 7 "remove of open directory on other node ============="
208
209 test_8() {
210         opendevunlink $DIR1/$tfile $DIR2/$tfile || \
211                 error "opendevunlink $DIR1/$tfile $DIR2/$tfile"
212 }
213 run_test 8 "remove of open special file on other node =========="
214
215 test_9() {
216         MTPT=1
217         local dir
218         > $DIR2/f9
219         for C in a b c d e f g h i j k l; do
220                 dir=`eval echo \\$DIR$MTPT`
221                 echo -n $C >> $dir/f9
222                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
223         done
224         [ "`cat $DIR1/f9`" = "abcdefghijkl" ] || \
225                 error "`od -a $DIR1/f9` != abcdefghijkl"
226 }
227 run_test 9 "append of file with sub-page size on multiple mounts"
228
229 test_10a() {
230         MTPT=1
231         local dir
232         OFFSET=0
233         > $DIR2/f10
234         for C in a b c d e f g h i j k l; do
235                 dir=`eval echo \\$DIR$MTPT`
236                 echo -n $C | dd of=$dir/f10 bs=1 seek=$OFFSET count=1
237                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
238                 OFFSET=`expr $OFFSET + 1`
239         done
240         [ "`cat $DIR1/f10`" = "abcdefghijkl" ] || \
241                 error "`od -a $DIR1/f10` != abcdefghijkl"
242 }
243 run_test 10a "write of file with sub-page size on multiple mounts "
244
245 test_10b() {
246         # create a seed file
247         yes "R" | head -c 4000 >$TMP/f10b-seed
248         dd if=$TMP/f10b-seed of=$DIR1/f10b bs=3k count=1 || error "dd $DIR1"
249
250         $TRUNCATE $DIR1/f10b 4096 || error "truncate 4096"
251
252         dd if=$DIR2/f10b of=$TMP/f10b-lustre bs=4k count=1 || error "dd $DIR2"
253
254         # create a test file locally to compare
255         dd if=$TMP/f10b-seed of=$TMP/f10b bs=3k count=1 || error "dd random"
256         $TRUNCATE $TMP/f10b 4096 || error "truncate 4096"
257         cmp $TMP/f10b $TMP/f10b-lustre || error "file miscompare"
258         rm $TMP/f10b $TMP/f10b-lustre $TMP/f10b-seed
259 }
260 run_test 10b "write of file with sub-page size on multiple mounts "
261
262 test_11() {
263         test_mkdir $DIR1/d11
264         multiop_bg_pause $DIR1/d11/f O_c || return 1
265         MULTIPID=$!
266         cp -p /bin/ls $DIR1/d11/f
267         $DIR2/d11/f
268         RC=$?
269         kill -USR1 $MULTIPID
270         wait $MULTIPID || error
271         [ $RC -eq 0 ] && error || true
272 }
273 run_test 11 "execution of file opened for write should return error ===="
274
275 test_12() {
276        DIR=$DIR DIR2=$DIR2 sh lockorder.sh
277 }
278 run_test 12 "test lock ordering (link, stat, unlink) ==========="
279
280 test_13() {     # bug 2451 - directory coherency
281         test_mkdir $DIR1/d13 || error
282        cd $DIR1/d13 || error
283        ls
284        ( touch $DIR1/d13/f13 ) # needs to be a separate shell
285        ls
286        rm -f $DIR2/d13/f13 || error
287        ls 2>&1 | grep f13 && error "f13 shouldn't return an error (1)" || true
288        # need to run it twice
289        ( touch $DIR1/d13/f13 ) # needs to be a separate shell
290        ls
291        rm -f $DIR2/d13/f13 || error
292        ls 2>&1 | grep f13 && error "f13 shouldn't return an error (2)" || true
293 }
294 run_test 13 "test directory page revocation ===================="
295
296 test_14() {
297         test_mkdir -p $DIR1/$tdir
298         cp -p /bin/ls $DIR1/$tdir/$tfile
299         multiop_bg_pause $DIR1/$tdir/$tfile Ow_c || return 1
300         MULTIPID=$!
301
302         $DIR2/$tdir/$tfile && error || true
303         kill -USR1 $MULTIPID
304         wait $MULTIPID || return 2
305 }
306 run_test 14 "execution of file open for write returns -ETXTBSY ="
307
308 test_14a() {
309         test_mkdir -p $DIR1/d14
310         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
311         MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
312         MULTIOP_PID=$!
313         $MULTIOP $DIR2/d14/multiop Oc && error "expected error, got success"
314         kill -USR1 $MULTIOP_PID || return 2
315         wait $MULTIOP_PID || return 3
316         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
317 }
318 run_test 14a "open(RDWR) of executing file returns -ETXTBSY ===="
319
320 test_14b() { # bug 3192, 7040
321         test_mkdir -p $DIR1/d14
322         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
323         MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
324         MULTIOP_PID=$!
325         $TRUNCATE $DIR2/d14/multiop 0 && kill -9 $MULTIOP_PID && \
326                 error "expected truncate error, got success"
327         kill -USR1 $MULTIOP_PID || return 2
328         wait $MULTIOP_PID || return 3
329         cmp `which multiop` $DIR1/d14/multiop || error "binary changed"
330         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
331 }
332 run_test 14b "truncate of executing file returns -ETXTBSY ======"
333
334 test_14c() { # bug 3430, 7040
335         test_mkdir -p $DIR1/d14
336         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
337         MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
338         MULTIOP_PID=$!
339         cp /etc/hosts $DIR2/d14/multiop && error "expected error, got success"
340         kill -USR1 $MULTIOP_PID || return 2
341         wait $MULTIOP_PID || return 3
342         cmp `which multiop` $DIR1/d14/multiop || error "binary changed"
343         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
344 }
345 run_test 14c "open(O_TRUNC) of executing file return -ETXTBSY =="
346
347 test_14d() { # bug 10921
348         test_mkdir -p $DIR1/d14
349         cp -p `which multiop` $DIR1/d14/multiop || error "cp failed"
350         MULTIOP_PROG=$DIR1/d14/multiop multiop_bg_pause $TMP/test14.junk O_c || return 1
351         MULTIOP_PID=$!
352         log chmod
353         chmod 600 $DIR1/d14/multiop || error "chmod failed"
354         kill -USR1 $MULTIOP_PID || return 2
355         wait $MULTIOP_PID || return 3
356         cmp `which multiop` $DIR1/d14/multiop || error "binary changed"
357         rm $TMP/test14.junk $DIR1/d14/multiop || error "removing multiop"
358 }
359 run_test 14d "chmod of executing file is still possible ========"
360
361 test_15() {     # bug 974 - ENOSPC
362         echo "PATH=$PATH"
363         sh oos2.sh $MOUNT1 $MOUNT2
364         wait_delete_completed
365         grant_error=`dmesg | grep "> available"`
366         [ -z "$grant_error" ] || error "$grant_error"
367 }
368 run_test 15 "test out-of-space with multiple writers ==========="
369
370 COUNT=${COUNT:-2500}
371 # The FSXNUM reduction for ZFS is needed until ORI-487 is fixed.
372 # We don't want to skip it entirely, but ZFS is VERY slow and cannot
373 # pass a 2500 operation dual-mount run within the time limit.
374 if [ "$(facet_fstype ost1)" = "zfs" ]; then
375         FSXNUM=$((COUNT / 5))
376         FSXP=1
377 elif [ "$SLOW" = "yes" ]; then
378         FSXNUM=$((COUNT * 5))
379         FSXP=500
380 else
381         FSXNUM=$COUNT
382         FSXP=100
383 fi
384
385 test_16() {
386         local file1=$DIR1/$tfile
387         local file2=$DIR2/$tfile
388
389         # to allocate grant because it may run out due to test_15.
390         lfs setstripe -c -1 $file1
391         dd if=/dev/zero of=$file1 bs=$STRIPE_BYTES count=$OSTCOUNT oflag=sync
392         dd if=/dev/zero of=$file2 bs=$STRIPE_BYTES count=$OSTCOUNT oflag=sync
393         rm -f $file1
394
395         lfs setstripe -c -1 $file1 # b=10919
396         fsx -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -S 0 $file1 $file2
397 }
398 run_test 16 "$FSXNUM iterations of dual-mount fsx"
399
400 test_17() { # bug 3513, 3667
401         remote_ost_nodsh && skip "remote OST with nodsh" && return
402
403         lfs setstripe $DIR1/$tfile -i 0 -c 1
404         cp $SAMPLE_FILE $DIR1/$tfile
405         cancel_lru_locks osc > /dev/null
406         #define OBD_FAIL_ONCE|OBD_FAIL_LDLM_CREATE_RESOURCE    0x30a
407         do_facet ost1 lctl set_param fail_loc=0x8000030a
408         ls -ls $DIR1/$tfile | awk '{ print $1,$6 }' > $DIR1/$tfile-1 & \
409         ls -ls $DIR2/$tfile | awk '{ print $1,$6 }' > $DIR2/$tfile-2
410         wait
411         diff -u $DIR1/$tfile-1 $DIR2/$tfile-2 || error "files are different"
412 }
413 run_test 17 "resource creation/LVB creation race ==============="
414
415 test_18() {
416         # turn e.g. ALWAYS_EXCEPT="18c" into "-e 3"
417         local idx
418         local excepts=
419         for idx in {a..z}; do
420                 local ptr=EXCEPT_ALWAYS_18$idx
421                 [ x${!ptr} = xtrue ] || continue
422
423                 excepts="$excepts -e $(($(printf %d \'$idx)-96))"
424         done
425
426         $LUSTRE/tests/mmap_sanity -d $MOUNT1 -m $MOUNT2 $excepts
427         sync; sleep 1; sync
428 }
429 run_test 18 "mmap sanity check ================================="
430
431 test_19() { # bug3811
432         local node=$(facet_active_host ost1)
433
434         # check whether obdfilter is cache capable at all
435         if ! get_osd_param $node '' read_cache_enable >/dev/null; then
436                 echo "not cache-capable obdfilter"
437                 return 0
438         fi
439
440         local MAX=$(get_osd_param $node '' readcache_max_filesize | \
441                     head -n 1)
442         set_osd_param $node '' readcache_max_filesize 4096
443         dd if=/dev/urandom of=$TMP/$tfile bs=512k count=32
444         local SUM=$(cksum $TMP/$tfile | cut -d" " -f 1,2)
445         cp $TMP/$tfile $DIR1/$tfile
446         for i in `seq 1 20`; do
447                 [ $((i % 5)) -eq 0 ] && log "$testname loop $i"
448                 cancel_lru_locks osc > /dev/null
449                 cksum $DIR1/$tfile | cut -d" " -f 1,2 > $TMP/sum1 & \
450                 cksum $DIR2/$tfile | cut -d" " -f 1,2 > $TMP/sum2
451                 wait
452                 [ "$(cat $TMP/sum1)" = "$SUM" ] || \
453                         error "$DIR1/$tfile $(cat $TMP/sum1) != $SUM"
454                 [ "$(cat $TMP/sum2)" = "$SUM" ] || \
455                         error "$DIR2/$tfile $(cat $TMP/sum2) != $SUM"
456         done
457         set_osd_param $node '' readcache_max_filesize $MAX
458         rm $DIR1/$tfile
459 }
460 run_test 19 "test concurrent uncached read races ==============="
461
462 test_20() {
463         test_mkdir $DIR1/d20
464         cancel_lru_locks osc
465         CNT=$((`lctl get_param -n llite.*.dump_page_cache | wc -l`))
466         $MULTIOP $DIR1/f20 Ow8190c
467         $MULTIOP $DIR2/f20 Oz8194w8190c
468         $MULTIOP $DIR1/f20 Oz0r8190c
469         cancel_lru_locks osc
470         CNTD=$((`lctl get_param -n llite.*.dump_page_cache | wc -l` - $CNT))
471         [ $CNTD -gt 0 ] && \
472             error $CNTD" page left in cache after lock cancel" || true
473 }
474 run_test 20 "test extra readahead page left in cache ===="
475
476 cleanup_21() {
477         trap 0
478         umount $DIR1/$tdir
479 }
480
481 test_21() { # Bug 5907
482         test_mkdir $DIR1/$tdir
483         mount /etc $DIR1/$tdir --bind || error "mount failed" # Poor man's mount.
484         trap cleanup_21 EXIT
485         rmdir -v $DIR1/$tdir && error "Removed mounted directory"
486         rmdir -v $DIR2/$tdir && echo "Removed mounted directory from another mountpoint, needs to be fixed"
487         test -d $DIR1/$tdir || error "Mounted directory disappeared"
488         cleanup_21
489         test -d $DIR2/$tdir || test -d $DIR1/$tdir && error "Removed dir still visible after umount"
490         true
491 }
492 run_test 21 " Try to remove mountpoint on another dir ===="
493
494 test_23() { # Bug 5972
495         local at_diff=$(do_facet $SINGLEMDS \
496                 $LCTL get_param -n mdd.*MDT0000*.atime_diff | head -1)
497         echo "atime should be updated while another read" > $DIR1/$tfile
498
499         # clear the lock(mode: LCK_PW) gotten from creating operation
500         cancel_lru_locks osc
501         time1=$(date +%s)
502         echo "now is $time1"
503         sleep $((at_diff + 1))
504
505         echo "starting reads"
506         multiop_bg_pause $DIR1/$tfile or20_c || return 1
507         # with SOM and opencache enabled, we need to close a file and cancel
508         # open lock to get atime propogated to MDS
509         kill -USR1 $! || return 2
510         cancel_lru_locks mdc
511
512         time2=$(stat -c "%X" $DIR/$tfile)
513         echo "new atime is $time2"
514
515         [ $time2 -gt $time1 ] || error "atime was not updated"
516         rm -f $DIR1/$tfile || error "rm -f $DIR1/$tfile failed"
517         true
518 }
519 run_test 23 " others should see updated atime while another read===="
520
521 test_24a() {
522         touch $DIR1/$tfile
523         lfs df || error "lfs df failed"
524         lfs df -ih || error "lfs df -ih failed"
525         lfs df -h $DIR1 || error "lfs df -h $DIR1 failed"
526         lfs df -i $DIR2 || error "lfs df -i $DIR2 failed"
527         lfs df $DIR1/$tfile || error "lfs df $DIR1/$tfile failed"
528         lfs df -ih $DIR2/$tfile || error "lfs df -ih $DIR2/$tfile failed"
529
530         OSC=`lctl dl | awk '/-osc-|OSC.*MNT/ {print $4}' | head -n 1`
531 #       OSC=`lctl dl | awk '/-osc-/ {print $4}' | head -n 1`
532         lctl --device %$OSC deactivate
533         lfs df -i || error "lfs df -i with deactivated OSC failed"
534         lctl --device %$OSC activate
535         lfs df || error "lfs df with reactivated OSC failed"
536 }
537 run_test 24a "lfs df [-ih] [path] test ========================="
538
539 test_24b() {
540         touch $DIR1/$tfile
541         fsnum=$(lfs_df | grep -c "summary")
542         [ $fsnum -eq 2 ] || error "lfs df shows $fsnum != 2 filesystems."
543 }
544 run_test 24b "lfs df should show both filesystems ==============="
545
546 test_25a() {
547         local acl=$(lctl get_param -n mdc.*MDT0000-mdc-*.connect_flags |
548                                                                 grep -c acl)
549         [ "$acl" -lt 1 ] && skip "must have acl, skipping" && return
550
551         mkdir -p $DIR1/$tdir
552         touch $DIR1/$tdir/f1 || error "touch $DIR1/$tdir/f1"
553         chmod 0755 $DIR1/$tdir/f1 || error "chmod 0755 $DIR1/$tdir/f1"
554
555         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #1"
556         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
557                 error "setfacl $DIR2/$tdir #1"
558         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #2"
559         setfacl -m u:$RUNAS_ID:r-x -m g:$RUNAS_GID:r-x $DIR1/$tdir ||
560                 error "setfacl $DIR2/$tdir #2"
561         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #3"
562         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
563                 error "setfacl $DIR2/$tdir #3"
564         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #4"
565         setfacl -x u:$RUNAS_ID: -x g:$RUNAS_GID: $DIR1/$tdir ||
566                 error "setfacl $DIR2/$tdir #4"
567         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #5"
568
569         rm -rf $DIR1/$tdir
570 }
571 run_test 25a "change ACL on one mountpoint be seen on another ==="
572
573 test_25b() {
574         local acl=$(lctl get_param -n mdc.*MDT0000-mdc-*.connect_flags |
575                                                         grep -c acl)
576         [ "$acl" -lt 1 ] && skip "must have acl, skipping" && return
577
578         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
579
580         rm -rf $DIR1/$tdir
581         $LFS mkdir -i 1 $DIR1/$tdir
582         touch $DIR1/$tdir/f1 || error "touch $DIR1/$tdir/f1"
583         chmod 0755 $DIR1/$tdir/f1 || error "chmod 0755 $DIR1/$tdir/f1"
584
585         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #1"
586         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
587                 error "setfacl $DIR2/$tdir #1"
588         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #2"
589         setfacl -m u:$RUNAS_ID:r-x -m g:$RUNAS_GID:r-x $DIR1/$tdir ||
590                 error "setfacl $DIR2/$tdir #2"
591         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #3"
592         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
593                 error "setfacl $DIR2/$tdir #3"
594         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #4"
595         setfacl -x u:$RUNAS_ID: -x g:$RUNAS_GID: $DIR1/$tdir ||
596                 error "setfacl $DIR2/$tdir #4"
597         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #5"
598
599         rm -rf $DIR1/$tdir
600 }
601 run_test 25b "change ACL under remote dir on one mountpoint be seen on another"
602
603 test_26a() {
604         utime $DIR1/f26a -s $DIR2/f26a || error
605 }
606 run_test 26a "allow mtime to get older"
607
608 test_26b() {
609         touch $DIR1/$tfile
610         sleep 1
611         echo "aaa" >> $DIR1/$tfile
612         sleep 1
613         chmod a+x $DIR2/$tfile
614         mt1=`stat -c %Y $DIR1/$tfile`
615         mt2=`stat -c %Y $DIR2/$tfile`
616
617         if [ x"$mt1" != x"$mt2" ]; then
618                 error "not equal mtime, client1: "$mt1", client2: "$mt2"."
619         fi
620 }
621 run_test 26b "sync mtime between ost and mds"
622
623 test_27() {
624         cancel_lru_locks osc
625         lctl clear
626         dd if=/dev/zero of=$DIR2/$tfile bs=$((4096+4))k conv=notrunc count=4 seek=3 &
627         DD2_PID=$!
628         usleep 50
629         log "dd 1 started"
630         
631         dd if=/dev/zero of=$DIR1/$tfile bs=$((16384-1024))k conv=notrunc count=1 seek=4 &
632         DD1_PID=$!
633         log "dd 2 started"
634         
635         sleep 1
636         dd if=/dev/zero of=$DIR1/$tfile bs=8k conv=notrunc count=1 seek=0
637         log "dd 3 finished"
638         lctl set_param -n ldlm.dump_namespaces ""
639         wait $DD1_PID $DD2_PID
640         [ $? -ne 0 ] && lctl dk $TMP/debug || true
641 }
642 run_test 27 "align non-overlapping extent locks from request ==="
643
644 test_28() { # bug 9977
645         ECHO_UUID="ECHO_osc1_UUID"
646         tOST=`$LCTL dl | | awk '/-osc-|OSC.*MNT/ { print $4 }' | head -1`
647
648         $LFS setstripe $DIR1/$tfile -S 1048576 -i 0 -c 2
649         tOBJID=`$LFS getstripe $DIR1/$tfile | awk '$1 == 1 {print $2}'`
650         dd if=/dev/zero of=$DIR1/$tfile bs=1024k count=2
651
652         $LCTL <<-EOF
653                 newdev
654                 attach echo_client ECHO_osc1 $ECHO_UUID
655                 setup $tOST
656         EOF
657
658         tECHOID=`$LCTL dl | grep $ECHO_UUID | awk '{ print $1 }'`
659         $LCTL --device $tECHOID destroy "${tOBJID}:0"
660
661         $LCTL <<-EOF
662                 cfg_device ECHO_osc1
663                 cleanup
664                 detach
665         EOF
666
667         # reading of 1st stripe should pass
668         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 || error
669         # reading of 2nd stripe should fail (this stripe was destroyed)
670         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 skip=1 && error
671
672         # now, recreating test file
673         dd if=/dev/zero of=$DIR1/$tfile bs=1024k count=2 || error
674         # reading of 1st stripe should pass
675         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 || error
676         # reading of 2nd stripe should pass
677         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 skip=1 || error
678 }
679 run_test 28 "read/write/truncate file with lost stripes"
680
681 test_29() { # bug 10999
682         touch $DIR1/$tfile
683         #define OBD_FAIL_LDLM_GLIMPSE  0x30f
684         lctl set_param fail_loc=0x8000030f
685         ls -l $DIR2/$tfile &
686         usleep 500
687         dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1
688         wait
689 }
690 #bug 11549 - permanently turn test off in b1_5
691 run_test 29 "lock put race between glimpse and enqueue ========="
692
693 test_30() { #bug #11110, LU-2523
694         test_mkdir -p $DIR1/$tdir
695         cp -f /bin/bash $DIR1/$tdir/bash
696         /bin/sh -c 'sleep 1; rm -f $DIR2/$tdir/bash;
697                     cp /bin/bash $DIR2/$tdir' &
698         $DIR1/$tdir/bash -c 'sleep 2;
699                 openfile -f O_RDONLY /proc/$$/exe >& /dev/null; echo $?'
700         wait
701         true
702 }
703
704 run_test 30 "recreate file race"
705
706 test_31a() {
707         test_mkdir -p $DIR1/$tdir || error "Creating dir $DIR1/$tdir"
708         local writes=$(LANG=C dd if=/dev/zero of=$DIR/$tdir/$tfile \
709                        count=1 2>&1 | awk 'BEGIN { FS="+" } /out/ {print $1}')
710         #define OBD_FAIL_LDLM_CANCEL_BL_CB_RACE   0x314
711         lctl set_param fail_loc=0x314
712         local reads=$(LANG=C dd if=$DIR2/$tdir/$tfile of=/dev/null 2>&1 |
713                       awk 'BEGIN { FS="+" } /in/ {print $1}')
714         [ $reads -eq $writes ] || error "read" $reads "blocks, must be" $writes
715 }
716 run_test 31a "voluntary cancel / blocking ast race=============="
717
718 test_31b() {
719         remote_ost || { skip "local OST" && return 0; }
720         remote_ost_nodsh && skip "remote OST w/o dsh" && return 0
721
722         # make sure there is no local locks due to destroy
723         wait_mds_ost_sync || error "wait_mds_ost_sync()"
724         wait_delete_completed || error "wait_delete_completed()"
725
726         test_mkdir -p $DIR1/$tdir || error "Creating dir $DIR1/$tdir"
727         lfs setstripe $DIR/$tdir/$tfile -i 0 -c 1
728         cp /etc/hosts $DIR/$tdir/$tfile
729         #define OBD_FAIL_LDLM_CANCEL_BL_CB_RACE   0x314
730         lctl set_param fail_loc=0x314
731         #define OBD_FAIL_LDLM_OST_FAIL_RACE      0x316
732         do_facet ost1 lctl set_param fail_loc=0x316
733         # Don't crash kernel
734         cat $DIR2/$tdir/$tfile > /dev/null 2>&1
735         lctl set_param fail_loc=0
736         do_facet ost1 lctl set_param fail_loc=0
737         # cleanup: reconnect the client back
738         df $DIR2
739 }
740 run_test 31b "voluntary OST cancel / blocking ast race=============="
741
742 # enable/disable lockless truncate feature, depending on the arg 0/1
743 enable_lockless_truncate() {
744         lctl set_param -n osc.*.lockless_truncate $1
745 }
746
747 test_32a() { # bug 11270
748         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
749         save_lustre_params client "osc.*.lockless_truncate" > $p
750         cancel_lru_locks osc
751         enable_lockless_truncate 1
752         rm -f $DIR1/$tfile
753         lfs setstripe -c -1 $DIR1/$tfile
754         dd if=/dev/zero of=$DIR1/$tfile count=$OSTCOUNT bs=$STRIPE_BYTES > \
755                 /dev/null 2>&1
756         clear_osc_stats
757
758         log "checking cached lockless truncate"
759         $TRUNCATE $DIR1/$tfile 8000000
760         $CHECKSTAT -s 8000000 $DIR2/$tfile || error "wrong file size"
761         [ $(calc_osc_stats lockless_truncate) -eq 0 ] ||
762                 error "lockless truncate doesn't use cached locks"
763
764         log "checking not cached lockless truncate"
765         $TRUNCATE $DIR2/$tfile 5000000
766         $CHECKSTAT -s 5000000 $DIR1/$tfile || error "wrong file size"
767         [ $(calc_osc_stats lockless_truncate) -ne 0 ] ||
768                 error "not cached trancate isn't lockless"
769
770         log "disabled lockless truncate"
771         enable_lockless_truncate 0
772         clear_osc_stats
773         $TRUNCATE $DIR2/$tfile 3000000
774         $CHECKSTAT -s 3000000 $DIR1/$tfile || error "wrong file size"
775         [ $(calc_osc_stats lockless_truncate) -eq 0 ] ||
776                 error "lockless truncate disabling failed"
777         rm $DIR1/$tfile
778         # restore lockless_truncate default values
779         restore_lustre_params < $p
780         rm -f $p
781 }
782 run_test 32a "lockless truncate"
783
784 test_32b() { # bug 11270
785         remote_ost_nodsh && skip "remote OST with nodsh" && return
786
787         local node
788         local facets=$(get_facets OST)
789         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
790
791         save_lustre_params client "osc.*.contention_seconds" > $p
792         save_lustre_params $facets \
793                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
794         save_lustre_params $facets \
795                 "ldlm.namespaces.filter-*.contended_locks" >> $p
796         save_lustre_params $facets \
797                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
798         clear_osc_stats
799
800         # agressive lockless i/o settings
801         for node in $(osts_nodes); do
802                 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'
803         done
804         lctl set_param -n osc.*.contention_seconds 60
805         for i in $(seq 5); do
806                 dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
807                 dd if=/dev/zero of=$DIR2/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
808         done
809         [ $(calc_osc_stats lockless_write_bytes) -ne 0 ] || error "lockless i/o was not triggered"
810         # disable lockless i/o (it is disabled by default)
811         for node in $(osts_nodes); do
812                 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'
813         done
814         # set contention_seconds to 0 at client too, otherwise Lustre still
815         # remembers lock contention
816         lctl set_param -n osc.*.contention_seconds 0
817         clear_osc_stats
818         for i in $(seq 1); do
819                 dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
820                 dd if=/dev/zero of=$DIR2/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
821         done
822         [ $(calc_osc_stats lockless_write_bytes) -eq 0 ] ||
823                 error "lockless i/o works when disabled"
824         rm -f $DIR1/$tfile
825         restore_lustre_params <$p
826         rm -f $p
827 }
828 run_test 32b "lockless i/o"
829
830 print_jbd_stat () {
831     local dev
832     local mdts=$(get_facets MDS)
833     local varcvs
834     local mds
835
836     local stat=0
837     for mds in ${mdts//,/ }; do
838         varsvc=${mds}_svc
839         dev=$(basename $(do_facet $mds "lctl get_param -n osd*.${!varsvc}.mntdev|\
840                 xargs readlink -f" ))
841         val=$(do_facet $mds "cat /proc/fs/jbd*/${dev}{,:*,-*}/info 2>/dev/null|\
842                 head -1")
843         val=${val%% *};
844         stat=$(( stat + val))
845     done
846     echo $stat
847 }
848
849 # commit on sharing tests
850 test_33a() {
851     remote_mds_nodsh && skip "remote MDS with nodsh" && return
852
853     [ -z "$CLIENTS" ] && skip "Need two or more clients, have $CLIENTS" && return 0
854     [ $CLIENTCOUNT -lt 2 ] &&
855         skip "Need two or more clients, have $CLIENTCOUNT" && return 0
856
857     local nfiles=${TEST33_NFILES:-10000}
858     local param_file=$TMP/$tfile-params
859     local fstype=$(facet_fstype $SINGLEMDS)
860
861         save_lustre_params $(get_facets MDS) \
862                 "mdt.*.commit_on_sharing" > $param_file
863
864     local COS
865     local jbdold="N/A"
866     local jbdnew="N/A"
867     local jbd
868
869     for COS in 0 1; do
870         do_facet $SINGLEMDS lctl set_param mdt.*.commit_on_sharing=$COS
871         avgjbd=0
872         avgtime=0
873         for i in 1 2 3; do
874             do_nodes $CLIENT1,$CLIENT2 "mkdir -p $DIR1/$tdir-\\\$(hostname)-$i"
875
876             [ $fstype = ldiskfs ] && jbdold=$(print_jbd_stat)
877             echo "=== START createmany old: $jbdold transaction"
878             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")
879             [ $fstype = ldiskfs ] && jbdnew=$(print_jbd_stat)
880             [ $fstype = ldiskfs ] && jbd=$(( jbdnew - jbdold ))
881             echo "=== END   createmany new: $jbdnew transaction :  $jbd transactions  nfiles $nfiles time $elapsed COS=$COS"
882             [ $fstype = ldiskfs ] && avgjbd=$(( avgjbd + jbd ))
883             avgtime=$(( avgtime + elapsed ))
884         done
885         eval cos${COS}_jbd=$((avgjbd / 3))
886         eval cos${COS}_time=$((avgtime / 3))
887     done
888
889     echo "COS=0 transactions (avg): $cos0_jbd  time (avg): $cos0_time"
890     echo "COS=1 transactions (avg): $cos1_jbd  time (avg): $cos1_time"
891     [ "$cos0_jbd" != 0 ] && echo "COS=1 vs COS=0 jbd:  $((((cos1_jbd/cos0_jbd - 1)) * 100 )) %"
892     [ "$cos0_time" != 0 ] && echo "COS=1 vs COS=0 time: $((((cos1_time/cos0_time - 1)) * 100 )) %"
893
894     restore_lustre_params < $param_file
895     rm -f $param_file
896     return 0
897 }
898 run_test 33a "commit on sharing, cross crete/delete, 2 clients, benchmark"
899
900 # commit on sharing tests
901 test_33b() {
902         remote_mds_nodsh && skip "remote MDS with nodsh" && return
903
904         [ -n "$CLIENTS" ] || { skip "Need two or more clients" && return 0; }
905         [ $CLIENTCOUNT -ge 2 ] ||
906                 { skip "Need two or more clients, have $CLIENTCOUNT" &&
907                                                                 return 0; }
908         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
909
910         local nfiles=${TEST33_NFILES:-10000}
911         local param_file=$TMP/$tfile-params
912
913         save_lustre_params $(get_facets MDS) \
914                 "mdt.*.commit_on_sharing" > $param_file
915
916         local COS
917         local jbdold
918         local jbdnew
919         local jbd
920         local MDTIDX=1
921
922         for COS in 0 1; do
923                 do_facet $SINGLEMDS lctl set_param mdt.*.commit_on_sharing=$COS
924                 avgjbd=0
925                 avgtime=0
926                 for i in 1 2 3; do
927                         do_node $CLIENT1 "$LFS mkdir -i $MDTIDX -p \
928                                           $DIR1/$tdir-\\\$(hostname)-$i"
929
930                         jbdold=$(print_jbd_stat)
931                         echo "=== START createmany old: $jbdold transaction"
932                         local elapsed=$(do_and_time "do_nodes $CLIENT1,$CLIENT2\
933                                 createmany -o $DIR1/$tdir-\\\$(hostname)-$i/f- \
934                                 -r $DIR2/$tdir-\\\$(hostname)-$i/f- $nfiles > \
935                                                                 /dev/null 2>&1")
936                         jbdnew=$(print_jbd_stat)
937                         jbd=$(( jbdnew - jbdold ))
938                         echo "=== END   createmany new: $jbdnew transaction : \
939                         $jbd transactions nfiles $nfiles time $elapsed COS=$COS"
940                         avgjbd=$(( avgjbd + jbd ))
941                         avgtime=$(( avgtime + elapsed ))
942                 done
943                 eval cos${COS}_jbd=$((avgjbd / 3))
944                 eval cos${COS}_time=$((avgtime / 3))
945         done
946
947         echo "COS=0 transactions (avg): $cos0_jbd  time (avg): $cos0_time"
948         echo "COS=1 transactions (avg): $cos1_jbd  time (avg): $cos1_time"
949         [ "$cos0_jbd" != 0 ] &&
950             echo "COS=1 vs COS=0 jbd: $(((cos1_jbd/cos0_jbd - 1) * 100)) %"
951         [ "$cos0_time" != 0 ] &&
952             echo "COS=1 vs COS=0 time: $(((cos1_time/cos0_time - 1) * 100)) %"
953
954         restore_lustre_params < $param_file
955         rm -f $param_file
956         return 0
957 }
958 run_test 33b "COS: cross create/delete, 2 clients, benchmark under remote dir"
959
960 # End commit on sharing tests
961
962 get_ost_lock_timeouts() {
963     local nodes=${1:-$(comma_list $(osts_nodes))}
964
965     local locks=$(do_nodes $nodes \
966         "lctl get_param -n ldlm.namespaces.filter-*.lock_timeouts" | calc_sum)
967
968     echo $locks
969 }
970
971 cleanup_34() {
972         local i
973         trap 0
974         do_nodes $(comma_list $(osts_nodes)) \
975                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
976         for i in $(seq $OSTCOUNT); do
977                 wait_osc_import_state client ost$i FULL
978         done
979 }
980
981 test_34() { #16129
982         local OPER
983         local lock_in
984         local lock_out
985         trap cleanup_34 EXIT RETURN
986         for OPER in notimeout timeout ; do
987                 rm $DIR1/$tfile 2>/dev/null
988                 lock_in=$(get_ost_lock_timeouts)
989                 if [ $OPER == "timeout" ] ; then
990                         for j in `seq $OSTCOUNT`; do
991                                 #define OBD_FAIL_PTLRPC_HPREQ_TIMEOUT    0x511
992                                 do_facet ost$j lctl set_param fail_loc=0x511
993                         done
994                         echo lock should expire
995                 else
996                         for j in `seq $OSTCOUNT`; do
997                                 #define OBD_FAIL_PTLRPC_HPREQ_NOTIMEOUT  0x512
998                                 do_facet ost$j lctl set_param fail_loc=0x512
999                         done
1000                         echo lock should not expire
1001                 fi
1002                 echo writing on client1
1003                 dd if=/dev/zero of=$DIR1/$tfile count=100 conv=notrunc > /dev/null 2>&1
1004                 sync &
1005                 echo reading on client2
1006                 dd of=/dev/null if=$DIR2/$tfile > /dev/null 2>&1
1007                 # wait for a lock timeout
1008                 sleep 4
1009                 lock_out=$(get_ost_lock_timeouts)
1010                 if [ $OPER == "timeout" ] ; then
1011                         if [ $lock_in == $lock_out ]; then
1012                                 error "no lock timeout happened"
1013                         else
1014                                 echo "success"
1015                         fi
1016                 else
1017                         if [ $lock_in != $lock_out ]; then
1018                                 error "lock timeout happened"
1019                         else
1020                                 echo "success"
1021                         fi
1022                 fi
1023         done
1024         cleanup_34
1025 }
1026 run_test 34 "no lock timeout under IO"
1027
1028 test_35() { # bug 17645
1029         local generation=[]
1030         local count=0
1031         for imp in /proc/fs/lustre/mdc/$FSNAME-MDT*-mdc-*; do
1032             g=$(awk '/generation/{print $2}' $imp/import)
1033             generation[count]=$g
1034             let count=count+1
1035         done
1036
1037         test_mkdir -p $MOUNT1/$tfile
1038         cancel_lru_locks mdc
1039
1040         # Let's initiate -EINTR situation by setting fail_loc and take
1041         # write lock on same file from same client. This will not cause
1042         # bl_ast yet as lock is already in local cache.
1043 #define OBD_FAIL_LDLM_INTR_CP_AST        0x317
1044         do_facet client "lctl set_param fail_loc=0x80000317"
1045         local timeout=`do_facet $SINGLEMDS lctl get_param  -n timeout`
1046         let timeout=timeout*3
1047         local nr=0
1048         while test $nr -lt 10; do
1049                 log "Race attempt $nr"
1050                 local blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
1051                 test "x$blk1" = "x" && blk1=0
1052                 createmany -o $MOUNT2/$tfile/a 4000 &
1053                 pid1=$!
1054                 sleep 1
1055
1056                 # Let's make conflict and bl_ast
1057                 ls -la $MOUNT1/$tfile > /dev/null &
1058                 pid2=$!
1059
1060                 log "Wait for $pid1 $pid2 for $timeout sec..."
1061                 sleep $timeout
1062                 kill -9 $pid1 $pid2 > /dev/null 2>&1
1063                 wait
1064                 local blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
1065                 test "x$blk2" = "x" && blk2=0
1066                 test $blk2 -gt $blk1 && break
1067                 rm -fr $MOUNT1/$tfile/*
1068                 cancel_lru_locks mdc
1069                 let nr=nr+1
1070         done
1071         do_facet client "lctl set_param fail_loc=0x0"
1072         df -h $MOUNT1 $MOUNT2
1073         count=0
1074         for imp in /proc/fs/lustre/mdc/$FSNAME-MDT*-mdc-*; do
1075             g=$(awk '/generation/{print $2}' $imp/import)
1076             if ! test "$g" -eq "${generation[count]}"; then
1077                 error "Eviction happened on import $(basename $imp)"
1078             fi
1079             let count=count+1
1080         done
1081 }
1082 run_test 35 "-EINTR cp_ast vs. bl_ast race does not evict client"
1083
1084 test_36() { #bug 16417
1085         local SIZE
1086         local SIZE_B
1087         local i
1088
1089         test_mkdir -p $DIR1/$tdir
1090         $LFS setstripe -c -1 $DIR1/$tdir
1091         i=0
1092         SIZE=50
1093         let SIZE_B=SIZE*1024*1024
1094         sync; sleep 5; sync # wait for delete thread
1095
1096         while [ $i -le 10 ]; do
1097                 lctl mark "start test"
1098                 local before=$(lfs_df $MOUNT1 | awk '/^filesystem/{ print $4; exit }')
1099                 dd if=/dev/zero of=$DIR1/$tdir/$tfile bs=1M count=$SIZE ||
1100                         error "dd $DIR1/$tdir/$tfile ${SIZE}MB failed"
1101                 sync          # sync data from client cache
1102                 sync_all_data # sync data from server cache (delayed allocation)
1103                 sleep 2
1104                 local after_dd=$(lfs_df $MOUNT1 | awk '/^filesystem/{ print $4; exit }')
1105                 multiop_bg_pause $DIR2/$tdir/$tfile O_r${SIZE_B}c || return 3
1106                 read_pid=$!
1107                 rm -f $DIR1/$tdir/$tfile
1108                 kill -USR1 $read_pid
1109                 wait $read_pid
1110                 wait_delete_completed
1111                 local after=$(lfs_df $MOUNT1 | awk '/^filesystem/{ print $4; exit }')
1112                 echo "*** cycle($i) *** before($before) after_dd($after_dd)" \
1113                         "after($after)"
1114                 # this free space! not used
1115                 (( $after_dd <= $after)) ||
1116                         error "space leaked after_dd:$after_dd > after:$after"
1117                 let i=i+1
1118         done
1119 }
1120 run_test 36 "handle ESTALE/open-unlink correctly"
1121
1122 test_37() { # bug 18695
1123         test_mkdir -p $DIR1/$tdir
1124         multiop_bg_pause $DIR1/$tdir D_c || return 1
1125         MULTIPID=$!
1126         # create large directory (32kB seems enough from e2fsck, ~= 1000 files)
1127         createmany -m $DIR2/$tdir/f 10000
1128         # set mtime/atime backward
1129         touch -t 198001010000 $DIR2/$tdir
1130         kill -USR1 $MULTIPID
1131         nr_files=`lfs find $DIR1/$tdir -type f | wc -l`
1132         [ $nr_files -eq 10000 ] || error "$nr_files != 10000 truncated directory?"
1133
1134 }
1135 run_test 37 "check i_size is not updated for directory on close (bug 18695) =============="
1136
1137 # this should be set to past
1138 TEST_39_MTIME=`date -d "1 year ago" +%s`
1139
1140 # bug 11063
1141 test_39a() {
1142         local client1=${CLIENT1:-`hostname`}
1143         local client2=${CLIENT2:-`hostname`}
1144
1145         do_node $client1 "touch $DIR1/$tfile"
1146
1147         do_node $client1 "touch -m -d @$TEST_39_MTIME $DIR1/$tfile"
1148         local mtime1=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1149         [ "$mtime1" = $TEST_39_MTIME ] || \
1150                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
1151
1152         local d1=`do_node $client1 date +%s`
1153         do_node $client1 'echo hello >> '$DIR1/$tfile
1154         local d2=`do_node $client1 date +%s`
1155
1156         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1157         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
1158                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
1159
1160         do_node $client1 "mv $DIR1/$tfile $DIR1/$tfile-1"
1161
1162         for (( i=0; i < 2; i++ )) ; do
1163                 local mtime3=`do_node $client2 "stat -c %Y $DIR1/$tfile-1"`
1164                 [ "$mtime2" = "$mtime3" ] || \
1165                         error "mtime ($mtime2) changed (to $mtime3) on rename"
1166
1167                 cancel_lru_locks osc
1168                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1169         done
1170 }
1171 run_test 39a "test from 11063 =================================="
1172
1173 test_39b() {
1174         local client1=${CLIENT1:-`hostname`}
1175         local client2=${CLIENT2:-`hostname`}
1176
1177         touch $DIR1/$tfile
1178
1179         local mtime1=`stat -c %Y $DIR1/$tfile`
1180         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1181
1182         sleep 1
1183         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
1184
1185         for (( i=0; i < 2; i++ )) ; do
1186                 local mtime3=`stat -c %Y $DIR1/$tfile`
1187                 local mtime4=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1188
1189                 [ "$mtime3" = "$mtime4" ] || \
1190                         error "different mtime on clients: $mtime3, $mtime4"
1191                 [ "$mtime3" = $TEST_39_MTIME ] || \
1192                         error "lost mtime: $mtime3, should be $TEST_39_MTIME"
1193
1194                 cancel_lru_locks osc
1195                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1196         done
1197 }
1198 run_test 39b "11063 problem 1 =================================="
1199
1200 test_39c() {
1201         local client1=${CLIENT1:-`hostname`}
1202         local client2=${CLIENT2:-`hostname`}
1203
1204         echo hello > $DIR1/$tfile
1205
1206         local mtime1=`stat -c %Y $DIR1/$tfile`
1207         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1208         [ "$mtime1" = "$mtime2" ] || \
1209                 error "create: different mtime on clients: $mtime1, $mtime2"
1210
1211         sleep 1
1212         $TRUNCATE $DIR1/$tfile 1
1213
1214         for (( i=0; i < 2; i++ )) ; do
1215                 local mtime3=`stat -c %Y $DIR1/$tfile`
1216                 local mtime4=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1217
1218                 [ "$mtime3" = "$mtime4" ] || \
1219                         error "different mtime on clients: $mtime3, $mtime4"
1220                 [ "$mtime3" -gt $mtime2 ] || \
1221                         error "truncate did not update mtime: $mtime2, $mtime3"
1222
1223                 cancel_lru_locks osc
1224                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1225         done
1226 }
1227 run_test 39c "check truncate mtime update ======================"
1228
1229 # check that pid exists hence second operation wasn't blocked by first one
1230 # if it is so then there is no conflict, return 0
1231 # else second operation is conflicting with first one, return 1
1232 check_pdo_conflict() {
1233         local pid=$1
1234         local conflict=0
1235         sleep 1 # to ensure OP1 is finished on client if OP2 is blocked by OP1
1236         if [[ `ps --pid $pid | wc -l` == 1 ]]; then
1237                 conflict=1
1238                 echo "Conflict"
1239         else
1240                 echo "No conflict"
1241         fi
1242         return $conflict
1243 }
1244
1245 # pdirop tests
1246 # test 40: check non-blocking operations
1247 test_40a() {
1248 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1249         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1250         mkdir $DIR1/$tfile &
1251         PID1=$!
1252         sleep 1
1253         touch $DIR2/$tfile-2
1254         check_pdo_conflict $PID1 || error "create is blocked"
1255         mkdir $DIR2/$tfile-3
1256         check_pdo_conflict $PID1 || error "mkdir is blocked"
1257         link $DIR2/$tfile-2 $DIR2/$tfile-4
1258         check_pdo_conflict $PID1 || error "link is blocked"
1259         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1260         check_pdo_conflict $PID1 || error "rename is blocked"
1261         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1262         check_pdo_conflict $PID1 || error "getattr is blocked"
1263         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1264         rmdir $DIR2/$tfile-3
1265         check_pdo_conflict $PID1 || error "unlink is blocked"
1266
1267         if [ $MDSCOUNT -ge 2 ]; then
1268                 $LFS mkdir -i 1 $DIR2/$tfile-6
1269                 check_pdo_conflict $PID1 || error "remote mkdir is blocked"
1270         fi
1271
1272         # all operations above shouldn't wait the first one
1273         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1274         wait $PID1
1275         rm -r $DIR1/*
1276         return 0
1277 }
1278 run_test 40a "pdirops: create vs others =============="
1279
1280 test_40b() {
1281 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1282         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1283         touch $DIR1/$tfile &
1284         PID1=$!
1285         sleep 1
1286         # open|create
1287         touch $DIR2/$tfile-2
1288         check_pdo_conflict $PID1 || error "create is blocked"
1289         mkdir $DIR2/$tfile-3
1290         check_pdo_conflict $PID1 || error "mkdir is blocked"
1291         link $DIR2/$tfile-2 $DIR2/$tfile-4
1292         check_pdo_conflict $PID1 || error "link is blocked"
1293         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1294         check_pdo_conflict $PID1 || error "rename is blocked"
1295         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1296         check_pdo_conflict $PID1 || error "getattr is blocked"
1297         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1298         rmdir $DIR2/$tfile-3
1299         check_pdo_conflict $PID1 || error "unlink is blocked"
1300         # all operations above shouldn't wait the first one
1301
1302         if [ $MDSCOUNT -ge 2 ]; then
1303                 $LFS mkdir -i 1 $DIR2/$tfile-6
1304                 check_pdo_conflict $PID1 || error "remote mkdir is blocked"
1305         fi
1306
1307         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1308         wait $PID1
1309         rm -r $DIR1/*
1310         return 0
1311 }
1312 run_test 40b "pdirops: open|create and others =============="
1313
1314 test_40c() {
1315         touch $DIR1/$tfile
1316 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1317         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1318         link $DIR1/$tfile $DIR1/$tfile-0 &
1319         PID1=$!
1320         sleep 1
1321         # open|create
1322         touch $DIR2/$tfile-2
1323         check_pdo_conflict $PID1 || error "create is blocked"
1324         mkdir $DIR2/$tfile-3
1325         check_pdo_conflict $PID1 || error "mkdir is blocked"
1326         link $DIR2/$tfile-2 $DIR2/$tfile-4
1327         check_pdo_conflict $PID1 || error "link is blocked"
1328         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1329         check_pdo_conflict $PID1 || error "rename is blocked"
1330         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1331         check_pdo_conflict $PID1 || error "getattr is blocked"
1332         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1333         rmdir $DIR2/$tfile-3
1334         check_pdo_conflict $PID1 || error "unlink is blocked"
1335
1336         if [ $MDSCOUNT -ge 2 ]; then
1337                 $LFS mkdir -i 1 $DIR2/$tfile-6
1338                 check_pdo_conflict $PID1 || error "remote mkdir is blocked"
1339         fi
1340
1341         # all operations above shouldn't wait the first one
1342         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1343         wait $PID1
1344         rm -r $DIR1/*
1345         return 0
1346 }
1347 run_test 40c "pdirops: link and others =============="
1348
1349 test_40d() {
1350         touch $DIR1/$tfile
1351 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1352         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1353         rm $DIR1/$tfile &
1354         PID1=$!
1355         sleep 1
1356         # open|create
1357         touch $DIR2/$tfile-2
1358         check_pdo_conflict $PID1 || error "create is blocked"
1359         mkdir $DIR2/$tfile-3
1360         check_pdo_conflict $PID1 || error "mkdir is blocked"
1361         link $DIR2/$tfile-2 $DIR2/$tfile-4
1362         check_pdo_conflict $PID1 || error "link is blocked"
1363         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1364         check_pdo_conflict $PID1 || error "rename is blocked"
1365         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1366         check_pdo_conflict $PID1 || error "getattr is blocked"
1367         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1368         rmdir $DIR2/$tfile-3
1369         check_pdo_conflict $PID1 || error "unlink is blocked"
1370
1371         if [ $MDSCOUNT -ge 2 ]; then
1372                 $LFS mkdir -i 1 $DIR2/$tfile-6
1373                 check_pdo_conflict $PID1 || error "remote mkdir is blocked"
1374         fi
1375
1376         # all operations above shouldn't wait the first one
1377         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1378         wait $PID1
1379         return 0
1380 }
1381 run_test 40d "pdirops: unlink and others =============="
1382
1383 test_40e() {
1384         touch $DIR1/$tfile
1385 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1386         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1387         mv $DIR1/$tfile $DIR1/$tfile-0 &
1388         PID1=$!
1389         sleep 1
1390         # open|create
1391         touch $DIR2/$tfile-2
1392         check_pdo_conflict $PID1 || error "create is blocked"
1393         mkdir $DIR2/$tfile-3
1394         check_pdo_conflict $PID1 || error "mkdir is blocked"
1395         link $DIR2/$tfile-2 $DIR2/$tfile-4
1396         check_pdo_conflict $PID1 || error "link is blocked"
1397         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1398         check_pdo_conflict $PID1 || error "getattr is blocked"
1399         rm $DIR2/$tfile-4 $DIR2/$tfile-2
1400         rmdir $DIR2/$tfile-3
1401         check_pdo_conflict $PID1 || error "unlink is blocked"
1402
1403         if [ $MDSCOUNT -ge 2 ]; then
1404                 $LFS mkdir -i 1 $DIR2/$tfile-6
1405                 check_pdo_conflict $PID1 || error "remote mkdir is blocked"
1406         fi
1407
1408        # all operations above shouldn't wait the first one
1409         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1410         wait $PID1
1411         rm -r $DIR1/*
1412         return 0
1413 }
1414 run_test 40e "pdirops: rename and others =============="
1415
1416 # test 41: create blocking operations
1417 test_41a() {
1418 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1419         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1420         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1421         PID1=$!
1422         sleep 1
1423         mkdir $DIR2/$tfile && error "mkdir must fail"
1424         check_pdo_conflict $PID1 && { wait $PID1; echo "mkdir isn't blocked"; }
1425         rm -r $DIR1/*
1426         return 0
1427 }
1428 run_test 41a "pdirops: create vs mkdir =============="
1429
1430 test_41b() {
1431 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1432         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1433         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1434         PID1=$!
1435         sleep 1
1436         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
1437         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1438         rm -r $DIR1/*
1439         return 0
1440 }
1441 run_test 41b "pdirops: create vs create =============="
1442
1443 test_41c() {
1444         touch $DIR1/$tfile-2
1445 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1446         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1447         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1448         PID1=$!
1449         sleep 1
1450         link $DIR2/$tfile-2 $DIR2/$tfile && error "link must fail"
1451         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1452         rm -r $DIR1/*
1453         return 0
1454 }
1455 run_test 41c "pdirops: create vs link =============="
1456
1457 test_41d() {
1458 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1459         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1460         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1461         PID1=$!
1462         sleep 1
1463         rm $DIR2/$tfile || error "unlink must succeed"
1464         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1465         rm -r $DIR1/*
1466         return 0
1467 }
1468 run_test 41d "pdirops: create vs unlink =============="
1469
1470 test_41e() {
1471         touch $DIR1/$tfile-2
1472 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1473         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1474         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1475         PID1=$!
1476         sleep 1
1477         mv $DIR2/$tfile-2 $DIR2/$tfile || error "rename must succeed"
1478         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1479         rm -r $DIR1/*
1480         return 0
1481 }
1482 run_test 41e "pdirops: create and rename (tgt) =============="
1483
1484 test_41f() {
1485 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1486         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1487         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1488         PID1=$!
1489         sleep 1
1490         mv $DIR2/$tfile $DIR2/$tfile-2 || error "rename must succeed"
1491         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1492         rm -r $DIR1/*
1493         return 0
1494 }
1495 run_test 41f "pdirops: create and rename (src) =============="
1496
1497 test_41g() {
1498 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1499         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1500         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1501         PID1=$!
1502         sleep 1
1503         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
1504         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1505         rm -r $DIR1/*
1506         return 0
1507 }
1508 run_test 41g "pdirops: create vs getattr =============="
1509
1510 test_41h() {
1511 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1512         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1513         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1514         PID1=$!
1515         sleep 1
1516         ls -lia $DIR2/ > /dev/null
1517         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1518         rm -r $DIR1/*
1519         return 0
1520 }
1521 run_test 41h "pdirops: create vs readdir =============="
1522
1523 # test 42: unlink and blocking operations
1524 test_42a() {
1525 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1526         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1527         mkdir $DIR1/$tfile &
1528         PID1=$!
1529         sleep 1
1530         mkdir $DIR2/$tfile && error "mkdir must fail"
1531         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1532         rm -r $DIR1/*
1533         return 0
1534 }
1535 run_test 42a "pdirops: mkdir vs mkdir =============="
1536
1537 test_42b() {
1538 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1539         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1540         mkdir $DIR1/$tfile &
1541         PID1=$!
1542         sleep 1
1543         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
1544         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1545         rm -r $DIR1/*
1546         return 0
1547 }
1548 run_test 42b "pdirops: mkdir vs create =============="
1549
1550 test_42c() {
1551         touch $DIR1/$tfile-2
1552 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1553         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1554         mkdir $DIR1/$tfile &
1555         PID1=$!
1556         sleep 1
1557         link $DIR2/$tfile-2 $DIR2/$tfile && error "link must fail"
1558         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1559         rm -r $DIR1/*
1560         return 0
1561 }
1562 run_test 42c "pdirops: mkdir vs link =============="
1563
1564 test_42d() {
1565 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1566         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1567         mkdir $DIR1/$tfile &
1568         PID1=$!
1569         sleep 1
1570         rmdir $DIR2/$tfile || error "unlink must succeed"
1571         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1572         rm -r $DIR1/*
1573         return 0
1574 }
1575 run_test 42d "pdirops: mkdir vs unlink =============="
1576
1577 test_42e() {
1578         touch $DIR1/$tfile-2
1579 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1580         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1581         mkdir $DIR1/$tfile &
1582         PID1=$!
1583         sleep 1
1584         mv -T $DIR2/$tfile-2 $DIR2/$tfile && error "rename must fail"
1585         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1586         rm -r $DIR1/*
1587         return 0
1588 }
1589 run_test 42e "pdirops: mkdir and rename (tgt) =============="
1590
1591 test_42f() {
1592 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1593         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1594         mkdir $DIR1/$tfile &
1595         PID1=$!
1596         sleep 1
1597         mv $DIR2/$tfile $DIR2/$tfile-2 || error "rename must succeed"
1598         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1599         rm -r $DIR1/*
1600         return 0
1601 }
1602 run_test 42f "pdirops: mkdir and rename (src) =============="
1603
1604 test_42g() {
1605 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1606         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1607         mkdir $DIR1/$tfile &
1608         PID1=$!
1609         sleep 1
1610         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
1611         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1612         rm -r $DIR1/*
1613         return 0
1614 }
1615 run_test 42g "pdirops: mkdir vs getattr =============="
1616
1617 test_42h() {
1618 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1619         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1620         mkdir $DIR1/$tfile &
1621         PID1=$!
1622         sleep 1
1623         ls -lia $DIR2/ > /dev/null
1624         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1625         rm -r $DIR1/*
1626         return 0
1627 }
1628 run_test 42h "pdirops: mkdir vs readdir =============="
1629
1630 # test 43: unlink and blocking operations
1631 test_43a() {
1632         touch $DIR1/$tfile
1633 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1634         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1635         rm $DIR1/$tfile &
1636         PID1=$!
1637         sleep 1
1638         mkdir $DIR2/$tfile || error "mkdir must succeed"
1639         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1640         rm -r $DIR1/*
1641         return 0
1642 }
1643 run_test 43a "pdirops: unlink vs mkdir =============="
1644
1645 test_43b() {
1646         touch $DIR1/$tfile
1647 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1648         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1649         rm $DIR1/$tfile &
1650         PID1=$!
1651         sleep 1
1652         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c || error "create must succeed"
1653         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1654         rm -r $DIR1/*
1655         return 0
1656 }
1657 run_test 43b "pdirops: unlink vs create =============="
1658
1659 test_43c() {
1660         touch $DIR1/$tfile
1661         touch $DIR1/$tfile-2
1662 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1663         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1664         rm $DIR1/$tfile &
1665         PID1=$!
1666         sleep 1
1667         link $DIR2/$tfile-2 $DIR2/$tfile || error "link must succeed"
1668         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1669         rm -r $DIR1/*
1670         return 0
1671 }
1672 run_test 43c "pdirops: unlink vs link =============="
1673
1674 test_43d() {
1675         touch $DIR1/$tfile
1676 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1677         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1678         rm $DIR1/$tfile &
1679         PID1=$!
1680         sleep 1
1681         rm $DIR2/$tfile && error "unlink must fail"
1682         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1683         rm -r $DIR1/*
1684         return 0
1685 }
1686 run_test 43d "pdirops: unlink vs unlink =============="
1687
1688 test_43e() {
1689         touch $DIR1/$tfile
1690         touch $DIR1/$tfile-2
1691 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1692         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1693         rm $DIR1/$tfile &
1694         PID1=$!
1695         sleep 1
1696         mv -u $DIR2/$tfile-2 $DIR2/$tfile || error "rename must succeed"
1697         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1698         rm -r $DIR1/*
1699         return 0
1700 }
1701 run_test 43e "pdirops: unlink and rename (tgt) =============="
1702
1703 test_43f() {
1704         touch $DIR1/$tfile
1705 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1706         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1707         rm $DIR1/$tfile &
1708         PID1=$!
1709         sleep 1
1710         mv $DIR2/$tfile $DIR2/$tfile-2 && error "rename must fail"
1711         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1712         rm -r $DIR1/*
1713         return 0
1714 }
1715 run_test 43f "pdirops: unlink and rename (src) =============="
1716
1717 test_43g() {
1718         touch $DIR1/$tfile
1719 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1720         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1721         rm $DIR1/$tfile &
1722         PID1=$!
1723         sleep 1
1724         stat $DIR2/$tfile > /dev/null && error "stat must fail"
1725         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1726         rm -r $DIR1/*
1727         return 0
1728 }
1729 run_test 43g "pdirops: unlink vs getattr =============="
1730
1731 test_43h() {
1732         touch $DIR1/$tfile
1733 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1734         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1735         rm $DIR1/$tfile &
1736         PID1=$!
1737         sleep 1
1738         ls -lia $DIR2/ > /dev/null
1739         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1740         rm -r $DIR1/*
1741         return 0
1742 }
1743 run_test 43h "pdirops: unlink vs readdir =============="
1744
1745 test_43i() {
1746         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1747         touch $DIR1/$tfile
1748 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1749         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1750         rm $DIR1/$tfile &
1751         PID1=$!
1752         sleep 1
1753         $LFS mkdir -i 1 $DIR2/$tfile || error "remote mkdir must succeed"
1754         check_pdo_conflict $PID1 &&
1755                 { wait $PID1; error "remote mkdir isn't blocked"; }
1756         rm -r $DIR1/*
1757         return 0
1758 }
1759 run_test 43i "pdirops: unlink vs remote mkdir"
1760
1761 # test 44: rename tgt and blocking operations
1762 test_44a() {
1763         touch $DIR1/$tfile-2
1764 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
1765         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1766         mv $DIR1/$tfile-2 $DIR1/$tfile &
1767         PID1=$!
1768         sleep 1
1769         mkdir $DIR2/$tfile && error "mkdir must fail"
1770         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1771         rm -r $DIR1/*
1772         return 0
1773 }
1774 run_test 44a "pdirops: rename tgt vs mkdir =============="
1775
1776 test_44b() {
1777         touch $DIR1/$tfile-2
1778 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1779         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1780         mv $DIR1/$tfile-2 $DIR1/$tfile &
1781         PID1=$!
1782         sleep 1
1783         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
1784         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1785         rm -r $DIR1/*
1786         return 0
1787 }
1788 run_test 44b "pdirops: rename tgt vs create =============="
1789
1790 test_44c() {
1791         touch $DIR1/$tfile-2
1792         touch $DIR1/$tfile-3
1793 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1794         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1795         mv $DIR1/$tfile-2 $DIR1/$tfile &
1796         PID1=$!
1797         sleep 1
1798         link $DIR2/$tfile-3 $DIR2/$tfile && error "link must fail"
1799         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1800         rm -r $DIR1/*
1801         return 0
1802 }
1803 run_test 44c "pdirops: rename tgt vs link =============="
1804
1805 test_44d() {
1806         touch $DIR1/$tfile-2
1807 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1808         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1809         mv $DIR1/$tfile-2 $DIR1/$tfile &
1810         PID1=$!
1811         sleep 1
1812         rm $DIR2/$tfile || error "unlink must succeed"
1813         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1814         rm -r $DIR1/*
1815         return 0
1816 }
1817 run_test 44d "pdirops: rename tgt vs unlink =============="
1818
1819 test_44e() {
1820         touch $DIR1/$tfile
1821         touch $DIR1/$tfile-2
1822         touch $DIR1/$tfile-3
1823 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1824         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1825         mv $DIR1/$tfile-2 $DIR1/$tfile &
1826         PID1=$!
1827         sleep 1
1828         mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
1829         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1830         rm -r $DIR1/*
1831         return 0
1832 }
1833 run_test 44e "pdirops: rename tgt and rename (tgt) =============="
1834
1835 test_44f() {
1836         touch $DIR1/$tfile-2
1837         touch $DIR1/$tfile-3
1838 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1839         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1840         mv $DIR1/$tfile-2 $DIR1/$tfile &
1841         PID1=$!
1842         sleep 1
1843         mv $DIR2/$tfile $DIR2/$tfile-3 || error "rename must succeed"
1844         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1845         rm -r $DIR1/*
1846         return 0
1847 }
1848 run_test 44f "pdirops: rename tgt and rename (src) =============="
1849
1850 test_44g() {
1851         touch $DIR1/$tfile-2
1852 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1853         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1854         mv $DIR1/$tfile-2 $DIR1/$tfile &
1855         PID1=$!
1856         sleep 1
1857         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
1858         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1859         rm -r $DIR1/*
1860         return 0
1861 }
1862 run_test 44g "pdirops: rename tgt vs getattr =============="
1863
1864 test_44h() {
1865         touch $DIR1/$tfile-2
1866 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1867         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1868         mv $DIR1/$tfile-2 $DIR1/$tfile &
1869         PID1=$!
1870         sleep 1
1871         ls -lia $DIR2/ > /dev/null
1872         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1873         rm -r $DIR1/*
1874         return 0
1875 }
1876 run_test 44h "pdirops: rename tgt vs readdir =============="
1877
1878 # test 44: rename tgt and blocking operations
1879 test_44i() {
1880         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1881         touch $DIR1/$tfile-2
1882 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
1883         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1884         mv $DIR1/$tfile-2 $DIR1/$tfile &
1885         PID1=$!
1886         sleep 1
1887         $LFS mkdir -i 1 $DIR2/$tfile && error "remote mkdir must fail"
1888         check_pdo_conflict $PID1 && { wait $PID1;
1889                                 error "remote mkdir isn't blocked"; }
1890         rm -r $DIR1/*
1891         return 0
1892 }
1893 run_test 44i "pdirops: rename tgt vs remote mkdir"
1894
1895 # test 45: rename src and blocking operations
1896 test_45a() {
1897         touch $DIR1/$tfile
1898 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1899         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1900         mv $DIR1/$tfile $DIR1/$tfile-2 &
1901         PID1=$!
1902         sleep 1
1903         mkdir $DIR2/$tfile || error "mkdir must succeed"
1904         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1905         rm -r $DIR1/*
1906         return 0
1907 }
1908 run_test 45a "pdirops: rename src vs mkdir =============="
1909
1910 test_45b() {
1911         touch $DIR1/$tfile
1912 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1913         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1914         mv $DIR1/$tfile $DIR1/$tfile-2 &
1915         PID1=$!
1916         sleep 1
1917         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c || error "create must succeed"
1918         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1919         rm -r $DIR1/*
1920         return 0
1921 }
1922 run_test 45b "pdirops: rename src vs create =============="
1923
1924 test_45c() {
1925         touch $DIR1/$tfile
1926         touch $DIR1/$tfile-3
1927 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1928         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1929         mv $DIR1/$tfile $DIR1/$tfile-2 &
1930         PID1=$!
1931         sleep 1
1932         link $DIR2/$tfile-3 $DIR2/$tfile || error "link must succeed"
1933         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1934         rm -r $DIR1/*
1935         return 0
1936 }
1937 run_test 45c "pdirops: rename src vs link =============="
1938
1939 test_45d() {
1940         touch $DIR1/$tfile
1941 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1942         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1943         mv $DIR1/$tfile $DIR1/$tfile-2 &
1944         PID1=$!
1945         sleep 1
1946         rm $DIR2/$tfile && error "unlink must fail"
1947         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1948         rm -r $DIR1/*
1949         return 0
1950 }
1951 run_test 45d "pdirops: rename src vs unlink =============="
1952
1953 test_45e() {
1954         touch $DIR1/$tfile
1955         touch $DIR1/$tfile-3
1956 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1957         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1958         mv $DIR1/$tfile $DIR1/$tfile-2 &
1959         PID1=$!
1960         sleep 1
1961         mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
1962         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1963         rm -r $DIR1/*
1964         return 0
1965 }
1966 run_test 45e "pdirops: rename src and rename (tgt) =============="
1967
1968 test_45f() {
1969         touch $DIR1/$tfile
1970 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1971         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1972         mv $DIR1/$tfile $DIR1/$tfile-2 &
1973         PID1=$!
1974         sleep 1
1975         mv $DIR2/$tfile $DIR2/$tfile-3 && error "rename must fail"
1976         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1977         rm -r $DIR1/*
1978         return 0
1979 }
1980 run_test 45f "pdirops: rename src and rename (src) =============="
1981
1982 test_45g() {
1983         touch $DIR1/$tfile
1984 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1985         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1986         mv $DIR1/$tfile $DIR1/$tfile-2 &
1987         PID1=$!
1988         sleep 1
1989         stat $DIR2/$tfile > /dev/null && error "stat must fail"
1990         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1991         rm -r $DIR1/*
1992         return 0
1993 }
1994 run_test 45g "pdirops: rename src vs getattr =============="
1995
1996 test_45h() {
1997         touch $DIR1/$tfile
1998 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1999         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2000         mv $DIR1/$tfile $DIR1/$tfile-2 &
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 -r $DIR1/*
2006         return 0
2007 }
2008 run_test 45h "pdirops: unlink vs readdir =============="
2009
2010 test_45i() {
2011         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2012         touch $DIR1/$tfile
2013 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2014         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2015         mv $DIR1/$tfile $DIR1/$tfile-2 &
2016         PID1=$!
2017         sleep 1
2018         $LFS mkdir -i 1 $DIR2/$tfile || error "create remote dir must succeed"
2019         check_pdo_conflict $PID1 && { wait $PID1;
2020                                 error "create remote dir isn't blocked"; }
2021         rm -r $DIR1/*
2022         return 0
2023 }
2024 run_test 45i "pdirops: rename src vs remote mkdir"
2025
2026 # test 46: link and blocking operations
2027 test_46a() {
2028         touch $DIR1/$tfile-2
2029 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2030         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2031         link $DIR1/$tfile-2 $DIR1/$tfile &
2032         PID1=$!
2033         sleep 1
2034         mkdir $DIR2/$tfile && error "mkdir must fail"
2035         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
2036         rm -r $DIR1/*
2037         return 0
2038 }
2039 run_test 46a "pdirops: link vs mkdir =============="
2040
2041 test_46b() {
2042         touch $DIR1/$tfile-2
2043 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2044         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2045         link $DIR1/$tfile-2 $DIR1/$tfile &
2046         PID1=$!
2047         sleep 1
2048         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
2049         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
2050         rm -r $DIR1/*
2051         return 0
2052 }
2053 run_test 46b "pdirops: link vs create =============="
2054
2055 test_46c() {
2056         touch $DIR1/$tfile-2
2057 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2058         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2059         link $DIR1/$tfile-2 $DIR1/$tfile &
2060         PID1=$!
2061         sleep 1
2062         link $DIR2/$tfile $DIR2/$tfile && error "link must fail"
2063         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2064         rm -r $DIR1/*
2065         return 0
2066 }
2067 run_test 46c "pdirops: link vs link =============="
2068
2069 test_46d() {
2070         touch $DIR1/$tfile-2
2071 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2072         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2073         link $DIR1/$tfile-2 $DIR1/$tfile &
2074         PID1=$!
2075         sleep 1
2076         rm $DIR2/$tfile || error "unlink must succeed"
2077         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
2078         rm -r $DIR1/*
2079         return 0
2080 }
2081 run_test 46d "pdirops: link vs unlink =============="
2082
2083 test_46e() {
2084         touch $DIR1/$tfile-2
2085         touch $DIR1/$tfile-3
2086 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2087         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2088         link $DIR1/$tfile-2 $DIR1/$tfile &
2089         PID1=$!
2090         sleep 1
2091         mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
2092         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2093         rm -r $DIR1/*
2094         return 0
2095 }
2096 run_test 46e "pdirops: link and rename (tgt) =============="
2097
2098 test_46f() {
2099         touch $DIR1/$tfile-2
2100         touch $DIR1/$tfile-3
2101 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2102         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2103         link $DIR1/$tfile-2 $DIR1/$tfile &
2104         PID1=$!
2105         sleep 1
2106         mv $DIR2/$tfile $DIR2/$tfile-3 || error "rename must succeed"
2107         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2108         rm -r $DIR1/*
2109         return 0
2110 }
2111 run_test 46f "pdirops: link and rename (src) =============="
2112
2113 test_46g() {
2114         touch $DIR1/$tfile-2
2115 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2116         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2117         link $DIR1/$tfile-2 $DIR1/$tfile &
2118         PID1=$!
2119         sleep 1
2120         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
2121         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
2122         rm -r $DIR1/*
2123         return 0
2124 }
2125 run_test 46g "pdirops: link vs getattr =============="
2126
2127 test_46h() {
2128         touch $DIR1/$tfile-2
2129 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2130         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2131         link $DIR1/$tfile-2 $DIR1/$tfile &
2132         PID1=$!
2133         sleep 1
2134         ls -lia $DIR2/ > /dev/null
2135         check_pdo_conflict $PID1 && { wait $PID1;
2136                         error "readdir isn't blocked"; }
2137         rm -r $DIR1/*
2138         return 0
2139 }
2140 run_test 46h "pdirops: link vs readdir =============="
2141
2142 test_46i() {
2143         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2144         touch $DIR1/$tfile-2
2145 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2146         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2147         link $DIR1/$tfile-2 $DIR1/$tfile &
2148         PID1=$!
2149         sleep 1
2150         $LFS mkdir -i 1 $DIR2/$tfile && error "remote mkdir must fail"
2151         check_pdo_conflict $PID1 && { wait $PID1;
2152                                 error "remote mkdir isn't blocked"; }
2153         rm -r $DIR1/*
2154         return 0
2155 }
2156 run_test 46i "pdirops: link vs remote mkdir"
2157
2158 # test 47: remote mkdir and blocking operations
2159 test_47a() {
2160 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2161         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2162         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2163         $LFS mkdir -i 1 $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 -r $DIR1/*
2169         return 0
2170 }
2171 run_test 47a "pdirops: remote mkdir vs mkdir"
2172
2173 test_47b() {
2174 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2175         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2176         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2177         $LFS mkdir -i 1 $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;
2182                                         error "create isn't blocked"; }
2183         rm -r $DIR1/*
2184         return 0
2185 }
2186 run_test 47b "pdirops: remote mkdir vs create"
2187
2188 test_47c() {
2189         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2190         touch $DIR1/$tfile-2
2191 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2192         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2193         $LFS mkdir -i 1 $DIR1/$tfile &
2194         PID1=$!
2195         sleep 1
2196         link $DIR2/$tfile-2 $DIR2/$tfile && error "link must fail"
2197         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2198         rm -r $DIR1/*
2199         return 0
2200 }
2201 run_test 47c "pdirops: remote mkdir vs link"
2202
2203 test_47d() {
2204         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2205 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2206         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2207         $LFS mkdir -i 1 $DIR1/$tfile &
2208         PID1=$!
2209         sleep 1
2210         rmdir $DIR2/$tfile || error "unlink must succeed"
2211         check_pdo_conflict $PID1 && { wait $PID1;
2212                                         error "unlink isn't blocked"; }
2213         rm -r $DIR1/*
2214         return 0
2215 }
2216 run_test 47d "pdirops: remote mkdir vs unlink"
2217
2218 test_47e() {
2219         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2220         touch $DIR1/$tfile-2
2221 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2222         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2223         $LFS mkdir -i 1 $DIR1/$tfile &
2224         PID1=$!
2225         sleep 1
2226         mv -T $DIR2/$tfile-2 $DIR2/$tfile && error "rename must fail"
2227         check_pdo_conflict $PID1 && { wait $PID1;
2228                                         error "rename isn't blocked"; }
2229         rm -r $DIR1/*
2230         return 0
2231 }
2232 run_test 47e "pdirops: remote mkdir and rename (tgt)"
2233
2234 test_47f() {
2235         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2236 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2237         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2238         $LFS mkdir -i 1 $DIR1/$tfile &
2239         PID1=$!
2240         sleep 1
2241         mv $DIR2/$tfile $DIR2/$tfile-2 || error "rename must succeed"
2242         check_pdo_conflict $PID1 && { wait $PID1;
2243                                         error "rename isn't blocked"; }
2244         rm -r $DIR1/*
2245         return 0
2246 }
2247 run_test 47f "pdirops: remote mkdir and rename (src)"
2248
2249 test_47g() {
2250         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2251 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2252         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2253         $LFS mkdir -i 1 $DIR1/$tfile &
2254         PID1=$!
2255         sleep 1
2256         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
2257         check_pdo_conflict $PID1 && { wait $PID1;
2258                                         error "getattr isn't blocked"; }
2259         rm -r $DIR1/*
2260         return 0
2261 }
2262 run_test 47g "pdirops: remote mkdir vs getattr"
2263
2264 test_50() {
2265         trunc_size=4096
2266         dd if=/dev/zero of=$DIR1/$tfile bs=1K count=10
2267 #define OBD_FAIL_OSC_CP_ENQ_RACE         0x410
2268         do_facet client "lctl set_param fail_loc=0x410"
2269         $TRUNCATE $DIR2/$tfile $trunc_size
2270         do_facet client "lctl set_param fail_loc=0x0"
2271         sleep 3
2272         size=`stat -c %s $DIR2/$tfile`
2273         [ $size -eq $trunc_size ] || error "wrong size"
2274 }
2275 run_test 50 "osc lvb attrs: enqueue vs. CP AST =============="
2276
2277 test_51a() {
2278         local filesize
2279         local origfile=/etc/hosts
2280
2281         filesize=`stat -c %s $origfile`
2282
2283         # create an empty file
2284         $MCREATE $DIR1/$tfile
2285         # cache layout lock on both mount point
2286         stat $DIR1/$tfile > /dev/null
2287         stat $DIR2/$tfile > /dev/null
2288
2289         # open and sleep 2 seconds then read
2290         $MULTIOP $DIR2/$tfile o_2r${filesize}c &
2291         local pid=$!
2292         sleep 1
2293
2294         # create the layout of testing file
2295         dd if=$origfile of=$DIR1/$tfile conv=notrunc > /dev/null
2296
2297         # MULTIOP proc should be able to read enough bytes and exit
2298         sleep 2
2299         kill -0 $pid && error "multiop is still there"
2300         cmp $origfile $DIR2/$tfile || error "$MCREATE and $DIR2/$tfile differs"
2301
2302         rm -f $DIR1/$tfile
2303 }
2304 run_test 51a "layout lock: refresh layout should work"
2305
2306 test_51b() {
2307         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.59) ]] ||
2308                 { skip "Need MDS version at least 2.3.59"; return 0; }
2309
2310         local tmpfile=`mktemp`
2311
2312         # create an empty file
2313         $MCREATE $DIR1/$tfile
2314
2315         # delay glimpse so that layout has changed when glimpse finish
2316 #define OBD_FAIL_GLIMPSE_DELAY 0x1404
2317         $LCTL set_param fail_loc=0x1404
2318         stat -c %s $DIR2/$tfile |tee $tmpfile &
2319         local pid=$!
2320         sleep 1
2321
2322         # create layout of testing file
2323         dd if=/dev/zero of=$DIR1/$tfile bs=1k count=1 conv=notrunc > /dev/null
2324
2325         wait $pid
2326         local fsize=`cat $tmpfile`
2327
2328         [ x$fsize = x1024 ] || error "file size is $fsize, should be 1024"
2329
2330         rm -f $DIR1/$tfile $tmpfile
2331 }
2332 run_test 51b "layout lock: glimpse should be able to restart if layout changed"
2333
2334 test_51c() {
2335         # create an empty file
2336         $MCREATE $DIR1/$tfile
2337
2338 #define OBD_FAIL_MDS_LL_BLOCK 0x172
2339         $LCTL set_param fail_loc=0x172
2340
2341         # change the layout of testing file
2342         echo "Setting layout ..."
2343         $LFS setstripe -c $OSTCOUNT $DIR1/$tfile &
2344         pid=$!
2345         sleep 1
2346
2347         # get layout of this file should wait until dd is finished
2348         local stripecnt=`$LFS getstripe -c $DIR2/$tfile`
2349         [ $stripecnt -eq $OSTCOUNT ] || error "layout wrong"
2350
2351         rm -f $DIR1/$tfile
2352 }
2353 run_test 51c "layout lock: IT_LAYOUT blocked and correct layout can be returned"
2354
2355 test_60() {
2356         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
2357         { skip "Need MDS version at least 2.3.0"; return; }
2358         # Create a file
2359         test_mkdir -p $DIR1/$tdir
2360         file1=$DIR1/$tdir/file
2361         file2=$DIR2/$tdir/file
2362
2363         echo orig > $file2 || error "Could not create $file2"
2364         version=$($LFS data_version $file1)
2365
2366         # Append data
2367         echo append >> $file2 || error "Could not append to $file2"
2368         version2=$($LFS data_version $file1)
2369         [ "$version" != "$version2" ] ||
2370             error "append did not change data version: $version"
2371
2372         # Overwrite data
2373         echo overwrite > $file2 || error "Could not overwrite $file2"
2374         version3=$($LFS data_version $file1)
2375         [ "$version2" != "$version3" ] ||
2376             error "overwrite did not change data version: $version2"
2377
2378         # Truncate before EOF
2379         $TRUNCATE $file2 3 || error "Could not truncate $file2"
2380         version4=$($LFS data_version $file1)
2381         [ "$version3" != "$version4" ] ||
2382             error "truncate did not change data version: $version3"
2383
2384         # Truncate after EOF
2385         $TRUNCATE $file2 123456 || error "Could not truncate $file2"
2386         version5=$($LFS data_version $file1)
2387         [ "$version4" != "$version5" ] ||
2388             error "truncate did not change data version: $version4"
2389
2390         # Chmod do not change version
2391         chmod 400 $file2 || error "Could not chmod 400 $file2"
2392         version6=$($LFS data_version $file1)
2393         [ "$version5" == "$version6" ] ||
2394             error "chmod should not change data version: $version5 != $version6"
2395
2396         # Chown do not change version
2397         chown $RUNAS_ID $file2 || error "Could not chown $RUNAS_ID $file2"
2398         version7=$($LFS data_version $file1)
2399         [ "$version5" == "$version7" ] ||
2400             error "chown should not change data version: $version5 != $version7"
2401 }
2402 run_test 60 "Verify data_version behaviour"
2403
2404 test_70a() {
2405         local test_dir=$tdir/test_dir
2406
2407         mkdir -p $DIR1/$tdir
2408         if [ $MDSCOUNT -ge 2 ]; then
2409                 local MDTIDX=1
2410                 $LFS mkdir -i $MDTIDX $DIR1/$test_dir ||
2411                         error "Create remote directory failed"
2412         else
2413                 mkdir -p $DIR1/$test_dir
2414         fi
2415         cd $DIR2/$test_dir || error "cd directory failed"
2416         rm -rf $DIR1/$test_dir || error "unlink directory failed"
2417
2418         cd $DIR2/$tdir || error "exit directory"
2419 }
2420 run_test 70a "cd directory && rm directory"
2421
2422 test_70b() { # LU-2781
2423         local i
2424         mkdir -p $DIR1/$tdir
2425
2426         touch $DIR1/$tdir/file
2427         for ((i = 0; i < 32; i++)); do
2428             $LFS rm_entry $DIR1/$tdir/non_existent_dir &>/dev/null
2429         done
2430         rm $DIR1/$tdir/file || error "cannot remove file after rm_entry"
2431
2432         touch $DIR1/$tdir/file
2433         $LFS mkdir -i0 $DIR1/$tdir/test_dir
2434         $LFS rm_entry $DIR1/$tdir/test_dir &>/dev/null
2435         rm -rf $DIR1/$tdir/test_dir ||
2436                 error "cannot remove directory after rm_entry"
2437         rm $DIR1/$tdir/file || error "cannot remove file after rm_entry"
2438 }
2439 run_test 70b "remove files after calling rm_entry"
2440
2441 test_71() {
2442         local server_version=$(lustre_version_code $SINGLEMDS)
2443
2444         [[ $server_version -lt $(version_code 2.1.6) ]] &&
2445                 skip "Need MDS version at least 2.1.6" && return
2446
2447         # Patch not applied to 2.2 and 2.3 branches
2448         [[ $server_version -ge $(version_code 2.2.0) ]] &&
2449         [[ $server_version -lt $(version_code 2.4.0) ]] &&
2450                 skip "Need MDS version at least 2.4.0" && return
2451
2452         checkfiemap --test ||
2453                 { skip "checkfiemap not runnable: $?" && return; }
2454         # write data this way: hole - data - hole - data
2455         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=1 count=1
2456         [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR1/$tfile) + 1)))" = \
2457                 "zfs" ] &&
2458                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return 0
2459         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=3 count=1
2460         GET_STAT="lctl get_param -n ldlm.services.ldlm_cbd.stats"
2461         stat $DIR2/$tfile
2462         local can1=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
2463         echo $can1
2464         checkfiemap $DIR2/$tfile 81920 ||
2465                 error "data is not flushed from client"
2466         local can2=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
2467         echo $can2
2468
2469         # common case of "create file, copy file" on a single node
2470         # should not flush data from ost
2471         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=1 count=1
2472         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=3 count=1
2473         stat $DIR1/$tfile
2474         local can3=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
2475         echo $can3
2476         checkfiemap $DIR1/$tfile 81920 ||
2477         error 4
2478         local can4=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
2479         echo $can2
2480         [ $can3 -eq $can4 ] || error $((can2-can1)) "cancel RPC occured."
2481 }
2482 run_test 71 "correct file map just after write operation is finished"
2483
2484 test_72() {
2485         local p="$TMP/sanityN-$TESTNAME.parameters"
2486         local tlink1
2487         local tlink2
2488         save_lustre_params client "llite.*.xattr_cache" > $p
2489         lctl set_param llite.*.xattr_cache 1 ||
2490                 { skip "xattr cache is not supported"; return 0; }
2491
2492         touch $DIR1/$tfile
2493         setfattr -n user.attr1 -v value1 $DIR1/$tfile ||
2494                 error "setfattr1 failed"
2495         getfattr -n user.attr1 $DIR2/$tfile | grep value1 ||
2496                 error "getfattr1 failed"
2497         setfattr -n user.attr1 -v value2 $DIR2/$tfile ||
2498                 error "setfattr2 failed"
2499         getfattr -n user.attr1 $DIR1/$tfile | grep value2 ||
2500                 error "getfattr2 failed"
2501
2502         # check that trusted.link is consistent
2503         tlink1=$(getfattr -n trusted.link $DIR1/$tfile | md5sum)
2504         ln $DIR2/$tfile $DIR2/$tfile-2 || error "failed to link"
2505         tlink2=$(getfattr -n trusted.link $DIR1/$tfile | md5sum)
2506         echo "$tlink1 $tlink2"
2507         [ "$tlink1" = "$tlink2" ] && error "trusted.link should have changed!"
2508
2509         rm -f $DIR2/$tfile
2510
2511         restore_lustre_params < $p
2512         rm -f $p
2513 }
2514 run_test 72 "getxattr/setxattr cache should be consistent between nodes"
2515
2516 test_73() {
2517         local p="$TMP/sanityN-$TESTNAME.parameters"
2518         save_lustre_params client "llite.*.xattr_cache" > $p
2519         lctl set_param llite.*.xattr_cache 1 ||
2520                 { skip "xattr cache is not supported"; return 0; }
2521
2522         touch $DIR1/$tfile
2523         setfattr -n user.attr1 -v value1 $DIR1/$tfile ||
2524                 error "setfattr1 failed"
2525         getfattr -n user.attr1 $DIR2/$tfile || error "getfattr1 failed"
2526         getfattr -n user.attr1 $DIR1/$tfile || error "getfattr2 failed"
2527         clear_llite_stats
2528         # PR lock should be cached by now on both clients
2529         getfattr -n user.attr1 $DIR1/$tfile || error "getfattr3 failed"
2530         # 2 hits for getfattr(0)+getfattr(size)
2531         [ $(calc_llite_stats getxattr_hits) -eq 2 ] || error "not cached in $DIR1"
2532         getfattr -n user.attr1 $DIR2/$tfile || error "getfattr4 failed"
2533         # 4 hits for more getfattr(0)+getfattr(size)
2534         [ $(calc_llite_stats getxattr_hits) -eq 4 ] || error "not cached in $DIR2"
2535         rm -f $DIR2/$tfile
2536
2537         restore_lustre_params < $p
2538         rm -f $p
2539 }
2540 run_test 73 "getxattr should not cause xattr lock cancellation"
2541
2542 test_74() {
2543         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.93) ] &&
2544                 skip "Need MDS version at least 2.4.93" && return
2545
2546         dd if=/dev/zero of=$DIR1/$tfile-1 bs=1K count=1
2547         dd if=/dev/zero of=$DIR1/$tfile-2 bs=1K count=1
2548         flocks_test 4 $DIR1/$tfile-1 $DIR2/$tfile-2
2549 }
2550 run_test 74 "flock deadlock: different mounts =============="
2551
2552 # LU-3889
2553 test_75() {
2554         $LFS setstripe -c 2 -S 1m -i 0 $DIR1/$tfile
2555         dd if=/dev/zero of=$DIR1/$tfile bs=1M count=2
2556         cancel_lru_locks osc
2557
2558         dd of=$DIR1/$tfile if=/dev/zero bs=1M count=1 seek=1 conv=notrunc
2559         sync
2560
2561         # define OBD_FAIL_LDLM_ENQUEUE_HANG 0x31d
2562         $LCTL set_param fail_loc=0x31d
2563         stat -c %s $DIR1/$tfile &
2564         local pid=$!
2565         sleep 1
2566         kill -9 $pid
2567
2568         # For bad lock error handler we should ASSERT and got kernel panic here
2569         sleep 4
2570         $LCTL set_param fail_loc=0
2571 }
2572 run_test 75 "osc: upcall after unuse lock==================="
2573
2574 test_76() { #LU-946
2575         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
2576                 skip "Need MDS version at least 2.5.53" && return
2577
2578         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2579         local fcount=2048
2580         local fd
2581         local cmd
2582         local mdt_idx
2583         local mds_idx
2584         declare -a fd_list
2585         declare -a fid_list
2586
2587         if remote_mds; then
2588                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
2589         else
2590                 nid="0@lo"
2591         fi
2592
2593         rm -rf $DIR/$tdir
2594         test_mkdir -p $DIR/$tdir
2595         if [ $MDSCOUNT -gt 1 ]; then
2596                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
2597         else
2598                 mdt_idx=0
2599         fi
2600         mds_idx=$((mdt_idx + 1))
2601         proc_ofile="mdt.*$mdt_idx.exports.'$nid'.open_files"
2602
2603         cancel_lru_locks mdc
2604
2605         echo -n "open files "
2606         ulimit -n 8096
2607         for (( i = 0; i < $fcount; i++ )) ; do
2608                 touch $DIR/$tdir/f_$i
2609                 fd=$(free_fd)
2610                 cmd="exec $fd<$DIR/$tdir/f_$i"
2611                 eval $cmd
2612                 fd_list[i]=$fd
2613                 echo -n "."
2614         done
2615         echo
2616
2617         fid_list=($(do_facet mds$mds_idx $LCTL get_param -n $proc_ofile))
2618
2619         # Possible errors in openfiles FID list.
2620         # 1. Missing FIDs. Check 1
2621         # 2. Extra FIDs. Check 1
2622         # 3. Duplicated FID. Check 2
2623         # 4. Invalid FIDs. Check 2
2624         # 5. Valid FID, points to some other file. Check 3
2625
2626         # Check 1
2627         [ ${#fid_list[@]} -ne $fcount ] &&
2628                 error "${#fid_list[@]} != $fcount open files"
2629
2630         for (( i = 0; i < $fcount; i++ )) ; do
2631                 cmd="exec ${fd_list[i]}</dev/null"
2632                 eval $cmd
2633                 filename=$($LFS fid2path $DIR2 ${fid_list[i]})
2634
2635                 # Check 2
2636                 rm --interactive=no $filename
2637                 [ $? -ne 0 ] &&
2638                         error "Nonexisting fid ${fid_list[i]} listed."
2639         done
2640
2641         # Check 3
2642         ls_op=$(ls $DIR2/$tdir | wc -l)
2643         [ $ls_op -ne 0 ] &&
2644                 error "Some openfiles are missing in lproc output"
2645
2646         rm -rf $DIR/$tdir
2647 }
2648 run_test 76 "Verify open file for 2048 files"
2649
2650 log "cleanup: ======================================================"
2651
2652 [ "$(mount | grep $MOUNT2)" ] && umount $MOUNT2
2653
2654 complete $SECONDS
2655 check_and_cleanup_lustre
2656 exit_status