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