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