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