Whamcloud - gitweb
LU-1303 tests: Support for MDS-initiated OST_DESTROYs
[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 test_16() {
332         rm -f $MOUNT1/fsxfile
333         lfs setstripe $MOUNT1/fsxfile -c -1 # b=10919
334         fsx -c 50 -p 100 -N 2500 -l $((SIZE * 256)) -S 0 $FSXOPT \
335                 $MOUNT1/fsxfile $MOUNT2/fsxfile
336 }
337 run_test 16 "2500 iterations of dual-mount fsx ================="
338
339 test_17() { # bug 3513, 3667
340         remote_ost_nodsh && skip "remote OST with nodsh" && return
341
342         lfs setstripe $DIR1/$tfile -i 0 -c 1
343         cp $SAMPLE_FILE $DIR1/$tfile
344         cancel_lru_locks osc > /dev/null
345         #define OBD_FAIL_ONCE|OBD_FAIL_LDLM_CREATE_RESOURCE    0x30a
346         do_facet ost1 lctl set_param fail_loc=0x8000030a
347         ls -ls $DIR1/$tfile | awk '{ print $1,$6 }' > $DIR1/$tfile-1 & \
348         ls -ls $DIR2/$tfile | awk '{ print $1,$6 }' > $DIR2/$tfile-2
349         wait
350         diff -u $DIR1/$tfile-1 $DIR2/$tfile-2 || error "files are different"
351 }
352 run_test 17 "resource creation/LVB creation race ==============="
353
354 test_18() {
355         # turn e.g. ALWAYS_EXCEPT="18c" into "-e 3"
356         local idx
357         local excepts=
358         for idx in {a..z}; do
359                 local ptr=EXCEPT_ALWAYS_18$idx
360                 [ x${!ptr} = xtrue ] || continue
361
362                 excepts="$excepts -e $(($(printf %d \'$idx)-96))"
363         done
364
365         $LUSTRE/tests/mmap_sanity -d $MOUNT1 -m $MOUNT2 $excepts
366         sync; sleep 1; sync
367 }
368 run_test 18 "mmap sanity check ================================="
369
370 test_19() { # bug3811
371         [ -d /proc/fs/lustre/obdfilter ] || return 0
372
373         MAX=`lctl get_param -n obdfilter.*.readcache_max_filesize | head -n 1`
374         lctl set_param -n obdfilter.*OST*.readcache_max_filesize=4096
375         dd if=/dev/urandom of=$TMP/f19b bs=512k count=32
376         SUM=`cksum $TMP/f19b | cut -d" " -f 1,2`
377         cp $TMP/f19b $DIR1/f19b
378         for i in `seq 1 20`; do
379                 [ $((i % 5)) -eq 0 ] && log "test_18 loop $i"
380                 cancel_lru_locks osc > /dev/null
381                 cksum $DIR1/f19b | cut -d" " -f 1,2 > $TMP/sum1 & \
382                 cksum $DIR2/f19b | cut -d" " -f 1,2 > $TMP/sum2
383                 wait
384                 [ "`cat $TMP/sum1`" = "$SUM" ] || \
385                         error "$DIR1/f19b `cat $TMP/sum1` != $SUM"
386                 [ "`cat $TMP/sum2`" = "$SUM" ] || \
387                         error "$DIR2/f19b `cat $TMP/sum2` != $SUM"
388         done
389         lctl set_param -n obdfilter.*OST*.readcache_max_filesize=$MAX
390         rm $DIR1/f19b
391 }
392 run_test 19 "test concurrent uncached read races ==============="
393
394 test_20() {
395         mkdir $DIR1/d20
396         cancel_lru_locks osc
397         CNT=$((`lctl get_param -n llite.*.dump_page_cache | wc -l`))
398         $MULTIOP $DIR1/f20 Ow8190c
399         $MULTIOP $DIR2/f20 Oz8194w8190c
400         $MULTIOP $DIR1/f20 Oz0r8190c
401         cancel_lru_locks osc
402         CNTD=$((`lctl get_param -n llite.*.dump_page_cache | wc -l` - $CNT))
403         [ $CNTD -gt 0 ] && \
404             error $CNTD" page left in cache after lock cancel" || true
405 }
406 run_test 20 "test extra readahead page left in cache ===="
407
408 cleanup_21() {
409         trap 0
410         umount $DIR1/d21
411 }
412
413 test_21() { # Bug 5907
414         mkdir $DIR1/d21
415         mount /etc $DIR1/d21 --bind || error "mount failed" # Poor man's mount.
416         trap cleanup_21 EXIT
417         rmdir -v $DIR1/d21 && error "Removed mounted directory"
418         rmdir -v $DIR2/d21 && echo "Removed mounted directory from another mountpoint, needs to be fixed"
419         test -d $DIR1/d21 || error "Mounted directory disappeared"
420         cleanup_21
421         test -d $DIR2/d21 || test -d $DIR1/d21 && error "Removed dir still visible after umount"
422         true
423 }
424 run_test 21 " Try to remove mountpoint on another dir ===="
425
426 test_23() { # Bug 5972
427         echo "others should see updated atime while another read" > $DIR1/f23
428         
429         # clear the lock(mode: LCK_PW) gotten from creating operation
430         cancel_lru_locks osc
431         
432         time1=`date +%s`        
433         #MAX_ATIME_DIFF 60, we update atime only if older than 60 seconds
434         sleep 61
435         
436         multiop_bg_pause $DIR1/f23 or20_c || return 1
437         # with SOM and opencache enabled, we need to close a file and cancel
438         # open lock to get atime propogated to MDS
439         kill -USR1 $!
440         cancel_lru_locks mdc
441
442         time2=`stat -c "%X" $DIR2/f23`
443
444         if (( $time2 <= $time1 )); then
445                 error "atime doesn't update among nodes"
446         fi
447
448         rm -f $DIR1/f23 || error "rm -f $DIR1/f23 failed"
449         true
450 }
451 run_test 23 " others should see updated atime while another read===="
452
453 test_24a() {
454         touch $DIR1/$tfile
455         lfs df || error "lfs df failed"
456         lfs df -ih || error "lfs df -ih failed"
457         lfs df -h $DIR1 || error "lfs df -h $DIR1 failed"
458         lfs df -i $DIR2 || error "lfs df -i $DIR2 failed"
459         lfs df $DIR1/$tfile || error "lfs df $DIR1/$tfile failed"
460         lfs df -ih $DIR2/$tfile || error "lfs df -ih $DIR2/$tfile failed"
461         
462         OSC=`lctl dl | awk '/-osc-|OSC.*MNT/ {print $4}' | head -n 1`
463 #       OSC=`lctl dl | awk '/-osc-/ {print $4}' | head -n 1`
464         lctl --device %$OSC deactivate
465         lfs df -i || error "lfs df -i with deactivated OSC failed"
466         lctl --device %$OSC activate
467         lfs df || error "lfs df with reactivated OSC failed"
468 }
469 run_test 24a "lfs df [-ih] [path] test ========================="
470
471 test_24b() {
472         touch $DIR1/$tfile
473         fsnum=`lfs df | grep -c "filesystem summary:"`
474         [ $fsnum -eq 2 ] || error "lfs df shows $fsnum != 2 filesystems."
475 }
476 run_test 24b "lfs df should show both filesystems ==============="
477
478 test_25() {
479         [ `lctl get_param -n mdc.*-mdc-*.connect_flags | grep -c acl` -lt 2 ] &&
480                 skip "must have acl, skipping" && return
481
482         mkdir -p $DIR1/$tdir
483         touch $DIR1/$tdir/f1 || error "touch $DIR1/$tdir/f1"
484         chmod 0755 $DIR1/$tdir/f1 || error "chmod 0755 $DIR1/$tdir/f1"
485
486         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #1"
487         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
488                 error "setfacl $DIR2/$tdir #1"
489         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #2"
490         setfacl -m u:$RUNAS_ID:r-x -m g:$RUNAS_GID:r-x $DIR1/$tdir ||
491                 error "setfacl $DIR2/$tdir #2"
492         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #3"
493         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
494                 error "setfacl $DIR2/$tdir #3"
495         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #4"
496         setfacl -x u:$RUNAS_ID: -x g:$RUNAS_GID: $DIR1/$tdir ||
497                 error "setfacl $DIR2/$tdir #4"
498         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #5"
499
500         rm -rf $DIR1/$tdir
501 }
502 run_test 25 "change ACL on one mountpoint be seen on another ==="
503
504 test_26a() {
505         utime $DIR1/f26a -s $DIR2/f26a || error
506 }
507 run_test 26a "allow mtime to get older"
508
509 test_26b() {
510         touch $DIR1/$tfile
511         sleep 1
512         echo "aaa" >> $DIR1/$tfile
513         sleep 1
514         chmod a+x $DIR2/$tfile
515         mt1=`stat -c %Y $DIR1/$tfile`
516         mt2=`stat -c %Y $DIR2/$tfile`
517
518         if [ x"$mt1" != x"$mt2" ]; then
519                 error "not equal mtime, client1: "$mt1", client2: "$mt2"."
520         fi
521 }
522 run_test 26b "sync mtime between ost and mds"
523
524 test_27() {
525         cancel_lru_locks osc
526         lctl clear
527         dd if=/dev/zero of=$DIR2/$tfile bs=$((4096+4))k conv=notrunc count=4 seek=3 &
528         DD2_PID=$!
529         usleep 50
530         log "dd 1 started"
531         
532         dd if=/dev/zero of=$DIR1/$tfile bs=$((16384-1024))k conv=notrunc count=1 seek=4 &
533         DD1_PID=$!
534         log "dd 2 started"
535         
536         sleep 1
537         dd if=/dev/zero of=$DIR1/$tfile bs=8k conv=notrunc count=1 seek=0
538         log "dd 3 finished"
539         lctl set_param -n ldlm.dump_namespaces ""
540         wait $DD1_PID $DD2_PID
541         [ $? -ne 0 ] && lctl dk $TMP/debug || true
542 }
543 run_test 27 "align non-overlapping extent locks from request ==="
544
545 test_28() { # bug 9977
546         ECHO_UUID="ECHO_osc1_UUID"
547         tOST=`$LCTL dl | | awk '/-osc-|OSC.*MNT/ { print $4 }' | head -1`
548
549         $LFS setstripe $DIR1/$tfile -S 1048576 -i 0 -c 2
550         tOBJID=`$LFS getstripe $DIR1/$tfile | awk '$1 == 1 {print $2}'`
551         dd if=/dev/zero of=$DIR1/$tfile bs=1024k count=2
552
553         $LCTL <<-EOF
554                 newdev
555                 attach echo_client ECHO_osc1 $ECHO_UUID
556                 setup $tOST
557         EOF
558
559         tECHOID=`$LCTL dl | grep $ECHO_UUID | awk '{ print $1 }'`
560         $LCTL --device $tECHOID destroy "${tOBJID}:0"
561
562         $LCTL <<-EOF
563                 cfg_device ECHO_osc1
564                 cleanup
565                 detach
566         EOF
567
568         # reading of 1st stripe should pass
569         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 || error
570         # reading of 2nd stripe should fail (this stripe was destroyed)
571         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 skip=1 && error
572
573         # now, recreating test file
574         dd if=/dev/zero of=$DIR1/$tfile bs=1024k count=2 || error
575         # reading of 1st stripe should pass
576         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 || error
577         # reading of 2nd stripe should pass
578         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 skip=1 || error
579 }
580 run_test 28 "read/write/truncate file with lost stripes"
581
582 test_29() { # bug 10999
583         touch $DIR1/$tfile
584         #define OBD_FAIL_LDLM_GLIMPSE  0x30f
585         lctl set_param fail_loc=0x8000030f
586         ls -l $DIR2/$tfile &
587         usleep 500
588         dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1
589         wait
590 }
591 #bug 11549 - permanently turn test off in b1_5
592 run_test 29 "lock put race between glimpse and enqueue ========="
593
594 test_30() { #bug #11110
595     mkdir -p $DIR1/$tdir
596     cp -f /bin/bash $DIR1/$tdir/bash
597     /bin/sh -c 'sleep 1; rm -f $DIR2/$tdir/bash; cp /bin/bash $DIR2/$tdir' &
598     err=$($DIR1/$tdir/bash -c 'sleep 2; openfile -f O_RDONLY /proc/$$/exe >& /dev/null; echo $?')
599     wait
600     [ $err -ne 116 ] && error_ignore 12900 "return code ($err) != -ESTALE" && return
601     true
602 }
603
604 run_test 30 "recreate file race ========="
605
606 test_31a() {
607         mkdir -p $DIR1/$tdir || error "Creating dir $DIR1/$tdir"
608         writes=`LANG=C dd if=/dev/zero of=$DIR/$tdir/$tfile count=1 2>&1 |
609                 awk 'BEGIN { FS="+" } /out/ {print $1}'`
610         #define OBD_FAIL_LDLM_CANCEL_BL_CB_RACE   0x314
611         lctl set_param fail_loc=0x314
612         reads=`LANG=C dd if=$DIR2/$tdir/$tfile of=/dev/null 2>&1 |
613                awk 'BEGIN { FS="+" } /in/ {print $1}'`
614         [ $reads -eq $writes ] || error "read" $reads "blocks, must be" $writes
615 }
616 run_test 31a "voluntary cancel / blocking ast race=============="
617
618 test_31b() {
619         remote_ost || { skip "local OST" && return 0; }
620         remote_ost_nodsh && skip "remote OST w/o dsh" && return 0
621
622         # make sure there is no local locks due to destroy
623         wait_mds_ost_sync || error "wait_mds_ost_sync()"
624         wait_delete_completed || error "wait_delete_completed()"
625
626         mkdir -p $DIR1/$tdir || error "Creating dir $DIR1/$tdir"
627         lfs setstripe $DIR/$tdir/$tfile -i 0 -c 1
628         cp /etc/hosts $DIR/$tdir/$tfile
629         #define OBD_FAIL_LDLM_CANCEL_BL_CB_RACE   0x314
630         lctl set_param fail_loc=0x314
631         #define OBD_FAIL_LDLM_OST_FAIL_RACE      0x316
632         do_facet ost1 lctl set_param fail_loc=0x316
633         # Don't crash kernel
634         cat $DIR2/$tdir/$tfile > /dev/null 2>&1
635         lctl set_param fail_loc=0
636         do_facet ost1 lctl set_param fail_loc=0
637         # cleanup: reconnect the client back
638         df $DIR2
639 }
640 run_test 31b "voluntary OST cancel / blocking ast race=============="
641
642 # enable/disable lockless truncate feature, depending on the arg 0/1
643 enable_lockless_truncate() {
644         lctl set_param -n osc.*.lockless_truncate $1
645 }
646
647 test_32a() { # bug 11270
648         local p="$TMP/sanityN-$TESTNAME.parameters"
649         save_lustre_params $HOSTNAME osc.*.lockless_truncate > $p
650         cancel_lru_locks osc
651         enable_lockless_truncate 1
652         rm -f $DIR1/$tfile
653         lfs setstripe -c -1 $DIR1/$tfile
654         dd if=/dev/zero of=$DIR1/$tfile count=$OSTCOUNT bs=$STRIPE_BYTES > \
655                 /dev/null 2>&1
656         clear_osc_stats
657
658         log "checking cached lockless truncate"
659         $TRUNCATE $DIR1/$tfile 8000000
660         $CHECKSTAT -s 8000000 $DIR2/$tfile || error "wrong file size"
661         [ $(calc_osc_stats lockless_truncate) -eq 0 ] ||
662                 error "lockless truncate doesn't use cached locks"
663
664         log "checking not cached lockless truncate"
665         $TRUNCATE $DIR2/$tfile 5000000
666         $CHECKSTAT -s 5000000 $DIR1/$tfile || error "wrong file size"
667         [ $(calc_osc_stats lockless_truncate) -ne 0 ] ||
668                 error "not cached trancate isn't lockless"
669
670         log "disabled lockless truncate"
671         enable_lockless_truncate 0
672         clear_osc_stats
673         $TRUNCATE $DIR2/$tfile 3000000
674         $CHECKSTAT -s 3000000 $DIR1/$tfile || error "wrong file size"
675         [ $(calc_osc_stats lockless_truncate) -eq 0 ] ||
676                 error "lockless truncate disabling failed"
677         rm $DIR1/$tfile
678         # restore lockless_truncate default values
679         restore_lustre_params < $p
680         rm -f $p
681 }
682 run_test 32a "lockless truncate"
683
684 test_32b() { # bug 11270
685         remote_ost_nodsh && skip "remote OST with nodsh" && return
686
687         local node
688         local p="$TMP/sanityN-$TESTNAME.parameters"
689         save_lustre_params $HOSTNAME "osc.*.contention_seconds" > $p
690         for node in $(osts_nodes); do
691                 save_lustre_params $node "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
692                 save_lustre_params $node "ldlm.namespaces.filter-*.contended_locks" >> $p
693                 save_lustre_params $node "ldlm.namespaces.filter-*.contention_seconds" >> $p
694         done
695         clear_osc_stats
696         # agressive lockless i/o settings
697         for node in $(osts_nodes); do
698                 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'
699         done
700         lctl set_param -n osc.*.contention_seconds 60
701         for i in $(seq 5); do
702                 dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
703                 dd if=/dev/zero of=$DIR2/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
704         done
705         [ $(calc_osc_stats lockless_write_bytes) -ne 0 ] || error "lockless i/o was not triggered"
706         # disable lockless i/o (it is disabled by default)
707         for node in $(osts_nodes); do
708                 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'
709         done
710         # set contention_seconds to 0 at client too, otherwise Lustre still
711         # remembers lock contention
712         lctl set_param -n osc.*.contention_seconds 0
713         clear_osc_stats
714         for i in $(seq 1); do
715                 dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
716                 dd if=/dev/zero of=$DIR2/$tfile bs=4k count=1 conv=notrunc > /dev/null 2>&1
717         done
718         [ $(calc_osc_stats lockless_write_bytes) -eq 0 ] ||
719                 error "lockless i/o works when disabled"
720         rm -f $DIR1/$tfile
721         restore_lustre_params <$p
722         rm -f $p
723 }
724 run_test 32b "lockless i/o"
725
726 print_jbd_stat () {
727     local dev
728     local mdts=$(get_facets MDS)
729     local varcvs
730     local mds
731
732     local stat=0
733     for mds in ${mdts//,/ }; do
734         varsvc=${mds}_svc
735         dev=$(basename $(do_facet $mds lctl get_param -n osd*.${!varsvc}.mntdev))
736         val=$(do_facet $mds "procfile=/proc/fs/jbd/$dev/info;
737 [ -f \\\$procfile ] || procfile=/proc/fs/jbd2/$dev/info;
738 [ -f \\\$procfile ] || procfile=/proc/fs/jbd2/${dev}\:\\\*/info;
739 cat \\\$procfile | head -1;")
740         val=${val%% *};
741         stat=$(( stat + val))
742     done
743     echo $stat
744 }
745
746 # commit on sharing tests
747 test_33a() {
748     remote_mds_nodsh && skip "remote MDS with nodsh" && return
749
750     [ -n "$CLIENTS" ] || { skip "Need two or more clients" && return 0; }
751     [ $CLIENTCOUNT -ge 2 ] || \
752         { skip "Need two or more clients, have $CLIENTCOUNT" && return 0; }
753
754     local nfiles=${TEST33_NFILES:-10000}
755     local param_file=$TMP/$tfile-params
756
757     save_lustre_params $(comma_list $(mdts_nodes)) "mdt.*.commit_on_sharing" > $param_file
758
759     local COS
760     local jbdold
761     local jbdnew
762     local jbd
763
764     for COS in 0 1; do
765         do_facet $SINGLEMDS lctl set_param mdt.*.commit_on_sharing=$COS
766         avgjbd=0
767         avgtime=0
768         for i in 1 2 3; do
769             do_nodes $CLIENT1,$CLIENT2 "mkdir -p $DIR1/$tdir-\\\$(hostname)-$i"
770
771             jbdold=$(print_jbd_stat)
772             echo "=== START createmany old: $jbdold transaction"
773             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")
774             jbdnew=$(print_jbd_stat)
775             jbd=$(( jbdnew - jbdold ))
776             echo "=== END   createmany new: $jbdnew transaction :  $jbd transactions  nfiles $nfiles time $elapsed COS=$COS"
777             avgjbd=$(( avgjbd + jbd ))
778             avgtime=$(( avgtime + elapsed ))
779         done
780         eval cos${COS}_jbd=$((avgjbd / 3))
781         eval cos${COS}_time=$((avgtime / 3))
782     done
783
784     echo "COS=0 transactions (avg): $cos0_jbd  time (avg): $cos0_time"
785     echo "COS=1 transactions (avg): $cos1_jbd  time (avg): $cos1_time"
786     [ "$cos0_jbd" != 0 ] && echo "COS=1 vs COS=0 jbd:  $((((cos1_jbd/cos0_jbd - 1)) * 100 )) %"
787     [ "$cos0_time" != 0 ] && echo "COS=1 vs COS=0 time: $((((cos1_time/cos0_time - 1)) * 100 )) %"
788
789     restore_lustre_params < $param_file
790     rm -f $param_file
791     return 0
792 }
793 run_test 33a "commit on sharing, cross crete/delete, 2 clients, benchmark"
794
795 # End commit on sharing tests
796
797 get_ost_lock_timeouts() {
798     local nodes=${1:-$(comma_list $(osts_nodes))}
799
800     local locks=$(do_nodes $nodes \
801         "lctl get_param -n ldlm.namespaces.filter-*.lock_timeouts" | calc_sum)
802
803     echo $locks
804 }
805
806 test_34() { #16129
807         local OPER
808         local lock_in
809         local lock_out
810         for OPER in notimeout timeout ; do
811                 rm $DIR1/$tfile 2>/dev/null
812                 lock_in=$(get_ost_lock_timeouts)
813                 if [ $OPER == "timeout" ] ; then
814                         for j in `seq $OSTCOUNT`; do
815                                 #define OBD_FAIL_PTLRPC_HPREQ_TIMEOUT    0x511
816                                 do_facet ost$j lctl set_param fail_loc=0x511
817                         done
818                         echo lock should expire
819                 else
820                         for j in `seq $OSTCOUNT`; do
821                                 #define OBD_FAIL_PTLRPC_HPREQ_NOTIMEOUT  0x512
822                                 do_facet ost$j lctl set_param fail_loc=0x512
823                         done
824                         echo lock should not expire
825                 fi
826                 echo writing on client1
827                 dd if=/dev/zero of=$DIR1/$tfile count=100 conv=notrunc > /dev/null 2>&1
828                 sync &
829                 echo reading on client2
830                 dd of=/dev/null if=$DIR2/$tfile > /dev/null 2>&1
831                 # wait for a lock timeout
832                 sleep 4
833                 lock_out=$(get_ost_lock_timeouts)
834                 if [ $OPER == "timeout" ] ; then
835                         if [ $lock_in == $lock_out ]; then
836                                 error "no lock timeout happened"
837                         else
838                                 echo "success"
839                         fi
840                 else
841                         if [ $lock_in != $lock_out ]; then
842                                 error "lock timeout happened"
843                         else
844                                 echo "success"
845                         fi
846                 fi
847         done
848 }
849 run_test 34 "no lock timeout under IO"
850
851 test_35() { # bug 17645
852         local generation=[]
853         local count=0
854         for imp in /proc/fs/lustre/mdc/$FSNAME-MDT*-mdc-*; do
855             g=$(awk '/generation/{print $2}' $imp/import)
856             generation[count]=$g
857             let count=count+1
858         done
859
860         mkdir -p $MOUNT1/$tfile
861         cancel_lru_locks mdc
862
863         # Let's initiate -EINTR situation by setting fail_loc and take
864         # write lock on same file from same client. This will not cause
865         # bl_ast yet as lock is already in local cache.
866 #define OBD_FAIL_LDLM_INTR_CP_AST        0x317
867         do_facet client "lctl set_param fail_loc=0x80000317"
868         local timeout=`do_facet $SINGLEMDS lctl get_param  -n timeout`
869         let timeout=timeout*3
870         local nr=0
871         while test $nr -lt 10; do
872                 log "Race attempt $nr"
873                 local blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
874                 test "x$blk1" = "x" && blk1=0
875                 createmany -o $MOUNT2/$tfile/a 4000 &
876                 pid1=$!
877                 sleep 1
878
879                 # Let's make conflict and bl_ast
880                 ls -la $MOUNT1/$tfile > /dev/null &
881                 pid2=$!
882
883                 log "Wait for $pid1 $pid2 for $timeout sec..."
884                 sleep $timeout
885                 kill -9 $pid1 $pid2 > /dev/null 2>&1
886                 wait
887                 local blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
888                 test "x$blk2" = "x" && blk2=0
889                 test $blk2 -gt $blk1 && break
890                 rm -fr $MOUNT1/$tfile/*
891                 cancel_lru_locks mdc
892                 let nr=nr+1
893         done
894         do_facet client "lctl set_param fail_loc=0x0"
895         df -h $MOUNT1 $MOUNT2
896         count=0
897         for imp in /proc/fs/lustre/mdc/$FSNAME-MDT*-mdc-*; do
898             g=$(awk '/generation/{print $2}' $imp/import)
899             if ! test "$g" -eq "${generation[count]}"; then
900                 error "Eviction happened on import $(basename $imp)"
901             fi
902             let count=count+1
903         done
904 }
905 run_test 35 "-EINTR cp_ast vs. bl_ast race does not evict client"
906
907 test_36() { #bug 16417
908         local SIZE
909         local SIZE_B
910         local i
911
912         mkdir -p $DIR1/$tdir
913         $LFS setstripe -c -1 $DIR1/$tdir
914         i=0
915         SIZE=50
916         let SIZE_B=SIZE*1024*1024
917
918         while [ $i -le 10 ]; do
919                 lctl mark "start test"
920                 local before=$($LFS df | awk '{if ($1 ~/^filesystem/) \
921                                                {print $5; exit} }')
922                 dd if=/dev/zero of=$DIR1/$tdir/file000 bs=1M count=$SIZE
923                 sync          # sync data from client's cache
924                 sync_all_data # sync data from server's cache (delayed
925                               # allocation)
926                 sleep 1
927                 local after_dd=$($LFS df | awk '{if ($1 ~/^filesystem/) \
928                                                  {print $5; exit} }')
929                 multiop_bg_pause $DIR2/$tdir/file000 O_r${SIZE_B}c || return 3
930                 read_pid=$!
931                 rm -f $DIR1/$tdir/file000
932                 kill -USR1 $read_pid
933                 wait $read_pid
934                 wait_delete_completed
935                 local after=$($LFS df | awk '{if ($1 ~/^filesystem/) \
936                                               {print $5; exit} }')
937                 echo "*** cycle($i) *** before($before) after_dd($after_dd)" \
938                         "after($after)"
939                 # this free space! not used
940                 if [ $after_dd -ge $after ]; then
941                         error "space leaked"
942                         return 1;
943                 fi
944                 let i=i+1
945         done
946 }
947 run_test 36 "handle ESTALE/open-unlink corectly"
948
949 test_37() { # bug 18695
950         mkdir -p $DIR1/$tdir
951         multiop_bg_pause $DIR1/$tdir D_c || return 1
952         MULTIPID=$!
953         # create large directory (32kB seems enough from e2fsck, ~= 1000 files)
954         createmany -m $DIR2/$tdir/f 10000
955         # set mtime/atime backward
956         touch -t 198001010000 $DIR2/$tdir
957         kill -USR1 $MULTIPID
958         nr_files=`lfs find $DIR1/$tdir -type f | wc -l`
959         [ $nr_files -eq 10000 ] || error "$nr_files != 10000 truncated directory?"
960
961 }
962 run_test 37 "check i_size is not updated for directory on close (bug 18695) =============="
963
964 # this should be set to past
965 TEST_39_MTIME=`date -d "1 year ago" +%s`
966
967 # bug 11063
968 test_39a() {
969         local client1=${CLIENT1:-`hostname`}
970         local client2=${CLIENT2:-`hostname`}
971
972         do_node $client1 "touch $DIR1/$tfile"
973
974         do_node $client1 "touch -m -d @$TEST_39_MTIME $DIR1/$tfile"
975         local mtime1=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
976         [ "$mtime1" = $TEST_39_MTIME ] || \
977                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
978
979         local d1=`do_node $client1 date +%s`
980         do_node $client1 'echo hello >> '$DIR1/$tfile
981         local d2=`do_node $client1 date +%s`
982
983         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
984         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
985                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
986
987         do_node $client1 "mv $DIR1/$tfile $DIR1/$tfile-1"
988
989         for (( i=0; i < 2; i++ )) ; do
990                 local mtime3=`do_node $client2 "stat -c %Y $DIR1/$tfile-1"`
991                 [ "$mtime2" = "$mtime3" ] || \
992                         error "mtime ($mtime2) changed (to $mtime3) on rename"
993
994                 cancel_lru_locks osc
995                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
996         done
997 }
998 run_test 39a "test from 11063 =================================="
999
1000 test_39b() {
1001         local client1=${CLIENT1:-`hostname`}
1002         local client2=${CLIENT2:-`hostname`}
1003
1004         touch $DIR1/$tfile
1005
1006         local mtime1=`stat -c %Y $DIR1/$tfile`
1007         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1008
1009         sleep 1
1010         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
1011
1012         for (( i=0; i < 2; i++ )) ; do
1013                 local mtime3=`stat -c %Y $DIR1/$tfile`
1014                 local mtime4=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1015
1016                 [ "$mtime3" = "$mtime4" ] || \
1017                         error "different mtime on clients: $mtime3, $mtime4"
1018                 [ "$mtime3" = $TEST_39_MTIME ] || \
1019                         error "lost mtime: $mtime3, should be $TEST_39_MTIME"
1020
1021                 cancel_lru_locks osc
1022                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1023         done
1024 }
1025 run_test 39b "11063 problem 1 =================================="
1026
1027 test_39c() {
1028         local client1=${CLIENT1:-`hostname`}
1029         local client2=${CLIENT2:-`hostname`}
1030
1031         echo hello > $DIR1/$tfile
1032
1033         local mtime1=`stat -c %Y $DIR1/$tfile`
1034         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1035         [ "$mtime1" = "$mtime2" ] || \
1036                 error "create: different mtime on clients: $mtime1, $mtime2"
1037
1038         sleep 1
1039         $TRUNCATE $DIR1/$tfile 1
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" -gt $mtime2 ] || \
1048                         error "truncate did not update mtime: $mtime2, $mtime3"
1049
1050                 cancel_lru_locks osc
1051                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1052         done
1053 }
1054 run_test 39c "check truncate mtime update ======================"
1055
1056 # check that pid exists hence second operation wasn't blocked by first one
1057 # if it is so then there is no conflict, return 0
1058 # else second operation is conflicting with first one, return 1
1059 check_pdo_conflict() {
1060         local pid=$1
1061         local conflict=0
1062         sleep 1 # to ensure OP1 is finished on client if OP2 is blocked by OP1
1063         if [[ `ps --pid $pid | wc -l` == 1 ]]; then
1064                 conflict=1
1065                 echo "Conflict"
1066         else
1067                 echo "No conflict"
1068         fi
1069         return $conflict
1070 }
1071
1072 # pdirop tests
1073 # test 40: check non-blocking operations
1074 test_40a() {
1075 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1076         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1077         mkdir $DIR1/$tfile &
1078         PID1=$!
1079         sleep 1
1080         touch $DIR2/$tfile-2
1081         check_pdo_conflict $PID1 || error "create is blocked"
1082         mkdir $DIR2/$tfile-3
1083         check_pdo_conflict $PID1 || error "mkdir is blocked"
1084         link $DIR2/$tfile-2 $DIR2/$tfile-4
1085         check_pdo_conflict $PID1 || error "link is blocked"
1086         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1087         check_pdo_conflict $PID1 || error "rename is blocked"
1088         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1089         check_pdo_conflict $PID1 || error "getattr is blocked"
1090         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1091         rmdir $DIR2/$tfile-3
1092         check_pdo_conflict $PID1 || error "unlink is blocked"
1093         # all operations above shouldn't wait the first one
1094         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1095         wait $PID1
1096         rm -r $DIR1/*
1097         return 0
1098 }
1099 run_test 40a "pdirops: create vs others =============="
1100
1101 test_40b() {
1102 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1103         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1104         touch $DIR1/$tfile &
1105         PID1=$!
1106         sleep 1
1107         # open|create
1108         touch $DIR2/$tfile-2
1109         check_pdo_conflict $PID1 || error "create is blocked"
1110         mkdir $DIR2/$tfile-3
1111         check_pdo_conflict $PID1 || error "mkdir is blocked"
1112         link $DIR2/$tfile-2 $DIR2/$tfile-4
1113         check_pdo_conflict $PID1 || error "link is blocked"
1114         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1115         check_pdo_conflict $PID1 || error "rename is blocked"
1116         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1117         check_pdo_conflict $PID1 || error "getattr is blocked"
1118         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1119         rmdir $DIR2/$tfile-3
1120         check_pdo_conflict $PID1 || error "unlink is blocked"
1121         # all operations above shouldn't wait the first one
1122         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1123         wait $PID1
1124         rm -r $DIR1/*
1125         return 0
1126 }
1127 run_test 40b "pdirops: open|create and others =============="
1128
1129 test_40c() {
1130         touch $DIR1/$tfile
1131 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1132         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1133         link $DIR1/$tfile $DIR1/$tfile-0 &
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 40c "pdirops: link and others =============="
1157
1158 test_40d() {
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         rm $DIR1/$tfile &
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         return 0
1183 }
1184 run_test 40d "pdirops: unlink and others =============="
1185
1186 test_40e() {
1187         touch $DIR1/$tfile
1188 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1189         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1190         mv $DIR1/$tfile $DIR1/$tfile-0 &
1191         PID1=$!
1192         sleep 1
1193         # open|create
1194         touch $DIR2/$tfile-2
1195         check_pdo_conflict $PID1 || error "create is blocked"
1196         mkdir $DIR2/$tfile-3
1197         check_pdo_conflict $PID1 || error "mkdir is blocked"
1198         link $DIR2/$tfile-2 $DIR2/$tfile-4
1199         check_pdo_conflict $PID1 || error "link is blocked"
1200         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1201         check_pdo_conflict $PID1 || error "getattr is blocked"
1202         rm $DIR2/$tfile-4 $DIR2/$tfile-2
1203         rmdir $DIR2/$tfile-3
1204         check_pdo_conflict $PID1 || error "unlink is blocked"
1205         # all operations above shouldn't wait the first one
1206         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1207         wait $PID1
1208         rm -r $DIR1/*
1209         return 0
1210 }
1211 run_test 40e "pdirops: rename and others =============="
1212
1213 # test 41: create blocking operations
1214 test_41a() {
1215 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1216         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1217         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1218         PID1=$!
1219         sleep 1
1220         mkdir $DIR2/$tfile && error "mkdir must fail"
1221         check_pdo_conflict $PID1 && { wait $PID1; echo "mkdir isn't blocked"; }
1222         rm -r $DIR1/*
1223         return 0
1224 }
1225 run_test 41a "pdirops: create vs mkdir =============="
1226
1227 test_41b() {
1228 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1229         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1230         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1231         PID1=$!
1232         sleep 1
1233         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
1234         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1235         rm -r $DIR1/*
1236         return 0
1237 }
1238 run_test 41b "pdirops: create vs create =============="
1239
1240 test_41c() {
1241         touch $DIR1/$tfile-2
1242 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1243         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1244         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1245         PID1=$!
1246         sleep 1
1247         link $DIR2/$tfile-2 $DIR2/$tfile && error "link must fail"
1248         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1249         rm -r $DIR1/*
1250         return 0
1251 }
1252 run_test 41c "pdirops: create vs link =============="
1253
1254 test_41d() {
1255 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1256         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1257         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1258         PID1=$!
1259         sleep 1
1260         rm $DIR2/$tfile || error "unlink must succeed"
1261         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1262         rm -r $DIR1/*
1263         return 0
1264 }
1265 run_test 41d "pdirops: create vs unlink =============="
1266
1267 test_41e() {
1268         touch $DIR1/$tfile-2
1269 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1270         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1271         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1272         PID1=$!
1273         sleep 1
1274         mv $DIR2/$tfile-2 $DIR2/$tfile || error "rename must succeed"
1275         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1276         rm -r $DIR1/*
1277         return 0
1278 }
1279 run_test 41e "pdirops: create and rename (tgt) =============="
1280
1281 test_41f() {
1282 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1283         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1284         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1285         PID1=$!
1286         sleep 1
1287         mv $DIR2/$tfile $DIR2/$tfile-2 || error "rename must succeed"
1288         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1289         rm -r $DIR1/*
1290         return 0
1291 }
1292 run_test 41f "pdirops: create and rename (src) =============="
1293
1294 test_41g() {
1295 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1296         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1297         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1298         PID1=$!
1299         sleep 1
1300         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
1301         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1302         rm -r $DIR1/*
1303         return 0
1304 }
1305 run_test 41g "pdirops: create vs getattr =============="
1306
1307 test_41h() {
1308 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1309         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1310         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1311         PID1=$!
1312         sleep 1
1313         ls -lia $DIR2/ > /dev/null
1314         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1315         rm -r $DIR1/*
1316         return 0
1317 }
1318 run_test 41h "pdirops: create vs readdir =============="
1319
1320 # test 42: unlink and blocking operations
1321 test_42a() {
1322 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1323         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1324         mkdir $DIR1/$tfile &
1325         PID1=$!
1326         sleep 1
1327         mkdir $DIR2/$tfile && error "mkdir must fail"
1328         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1329         rm -r $DIR1/*
1330         return 0
1331 }
1332 run_test 42a "pdirops: mkdir vs mkdir =============="
1333
1334 test_42b() {
1335 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1336         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1337         mkdir $DIR1/$tfile &
1338         PID1=$!
1339         sleep 1
1340         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
1341         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1342         rm -r $DIR1/*
1343         return 0
1344 }
1345 run_test 42b "pdirops: mkdir vs create =============="
1346
1347 test_42c() {
1348         touch $DIR1/$tfile-2
1349 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1350         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1351         mkdir $DIR1/$tfile &
1352         PID1=$!
1353         sleep 1
1354         link $DIR2/$tfile-2 $DIR2/$tfile && error "link must fail"
1355         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1356         rm -r $DIR1/*
1357         return 0
1358 }
1359 run_test 42c "pdirops: mkdir vs link =============="
1360
1361 test_42d() {
1362 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1363         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1364         mkdir $DIR1/$tfile &
1365         PID1=$!
1366         sleep 1
1367         rmdir $DIR2/$tfile || error "unlink must succeed"
1368         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1369         rm -r $DIR1/*
1370         return 0
1371 }
1372 run_test 42d "pdirops: mkdir vs unlink =============="
1373
1374 test_42e() {
1375         touch $DIR1/$tfile-2
1376 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1377         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1378         mkdir $DIR1/$tfile &
1379         PID1=$!
1380         sleep 1
1381         mv -T $DIR2/$tfile-2 $DIR2/$tfile && error "rename must fail"
1382         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1383         rm -r $DIR1/*
1384         return 0
1385 }
1386 run_test 42e "pdirops: mkdir and rename (tgt) =============="
1387
1388 test_42f() {
1389 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1390         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1391         mkdir $DIR1/$tfile &
1392         PID1=$!
1393         sleep 1
1394         mv $DIR2/$tfile $DIR2/$tfile-2 || error "rename must succeed"
1395         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1396         rm -r $DIR1/*
1397         return 0
1398 }
1399 run_test 42f "pdirops: mkdir and rename (src) =============="
1400
1401 test_42g() {
1402 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1403         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1404         mkdir $DIR1/$tfile &
1405         PID1=$!
1406         sleep 1
1407         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
1408         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1409         rm -r $DIR1/*
1410         return 0
1411 }
1412 run_test 42g "pdirops: mkdir vs getattr =============="
1413
1414 test_42h() {
1415 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1416         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1417         mkdir $DIR1/$tfile &
1418         PID1=$!
1419         sleep 1
1420         ls -lia $DIR2/ > /dev/null
1421         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1422         rm -r $DIR1/*
1423         return 0
1424 }
1425 run_test 42h "pdirops: mkdir vs readdir =============="
1426
1427 # test 43: unlink and blocking operations
1428 test_43a() {
1429         touch $DIR1/$tfile
1430 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1431         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1432         rm $DIR1/$tfile &
1433         PID1=$!
1434         sleep 1
1435         mkdir $DIR2/$tfile || error "mkdir must succeed"
1436         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1437         rm -r $DIR1/*
1438         return 0
1439 }
1440 run_test 43a "pdirops: unlink vs mkdir =============="
1441
1442 test_43b() {
1443         touch $DIR1/$tfile
1444 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1445         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1446         rm $DIR1/$tfile &
1447         PID1=$!
1448         sleep 1
1449         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c || error "create must succeed"
1450         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1451         rm -r $DIR1/*
1452         return 0
1453 }
1454 run_test 43b "pdirops: unlink vs create =============="
1455
1456 test_43c() {
1457         touch $DIR1/$tfile
1458         touch $DIR1/$tfile-2
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         link $DIR2/$tfile-2 $DIR2/$tfile || error "link must succeed"
1465         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1466         rm -r $DIR1/*
1467         return 0
1468 }
1469 run_test 43c "pdirops: unlink vs link =============="
1470
1471 test_43d() {
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         rm $DIR2/$tfile && error "unlink must fail"
1479         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1480         rm -r $DIR1/*
1481         return 0
1482 }
1483 run_test 43d "pdirops: unlink vs unlink =============="
1484
1485 test_43e() {
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         mv -u $DIR2/$tfile-2 $DIR2/$tfile || error "rename must succeed"
1494         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1495         rm -r $DIR1/*
1496         return 0
1497 }
1498 run_test 43e "pdirops: unlink and rename (tgt) =============="
1499
1500 test_43f() {
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         mv $DIR2/$tfile $DIR2/$tfile-2 && error "rename must fail"
1508         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1509         rm -r $DIR1/*
1510         return 0
1511 }
1512 run_test 43f "pdirops: unlink and rename (src) =============="
1513
1514 test_43g() {
1515         touch $DIR1/$tfile
1516 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1517         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1518         rm $DIR1/$tfile &
1519         PID1=$!
1520         sleep 1
1521         stat $DIR2/$tfile > /dev/null && error "stat must fail"
1522         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1523         rm -r $DIR1/*
1524         return 0
1525 }
1526 run_test 43g "pdirops: unlink vs getattr =============="
1527
1528 test_43h() {
1529         touch $DIR1/$tfile
1530 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1531         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1532         rm $DIR1/$tfile &
1533         PID1=$!
1534         sleep 1
1535         ls -lia $DIR2/ > /dev/null
1536         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1537         rm -r $DIR1/*
1538         return 0
1539 }
1540 run_test 43h "pdirops: unlink vs readdir =============="
1541
1542 # test 44: rename tgt and blocking operations
1543 test_44a() {
1544         touch $DIR1/$tfile-2
1545 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
1546         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1547         mv $DIR1/$tfile-2 $DIR1/$tfile &
1548         PID1=$!
1549         sleep 1
1550         mkdir $DIR2/$tfile && error "mkdir must fail"
1551         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1552         rm -r $DIR1/*
1553         return 0
1554 }
1555 run_test 44a "pdirops: rename tgt vs mkdir =============="
1556
1557 test_44b() {
1558         touch $DIR1/$tfile-2
1559 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1560         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1561         mv $DIR1/$tfile-2 $DIR1/$tfile &
1562         PID1=$!
1563         sleep 1
1564         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
1565         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1566         rm -r $DIR1/*
1567         return 0
1568 }
1569 run_test 44b "pdirops: rename tgt vs create =============="
1570
1571 test_44c() {
1572         touch $DIR1/$tfile-2
1573         touch $DIR1/$tfile-3
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         link $DIR2/$tfile-3 $DIR2/$tfile && error "link must fail"
1580         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1581         rm -r $DIR1/*
1582         return 0
1583 }
1584 run_test 44c "pdirops: rename tgt vs link =============="
1585
1586 test_44d() {
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         rm $DIR2/$tfile || error "unlink must succeed"
1594         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1595         rm -r $DIR1/*
1596         return 0
1597 }
1598 run_test 44d "pdirops: rename tgt vs unlink =============="
1599
1600 test_44e() {
1601         touch $DIR1/$tfile
1602         touch $DIR1/$tfile-2
1603         touch $DIR1/$tfile-3
1604 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1605         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1606         mv $DIR1/$tfile-2 $DIR1/$tfile &
1607         PID1=$!
1608         sleep 1
1609         mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
1610         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1611         rm -r $DIR1/*
1612         return 0
1613 }
1614 run_test 44e "pdirops: rename tgt and rename (tgt) =============="
1615
1616 test_44f() {
1617         touch $DIR1/$tfile-2
1618         touch $DIR1/$tfile-3
1619 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1620         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1621         mv $DIR1/$tfile-2 $DIR1/$tfile &
1622         PID1=$!
1623         sleep 1
1624         mv $DIR2/$tfile $DIR2/$tfile-3 || error "rename must succeed"
1625         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1626         rm -r $DIR1/*
1627         return 0
1628 }
1629 run_test 44f "pdirops: rename tgt and rename (src) =============="
1630
1631 test_44g() {
1632         touch $DIR1/$tfile-2
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         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
1639         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1640         rm -r $DIR1/*
1641         return 0
1642 }
1643 run_test 44g "pdirops: rename tgt vs getattr =============="
1644
1645 test_44h() {
1646         touch $DIR1/$tfile-2
1647 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
1648         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
1649         mv $DIR1/$tfile-2 $DIR1/$tfile &
1650         PID1=$!
1651         sleep 1
1652         ls -lia $DIR2/ > /dev/null
1653         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1654         rm -r $DIR1/*
1655         return 0
1656 }
1657 run_test 44h "pdirops: rename tgt vs readdir =============="
1658
1659 # test 45: rename src and blocking operations
1660 test_45a() {
1661         touch $DIR1/$tfile
1662 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1663         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1664         mv $DIR1/$tfile $DIR1/$tfile-2 &
1665         PID1=$!
1666         sleep 1
1667         mkdir $DIR2/$tfile || error "mkdir must succeed"
1668         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1669         rm -r $DIR1/*
1670         return 0
1671 }
1672 run_test 45a "pdirops: rename src vs mkdir =============="
1673
1674 test_45b() {
1675         touch $DIR1/$tfile
1676 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1677         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1678         mv $DIR1/$tfile $DIR1/$tfile-2 &
1679         PID1=$!
1680         sleep 1
1681         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c || error "create must succeed"
1682         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1683         rm -r $DIR1/*
1684         return 0
1685 }
1686 run_test 45b "pdirops: rename src vs create =============="
1687
1688 test_45c() {
1689         touch $DIR1/$tfile
1690         touch $DIR1/$tfile-3
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         link $DIR2/$tfile-3 $DIR2/$tfile || error "link must succeed"
1697         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1698         rm -r $DIR1/*
1699         return 0
1700 }
1701 run_test 45c "pdirops: rename src vs link =============="
1702
1703 test_45d() {
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         rm $DIR2/$tfile && error "unlink must fail"
1711         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1712         rm -r $DIR1/*
1713         return 0
1714 }
1715 run_test 45d "pdirops: rename src vs unlink =============="
1716
1717 test_45e() {
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         mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
1726         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1727         rm -r $DIR1/*
1728         return 0
1729 }
1730 run_test 45e "pdirops: rename src and rename (tgt) =============="
1731
1732 test_45f() {
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         mv $DIR2/$tfile $DIR2/$tfile-3 && error "rename must fail"
1740         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1741         rm -r $DIR1/*
1742         return 0
1743 }
1744 run_test 45f "pdirops: rename src and rename (src) =============="
1745
1746 test_45g() {
1747         touch $DIR1/$tfile
1748 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1749         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1750         mv $DIR1/$tfile $DIR1/$tfile-2 &
1751         PID1=$!
1752         sleep 1
1753         stat $DIR2/$tfile > /dev/null && "stat must fail"
1754         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1755         rm -r $DIR1/*
1756         return 0
1757 }
1758 run_test 45g "pdirops: rename src vs getattr =============="
1759
1760 test_45h() {
1761         touch $DIR1/$tfile
1762 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1763         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1764         mv $DIR1/$tfile $DIR1/$tfile-2 &
1765         PID1=$!
1766         sleep 1
1767         ls -lia $DIR2/ > /dev/null
1768         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1769         rm -r $DIR1/*
1770         return 0
1771 }
1772 run_test 45h "pdirops: unlink vs readdir =============="
1773
1774 # test 46: link and blocking operations
1775 test_46a() {
1776         touch $DIR1/$tfile-2
1777 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1778         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1779         link $DIR1/$tfile-2 $DIR1/$tfile &
1780         PID1=$!
1781         sleep 1
1782         mkdir $DIR2/$tfile && error "mkdir must fail"
1783         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1784         rm -r $DIR1/*
1785         return 0
1786 }
1787 run_test 46a "pdirops: link vs mkdir =============="
1788
1789 test_46b() {
1790         touch $DIR1/$tfile-2
1791 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1792         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1793         link $DIR1/$tfile-2 $DIR1/$tfile &
1794         PID1=$!
1795         sleep 1
1796         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
1797         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1798         rm -r $DIR1/*
1799         return 0
1800 }
1801 run_test 46b "pdirops: link vs create =============="
1802
1803 test_46c() {
1804         touch $DIR1/$tfile-2
1805 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1806         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1807         link $DIR1/$tfile-2 $DIR1/$tfile &
1808         PID1=$!
1809         sleep 1
1810         link $DIR2/$tfile $DIR2/$tfile && error "link must fail"
1811         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1812         rm -r $DIR1/*
1813         return 0
1814 }
1815 run_test 46c "pdirops: link vs link =============="
1816
1817 test_46d() {
1818         touch $DIR1/$tfile-2
1819 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1820         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1821         link $DIR1/$tfile-2 $DIR1/$tfile &
1822         PID1=$!
1823         sleep 1
1824         rm $DIR2/$tfile || error "unlink must succeed"
1825         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1826         rm -r $DIR1/*
1827         return 0
1828 }
1829 run_test 46d "pdirops: link vs unlink =============="
1830
1831 test_46e() {
1832         touch $DIR1/$tfile-2
1833         touch $DIR1/$tfile-3
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         mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
1840         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1841         rm -r $DIR1/*
1842         return 0
1843 }
1844 run_test 46e "pdirops: link and rename (tgt) =============="
1845
1846 test_46f() {
1847         touch $DIR1/$tfile-2
1848         touch $DIR1/$tfile-3
1849 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1850         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1851         link $DIR1/$tfile-2 $DIR1/$tfile &
1852         PID1=$!
1853         sleep 1
1854         mv $DIR2/$tfile $DIR2/$tfile-3 || error "rename must succeed"
1855         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1856         rm -r $DIR1/*
1857         return 0
1858 }
1859 run_test 46f "pdirops: link and rename (src) =============="
1860
1861 test_46g() {
1862         touch $DIR1/$tfile-2
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         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
1869         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1870         rm -r $DIR1/*
1871         return 0
1872 }
1873 run_test 46g "pdirops: link vs getattr =============="
1874
1875 test_46h() {
1876         touch $DIR1/$tfile-2
1877 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1878         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1879         link $DIR1/$tfile-2 $DIR1/$tfile &
1880         PID1=$!
1881         sleep 1
1882         ls -lia $DIR2/ > /dev/null
1883         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1884         rm -r $DIR1/*
1885         return 0
1886 }
1887 run_test 46h "pdirops: link vs readdir =============="
1888
1889 test_50() {
1890         trunc_size=4096
1891         dd if=/dev/zero of=$DIR1/$tfile bs=1K count=10
1892 #define OBD_FAIL_OSC_CP_ENQ_RACE         0x410
1893         do_facet client "lctl set_param fail_loc=0x410"
1894         $TRUNCATE $DIR2/$tfile $trunc_size
1895         do_facet client "lctl set_param fail_loc=0x0"
1896         sleep 3
1897         size=`stat -c %s $DIR2/$tfile`
1898         [ $size -eq $trunc_size ] || error "wrong size"
1899 }
1900 run_test 50 "osc lvb attrs: enqueue vs. CP AST =============="
1901
1902 test_60() {
1903         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
1904         { skip "Need MDS version at least 2.3.0"; return; }
1905         # Create a file
1906         mkdir -p $DIR1/$tdir
1907         file1=$DIR1/$tdir/file
1908         file2=$DIR2/$tdir/file
1909
1910         echo orig > $file2 || error "Could not create $file2"
1911         version=$($LFS data_version $file1)
1912
1913         # Append data
1914         echo append >> $file2 || error "Could not append to $file2"
1915         version2=$($LFS data_version $file1)
1916         [ "$version" != "$version2" ] ||
1917             error "append did not change data version: $version"
1918
1919         # Overwrite data
1920         echo overwrite > $file2 || error "Could not overwrite $file2"
1921         version3=$($LFS data_version $file1)
1922         [ "$version2" != "$version3" ] ||
1923             error "overwrite did not change data version: $version2"
1924
1925         # Truncate before EOF
1926         $TRUNCATE $file2 3 || error "Could not truncate $file2"
1927         version4=$($LFS data_version $file1)
1928         [ "$version3" != "$version4" ] ||
1929             error "truncate did not change data version: $version3"
1930
1931         # Truncate after EOF
1932         $TRUNCATE $file2 123456 || error "Could not truncate $file2"
1933         version5=$($LFS data_version $file1)
1934         [ "$version4" != "$version5" ] ||
1935             error "truncate did not change data version: $version4"
1936
1937         # Chmod do not change version
1938         chmod 400 $file2 || error "Could not chmod 400 $file2"
1939         version6=$($LFS data_version $file1)
1940         [ "$version5" == "$version6" ] ||
1941             error "chmod should not change data version: $version5 != $version6"
1942
1943         # Chown do not change version
1944         chown $RUNAS_ID $file2 || error "Could not chown $RUNAS_ID $file2"
1945         version7=$($LFS data_version $file1)
1946         [ "$version5" == "$version7" ] ||
1947             error "chown should not change data version: $version5 != $version7"
1948 }
1949 run_test 60 "Verify data_version behaviour"
1950
1951 log "cleanup: ======================================================"
1952
1953 [ "$(mount | grep $MOUNT2)" ] && umount $MOUNT2
1954
1955 complete $(basename $0) $SECONDS
1956 check_and_cleanup_lustre
1957 exit_status