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