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