Whamcloud - gitweb
LU-2233 tests: improve tests sanityn/40-47
[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: 9977/LU-7105
7 #               LU-7105
8 ALWAYS_EXCEPT=" 28      $SANITYN_EXCEPT"
9 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
10
11 SRCDIR=$(dirname $0)
12 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
13
14 SIZE=${SIZE:-40960}
15 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
16 OPENFILE=${OPENFILE:-openfile}
17 OPENUNLINK=${OPENUNLINK:-openunlink}
18 export MULTIOP=${MULTIOP:-multiop}
19 export TMP=${TMP:-/tmp}
20 MOUNT_2=${MOUNT_2:-"yes"}
21 CHECK_GRANT=${CHECK_GRANT:-"yes"}
22 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
23
24 SAVE_PWD=$PWD
25
26 export NAME=${NAME:-local}
27
28 LUSTRE=${LUSTRE:-`dirname $0`/..}
29 . $LUSTRE/tests/test-framework.sh
30 CLEANUP=${CLEANUP:-:}
31 SETUP=${SETUP:-:}
32 init_test_env $@
33 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
34 get_lustre_env
35 init_logging
36
37 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
38 # bug number for skipped test:
39         ALWAYS_EXCEPT="$ALWAYS_EXCEPT "
40 # LU-2829 / LU-2887 - make allowances for ZFS slowness
41         TEST33_NFILES=${TEST33_NFILES:-1000}
42 fi
43 #                                  23   (min)"
44 [ "$SLOW" = "no" ] && EXCEPT_SLOW="33a"
45
46 FAIL_ON_ERROR=false
47
48 SETUP=${SETUP:-:}
49 TRACE=${TRACE:-""}
50
51 check_and_setup_lustre
52
53 OSC=${OSC:-"osc"}
54
55 assert_DIR
56 rm -rf $DIR1/[df][0-9]* $DIR1/lnk $DIR/[df].${TESTSUITE}*
57
58 SAMPLE_FILE=$TMP/$(basename $0 .sh).junk
59 dd if=/dev/urandom of=$SAMPLE_FILE bs=1M count=1
60
61 # $RUNAS_ID may get set incorrectly somewhere else
62 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
63
64 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
65
66 build_test_filter
67
68 test_1() {
69         touch $DIR1/$tfile
70         [ -f $DIR2/$tfile ] || error "Check create"
71         chmod 777 $DIR2/$tfile
72         $CHECKSTAT -t file -p 0777 $DIR1/$tfile ||
73                 error "Check attribute update for 0777"
74
75         chmod a-x $DIR2/$tfile
76         $CHECKSTAT -t file -p 0666 $DIR1/$tfile ||
77                 error "Check attribute update for 0666"
78
79         rm $DIR2/$tfile
80         $CHECKSTAT -a $DIR1/$tfile ||
81                 error "Check unlink - removes file on other mountpoint"
82 }
83 run_test 1 "Check attribute updates on 2 mount points"
84
85 test_2a() {
86         touch $DIR1/f2a
87         ls -l $DIR2/f2a
88         chmod 777 $DIR2/f2a
89         $CHECKSTAT -t file -p 0777 $DIR1/f2a ||
90                 error "Either not file type or perms not 0777"
91 }
92 run_test 2a "check cached attribute updates on 2 mtpt's ========"
93
94 test_2b() {
95         touch $DIR1/f2b
96         ls -l $DIR2/f2b
97         chmod 777 $DIR1/f2b
98         $CHECKSTAT -t file -p 0777 $DIR2/f2b ||
99                 error "Either not file type or perms not 0777"
100 }
101 run_test 2b "check cached attribute updates on 2 mtpt's ========"
102
103 # NEED TO SAVE ROOT DIR MODE
104 test_2c() {
105         chmod 777 $DIR1
106         $CHECKSTAT -t dir -p 0777 $DIR2 ||
107                 error "Either not dir type or perms not 0777"
108 }
109 run_test 2c "check cached attribute updates on 2 mtpt's root ==="
110
111 test_2d() {
112         chmod 755 $DIR1
113         $CHECKSTAT -t dir -p 0755 $DIR2 ||
114                 error "Either not file type or perms not 0775"
115 }
116 run_test 2d "check cached attribute updates on 2 mtpt's root ==="
117
118 test_2e() {
119         chmod 755 $DIR1
120         ls -l $DIR1
121         ls -l $DIR2
122         chmod 777 $DIR1
123                 $RUNAS dd if=/dev/zero of=$DIR2/$tfile count=1 ||
124                         error "dd failed"
125 }
126 run_test 2e "check chmod on root is propagated to others"
127
128 test_2f() {
129         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
130         local MDTIDX=1
131         local remote_dir=$tdir/remote_dir
132
133         mkdir -p $DIR1/$tdir
134         $LFS mkdir -i $MDTIDX $DIR1/$remote_dir ||
135                    error "Create remote directory failed"
136
137         touch $DIR1/$remote_dir/$tfile ||
138                 error "Create file under remote directory failed"
139         chmod 777 $DIR1/$remote_dir/$tfile ||
140                 error "Chmod file under remote directory failed"
141
142         $CHECKSTAT -t file -p 0777 $DIR2/$remote_dir/$tfile ||
143                 error "Check attr of file under remote directory failed"
144
145         chown $RUNAS_ID:$RUNAS_GID $DIR1/$remote_dir/$tfile ||
146                 error "Chown file under remote directory failed"
147
148         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR2/$remote_dir/$tfile ||
149                 error "Check owner of file under remote directory failed"
150
151         cd $DIR2/$remote_dir || error "enter remote dir"
152         rm -rf $DIR1/$remote_dir/$tfile ||
153                 error "Unlink remote directory failed"
154
155         $CHECKSTAT -t file $DIR2/$remote_dir/$tfile &&
156                 error "unlink file still exists!"
157
158         cd $DIR2/$tdir || error "exit remote dir"
159         rm -rf $DIR1/$tdir || error "unlink directory failed"
160 }
161 run_test 2f "check attr/owner updates on DNE with 2 mtpt's"
162
163 test_2g() {
164         dd if=/dev/zero of=$DIR1/$tfile oflag=sync bs=1M count=2
165
166         local block1=$(stat $DIR1/$tfile | awk '/Blocks/ {print $4} ')
167         cancel_lru_locks osc
168         local block2=$(stat $DIR2/$tfile | awk '/Blocks/ {print $4} ')
169         echo "$DIR1/$tfile has $block1 blocks"
170         echo "$DIR2/$tfile has $block2 blocks"
171         [ $block1 -eq $block2 ] || error "$block1 not equal to $block2"
172 }
173 run_test 2g "check blocks update on sync write"
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 ||
192                 error "Either not file type or size not equal to 100 bytes"
193         rm $DIR1/f5
194 }
195 run_test 5 "create a file on one mount, truncate it on the other"
196
197 test_6() {
198         openunlink $DIR1/$tfile $DIR2/$tfile || \
199                 error "openunlink $DIR1/$tfile $DIR2/$tfile"
200 }
201 run_test 6 "remove of open file on other node =================="
202
203 test_7() {
204         local dir=d7
205         opendirunlink $DIR1/$dir $DIR2/$dir || \
206                 error "opendirunlink $DIR1/$dir $DIR2/$dir"
207 }
208 run_test 7 "remove of open directory on other node ============="
209
210 test_8() {
211         opendevunlink $DIR1/$tfile $DIR2/$tfile || \
212                 error "opendevunlink $DIR1/$tfile $DIR2/$tfile"
213 }
214 run_test 8 "remove of open special file on other node =========="
215
216 test_9a() {
217         MTPT=1
218         local dir
219         > $DIR2/f9
220         for C in a b c d e f g h i j k l; do
221                 dir=`eval echo \\$DIR$MTPT`
222                 echo -n $C >> $dir/f9
223                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
224         done
225         [ "`cat $DIR1/f9`" = "abcdefghijkl" ] || \
226                 error "`od -a $DIR1/f9` != abcdefghijkl"
227 }
228 run_test 9a "append of file with sub-page size on multiple mounts"
229
230 #LU-10681 - tiny writes & appending to sparse striped file
231 test_9b() {
232         [[ $OSTCOUNT -ge 2 ]] || { skip "needs >= 2 OSTs"; return; }
233
234         $LFS setstripe -c 2 -S 1M $DIR/$tfile
235         echo "foo" >> $DIR/$tfile
236         dd if=/dev/zero of=$DIR2/$tfile bs=1M count=1 seek=1 conv=notrunc ||
237                 error "sparse dd $DIR2/$tfile failed"
238         echo "foo" >> $DIR/$tfile
239
240         data=$(dd if=$DIR2/$tfile bs=1 count=3 skip=$((2 * 1048576)) conv=notrunc)
241         echo "Data read (expecting 'foo')": $data
242         [ "$data" = "foo" ] || error "append to sparse striped file failed"
243 }
244 run_test 9b "append to striped sparse file"
245
246 test_10a() {
247         MTPT=1
248         local dir
249         OFFSET=0
250         > $DIR2/f10
251         for C in a b c d e f g h i j k l; do
252                 dir=`eval echo \\$DIR$MTPT`
253                 echo -n $C | dd of=$dir/f10 bs=1 seek=$OFFSET count=1
254                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
255                 OFFSET=`expr $OFFSET + 1`
256         done
257         [ "`cat $DIR1/f10`" = "abcdefghijkl" ] || \
258                 error "`od -a $DIR1/f10` != abcdefghijkl"
259 }
260 run_test 10a "write of file with sub-page size on multiple mounts "
261
262 test_10b() {
263         # create a seed file
264         yes "R" | head -c 4000 >$TMP/f10b-seed
265         dd if=$TMP/f10b-seed of=$DIR1/f10b bs=3k count=1 || error "dd $DIR1"
266
267         $TRUNCATE $DIR1/f10b 4096 || error "truncate 4096"
268
269         dd if=$DIR2/f10b of=$TMP/f10b-lustre bs=4k count=1 || error "dd $DIR2"
270
271         # create a test file locally to compare
272         dd if=$TMP/f10b-seed of=$TMP/f10b bs=3k count=1 || error "dd random"
273         $TRUNCATE $TMP/f10b 4096 || error "truncate 4096"
274         cmp $TMP/f10b $TMP/f10b-lustre || error "file miscompare"
275         rm $TMP/f10b $TMP/f10b-lustre $TMP/f10b-seed
276 }
277 run_test 10b "write of file with sub-page size on multiple mounts "
278
279 test_11() {
280         test_mkdir $DIR1/d11
281         multiop_bg_pause $DIR1/d11/f O_c || return 1
282         MULTIPID=$!
283         cp -p /bin/ls $DIR1/d11/f
284         $DIR2/d11/f
285         RC=$?
286         kill -USR1 $MULTIPID
287         wait $MULTIPID || error "wait for PID $MULTIPID failed"
288         [ $RC -eq 0 ] && error || true
289 }
290 run_test 11 "execution of file opened for write should return error ===="
291
292 test_12() {
293         DIR=$DIR DIR2=$DIR2 sh lockorder.sh
294 }
295 run_test 12 "test lock ordering (link, stat, unlink)"
296
297 test_13() {     # bug 2451 - directory coherency
298         test_mkdir $DIR1/d13
299         cd $DIR1/d13 || error "cd to $DIR1/d13 failed"
300         ls
301         ( touch $DIR1/d13/f13 ) # needs to be a separate shell
302         ls
303         rm -f $DIR2/d13/f13 || error "Cannot remove $DIR2/d13/f13"
304         ls 2>&1 | grep f13 && error "f13 shouldn't return an error (1)" || true
305         # need to run it twice
306         ( touch $DIR1/d13/f13 ) # needs to be a separate shell
307         ls
308         rm -f $DIR2/d13/f13 || error "Cannot remove $DIR2/d13/f13"
309         ls 2>&1 | grep f13 && error "f13 shouldn't return an error (2)" || true
310 }
311 run_test 13 "test directory page revocation"
312
313 test_14aa() {
314         test_mkdir $DIR1/$tdir
315         cp -p /bin/ls $DIR1/$tdir/$tfile
316         multiop_bg_pause $DIR1/$tdir/$tfile Ow_c || return 1
317         MULTIPID=$!
318
319         $DIR2/$tdir/$tfile && error || true
320         kill $MULTIPID
321 }
322 run_test 14aa "execution of file open for write returns -ETXTBSY"
323
324 test_14ab() {
325         test_mkdir $DIR1/$tdir
326         cp -p $(which sleep) $DIR1/$tdir/sleep || error "cp failed"
327         $DIR1/$tdir/sleep 60 &
328         SLEEP_PID=$!
329         $MULTIOP $DIR2/$tdir/sleep Oc && error "expected error, got success"
330         kill $SLEEP_PID
331 }
332 run_test 14ab "open(RDWR) of executing file returns -ETXTBSY"
333
334 test_14b() { # bug 3192, 7040
335         test_mkdir $DIR1/$tdir
336         cp -p $(which sleep) $DIR1/$tdir/sleep || error "cp failed"
337         $DIR1/$tdir/sleep 60 &
338         SLEEP_PID=$!
339         $TRUNCATE $DIR2/$tdir/sleep 60 && kill -9 $SLEEP_PID && \
340                 error "expected truncate error, got success"
341         kill $SLEEP_PID
342         cmp $(which sleep) $DIR1/$tdir/sleep || error "binary changed"
343 }
344 run_test 14b "truncate of executing file returns -ETXTBSY ======"
345
346 test_14c() { # bug 3430, 7040
347         test_mkdir $DIR1/$tdir
348         cp -p $(which sleep) $DIR1/$tdir/sleep || error "cp failed"
349         $DIR1/$tdir/sleep 60 &
350         SLEEP_PID=$!
351         cp /etc/hosts $DIR2/$tdir/sleep && error "expected error, got success"
352         kill $SLEEP_PID
353         cmp $(which sleep) $DIR1/$tdir/sleep || error "binary changed"
354 }
355 run_test 14c "open(O_TRUNC) of executing file return -ETXTBSY =="
356
357 test_14d() { # bug 10921
358         test_mkdir $DIR1/$tdir
359         cp -p $(which sleep) $DIR1/$tdir/sleep || error "cp failed"
360         $DIR1/$tdir/sleep 60 &
361         SLEEP_PID=$!
362         log chmod
363         chmod 600 $DIR1/$tdir/sleep || error "chmod failed"
364         kill $SLEEP_PID
365         cmp $(which sleep) $DIR1/$tdir/sleep || error "binary changed"
366 }
367 run_test 14d "chmod of executing file is still possible ========"
368
369 test_15() {     # bug 974 - ENOSPC
370         echo "PATH=$PATH"
371         sh oos2.sh $MOUNT1 $MOUNT2
372         wait_delete_completed
373         grant_error=`dmesg | grep "> available"`
374         [ -z "$grant_error" ] || error "$grant_error"
375 }
376 run_test 15 "test out-of-space with multiple writers ==========="
377
378 COUNT=${COUNT:-2500}
379 # The FSXNUM reduction for ZFS is needed until ORI-487 is fixed.
380 # We don't want to skip it entirely, but ZFS is VERY slow and cannot
381 # pass a 2500 operation dual-mount run within the time limit.
382 if [ "$(facet_fstype ost1)" = "zfs" ]; then
383         FSXNUM=$((COUNT / 5))
384         FSXP=1
385 elif [ "$SLOW" = "yes" ]; then
386         FSXNUM=$((COUNT * 5))
387         FSXP=500
388 else
389         FSXNUM=$COUNT
390         FSXP=100
391 fi
392
393 test_16a() {
394         local file1=$DIR1/$tfile
395         local file2=$DIR2/$tfile
396         local stripe_size=$(do_facet $SINGLEMDS \
397                 "$LCTL get_param -n lod.$(facet_svc $SINGLEMDS)*.stripesize")
398
399         # to allocate grant because it may run out due to test_15.
400         $LFS setstripe -c -1 $file1
401         dd if=/dev/zero of=$file1 bs=$stripe_size count=$OSTCOUNT oflag=sync
402         dd if=/dev/zero of=$file2 bs=$stripe_size count=$OSTCOUNT oflag=sync
403         rm -f $file1
404
405         $LFS setstripe -c -1 $file1 # b=10919
406         fsx -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -S 0 $file1 $file2 \
407                 || error "fsx failed"
408         rm -f $file1
409
410         # O_DIRECT reads and writes must be aligned to the device block size.
411         fsx -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -S 0 -Z -r 4096 \
412                 -w 4096 $file1 $file2 || error "fsx with O_DIRECT failed."
413 }
414 run_test 16a "$FSXNUM iterations of dual-mount fsx"
415
416 # Consistency check for tiny writes, LU-9409
417 test_16b() {
418         local file1=$DIR1/$tfile
419         local file2=$DIR2/$tfile
420
421         # to allocate grant because it may run out due to test_15.
422         lfs setstripe -c -1 $file1
423         dd if=/dev/zero of=$file1 bs=$STRIPE_BYTES count=$OSTCOUNT oflag=sync
424         dd if=/dev/zero of=$file2 bs=$STRIPE_BYTES count=$OSTCOUNT oflag=sync
425         rm -f $file1
426
427         lfs setstripe -c -1 $file1 # b=10919
428         # -o is set to 8192 because writes < 1 page and between 1 and 2 pages
429         # create a mix of tiny writes & normal writes
430         fsx -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -o 8192 -S 0 $file1 \
431         $file2
432 }
433 run_test 16b "$FSXNUM iterations of dual-mount fsx at small size"
434
435 test_16c() {
436         local file1=$DIR1/$tfile
437         local file2=$DIR2/$tfile
438         local stripe_size=$(do_facet $SINGLEMDS \
439                 "$LCTL get_param -n lod.$(facet_svc $SINGLEMDS)*.stripesize")
440
441         [ $(facet_fstype ost1) != ldiskfs ] && skip "dio on ldiskfs only"
442
443         # to allocate grant because it may run out due to test_15.
444         $LFS setstripe -c -1 $file1
445         dd if=/dev/zero of=$file1 bs=$stripe_size count=$OSTCOUNT oflag=sync
446         dd if=/dev/zero of=$file2 bs=$stripe_size count=$OSTCOUNT oflag=sync
447         rm -f $file1
448         wait_delete_completed
449
450         local list=$(comma_list $(osts_nodes))
451         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
452                 skip "not cache-capable obdfilter"
453         fi
454
455         set_osd_param $list '' read_cache_enable 0
456         set_osd_param $list '' writethrough_cache_enable 0
457
458         $LFS setstripe -c -1 $file1 # b=10919
459         fsx -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -S 0 $file1 $file2 \
460                 || error "fsx failed"
461         rm -f $file1
462
463         set_osd_param $list '' read_cache_enable 1
464         set_osd_param $list '' writethrough_cache_enable 1
465
466         return 0
467 }
468 run_test 16c "verify data consistency on ldiskfs with cache disabled (b=17397)"
469
470
471 test_17() { # bug 3513, 3667
472         remote_ost_nodsh && skip "remote OST with nodsh" && return
473
474         lfs setstripe $DIR1/$tfile -i 0 -c 1
475         cp $SAMPLE_FILE $DIR1/$tfile
476         cancel_lru_locks osc > /dev/null
477         #define OBD_FAIL_ONCE|OBD_FAIL_LDLM_CREATE_RESOURCE    0x30a
478         do_facet ost1 lctl set_param fail_loc=0x8000030a
479         ls -ls $DIR1/$tfile | awk '{ print $1,$6 }' > $DIR1/$tfile-1 & \
480         ls -ls $DIR2/$tfile | awk '{ print $1,$6 }' > $DIR2/$tfile-2
481         wait
482         diff -u $DIR1/$tfile-1 $DIR2/$tfile-2 || error "files are different"
483 }
484 run_test 17 "resource creation/LVB creation race ==============="
485
486 test_18() {
487         # turn e.g. ALWAYS_EXCEPT="18c" into "-e 3"
488         local idx
489         local excepts=
490         for idx in {a..z}; do
491                 local ptr=EXCEPT_ALWAYS_18$idx
492                 [ x${!ptr} = xtrue ] || continue
493
494                 excepts="$excepts -e $(($(printf %d \'$idx)-96))"
495         done
496
497         $LUSTRE/tests/mmap_sanity -d $MOUNT1 -m $MOUNT2 $excepts
498         sync; sleep 1; sync
499 }
500 run_test 18 "mmap sanity check ================================="
501
502 test_19() { # bug3811
503         local node=$(facet_active_host ost1)
504
505         [ "x$DOM" = "xyes" ] && node=$(facet_active_host $SINGLEMDS)
506
507         # check whether obdfilter is cache capable at all
508         get_osd_param $node '' read_cache_enable >/dev/null ||
509                 skip "not cache-capable obdfilter"
510
511         local MAX=$(get_osd_param $node '' readcache_max_filesize | head -n 1)
512         set_osd_param $node '' readcache_max_filesize 4096
513         dd if=/dev/urandom of=$TMP/$tfile bs=512k count=32
514         local SUM=$(cksum $TMP/$tfile | cut -d" " -f 1,2)
515         cp $TMP/$tfile $DIR1/$tfile
516         for i in `seq 1 20`; do
517                 [ $((i % 5)) -eq 0 ] && log "$testname loop $i"
518                 cancel_lru_locks $OSC > /dev/null
519                 cksum $DIR1/$tfile | cut -d" " -f 1,2 > $TMP/sum1 & \
520                 cksum $DIR2/$tfile | cut -d" " -f 1,2 > $TMP/sum2
521                 wait
522                 [ "$(cat $TMP/sum1)" = "$SUM" ] || \
523                         error "$DIR1/$tfile $(cat $TMP/sum1) != $SUM"
524                 [ "$(cat $TMP/sum2)" = "$SUM" ] || \
525                         error "$DIR2/$tfile $(cat $TMP/sum2) != $SUM"
526         done
527         set_osd_param $node '' readcache_max_filesize $MAX
528         rm $DIR1/$tfile
529 }
530 run_test 19 "test concurrent uncached read races ==============="
531
532 test_20() {
533         test_mkdir $DIR1/d20
534         cancel_lru_locks $OSC
535         CNT=$((`lctl get_param -n llite.*.dump_page_cache | wc -l`))
536         $MULTIOP $DIR1/f20 Ow8190c
537         $MULTIOP $DIR2/f20 Oz8194w8190c
538         $MULTIOP $DIR1/f20 Oz0r8190c
539         cancel_lru_locks $OSC
540         CNTD=$((`lctl get_param -n llite.*.dump_page_cache | wc -l` - $CNT))
541         [ $CNTD -gt 0 ] && \
542             error $CNTD" page left in cache after lock cancel" || true
543 }
544 run_test 20 "test extra readahead page left in cache ===="
545
546 cleanup_21() {
547         trap 0
548         umount $DIR1/$tdir
549 }
550
551 test_21() { # Bug 5907
552         test_mkdir $DIR1/$tdir
553         mount /etc $DIR1/$tdir --bind || error "mount failed" # Poor man's mount.
554         trap cleanup_21 EXIT
555         rmdir -v $DIR1/$tdir && error "Removed mounted directory"
556         rmdir -v $DIR2/$tdir && echo "Removed mounted directory from another mountpoint, needs to be fixed"
557         test -d $DIR1/$tdir || error "Mounted directory disappeared"
558         cleanup_21
559         test -d $DIR2/$tdir || test -d $DIR1/$tdir && error "Removed dir still visible after umount"
560         true
561 }
562 run_test 21 " Try to remove mountpoint on another dir ===="
563
564 test_23() { # Bug 5972
565         local at_diff=$(do_facet $SINGLEMDS \
566                 $LCTL get_param -n mdd.*MDT0000*.atime_diff | head -n1)
567         echo "atime should be updated while another read" > $DIR1/$tfile
568
569         # clear the lock(mode: LCK_PW) gotten from creating operation
570         cancel_lru_locks $OSC
571         time1=$(date +%s)
572         echo "now is $time1"
573         sleep $((at_diff + 1))
574
575         echo "starting reads"
576         multiop_bg_pause $DIR1/$tfile or20_c || return 1
577         # with SOM and opencache enabled, we need to close a file and cancel
578         # open lock to get atime propogated to MDS
579         kill -USR1 $! || return 2
580         cancel_lru_locks mdc
581
582         time2=$(stat -c "%X" $DIR/$tfile)
583         echo "new atime is $time2"
584
585         [ $time2 -gt $time1 ] || error "atime was not updated"
586         rm -f $DIR1/$tfile || error "rm -f $DIR1/$tfile failed"
587         true
588 }
589 run_test 23 " others should see updated atime while another read===="
590
591 test_24a() {
592         touch $DIR1/$tfile
593         lfs df || error "lfs df failed"
594         lfs df -ih || error "lfs df -ih failed"
595         lfs df -h $DIR1 || error "lfs df -h $DIR1 failed"
596         lfs df -i $DIR2 || error "lfs df -i $DIR2 failed"
597         lfs df $DIR1/$tfile || error "lfs df $DIR1/$tfile failed"
598         lfs df -ih $DIR2/$tfile || error "lfs df -ih $DIR2/$tfile failed"
599
600         OSC=`lctl dl | awk '/-osc-|OSC.*MNT/ {print $4}' | head -n 1`
601 #       OSC=`lctl dl | awk '/-osc-/ {print $4}' | head -n 1`
602         lctl --device %osc deactivate
603         lfs df -i || error "lfs df -i with deactivated OSC failed"
604         lctl --device %osc activate
605         lfs df || error "lfs df with reactivated OSC failed"
606 }
607 run_test 24a "lfs df [-ih] [path] test ========================="
608
609 test_24b() {
610         touch $DIR1/$tfile
611         fsnum=$(lfs_df | grep -c "summary")
612         [ $fsnum -eq 2 ] || error "lfs df shows $fsnum != 2 filesystems."
613 }
614 run_test 24b "lfs df should show both filesystems ==============="
615
616 test_25a() {
617         local acl=$(lctl get_param -n mdc.*MDT0000-mdc-*.connect_flags |
618                                                                 grep -c acl)
619         [ "$acl" -lt 1 ] && skip "must have acl, skipping" && return
620
621         mkdir -p $DIR1/$tdir
622         touch $DIR1/$tdir/f1 || error "touch $DIR1/$tdir/f1"
623         chmod 0755 $DIR1/$tdir/f1 || error "chmod 0755 $DIR1/$tdir/f1"
624
625         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #1"
626         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
627                 error "setfacl $DIR2/$tdir #1"
628         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #2"
629         setfacl -m u:$RUNAS_ID:r-x -m g:$RUNAS_GID:r-x $DIR1/$tdir ||
630                 error "setfacl $DIR2/$tdir #2"
631         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #3"
632         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
633                 error "setfacl $DIR2/$tdir #3"
634         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #4"
635         setfacl -x u:$RUNAS_ID: -x g:$RUNAS_GID: $DIR1/$tdir ||
636                 error "setfacl $DIR2/$tdir #4"
637         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #5"
638
639         rm -rf $DIR1/$tdir
640 }
641 run_test 25a "change ACL on one mountpoint be seen on another ==="
642
643 test_25b() {
644         local acl=$(lctl get_param -n mdc.*MDT0000-mdc-*.connect_flags |
645                                                         grep -c acl)
646         [ "$acl" -lt 1 ] && skip "must have acl, skipping" && return
647
648         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
649
650         rm -rf $DIR1/$tdir
651         $LFS mkdir -i 1 $DIR1/$tdir
652         touch $DIR1/$tdir/f1 || error "touch $DIR1/$tdir/f1"
653         chmod 0755 $DIR1/$tdir/f1 || error "chmod 0755 $DIR1/$tdir/f1"
654
655         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #1"
656         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
657                 error "setfacl $DIR2/$tdir #1"
658         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #2"
659         setfacl -m u:$RUNAS_ID:r-x -m g:$RUNAS_GID:r-x $DIR1/$tdir ||
660                 error "setfacl $DIR2/$tdir #2"
661         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #3"
662         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
663                 error "setfacl $DIR2/$tdir #3"
664         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #4"
665         setfacl -x u:$RUNAS_ID: -x g:$RUNAS_GID: $DIR1/$tdir ||
666                 error "setfacl $DIR2/$tdir #4"
667         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #5"
668
669         rm -rf $DIR1/$tdir
670 }
671 run_test 25b "change ACL under remote dir on one mountpoint be seen on another"
672
673 test_26a() {
674         utime $DIR1/f26a -s $DIR2/f26a || error "utime failed for $DIR1/f26a"
675 }
676 run_test 26a "allow mtime to get older"
677
678 test_26b() {
679         touch $DIR1/$tfile
680         sleep 1
681         echo "aaa" >> $DIR1/$tfile
682         sleep 1
683         chmod a+x $DIR2/$tfile
684         mt1=`stat -c %Y $DIR1/$tfile`
685         mt2=`stat -c %Y $DIR2/$tfile`
686
687         if [ x"$mt1" != x"$mt2" ]; then
688                 error "not equal mtime, client1: "$mt1", client2: "$mt2"."
689         fi
690 }
691 run_test 26b "sync mtime between ost and mds"
692
693 test_27() {
694         cancel_lru_locks $OSC
695         lctl clear
696         dd if=/dev/zero of=$DIR2/$tfile bs=$((4096+4))k conv=notrunc count=4 seek=3 &
697         DD2_PID=$!
698         usleep 50
699         log "dd 1 started"
700
701         dd if=/dev/zero of=$DIR1/$tfile bs=$((16384-1024))k conv=notrunc count=1 seek=4 &
702         DD1_PID=$!
703         log "dd 2 started"
704
705         sleep 1
706         dd if=/dev/zero of=$DIR1/$tfile bs=8k conv=notrunc count=1 seek=0
707         log "dd 3 finished"
708         lctl set_param -n ldlm.dump_namespaces ""
709         wait $DD1_PID $DD2_PID
710         [ $? -ne 0 ] && lctl dk $TMP/debug || true
711 }
712 run_test 27 "align non-overlapping extent locks from request ==="
713
714 test_28() { # bug 9977
715         ECHO_UUID="ECHO_osc1_UUID"
716         tOST=$($LCTL dl | awk '/-osc-|OSC.*MNT/ { print $4 }' | head -n1)
717
718         $LFS setstripe $DIR1/$tfile -S 1048576 -i 0 -c 2
719         tOBJID=`$LFS getstripe $DIR1/$tfile | awk '$1 == 1 {print $2}'`
720         dd if=/dev/zero of=$DIR1/$tfile bs=1024k count=2
721
722         $LCTL <<-EOF
723                 newdev
724                 attach echo_client ECHO_osc1 $ECHO_UUID
725                 setup $tOST
726         EOF
727
728         tECHOID=`$LCTL dl | grep $ECHO_UUID | awk '{ print $1 }'`
729         $LCTL --device $tECHOID destroy "${tOBJID}:0"
730
731         $LCTL <<-EOF
732                 cfg_device ECHO_osc1
733                 cleanup
734                 detach
735         EOF
736
737         # reading of 1st stripe should pass
738         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 || error "dd failed"
739         # reading of 2nd stripe should fail (this stripe was destroyed)
740         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 skip=1 && error
741
742         # now, recreating test file
743         dd if=/dev/zero of=$DIR1/$tfile bs=1024k count=2 || error "dd failed"
744         # reading of 1st stripe should pass
745         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 || error "dd failed"
746         # reading of 2nd stripe should pass
747         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 skip=1 ||
748                 error "dd failed"
749 }
750 run_test 28 "read/write/truncate file with lost stripes"
751
752 test_30() { #b=11110, LU-2523
753         test_mkdir $DIR1/$tdir
754         cp -f /bin/bash $DIR1/$tdir/bash
755         /bin/sh -c 'sleep 1; rm -f $DIR2/$tdir/bash; cp /bin/bash $DIR2/$tdir' &
756         $DIR1/$tdir/bash -c 'sleep 2;
757                 openfile -f O_RDONLY /proc/$$/exe >& /dev/null; echo $?'
758         wait
759         true
760 }
761 run_test 30 "recreate file race"
762
763 test_31a() {
764         test_mkdir $DIR1/$tdir
765         local writes=$(LANG=C dd if=/dev/zero of=$DIR/$tdir/$tfile \
766                        count=1 2>&1 | awk 'BEGIN { FS="+" } /out/ {print $1}')
767         #define OBD_FAIL_LDLM_CANCEL_BL_CB_RACE   0x314
768         lctl set_param fail_loc=0x314
769         local reads=$(LANG=C dd if=$DIR2/$tdir/$tfile of=/dev/null 2>&1 |
770                       awk 'BEGIN { FS="+" } /in/ {print $1}')
771         [ $reads -eq $writes ] || error "read" $reads "blocks, must be" $writes
772 }
773 run_test 31a "voluntary cancel / blocking ast race=============="
774
775 test_31b() {
776         remote_ost || { skip "local OST" && return 0; }
777         remote_ost_nodsh && skip "remote OST w/o dsh" && return 0
778
779         # make sure there is no local locks due to destroy
780         wait_mds_ost_sync || error "wait_mds_ost_sync()"
781         wait_delete_completed || error "wait_delete_completed()"
782
783         test_mkdir $DIR1/$tdir
784         lfs setstripe $DIR/$tdir/$tfile -i 0 -c 1
785         cp /etc/hosts $DIR/$tdir/$tfile
786         #define OBD_FAIL_LDLM_CANCEL_BL_CB_RACE   0x314
787         lctl set_param fail_loc=0x314
788         #define OBD_FAIL_LDLM_OST_FAIL_RACE      0x316
789         do_facet ost1 lctl set_param fail_loc=0x316
790         # Don't crash kernel
791         cat $DIR2/$tdir/$tfile > /dev/null 2>&1
792         lctl set_param fail_loc=0
793         do_facet ost1 lctl set_param fail_loc=0
794         # cleanup: reconnect the client back
795         df $DIR2
796 }
797 run_test 31b "voluntary OST cancel / blocking ast race=============="
798
799 # enable/disable lockless truncate feature, depending on the arg 0/1
800 enable_lockless_truncate() {
801         lctl set_param -n $OSC.*.lockless_truncate $1
802 }
803
804 test_32a() { # bug 11270
805         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
806         local stripe_size=$(do_facet $SINGLEMDS \
807                 "$LCTL get_param -n lod.$(facet_svc $SINGLEMDS)*.stripesize")
808
809         save_lustre_params client "$OSC.*.lockless_truncate" > $save
810         # restore lockless_truncate default values on exit
811         stack_trap "restore_lustre_params < $save; rm -f $save" EXIT
812         cancel_lru_locks $OSC
813         enable_lockless_truncate 1
814         rm -f $DIR1/$tfile
815         lfs setstripe -c -1 $DIR1/$tfile
816         dd if=/dev/zero of=$DIR1/$tfile count=$OSTCOUNT bs=$stripe_size > \
817                 /dev/null 2>&1
818         clear_stats $OSC.*.${OSC}_stats
819
820         log "checking cached lockless truncate"
821         $TRUNCATE $DIR1/$tfile 8000000
822         $CHECKSTAT -s 8000000 $DIR2/$tfile || error "wrong file size"
823         [ $(calc_stats $OSC.*.${OSC}_stats lockless_truncate) -ne 0 ] ||
824                 error "cached truncate isn't lockless"
825
826         log "checking not cached lockless truncate"
827         $TRUNCATE $DIR2/$tfile 5000000
828         $CHECKSTAT -s 5000000 $DIR1/$tfile || error "wrong file size"
829         [ $(calc_stats $OSC.*.${OSC}_stats lockless_truncate) -ne 0 ] ||
830                 error "not cached truncate isn't lockless"
831
832         log "disabled lockless truncate"
833         enable_lockless_truncate 0
834         clear_stats $OSC.*.${OSC}_stats
835         $TRUNCATE $DIR2/$tfile 3000000
836         $CHECKSTAT -s 3000000 $DIR1/$tfile || error "wrong file size"
837         [ $(calc_stats $OSC.*.${OSC}_stats lockless_truncate) -eq 0 ] ||
838                 error "lockless truncate disabling failed"
839         rm -f $DIR1/$tfile
840 }
841 run_test 32a "lockless truncate"
842
843 test_32b() { # bug 11270
844         remote_ost_nodsh && skip "remote OST with nodsh" && return
845
846         local node
847         local facets=$(get_facets OST)
848         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
849
850         save_lustre_params client "osc.*.contention_seconds" > $p
851         save_lustre_params $facets \
852                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
853         save_lustre_params $facets \
854                 "ldlm.namespaces.filter-*.contended_locks" >> $p
855         save_lustre_params $facets \
856                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
857         clear_stats $OSC.*.${OSC}_stats
858
859         # agressive lockless i/o settings
860         do_nodes $(comma_list $(osts_nodes)) \
861                 "lctl set_param -n ldlm.namespaces.*.max_nolock_bytes=2000000 \
862                         ldlm.namespaces.filter-*.contended_locks=0 \
863                         ldlm.namespaces.filter-*.contention_seconds=60"
864         lctl set_param -n $OSC.*.contention_seconds=60
865         for i in {1..5}; do
866                 dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1 conv=notrunc > \
867                         /dev/null 2>&1
868                 dd if=/dev/zero of=$DIR2/$tfile bs=4k count=1 conv=notrunc > \
869                         /dev/null 2>&1
870         done
871         [ $(calc_stats $OSC.*.${OSC}_stats lockless_write_bytes) -ne 0 ] ||
872                 error "lockless i/o was not triggered"
873         # disable lockless i/o (it is disabled by default)
874         do_nodes $(comma_list $(osts_nodes)) \
875                 "lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes=0 \
876                         ldlm.namespaces.filter-*.contended_locks=32 \
877                         ldlm.namespaces.filter-*.contention_seconds=0"
878         # set contention_seconds to 0 at client too, otherwise Lustre still
879         # remembers lock contention
880         lctl set_param -n $OSC.*.contention_seconds=0
881         clear_stats $OSC.*.${OSC}_stats
882         for i in {1..1}; do
883                 dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1 conv=notrunc > \
884                         /dev/null 2>&1
885                 dd if=/dev/zero of=$DIR2/$tfile bs=4k count=1 conv=notrunc > \
886                         /dev/null 2>&1
887         done
888         [ $(calc_stats $OSC.*.${OSC}_stats lockless_write_bytes) -eq 0 ] ||
889                 error "lockless i/o works when disabled"
890         rm -f $DIR1/$tfile
891         restore_lustre_params <$p
892         rm -f $p
893 }
894 run_test 32b "lockless i/o"
895
896 print_jbd_stat () {
897     local dev
898     local mdts=$(get_facets MDS)
899     local varcvs
900     local mds
901
902     local stat=0
903     for mds in ${mdts//,/ }; do
904         varsvc=${mds}_svc
905         dev=$(basename $(do_facet $mds "lctl get_param -n osd*.${!varsvc}.mntdev|\
906                 xargs readlink -f" ))
907         val=$(do_facet $mds "cat /proc/fs/jbd*/${dev}{,:*,-*}/info 2>/dev/null |
908                 head -n1")
909         val=${val%% *};
910         stat=$(( stat + val))
911     done
912     echo $stat
913 }
914
915 # commit on sharing tests
916 test_33a() {
917     remote_mds_nodsh && skip "remote MDS with nodsh" && return
918
919     [ -z "$CLIENTS" ] && skip "Need two or more clients, have $CLIENTS" && return 0
920     [ $CLIENTCOUNT -lt 2 ] &&
921         skip "Need two or more clients, have $CLIENTCOUNT" && return 0
922
923     local nfiles=${TEST33_NFILES:-10000}
924     local param_file=$TMP/$tfile-params
925     local fstype=$(facet_fstype $SINGLEMDS)
926
927         save_lustre_params $(get_facets MDS) \
928                 "mdt.*.commit_on_sharing" > $param_file
929
930     local COS
931     local jbdold="N/A"
932     local jbdnew="N/A"
933     local jbd
934
935     for COS in 0 1; do
936         do_facet $SINGLEMDS lctl set_param mdt.*.commit_on_sharing=$COS
937         avgjbd=0
938         avgtime=0
939         for i in 1 2 3; do
940             do_nodes $CLIENT1,$CLIENT2 "mkdir -p $DIR1/$tdir-\\\$(hostname)-$i"
941
942             [ $fstype = ldiskfs ] && jbdold=$(print_jbd_stat)
943             echo "=== START createmany old: $jbdold transaction"
944             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")
945             [ $fstype = ldiskfs ] && jbdnew=$(print_jbd_stat)
946             [ $fstype = ldiskfs ] && jbd=$(( jbdnew - jbdold ))
947             echo "=== END   createmany new: $jbdnew transaction :  $jbd transactions  nfiles $nfiles time $elapsed COS=$COS"
948             [ $fstype = ldiskfs ] && avgjbd=$(( avgjbd + jbd ))
949             avgtime=$(( avgtime + elapsed ))
950         done
951         eval cos${COS}_jbd=$((avgjbd / 3))
952         eval cos${COS}_time=$((avgtime / 3))
953     done
954
955     echo "COS=0 transactions (avg): $cos0_jbd  time (avg): $cos0_time"
956     echo "COS=1 transactions (avg): $cos1_jbd  time (avg): $cos1_time"
957     [ "$cos0_jbd" != 0 ] && echo "COS=1 vs COS=0 jbd:  $((((cos1_jbd/cos0_jbd - 1)) * 100 )) %"
958     [ "$cos0_time" != 0 ] && echo "COS=1 vs COS=0 time: $((((cos1_time/cos0_time - 1)) * 100 )) %"
959
960     restore_lustre_params < $param_file
961     rm -f $param_file
962     return 0
963 }
964 run_test 33a "commit on sharing, cross crete/delete, 2 clients, benchmark"
965
966 # commit on sharing tests
967 test_33b() {
968         remote_mds_nodsh && skip "remote MDS with nodsh" && return
969
970         [ -n "$CLIENTS" ] || { skip "Need two or more clients" && return 0; }
971         [ $CLIENTCOUNT -ge 2 ] ||
972                 { skip "Need two or more clients, have $CLIENTCOUNT" &&
973                                                                 return 0; }
974         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
975
976         local nfiles=${TEST33_NFILES:-10000}
977         local param_file=$TMP/$tfile-params
978
979         save_lustre_params $(get_facets MDS) \
980                 "mdt.*.commit_on_sharing" > $param_file
981
982         local COS
983         local jbdold
984         local jbdnew
985         local jbd
986         local MDTIDX=1
987
988         for COS in 0 1; do
989                 do_facet $SINGLEMDS lctl set_param mdt.*.commit_on_sharing=$COS
990                 avgjbd=0
991                 avgtime=0
992                 for i in 1 2 3; do
993                         do_node $CLIENT1 "$LFS mkdir -i $MDTIDX \
994                                           $DIR1/$tdir-\\\$(hostname)-$i"
995
996                         jbdold=$(print_jbd_stat)
997                         echo "=== START createmany old: $jbdold transaction"
998                         local elapsed=$(do_and_time "do_nodes $CLIENT1,$CLIENT2\
999                                 createmany -o $DIR1/$tdir-\\\$(hostname)-$i/f- \
1000                                 -r$DIR2/$tdir-\\\$(hostname)-$i/f- $nfiles > \
1001                                                                 /dev/null 2>&1")
1002                         jbdnew=$(print_jbd_stat)
1003                         jbd=$(( jbdnew - jbdold ))
1004                         echo "=== END   createmany new: $jbdnew transaction : \
1005                         $jbd transactions nfiles $nfiles time $elapsed COS=$COS"
1006                         avgjbd=$(( avgjbd + jbd ))
1007                         avgtime=$(( avgtime + elapsed ))
1008                 done
1009                 eval cos${COS}_jbd=$((avgjbd / 3))
1010                 eval cos${COS}_time=$((avgtime / 3))
1011         done
1012
1013         echo "COS=0 transactions (avg): $cos0_jbd  time (avg): $cos0_time"
1014         echo "COS=1 transactions (avg): $cos1_jbd  time (avg): $cos1_time"
1015         [ "$cos0_jbd" != 0 ] &&
1016             echo "COS=1 vs COS=0 jbd: $(((cos1_jbd/cos0_jbd - 1) * 100)) %"
1017         [ "$cos0_time" != 0 ] &&
1018             echo "COS=1 vs COS=0 time: $(((cos1_time/cos0_time - 1) * 100)) %"
1019
1020         restore_lustre_params < $param_file
1021         rm -f $param_file
1022         return 0
1023 }
1024 run_test 33b "COS: cross create/delete, 2 clients, benchmark under remote dir"
1025
1026 test_33c() {
1027         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1028         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.63) ] &&
1029                 skip "DNE CoS not supported" && return
1030
1031         local sync_count
1032
1033         mkdir $DIR/$tdir
1034         sync_all_data
1035         do_facet mds1 "lctl set_param -n mdt.*.sync_count=0"
1036         # do twice in case transaction is committed before unlock, see LU-8200
1037         for i in 1 2; do
1038                 # remote dir is created on MDT1, which enqueued lock of $tdir on
1039                 # MDT0
1040                 $LFS mkdir -i 1 $DIR/$tdir/remote.$i
1041                 mkdir $DIR/$tdir/local.$i
1042         done
1043         sync_count=$(do_facet mds1 "lctl get_param -n mdt.*MDT0000.sync_count")
1044         echo "sync_count $sync_count"
1045         [ $sync_count -eq 0 ] && error "Sync-Lock-Cancel not triggered"
1046
1047         sync_all_data
1048         do_facet mds1 "lctl set_param -n mdt.*.sync_count=0"
1049         $LFS mkdir -i 1 $DIR/$tdir/remote.3
1050         # during sleep remote mkdir should have been committed and canceled
1051         # remote lock spontaneously, which shouldn't trigger sync
1052         sleep 6
1053         mkdir $DIR/$tdir/local.3
1054         sync_count=$(do_facet mds1 "lctl get_param -n mdt.*MDT0000.sync_count")
1055         echo "sync_count $sync_count"
1056         [ $sync_count -eq 0 ] || error "Sync-Lock-Cancel triggered"
1057 }
1058 run_test 33c "Cancel cross-MDT lock should trigger Sync-Lock-Cancel"
1059
1060 # arg1 is operations done before CoS, arg2 is the operation that triggers CoS
1061 op_trigger_cos() {
1062         local commit_nr
1063         local total=0
1064         local nodes=$(comma_list $(mdts_nodes))
1065
1066         sync_all_data
1067
1068         # trigger CoS twice in case transaction commit before unlock
1069         for i in 1 2; do
1070                 sh -c "$1"
1071                 do_nodes $nodes "lctl set_param -n mdt.*.async_commit_count=0"
1072                 sh -c "$2"
1073                 commit_nr=$(do_nodes $nodes \
1074                         "lctl get_param -n mdt.*.async_commit_count" | calc_sum)
1075                 total=$((total + commit_nr));
1076                 rm -rf $DIR/$tdir
1077                 sync_all_data
1078         done
1079
1080         echo "CoS count $total"
1081         [ $total -gt 0 ] || error "$2 didn't trigger CoS"
1082 }
1083
1084 test_33d() {
1085         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1086         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.63) ] &&
1087                 skip "DNE CoS not supported" && return
1088
1089         # remote directory create
1090         op_trigger_cos "mkdir $DIR/$tdir" "$LFS mkdir -i 1 $DIR/$tdir/subdir"
1091         # remote directory unlink
1092         op_trigger_cos "$LFS mkdir -i 1 $DIR/$tdir" "rmdir $DIR/$tdir"
1093         # striped directory create
1094         op_trigger_cos "mkdir $DIR/$tdir" "$LFS mkdir -c 2 $DIR/$tdir/subdir"
1095         # striped directory setattr
1096         op_trigger_cos "$LFS mkdir -c 2 $DIR/$tdir; touch $DIR/$tdir" \
1097                 "chmod 713 $DIR/$tdir"
1098         # striped directory unlink
1099         op_trigger_cos "$LFS mkdir -c 2 $DIR/$tdir; touch $DIR/$tdir" \
1100                 "rmdir $DIR/$tdir"
1101         # cross-MDT link
1102         op_trigger_cos "$LFS mkdir -c 2 $DIR/$tdir; \
1103                         $LFS mkdir -i 0 $DIR/$tdir/d1; \
1104                         $LFS mkdir -i 1 $DIR/$tdir/d2; \
1105                         touch $DIR/$tdir/d1/tgt" \
1106                 "ln $DIR/$tdir/d1/tgt $DIR/$tdir/d2/src"
1107         # cross-MDT rename
1108         op_trigger_cos "$LFS mkdir -c 2 $DIR/$tdir; \
1109                         $LFS mkdir -i 0 $DIR/$tdir/d1; \
1110                         $LFS mkdir -i 1 $DIR/$tdir/d2; \
1111                         touch $DIR/$tdir/d1/src" \
1112                 "mv $DIR/$tdir/d1/src $DIR/$tdir/d2/tgt"
1113         # migrate
1114         op_trigger_cos "$LFS mkdir -i 0 $DIR/$tdir" \
1115                 "$LFS migrate -m 1 $DIR/$tdir"
1116
1117         return 0
1118 }
1119 run_test 33d "DNE distributed operation should trigger COS"
1120
1121 test_33e() {
1122         [ -n "$CLIENTS" ] || { skip "Need two or more clients" && return 0; }
1123         [ $CLIENTCOUNT -ge 2 ] ||
1124                 { skip "Need two or more clients, have $CLIENTCOUNT" &&
1125                                                                 return 0; }
1126         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1127         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.63) ] &&
1128                 skip "DNE CoS not supported" && return
1129
1130         local client2=${CLIENT2:-$(hostname)}
1131
1132         sync
1133
1134         local nodes=$(comma_list $(mdts_nodes))
1135         do_nodes $nodes "lctl set_param -n mdt.*.async_commit_count=0"
1136
1137         $LFS mkdir -c 2 $DIR/$tdir
1138         mkdir $DIR/$tdir/subdir
1139         echo abc > $DIR/$tdir/$tfile
1140         do_node $client2 echo dfg >> $DIR/$tdir/$tfile
1141         do_node $client2 touch $DIR/$tdir/subdir
1142
1143         local async_commit_count=$(do_nodes $nodes \
1144                 "lctl get_param -n mdt.*.async_commit_count" | calc_sum)
1145         [ $async_commit_count -gt 0 ] && error "CoS triggerred"
1146
1147         return 0
1148 }
1149 run_test 33e "DNE local operation shouldn't trigger COS"
1150
1151 # End commit on sharing tests
1152
1153 get_ost_lock_timeouts() {
1154     local nodes=${1:-$(comma_list $(osts_nodes))}
1155
1156     local locks=$(do_nodes $nodes \
1157         "lctl get_param -n ldlm.namespaces.filter-*.lock_timeouts" | calc_sum)
1158
1159     echo $locks
1160 }
1161
1162 cleanup_34() {
1163         local i
1164         trap 0
1165         do_nodes $(comma_list $(osts_nodes)) \
1166                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
1167         for i in $(seq $OSTCOUNT); do
1168                 wait_osc_import_ready client ost$i
1169         done
1170 }
1171
1172 test_34() { #16129
1173         remote_ost_nodsh && skip "remote OST with nodsh" && return
1174         local OPER
1175         local lock_in
1176         local lock_out
1177         trap cleanup_34 EXIT RETURN
1178         for OPER in notimeout timeout ; do
1179                 rm $DIR1/$tfile 2>/dev/null
1180                 lock_in=$(get_ost_lock_timeouts)
1181                 if [ $OPER == "timeout" ] ; then
1182                         for j in `seq $OSTCOUNT`; do
1183                                 #define OBD_FAIL_PTLRPC_HPREQ_TIMEOUT    0x511
1184                                 do_facet ost$j lctl set_param fail_loc=0x511
1185                         done
1186                         echo lock should expire
1187                 else
1188                         for j in `seq $OSTCOUNT`; do
1189                                 #define OBD_FAIL_PTLRPC_HPREQ_NOTIMEOUT  0x512
1190                                 do_facet ost$j lctl set_param fail_loc=0x512
1191                         done
1192                         echo lock should not expire
1193                 fi
1194                 echo writing on client1
1195                 dd if=/dev/zero of=$DIR1/$tfile count=100 conv=notrunc > /dev/null 2>&1
1196                 sync &
1197                 echo reading on client2
1198                 dd of=/dev/null if=$DIR2/$tfile > /dev/null 2>&1
1199                 # wait for a lock timeout
1200                 sleep 4
1201                 lock_out=$(get_ost_lock_timeouts)
1202                 if [ $OPER == "timeout" ] ; then
1203                         if [ $lock_in == $lock_out ]; then
1204                                 error "no lock timeout happened"
1205                         else
1206                                 echo "success"
1207                         fi
1208                 else
1209                         if [ $lock_in != $lock_out ]; then
1210                                 error "lock timeout happened"
1211                         else
1212                                 echo "success"
1213                         fi
1214                 fi
1215         done
1216         cleanup_34
1217 }
1218 run_test 34 "no lock timeout under IO"
1219
1220 test_35() { # bug 17645
1221         local generation=[]
1222         local count=0
1223         gen=$(lctl get_param mdc.$FSNAME-MDT*-mdc-*.import | grep generation |
1224               awk '/generation/{print $2}')
1225         for g in $gen; do
1226                 generation[count]=$g
1227                 let count=count+1
1228         done
1229
1230         test_mkdir $MOUNT1/$tdir
1231         cancel_lru_locks mdc
1232
1233         # Let's initiate -EINTR situation by setting fail_loc and take
1234         # write lock on same file from same client. This will not cause
1235         # bl_ast yet as lock is already in local cache.
1236         #define OBD_FAIL_LDLM_INTR_CP_AST        0x317
1237         do_facet client "lctl set_param fail_loc=0x80000317"
1238         local timeout=$(do_facet $SINGLEMDS lctl get_param  -n timeout)
1239         let timeout=timeout*3
1240         local nr=0
1241         while test $nr -lt 10; do
1242                 log "Race attempt $nr"
1243                 local blk1=$(lctl get_param -n ldlm.services.ldlm_cbd.stats |
1244                              awk '/ldlm_bl_callback/ { print $2 }')
1245                 test "x$blk1" = "x" && blk1=0
1246                 createmany -o $MOUNT2/$tdir/a 4000 &
1247                 pid1=$!
1248                 sleep 1
1249
1250                 # Let's make conflict and bl_ast
1251                 ls -la $MOUNT1/$tdir > /dev/null &
1252                 pid2=$!
1253
1254                 log "Wait for $pid1 $pid2 for $timeout sec..."
1255                 sleep $timeout
1256                 kill -9 $pid1 $pid2 > /dev/null 2>&1
1257                 wait
1258                 local blk2=$(lctl get_param -n ldlm.services.ldlm_cbd.stats |
1259                              awk '/ldlm_bl_callback/ { print $2 }')
1260                 test "x$blk2" = "x" && blk2=0
1261                 test $blk2 -gt $blk1 && break
1262                 rm -fr $MOUNT1/$tdir
1263                 cancel_lru_locks mdc
1264                 let nr=nr+1
1265         done
1266         do_facet client "lctl set_param fail_loc=0x0"
1267         df -h $MOUNT1 $MOUNT2
1268         count=0
1269         gen=$(lctl get_param mdc.$FSNAME-MDT*-mdc-*.import | grep generation |
1270                 awk '/generation/{print $2}')
1271         for g in $gen; do
1272             if ! test "$g" -eq "${generation[count]}"; then
1273                 list=$(lctl list_param mdc.$FSNAME-MDT*-mdc-*.import)
1274                 local c=0
1275                 for imp in $list; do
1276                         if [ $c = $count ]; then
1277                                 break
1278                         fi
1279                         c=c+1
1280                 done
1281                 imp=$(echo "$imp" | awk -F"." '{print $2}')
1282                 error "Eviction happened on import $imp"
1283             fi
1284             let count=count+1
1285         done
1286 }
1287 run_test 35 "-EINTR cp_ast vs. bl_ast race does not evict client"
1288
1289 test_36() { #bug 16417
1290         local SIZE
1291         local SIZE_B
1292         local i
1293
1294         test_mkdir $DIR1/$tdir
1295         $LFS setstripe -c -1 $DIR1/$tdir
1296         i=0
1297         SIZE=50
1298         let SIZE_B=SIZE*1024*1024
1299         sync; sleep 2; sync # wait for delete thread
1300         wait_mds_ost_sync || error "wait_mds_ost_sync failed"
1301         wait_destroy_complete || error "wait_destroy_complete failed"
1302
1303         while [ $i -le 10 ]; do
1304                 lctl mark "start test - cycle ($i)"
1305                 local before=$(lfs_df $MOUNT1 | awk '/^filesystem/{ print $4; exit }')
1306                 dd if=/dev/zero of=$DIR1/$tdir/$tfile bs=1M count=$SIZE ||
1307                         error "dd $DIR1/$tdir/$tfile ${SIZE}MB failed"
1308                 sync          # sync data from client cache
1309                 sync_all_data # sync data from server cache (delayed allocation)
1310                 sleep 2
1311                 local after_dd=$(lfs_df $MOUNT1 | awk '/^filesystem/{ print $4; exit }')
1312                 multiop_bg_pause $DIR2/$tdir/$tfile O_r${SIZE_B}c || return 3
1313                 read_pid=$!
1314                 rm -f $DIR1/$tdir/$tfile
1315                 kill -USR1 $read_pid
1316                 wait $read_pid
1317                 sync; sleep 2; sync # Ensure new statfs
1318                 wait_delete_completed
1319                 local after=$(lfs_df $MOUNT1 | awk '/^filesystem/{ print $4; exit }')
1320                 echo "*** cycle($i) *** before($before) after_dd($after_dd)" \
1321                         "after($after)"
1322                 # this free space! not used
1323                 (( $after_dd <= $after)) ||
1324                         error "space leaked after_dd:$after_dd > after:$after"
1325                 let i=i+1
1326         done
1327 }
1328 run_test 36 "handle ESTALE/open-unlink correctly"
1329
1330 test_37() { # bug 18695
1331         test_mkdir $DIR1/$tdir
1332         multiop_bg_pause $DIR1/$tdir D_c || return 1
1333         MULTIPID=$!
1334         # create large directory (32kB seems enough from e2fsck, ~= 1000 files)
1335         createmany -m $DIR2/$tdir/f 10000
1336         # set mtime/atime backward
1337         touch -t 198001010000 $DIR2/$tdir
1338         kill -USR1 $MULTIPID
1339         nr_files=`lfs find $DIR1/$tdir -type f | wc -l`
1340         [ $nr_files -eq 10000 ] || error "$nr_files != 10000 truncated directory?"
1341
1342 }
1343 run_test 37 "check i_size is not updated for directory on close (bug 18695) =============="
1344
1345 # this should be set to past
1346 TEST_39_MTIME=`date -d "1 year ago" +%s`
1347
1348 # bug 11063
1349 test_39a() {
1350         local client1=${CLIENT1:-`hostname`}
1351         local client2=${CLIENT2:-`hostname`}
1352
1353         do_node $client1 "touch $DIR1/$tfile"
1354
1355         do_node $client1 "touch -m -d @$TEST_39_MTIME $DIR1/$tfile"
1356         local mtime1=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1357         [ "$mtime1" = $TEST_39_MTIME ] || \
1358                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
1359
1360         local d1=`do_node $client1 date +%s`
1361         do_node $client1 'echo hello >> '$DIR1/$tfile
1362         local d2=`do_node $client1 date +%s`
1363
1364         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1365         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
1366                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
1367
1368         do_node $client1 "mv $DIR1/$tfile $DIR1/$tfile-1"
1369
1370         for (( i=0; i < 2; i++ )) ; do
1371                 local mtime3=`do_node $client2 "stat -c %Y $DIR1/$tfile-1"`
1372                 [ "$mtime2" = "$mtime3" ] || \
1373                         error "mtime ($mtime2) changed (to $mtime3) on rename"
1374
1375                 cancel_lru_locks osc
1376                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1377         done
1378 }
1379 run_test 39a "test from 11063 =================================="
1380
1381 test_39b() {
1382         local client1=${CLIENT1:-`hostname`}
1383         local client2=${CLIENT2:-`hostname`}
1384
1385         touch $DIR1/$tfile
1386
1387         local mtime1=`stat -c %Y $DIR1/$tfile`
1388         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1389
1390         sleep 1
1391         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
1392
1393         for (( i=0; i < 2; i++ )) ; do
1394                 local mtime3=`stat -c %Y $DIR1/$tfile`
1395                 local mtime4=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1396
1397                 [ "$mtime3" = "$mtime4" ] || \
1398                         error "different mtime on clients: $mtime3, $mtime4"
1399                 [ "$mtime3" = $TEST_39_MTIME ] || \
1400                         error "lost mtime: $mtime3, should be $TEST_39_MTIME"
1401
1402                 cancel_lru_locks osc
1403                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1404         done
1405 }
1406 run_test 39b "11063 problem 1 =================================="
1407
1408 test_39c() {
1409         local client1=${CLIENT1:-`hostname`}
1410         local client2=${CLIENT2:-`hostname`}
1411
1412         echo hello > $DIR1/$tfile
1413
1414         local mtime1=`stat -c %Y $DIR1/$tfile`
1415         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1416         [ "$mtime1" = "$mtime2" ] || \
1417                 error "create: different mtime on clients: $mtime1, $mtime2"
1418
1419         sleep 1
1420         $TRUNCATE $DIR1/$tfile 1
1421
1422         for (( i=0; i < 2; i++ )) ; do
1423                 local mtime3=`stat -c %Y $DIR1/$tfile`
1424                 local mtime4=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1425
1426                 [ "$mtime3" = "$mtime4" ] || \
1427                         error "different mtime on clients: $mtime3, $mtime4"
1428                 [ "$mtime3" -gt $mtime2 ] || \
1429                         error "truncate did not update mtime: $mtime2, $mtime3"
1430
1431                 cancel_lru_locks osc
1432                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1433         done
1434 }
1435 run_test 39c "check truncate mtime update ======================"
1436
1437 test_39d() { # LU-7310
1438         touch $DIR1/$tfile
1439         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
1440
1441         local mtime1=$(stat -c %Y $DIR2/$tfile)
1442         [ "$mtime1" = $TEST_39_MTIME ] ||
1443                 error "mtime: $mtime1, should be $TEST_39_MTIME"
1444
1445         # force sync write
1446         # define OBD_FAIL_OSC_NO_GRANT 0x411
1447         $LCTL set_param fail_loc=0x411
1448
1449         local d1=$(date +%s)
1450         echo hello >> $DIR1/$tfile
1451         local d2=$(date +%s)
1452
1453         $LCTL set_param fail_loc=0
1454
1455         cancel_lru_locks $OSC
1456
1457         local mtime2=$(stat -c %Y $DIR2/$tfile)
1458         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] ||
1459                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
1460 }
1461 run_test 39d "sync write should update mtime"
1462
1463 pdo_sched() {
1464         # how long 40-47 take with specific delay
1465         # sleep 0.1 # 78s
1466         sleep 0.2 # 103s
1467         # sleep 0.3 # 124s
1468         # sleep 0.5 # 164s
1469 }
1470
1471 # check that pid exists hence second operation wasn't blocked by first one
1472 # if it is so then there is no conflict, return 0
1473 # else second operation is conflicting with first one, return 1
1474 check_pdo_conflict() {
1475         local pid=$1
1476         local conflict=0
1477         pdo_sched # to ensure OP1 is finished on client if OP2 is blocked by OP1
1478         if [[ `ps --pid $pid | wc -l` == 1 ]]; then
1479                 conflict=1
1480                 echo "Conflict"
1481         else
1482                 echo "No conflict"
1483         fi
1484         return $conflict
1485 }
1486
1487 # pdirop tests
1488 # test 40: check non-blocking operations
1489 test_40a() {
1490         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1491 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1492         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1493         touch $DIR2
1494         mkdir $DIR1/$tfile &
1495         PID1=$!; pdo_sched
1496         touch $DIR2/$tfile-2
1497         check_pdo_conflict $PID1 || error "create is blocked"
1498         mkdir $DIR2/$tfile-3
1499         check_pdo_conflict $PID1 || error "mkdir is blocked"
1500         link $DIR2/$tfile-2 $DIR2/$tfile-4
1501         check_pdo_conflict $PID1 || error "link is blocked"
1502         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1503         check_pdo_conflict $PID1 || error "rename is blocked"
1504         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1505         check_pdo_conflict $PID1 || error "getattr is blocked"
1506         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1507         rmdir $DIR2/$tfile-3
1508         check_pdo_conflict $PID1 || error "unlink is blocked"
1509
1510         #  all operations above shouldn't wait the first one
1511         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1512         do_facet $SINGLEMDS lctl set_param fail_loc=0
1513         wait $PID1
1514         rm -rf $DIR/$tfile*
1515         return 0
1516 }
1517 run_test 40a "pdirops: create vs others =============="
1518
1519 test_40b() {
1520         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1521 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1522         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1523         touch $DIR1/$tfile &
1524         PID1=$!; pdo_sched
1525         # open|create
1526         touch $DIR2/$tfile-2
1527         check_pdo_conflict $PID1 || error "create is blocked"
1528         mkdir $DIR2/$tfile-3
1529         check_pdo_conflict $PID1 || error "mkdir is blocked"
1530         link $DIR2/$tfile-2 $DIR2/$tfile-4
1531         check_pdo_conflict $PID1 || error "link is blocked"
1532         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1533         check_pdo_conflict $PID1 || error "rename is blocked"
1534         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1535         check_pdo_conflict $PID1 || error "getattr is blocked"
1536         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1537         rmdir $DIR2/$tfile-3
1538         check_pdo_conflict $PID1 || error "unlink is blocked"
1539         # all operations above shouldn't wait the first one
1540
1541         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1542         do_facet $SINGLEMDS lctl set_param fail_loc=0
1543         wait $PID1
1544         rm -rf $DIR/$tfile*
1545         return 0
1546 }
1547 run_test 40b "pdirops: open|create and others =============="
1548
1549 test_40c() {
1550         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1551         touch $DIR1/$tfile
1552 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1553         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1554         link $DIR1/$tfile $DIR1/$tfile-0 &
1555         PID1=$!; pdo_sched
1556         # open|create
1557         touch $DIR2/$tfile-2
1558         check_pdo_conflict $PID1 || error "create is blocked"
1559         mkdir $DIR2/$tfile-3
1560         check_pdo_conflict $PID1 || error "mkdir is blocked"
1561         link $DIR2/$tfile-2 $DIR2/$tfile-4
1562         check_pdo_conflict $PID1 || error "link is blocked"
1563         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1564         check_pdo_conflict $PID1 || error "rename is blocked"
1565         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1566         check_pdo_conflict $PID1 || error "getattr is blocked"
1567         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1568         rmdir $DIR2/$tfile-3
1569         check_pdo_conflict $PID1 || error "unlink is blocked"
1570
1571         # all operations above shouldn't wait the first one
1572         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1573         do_facet $SINGLEMDS lctl set_param fail_loc=0
1574         wait $PID1
1575         rm -rf $DIR/$tfile*
1576         return 0
1577 }
1578 run_test 40c "pdirops: link and others =============="
1579
1580 test_40d() {
1581         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1582         touch $DIR1/$tfile
1583 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1584         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1585         rm $DIR1/$tfile &
1586         PID1=$!; pdo_sched
1587         # open|create
1588         touch $DIR2/$tfile-2
1589         check_pdo_conflict $PID1 || error "create is blocked"
1590         mkdir $DIR2/$tfile-3
1591         check_pdo_conflict $PID1 || error "mkdir is blocked"
1592         link $DIR2/$tfile-2 $DIR2/$tfile-4
1593         check_pdo_conflict $PID1 || error "link is blocked"
1594         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1595         check_pdo_conflict $PID1 || error "rename is blocked"
1596         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1597         check_pdo_conflict $PID1 || error "getattr is blocked"
1598         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1599         rmdir $DIR2/$tfile-3
1600         check_pdo_conflict $PID1 || error "unlink is blocked"
1601
1602         # all operations above shouldn't wait the first one
1603         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1604         do_facet $SINGLEMDS lctl set_param fail_loc=0
1605         wait $PID1
1606         return 0
1607 }
1608 run_test 40d "pdirops: unlink and others =============="
1609
1610 test_40e() {
1611         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1612         touch $DIR1/$tfile
1613 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1614         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1615         mv $DIR1/$tfile $DIR1/$tfile-0 &
1616         PID1=$!; pdo_sched
1617         # open|create
1618         touch $DIR2/$tfile-2
1619         check_pdo_conflict $PID1 || error "create is blocked"
1620         mkdir $DIR2/$tfile-3
1621         check_pdo_conflict $PID1 || error "mkdir is blocked"
1622         link $DIR2/$tfile-2 $DIR2/$tfile-4
1623         check_pdo_conflict $PID1 || error "link is blocked"
1624         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1625         check_pdo_conflict $PID1 || error "getattr is blocked"
1626         rm $DIR2/$tfile-4 $DIR2/$tfile-2
1627         rmdir $DIR2/$tfile-3
1628         check_pdo_conflict $PID1 || error "unlink is blocked"
1629
1630        # all operations above shouldn't wait the first one
1631         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1632         do_facet $SINGLEMDS lctl set_param fail_loc=0
1633         wait $PID1
1634         rm -rf $DIR/$tfile*
1635         return 0
1636 }
1637 run_test 40e "pdirops: rename and others =============="
1638
1639 # test 41: create blocking operations
1640 test_41a() {
1641 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1642         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1643         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1644         PID1=$! ; pdo_sched
1645         mkdir $DIR2/$tfile &
1646         PID2=$! ; pdo_sched
1647         do_facet $SINGLEMDS lctl set_param fail_loc=0
1648         check_pdo_conflict $PID1 && { wait $PID1; echo "mkdir isn't blocked"; }
1649         wait $PID2 ; [ $? -ne 0 ] || error "mkdir must fail"
1650         rm -rf $DIR/$tfile*
1651         return 0
1652 }
1653 run_test 41a "pdirops: create vs mkdir =============="
1654
1655 test_41b() {
1656 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1657         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1658         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1659         PID1=$! ; pdo_sched
1660         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
1661         PID2=$! ; pdo_sched
1662         do_facet $SINGLEMDS lctl set_param fail_loc=0
1663         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1664         wait $PID2 ; [ $? -ne 0 ] || error "create must fail"
1665         rm -rf $DIR/$tfile*
1666         return 0
1667 }
1668 run_test 41b "pdirops: create vs create =============="
1669
1670 test_41c() {
1671         touch $DIR1/$tfile-2
1672 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1673         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1674         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1675         PID1=$! ; pdo_sched
1676         link $DIR2/$tfile-2 $DIR2/$tfile &
1677         PID2=$! ; pdo_sched
1678         do_facet $SINGLEMDS lctl set_param fail_loc=0
1679         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1680         wait $PID2 ; [ $? -ne 0 ] || error "link must fail"
1681         rm -rf $DIR/$tfile*
1682         return 0
1683 }
1684 run_test 41c "pdirops: create vs link =============="
1685
1686 test_41d() {
1687 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1688         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1689         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1690         PID1=$! ; pdo_sched
1691         rm $DIR2/$tfile &
1692         PID2=$! ; pdo_sched
1693         do_facet $SINGLEMDS lctl set_param fail_loc=0
1694         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1695         wait $PID2 ; [ $? -eq 0 ] || error "unlink must succeed"
1696         rm -rf $DIR/$tfile*
1697         return 0
1698 }
1699 run_test 41d "pdirops: create vs unlink =============="
1700
1701 test_41e() {
1702         touch $DIR1/$tfile-2
1703 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1704         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1705         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1706         PID1=$! ; pdo_sched
1707         mv $DIR2/$tfile-2 $DIR2/$tfile &
1708         PID2=$! ; pdo_sched
1709         do_facet $SINGLEMDS lctl set_param fail_loc=0
1710         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1711         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
1712         rm -rf $DIR/$tfile*
1713         return 0
1714 }
1715 run_test 41e "pdirops: create and rename (tgt) =============="
1716
1717 test_41f() {
1718 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1719         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1720         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1721         PID1=$! ; pdo_sched
1722         mv $DIR2/$tfile $DIR2/$tfile-2 &
1723         PID2=$! ; pdo_sched
1724         do_facet $SINGLEMDS lctl set_param fail_loc=0
1725         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1726         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
1727         rm -rf $DIR/$tfile*
1728         return 0
1729 }
1730 run_test 41f "pdirops: create and rename (src) =============="
1731
1732 test_41g() {
1733 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1734         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1735         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1736         PID1=$! ; pdo_sched
1737         stat $DIR2/$tfile > /dev/null &
1738         PID2=$! ; pdo_sched
1739         do_facet $SINGLEMDS lctl set_param fail_loc=0
1740         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1741         wait $PID2 ; [ $? -eq 0 ] || error "stat must succeed"
1742         rm -rf $DIR/$tfile*
1743         return 0
1744 }
1745 run_test 41g "pdirops: create vs getattr =============="
1746
1747 test_41h() {
1748 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1749         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1750         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1751         PID1=$! ; pdo_sched
1752         ls -lia $DIR2/ > /dev/null &
1753         PID2=$! ; pdo_sched
1754         do_facet $SINGLEMDS lctl set_param fail_loc=0
1755         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1756         wait $PID2
1757         rm -rf $DIR/$tfile*
1758         return 0
1759 }
1760 run_test 41h "pdirops: create vs readdir =============="
1761
1762 # test 42: unlink and blocking operations
1763 test_42a() {
1764 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1765         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1766         mkdir $DIR1/$tfile &
1767         PID1=$! ; pdo_sched
1768         mkdir $DIR2/$tfile &
1769         PID2=$! ; pdo_sched
1770         do_facet $SINGLEMDS lctl set_param fail_loc=0
1771         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1772         wait $PID2 ; [ $? -ne 0 ] || error "mkdir must fail"
1773         rm -rf $DIR/$tfile*
1774         return 0
1775 }
1776 run_test 42a "pdirops: mkdir vs mkdir =============="
1777
1778 test_42b() {
1779 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1780         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1781         mkdir $DIR1/$tfile &
1782         PID1=$! ; pdo_sched
1783         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
1784         PID2=$! ; pdo_sched
1785         do_facet $SINGLEMDS lctl set_param fail_loc=0
1786         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1787         wait $PID2 ; [ $? -ne 0 ] || error "create must fail"
1788         rm -rf $DIR/$tfile*
1789         return 0
1790 }
1791 run_test 42b "pdirops: mkdir vs create =============="
1792
1793 test_42c() {
1794         touch $DIR1/$tfile-2
1795 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1796         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1797         mkdir $DIR1/$tfile &
1798         PID1=$! ; pdo_sched
1799         link $DIR2/$tfile-2 $DIR2/$tfile &
1800         PID2=$! ; pdo_sched
1801         do_facet $SINGLEMDS lctl set_param fail_loc=0
1802         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1803         wait $PID2 ; [ $? -ne 0 ] || error "link must fail"
1804         rm -rf $DIR/$tfile*
1805         return 0
1806 }
1807 run_test 42c "pdirops: mkdir vs link =============="
1808
1809 test_42d() {
1810 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1811         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1812         mkdir $DIR1/$tfile &
1813         PID1=$! ; pdo_sched
1814         rmdir $DIR2/$tfile &
1815         PID2=$! ; pdo_sched
1816         do_facet $SINGLEMDS lctl set_param fail_loc=0
1817         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1818         wait $PID2 ; [ $? -eq 0 ] || error "unlink must succeed"
1819         rm -rf $DIR/$tfile*
1820         return 0
1821 }
1822 run_test 42d "pdirops: mkdir vs unlink =============="
1823
1824 test_42e() {
1825         touch $DIR1/$tfile-2
1826 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1827         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1828         mkdir $DIR1/$tfile &
1829         PID1=$! ; pdo_sched
1830         mv -T $DIR2/$tfile-2 $DIR2/$tfile &
1831         PID2=$! ; pdo_sched
1832         do_facet $SINGLEMDS lctl set_param fail_loc=0
1833         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1834         wait $PID2 ; [ $? -ne 0 ] || error "rename must fail"
1835         rm -rf $DIR/$tfile*
1836         return 0
1837 }
1838 run_test 42e "pdirops: mkdir and rename (tgt) =============="
1839
1840 test_42f() {
1841 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1842         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1843         mkdir $DIR1/$tfile &
1844         PID1=$! ; pdo_sched
1845         mv $DIR2/$tfile $DIR2/$tfile-2 &
1846         PID2=$! ; pdo_sched
1847         do_facet $SINGLEMDS lctl set_param fail_loc=0
1848         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1849         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
1850         rm -rf $DIR/$tfile*
1851         return 0
1852 }
1853 run_test 42f "pdirops: mkdir and rename (src) =============="
1854
1855 test_42g() {
1856 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1857         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1858         mkdir $DIR1/$tfile &
1859         PID1=$! ; pdo_sched
1860         stat $DIR2/$tfile > /dev/null &
1861         PID2=$! ; pdo_sched
1862         do_facet $SINGLEMDS lctl set_param fail_loc=0
1863         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1864         wait $PID2 ; [ $? -eq 0 ] || error "stat must succeed"
1865         rm -rf $DIR/$tfile*
1866         return 0
1867 }
1868 run_test 42g "pdirops: mkdir vs getattr =============="
1869
1870 test_42h() {
1871 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1872         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1873         mkdir $DIR1/$tfile &
1874         PID1=$! ; pdo_sched
1875         ls -lia $DIR2/ > /dev/null &
1876         PID2=$! ; pdo_sched
1877         do_facet $SINGLEMDS lctl set_param fail_loc=0
1878         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1879         wait $PID2
1880         rm -rf $DIR/$tfile*
1881         return 0
1882 }
1883 run_test 42h "pdirops: mkdir vs readdir =============="
1884
1885 # test 43: unlink and blocking operations
1886 test_43a() {
1887         touch $DIR1/$tfile
1888 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1889         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1890         rm $DIR1/$tfile &
1891         PID1=$! ; pdo_sched
1892         mkdir $DIR2/$tfile &
1893         PID2=$! ; pdo_sched
1894         do_facet $SINGLEMDS lctl set_param fail_loc=0
1895         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1896         wait $PID2 ; [ $? -eq 0 ] || error "mkdir must succeed"
1897         rm -rf $DIR/$tfile*
1898         return 0
1899 }
1900 run_test 43a "pdirops: unlink vs mkdir =============="
1901
1902 test_43b() {
1903         touch $DIR1/$tfile
1904 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1905         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1906         rm $DIR1/$tfile &
1907         PID1=$! ; pdo_sched
1908         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
1909         PID2=$! ; pdo_sched
1910         do_facet $SINGLEMDS lctl set_param fail_loc=0
1911         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1912         wait $PID2 ; [ $? -eq 0 ] || error "create must succeed"
1913         rm -rf $DIR/$tfile*
1914         return 0
1915 }
1916 run_test 43b "pdirops: unlink vs create =============="
1917
1918 test_43c() {
1919         touch $DIR1/$tfile
1920         touch $DIR1/$tfile-2
1921 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1922         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1923         rm $DIR1/$tfile &
1924         PID1=$! ; pdo_sched
1925         link $DIR2/$tfile-2 $DIR2/$tfile &
1926         PID2=$! ; pdo_sched
1927         do_facet $SINGLEMDS lctl set_param fail_loc=0
1928         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1929         wait $PID2 ; [ $? -eq 0 ] || error "link must succeed"
1930         rm -rf $DIR/$tfile*
1931         return 0
1932 }
1933 run_test 43c "pdirops: unlink vs link =============="
1934
1935 test_43d() {
1936         touch $DIR1/$tfile
1937 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1938         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1939         rm $DIR1/$tfile &
1940         PID1=$! ; pdo_sched
1941         rm $DIR2/$tfile &
1942         PID2=$! ; pdo_sched
1943         do_facet $SINGLEMDS lctl set_param fail_loc=0
1944         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1945         wait $PID2 ; [ $? -ne 0 ] || error "unlink must fail"
1946         rm -rf $DIR/$tfile*
1947         return 0
1948 }
1949 run_test 43d "pdirops: unlink vs unlink =============="
1950
1951 test_43e() {
1952         touch $DIR1/$tfile
1953         touch $DIR1/$tfile-2
1954 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1955         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1956         rm $DIR1/$tfile &
1957         PID1=$! ; pdo_sched
1958         mv -u $DIR2/$tfile-2 $DIR2/$tfile &
1959         PID2=$! ; pdo_sched
1960         do_facet $SINGLEMDS lctl set_param fail_loc=0
1961         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1962         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
1963         rm -rf $DIR/$tfile*
1964         return 0
1965 }
1966 run_test 43e "pdirops: unlink and rename (tgt) =============="
1967
1968 test_43f() {
1969         touch $DIR1/$tfile
1970 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1971         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1972         rm $DIR1/$tfile &
1973         PID1=$! ; pdo_sched
1974         mv $DIR2/$tfile $DIR2/$tfile-2 &
1975         PID2=$! ; pdo_sched
1976         do_facet $SINGLEMDS lctl set_param fail_loc=0
1977         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1978         wait $PID2 ; [ $? -ne 0 ] || error "rename must fail"
1979         rm -rf $DIR/$tfile*
1980         return 0
1981 }
1982 run_test 43f "pdirops: unlink and rename (src) =============="
1983
1984 test_43g() {
1985         touch $DIR1/$tfile
1986 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1987         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1988         rm $DIR1/$tfile &
1989         PID1=$! ; pdo_sched
1990         stat $DIR2/$tfile > /dev/null &
1991         PID2=$! ; pdo_sched
1992         do_facet $SINGLEMDS lctl set_param fail_loc=0
1993         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1994         wait $PID2 ; [ $? -ne 0 ] || error "stat must fail"
1995         rm -rf $DIR/$tfile*
1996         return 0
1997 }
1998 run_test 43g "pdirops: unlink vs getattr =============="
1999
2000 test_43h() {
2001         touch $DIR1/$tfile
2002 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2003         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2004         rm $DIR1/$tfile &
2005         PID1=$! ; pdo_sched
2006         ls -lia $DIR2/ > /dev/null &
2007         PID2=$! ; pdo_sched
2008         do_facet $SINGLEMDS lctl set_param fail_loc=0
2009         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
2010         wait $PID2
2011         rm -rf $DIR/$tfile*
2012         return 0
2013 }
2014 run_test 43h "pdirops: unlink vs readdir =============="
2015
2016 test_43i() {
2017         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2018         touch $DIR1/$tfile
2019 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2020         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2021         rm $DIR1/$tfile &
2022         PID1=$! ; pdo_sched
2023         $LFS mkdir -i 1 $DIR2/$tfile &
2024         PID2=$! ; pdo_sched
2025         do_facet $SINGLEMDS lctl set_param fail_loc=0
2026         check_pdo_conflict $PID1 &&
2027                 { wait $PID1; error "remote mkdir isn't blocked"; }
2028         wait $PID2 ; [ $? -eq 0 ] || error "remote mkdir must succeed"
2029         rm -rf $DIR/$tfile*
2030         return 0
2031 }
2032 run_test 43i "pdirops: unlink vs remote mkdir"
2033
2034 # test 44: rename tgt and blocking operations
2035 test_44a() {
2036         touch $DIR1/$tfile-2
2037 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
2038         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2039         mv $DIR1/$tfile-2 $DIR1/$tfile &
2040         PID1=$! ; pdo_sched
2041         mkdir $DIR2/$tfile &
2042         PID2=$! ; pdo_sched
2043         do_facet $SINGLEMDS lctl set_param fail_loc=0
2044         check_pdo_conflict $PID1 && { wait $PID1; date;error "mkdir isn't blocked"; }
2045         wait $PID2 ; [ $? -ne 0 ] || error "mkdir must fail"
2046         date
2047         rm -rf $DIR/$tfile*
2048         return 0
2049 }
2050 run_test 44a "pdirops: rename tgt vs mkdir =============="
2051
2052 test_44b() {
2053         touch $DIR1/$tfile-2
2054 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2055         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2056         mv $DIR1/$tfile-2 $DIR1/$tfile &
2057         PID1=$! ; pdo_sched
2058         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
2059         PID2=$! ; pdo_sched
2060         do_facet $SINGLEMDS lctl set_param fail_loc=0
2061         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
2062         wait $PID2 ; [ $? -ne 0 ] || error "create must fail"
2063         rm -rf $DIR/$tfile*
2064         return 0
2065 }
2066 run_test 44b "pdirops: rename tgt vs create =============="
2067
2068 test_44c() {
2069         touch $DIR1/$tfile-2
2070         touch $DIR1/$tfile-3
2071 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2072         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2073         mv $DIR1/$tfile-2 $DIR1/$tfile &
2074         PID1=$! ; pdo_sched
2075         link $DIR2/$tfile-3 $DIR2/$tfile &
2076         PID2=$! ; pdo_sched
2077         do_facet $SINGLEMDS lctl set_param fail_loc=0
2078         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2079         wait $PID2 ; [ $? -ne 0 ] || error "link must fail"
2080         rm -rf $DIR/$tfile*
2081         return 0
2082 }
2083 run_test 44c "pdirops: rename tgt vs link =============="
2084
2085 test_44d() {
2086         touch $DIR1/$tfile-2
2087 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2088         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2089         mv $DIR1/$tfile-2 $DIR1/$tfile &
2090         PID1=$! ; pdo_sched
2091         rm $DIR2/$tfile &
2092         PID2=$! ; pdo_sched
2093         do_facet $SINGLEMDS lctl set_param fail_loc=0
2094         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
2095         wait $PID2 ; [ $? -eq 0 ] || error "unlink must succeed"
2096         rm -rf $DIR/$tfile*
2097         return 0
2098 }
2099 run_test 44d "pdirops: rename tgt vs unlink =============="
2100
2101 test_44e() {
2102         touch $DIR1/$tfile
2103         touch $DIR1/$tfile-2
2104         touch $DIR1/$tfile-3
2105 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2106         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2107         mv $DIR1/$tfile-2 $DIR1/$tfile &
2108         PID1=$! ; pdo_sched
2109         mv $DIR2/$tfile-3 $DIR2/$tfile &
2110         PID2=$! ; pdo_sched
2111         do_facet $SINGLEMDS lctl set_param fail_loc=0
2112         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2113         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
2114         rm -rf $DIR/$tfile*
2115         return 0
2116 }
2117 run_test 44e "pdirops: rename tgt and rename (tgt) =============="
2118
2119 test_44f() {
2120         touch $DIR1/$tfile-2
2121         touch $DIR1/$tfile-3
2122 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2123         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2124         mv $DIR1/$tfile-2 $DIR1/$tfile &
2125         PID1=$! ; pdo_sched
2126         mv $DIR2/$tfile $DIR2/$tfile-3 &
2127         PID2=$! ; pdo_sched
2128         do_facet $SINGLEMDS lctl set_param fail_loc=0
2129         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2130         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
2131         rm -rf $DIR/$tfile*
2132         return 0
2133 }
2134 run_test 44f "pdirops: rename tgt and rename (src) =============="
2135
2136 test_44g() {
2137         touch $DIR1/$tfile-2
2138 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2139         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2140         mv $DIR1/$tfile-2 $DIR1/$tfile &
2141         PID1=$! ; pdo_sched
2142         stat $DIR2/$tfile > /dev/null &
2143         PID2=$! ; pdo_sched
2144         do_facet $SINGLEMDS lctl set_param fail_loc=0
2145         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
2146         wait $PID2 ; [ $? -eq 0 ] || error "stat must succeed"
2147         rm -rf $DIR/$tfile*
2148         return 0
2149 }
2150 run_test 44g "pdirops: rename tgt vs getattr =============="
2151
2152 test_44h() {
2153         touch $DIR1/$tfile-2
2154 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2155         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2156         mv $DIR1/$tfile-2 $DIR1/$tfile &
2157         PID1=$! ; pdo_sched
2158         ls -lia $DIR2/ > /dev/null &
2159         PID2=$! ; pdo_sched
2160         do_facet $SINGLEMDS lctl set_param fail_loc=0
2161         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
2162         wait $PID2
2163         rm -rf $DIR/$tfile*
2164         return 0
2165 }
2166 run_test 44h "pdirops: rename tgt vs readdir =============="
2167
2168 # test 44: rename tgt and blocking operations
2169 test_44i() {
2170         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2171         touch $DIR1/$tfile-2
2172 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
2173         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2174         mv $DIR1/$tfile-2 $DIR1/$tfile &
2175         PID1=$! ; pdo_sched
2176         $LFS mkdir -i 1 $DIR2/$tfile &
2177         PID2=$! ; pdo_sched
2178         do_facet $SINGLEMDS lctl set_param fail_loc=0
2179         check_pdo_conflict $PID1 && { wait $PID1;
2180                                 error "remote mkdir isn't blocked"; }
2181         wait $PID2 ; [ $? -ne 0 ] || error "remote mkdir must fail"
2182         rm -rf $DIR/$tfile*
2183         return 0
2184 }
2185 run_test 44i "pdirops: rename tgt vs remote mkdir"
2186
2187 # test 45: rename src and blocking operations
2188 test_45a() {
2189         touch $DIR1/$tfile
2190 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2191         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2192         mv $DIR1/$tfile $DIR1/$tfile-2 &
2193         PID1=$! ; pdo_sched
2194         mkdir $DIR2/$tfile &
2195         PID2=$! ; pdo_sched
2196         do_facet $SINGLEMDS lctl set_param fail_loc=0
2197         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
2198         wait $PID2 ; [ $? -eq 0 ] || error "mkdir must succeed"
2199         rm -rf $DIR/$tfile*
2200         return 0
2201 }
2202 run_test 45a "pdirops: rename src vs mkdir =============="
2203
2204 test_45b() {
2205         touch $DIR1/$tfile
2206 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2207         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2208         mv $DIR1/$tfile $DIR1/$tfile-2 &
2209         PID1=$! ; pdo_sched
2210         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
2211         PID2=$! ; pdo_sched
2212         do_facet $SINGLEMDS lctl set_param fail_loc=0
2213         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
2214         wait $PID2 ; [ $? -eq 0 ] || error "create must succeed"
2215         rm -rf $DIR/$tfile*
2216         return 0
2217 }
2218 run_test 45b "pdirops: rename src vs create =============="
2219
2220 test_45c() {
2221         touch $DIR1/$tfile
2222         touch $DIR1/$tfile-3
2223 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2224         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2225         mv $DIR1/$tfile $DIR1/$tfile-2 &
2226         PID1=$! ; pdo_sched
2227         link $DIR2/$tfile-3 $DIR2/$tfile &
2228         PID2=$! ; pdo_sched
2229         do_facet $SINGLEMDS lctl set_param fail_loc=0
2230         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2231         wait $PID2 ; [ $? -eq 0 ] || error "link must succeed"
2232         rm -rf $DIR/$tfile*
2233         return 0
2234 }
2235 run_test 45c "pdirops: rename src vs link =============="
2236
2237 test_45d() {
2238         touch $DIR1/$tfile
2239 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2240         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2241         mv $DIR1/$tfile $DIR1/$tfile-2 &
2242         PID1=$! ; pdo_sched
2243         rm $DIR2/$tfile &
2244         PID2=$! ; pdo_sched
2245         do_facet $SINGLEMDS lctl set_param fail_loc=0
2246         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
2247         wait $PID2 ; [ $? -ne 0 ] || error "unlink must fail"
2248         rm -rf $DIR/$tfile*
2249         return 0
2250 }
2251 run_test 45d "pdirops: rename src vs unlink =============="
2252
2253 test_45e() {
2254         touch $DIR1/$tfile
2255         touch $DIR1/$tfile-3
2256 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2257         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2258         mv $DIR1/$tfile $DIR1/$tfile-2 &
2259         PID1=$! ; pdo_sched
2260         mv $DIR2/$tfile-3 $DIR2/$tfile &
2261         PID2=$! ; pdo_sched
2262         do_facet $SINGLEMDS lctl set_param fail_loc=0
2263         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2264         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
2265         rm -rf $DIR/$tfile*
2266         return 0
2267 }
2268 run_test 45e "pdirops: rename src and rename (tgt) =============="
2269
2270 test_45f() {
2271         touch $DIR1/$tfile
2272 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2273         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2274         mv $DIR1/$tfile $DIR1/$tfile-2 &
2275         PID1=$! ; pdo_sched
2276         mv $DIR2/$tfile $DIR2/$tfile-3 &
2277         PID2=$! ; pdo_sched
2278         do_facet $SINGLEMDS lctl set_param fail_loc=0
2279         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2280         wait $PID2 ; [ $? -ne 0 ] || error "rename must fail"
2281         rm -rf $DIR/$tfile*
2282         return 0
2283 }
2284 run_test 45f "pdirops: rename src and rename (src) =============="
2285
2286 test_45g() {
2287         touch $DIR1/$tfile
2288 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2289         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2290         mv $DIR1/$tfile $DIR1/$tfile-2 &
2291         PID1=$! ; pdo_sched
2292         stat $DIR2/$tfile > /dev/null &
2293         PID2=$! ; pdo_sched
2294         do_facet $SINGLEMDS lctl set_param fail_loc=0
2295         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
2296         wait $PID2 ; [ $? -ne 0 ] || error "stat must fail"
2297         rm -rf $DIR/$tfile*
2298         return 0
2299 }
2300 run_test 45g "pdirops: rename src vs getattr =============="
2301
2302 test_45h() {
2303         touch $DIR1/$tfile
2304 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2305         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2306         mv $DIR1/$tfile $DIR1/$tfile-2 &
2307         PID1=$! ; pdo_sched
2308         ls -lia $DIR2/ > /dev/null &
2309         do_facet $SINGLEMDS lctl set_param fail_loc=0
2310         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
2311         wait $PID2
2312         rm -rf $DIR/$tfile*
2313         return 0
2314 }
2315 run_test 45h "pdirops: unlink vs readdir =============="
2316
2317 test_45i() {
2318         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2319         touch $DIR1/$tfile
2320 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2321         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2322         mv $DIR1/$tfile $DIR1/$tfile-2 &
2323         PID1=$! ; pdo_sched
2324         $LFS mkdir -i 1 $DIR2/$tfile &
2325         PID2=$! ; pdo_sched
2326         do_facet $SINGLEMDS lctl set_param fail_loc=0
2327         check_pdo_conflict $PID1 && { wait $PID1;
2328                                 error "create remote dir isn't blocked"; }
2329         wait $PID2 ; [ $? -eq 0 ] || error "create remote dir must succeed"
2330         rm -rf $DIR/$tfile*
2331         return 0
2332 }
2333 run_test 45i "pdirops: rename src vs remote mkdir"
2334
2335 # test 46: link and blocking operations
2336 test_46a() {
2337         touch $DIR1/$tfile-2
2338 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2339         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2340         link $DIR1/$tfile-2 $DIR1/$tfile &
2341         PID1=$! ; pdo_sched
2342         mkdir $DIR2/$tfile &
2343         PID2=$! ; pdo_sched
2344         do_facet $SINGLEMDS lctl set_param fail_loc=0
2345         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
2346         wait $PID2 ; [ $? -ne 0 ] || error "mkdir must fail"
2347         rm -rf $DIR/$tfile*
2348         return 0
2349 }
2350 run_test 46a "pdirops: link vs mkdir =============="
2351
2352 test_46b() {
2353         touch $DIR1/$tfile-2
2354 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2355         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2356         link $DIR1/$tfile-2 $DIR1/$tfile &
2357         PID1=$! ; pdo_sched
2358         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
2359         PID2=$! ; pdo_sched
2360         do_facet $SINGLEMDS lctl set_param fail_loc=0
2361         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
2362         wait $PID2 ; [ $? -ne 0 ] || error "create must fail"
2363         rm -rf $DIR/$tfile*
2364         return 0
2365 }
2366 run_test 46b "pdirops: link vs create =============="
2367
2368 test_46c() {
2369         touch $DIR1/$tfile-2
2370 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2371         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2372         link $DIR1/$tfile-2 $DIR1/$tfile &
2373         PID1=$! ; pdo_sched
2374         link $DIR2/$tfile $DIR2/$tfile &
2375         PID2=$! ; pdo_sched
2376         do_facet $SINGLEMDS lctl set_param fail_loc=0
2377         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2378         wait $PID2 ; [ $? -ne 0 ] || error "link must fail"
2379         rm -rf $DIR/$tfile*
2380         return 0
2381 }
2382 run_test 46c "pdirops: link vs link =============="
2383
2384 test_46d() {
2385         touch $DIR1/$tfile-2
2386 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2387         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2388         link $DIR1/$tfile-2 $DIR1/$tfile &
2389         PID1=$! ; pdo_sched
2390         rm $DIR2/$tfile &
2391         PID2=$! ; pdo_sched
2392         do_facet $SINGLEMDS lctl set_param fail_loc=0
2393         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
2394         wait $PID2 ; [ $? -eq 0 ] || error "unlink must succeed"
2395         rm -rf $DIR/$tfile*
2396         return 0
2397 }
2398 run_test 46d "pdirops: link vs unlink =============="
2399
2400 test_46e() {
2401         touch $DIR1/$tfile-2
2402         touch $DIR1/$tfile-3
2403 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2404         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2405         link $DIR1/$tfile-2 $DIR1/$tfile &
2406         PID1=$! ; pdo_sched
2407         mv $DIR2/$tfile-3 $DIR2/$tfile &
2408         PID2=$! ; pdo_sched
2409         do_facet $SINGLEMDS lctl set_param fail_loc=0
2410         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2411         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
2412         rm -rf $DIR/$tfile*
2413         return 0
2414 }
2415 run_test 46e "pdirops: link and rename (tgt) =============="
2416
2417 test_46f() {
2418         touch $DIR1/$tfile-2
2419         touch $DIR1/$tfile-3
2420 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2421         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2422         link $DIR1/$tfile-2 $DIR1/$tfile &
2423         PID1=$! ; pdo_sched
2424         mv $DIR2/$tfile $DIR2/$tfile-3 &
2425         PID2=$! ; pdo_sched
2426         do_facet $SINGLEMDS lctl set_param fail_loc=0
2427         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2428         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
2429         rm -rf $DIR/$tfile*
2430         return 0
2431 }
2432 run_test 46f "pdirops: link and rename (src) =============="
2433
2434 test_46g() {
2435         touch $DIR1/$tfile-2
2436 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2437         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2438         link $DIR1/$tfile-2 $DIR1/$tfile &
2439         PID1=$! ; pdo_sched
2440         stat $DIR2/$tfile > /dev/null &
2441         PID2=$! ; pdo_sched
2442         do_facet $SINGLEMDS lctl set_param fail_loc=0
2443         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
2444         wait $PID2 ; [ $? -eq 0 ] || error "stat must succeed"
2445         rm -rf $DIR/$tfile*
2446         return 0
2447 }
2448 run_test 46g "pdirops: link vs getattr =============="
2449
2450 test_46h() {
2451         touch $DIR1/$tfile-2
2452 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2453         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2454         link $DIR1/$tfile-2 $DIR1/$tfile &
2455         PID1=$! ; pdo_sched
2456         ls -lia $DIR2/ > /dev/null &
2457         PID2=$! ; pdo_sched
2458         do_facet $SINGLEMDS lctl set_param fail_loc=0
2459         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
2460         wait $PID2
2461         rm -rf $DIR/$tfile*
2462         return 0
2463 }
2464 run_test 46h "pdirops: link vs readdir =============="
2465
2466 test_46i() {
2467         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2468         touch $DIR1/$tfile-2
2469 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2470         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2471         link $DIR1/$tfile-2 $DIR1/$tfile &
2472         PID1=$! ; pdo_sched
2473         $LFS mkdir -i 1 $DIR2/$tfile &
2474         PID2=$! ; pdo_sched
2475         do_facet $SINGLEMDS lctl set_param fail_loc=0
2476         check_pdo_conflict $PID1 && { wait $PID1;
2477                                 error "remote mkdir isn't blocked"; }
2478         wait $PID2 ; [ $? -ne 0 ] || error "remote mkdir must fail"
2479         rm -rf $DIR/$tfile*
2480         return 0
2481 }
2482 run_test 46i "pdirops: link vs remote mkdir"
2483
2484 # test 47: remote mkdir and blocking operations
2485 test_47a() {
2486 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2487         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2488         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2489         $LFS mkdir -i 1 $DIR1/$tfile &
2490         PID1=$! ; pdo_sched
2491         mkdir $DIR2/$tfile &
2492         PID2=$! ; pdo_sched
2493         do_facet $SINGLEMDS lctl set_param fail_loc=0
2494         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
2495         wait $PID2 ; [ $? -ne 0 ] || error "mkdir must fail"
2496         rm -rf $DIR/$tfile*
2497         return 0
2498 }
2499 run_test 47a "pdirops: remote mkdir vs mkdir"
2500
2501 test_47b() {
2502 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2503         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2504         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2505         $LFS mkdir -i 1 $DIR1/$tfile &
2506         PID1=$! ; pdo_sched
2507         multiop $DIR2/$tfile oO_CREAT:O_EXCL:c &
2508         PID2=$! ; pdo_sched
2509         do_facet $SINGLEMDS lctl set_param fail_loc=0
2510         check_pdo_conflict $PID1 && { wait $PID1;
2511                                         error "create isn't blocked"; }
2512         wait $PID2 ; [ $? -ne 0 ] || error "create must fail"
2513         rm -rf $DIR/$tfile*
2514         return 0
2515 }
2516 run_test 47b "pdirops: remote mkdir vs create"
2517
2518 test_47c() {
2519         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2520         touch $DIR1/$tfile-2
2521 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2522         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2523         $LFS mkdir -i 1 $DIR1/$tfile &
2524         PID1=$! ; pdo_sched
2525         link $DIR2/$tfile-2 $DIR2/$tfile &
2526         PID2=$! ; pdo_sched
2527         do_facet $SINGLEMDS lctl set_param fail_loc=0
2528         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2529         wait $PID2 ; [ $? -ne 0 ] || error "link must fail"
2530         rm -rf $DIR/$tfile*
2531         return 0
2532 }
2533 run_test 47c "pdirops: remote mkdir vs link"
2534
2535 test_47d() {
2536         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2537 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2538         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2539         $LFS mkdir -i 1 $DIR1/$tfile &
2540         PID1=$! ; pdo_sched
2541         rmdir $DIR2/$tfile &
2542         PID2=$! ; pdo_sched
2543         do_facet $SINGLEMDS lctl set_param fail_loc=0
2544         check_pdo_conflict $PID1 && { wait $PID1;
2545                                         error "unlink isn't blocked"; }
2546         wait $PID2 ; [ $? -eq 0 ] || error "rmdir must succeed"
2547         rm -rf $DIR/$tfile*
2548         return 0
2549 }
2550 run_test 47d "pdirops: remote mkdir vs unlink"
2551
2552 test_47e() {
2553         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2554         touch $DIR1/$tfile-2
2555 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2556         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2557         $LFS mkdir -i 1 $DIR1/$tfile &
2558         PID1=$! ; pdo_sched
2559         mv -T $DIR2/$tfile-2 $DIR2/$tfile &
2560         PID2=$! ; pdo_sched
2561         do_facet $SINGLEMDS lctl set_param fail_loc=0
2562         check_pdo_conflict $PID1 && { wait $PID1;
2563                                         error "rename isn't blocked"; }
2564         wait $PID2 ; [ $? -ne 0 ] || error "rename must fail"
2565         rm -rf $DIR/$tfile*
2566         return 0
2567 }
2568 run_test 47e "pdirops: remote mkdir and rename (tgt)"
2569
2570 test_47f() {
2571         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2572 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2573         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2574         $LFS mkdir -i 1 $DIR1/$tfile &
2575         PID1=$! ; pdo_sched
2576         mv $DIR2/$tfile $DIR2/$tfile-2 &
2577         PID2=$! ; pdo_sched
2578         do_facet $SINGLEMDS lctl set_param fail_loc=0
2579         check_pdo_conflict $PID1 && { wait $PID1;
2580                                         error "rename isn't blocked"; }
2581         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
2582         rm -rf $DIR/$tfile*
2583         return 0
2584 }
2585 run_test 47f "pdirops: remote mkdir and rename (src)"
2586
2587 test_47g() {
2588         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2589         sync
2590         sync_all_data
2591 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2592         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2593         $LFS mkdir -i 1 $DIR1/$tfile &
2594         PID1=$! ; pdo_sched
2595         stat $DIR2/$tfile > /dev/null &
2596         PID2=$! ; pdo_sched
2597         do_facet $SINGLEMDS lctl set_param fail_loc=0
2598         check_pdo_conflict $PID1 && { wait $PID1;
2599                                         error "getattr isn't blocked"; }
2600         wait $PID2 ; [ $? -eq 0 ] || error "stat must succeed"
2601         rm -rf $DIR/$tfile*
2602         return 0
2603 }
2604 run_test 47g "pdirops: remote mkdir vs getattr"
2605
2606 test_50() {
2607         trunc_size=4096
2608         dd if=/dev/zero of=$DIR1/$tfile bs=1K count=10
2609 #define OBD_FAIL_OSC_CP_ENQ_RACE         0x410
2610         do_facet client "lctl set_param fail_loc=0x410"
2611         $TRUNCATE $DIR2/$tfile $trunc_size
2612         do_facet client "lctl set_param fail_loc=0x0"
2613         sleep 3
2614         size=`stat -c %s $DIR2/$tfile`
2615         [ $size -eq $trunc_size ] || error "wrong size"
2616 }
2617 run_test 50 "osc lvb attrs: enqueue vs. CP AST =============="
2618
2619 test_51a() {
2620         local filesize
2621         local origfile=/etc/hosts
2622
2623         filesize=$(stat -c %s $origfile)
2624
2625         # create an empty file
2626         $MCREATE $DIR1/$tfile || error "can't create $DIR1/$tfile"
2627         # cache layout lock on both mount point
2628         stat $DIR1/$tfile > /dev/null || error "stat $DIR1/$tfile failed"
2629         stat $DIR2/$tfile > /dev/null || error "stat $DIR2/$tfile failed"
2630
2631         # open and sleep 2 seconds then read
2632         $MULTIOP $DIR2/$tfile o_2r${filesize}c &
2633         local pid=$!
2634         sleep 1
2635
2636         # create the layout of testing file
2637         dd if=$origfile of=$DIR1/$tfile conv=notrunc > /dev/null ||
2638                 error "dd $DIR1/$tfile failed"
2639
2640         # MULTIOP proc should be able to read enough bytes and exit
2641         for ((i = 0; i < 6; i++)); do
2642                 sleep 1
2643                 kill -0 $pid || break
2644         done
2645         kill -0 $pid 2> /dev/null && error "multiop is still there"
2646         cmp $origfile $DIR2/$tfile || error "$origfile and $DIR2/$tfile differs"
2647
2648         rm -f $DIR1/$tfile
2649 }
2650 run_test 51a "layout lock: refresh layout should work"
2651
2652 test_51b() {
2653         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.59) ]] ||
2654                 { skip "Need MDS version at least 2.3.59"; return 0; }
2655
2656         local tmpfile=`mktemp`
2657
2658         # create an empty file
2659         $MCREATE $DIR1/$tfile || error "mcreate $DIR1/$tfile failed"
2660
2661         # delay glimpse so that layout has changed when glimpse finish
2662 #define OBD_FAIL_GLIMPSE_DELAY 0x1404
2663         $LCTL set_param fail_loc=0x1404
2664         stat -c %s $DIR2/$tfile |tee $tmpfile &
2665         local pid=$!
2666         sleep 1
2667
2668         # create layout of testing file
2669         dd if=/dev/zero of=$DIR1/$tfile bs=1k count=1 conv=notrunc >/dev/null ||
2670                 error "dd $DIR1/$tfile failed"
2671
2672         wait $pid
2673         local fsize=$(cat $tmpfile)
2674
2675         [ x$fsize = x1024 ] || error "file size is $fsize, should be 1024"
2676
2677         rm -f $DIR1/$tfile $tmpfile
2678 }
2679 run_test 51b "layout lock: glimpse should be able to restart if layout changed"
2680
2681 test_51c() {
2682         [ $OSTCOUNT -ge 2 ] || { skip "needs >= 2 osts"; return; }
2683
2684         # set default layout to have 1 stripe
2685         mkdir $DIR1/$tdir
2686         $LFS setstripe -c 1 $DIR1/$tdir
2687
2688         # create a file with empty layout
2689         $MCREATE $DIR1/$tdir/$tfile ||
2690                 error "$MCREATE $DIR1/$tdir/$tfile failed"
2691
2692 #define OBD_FAIL_MDS_LL_BLOCK 0x172
2693         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x172
2694
2695         # change the layout of testing file
2696         echo "Setting layout to have $OSTCOUNT stripes ..."
2697         $LFS setstripe -c $OSTCOUNT $DIR1/$tdir/$tfile &
2698         pid=$!
2699         sleep 1
2700
2701         # write something to the file, it should be blocked on fetching layout
2702         dd if=/dev/zero of=$DIR2/$tdir/$tfile bs=1k count=1 conv=notrunc
2703         local stripe_count=$($LFS getstripe -c $DIR2/$tdir/$tfile)
2704         wait $pid
2705
2706         # lod_qos.c::min_stripe_count() allows setstripe with a default stripe
2707         # count to succeed with only 3/4 of the number of stripes (rounded up),
2708         # so creating striped files does not fail if an OST is offline or full
2709         [ $stripe_count -ge $((OSTCOUNT - $OSTCOUNT / 4)) ] ||
2710                 error "bad layout: getstripe -c $stripe_count < $OSTCOUNT * 3/4"
2711
2712         rm -fr $DIR1/$tdir
2713 }
2714 run_test 51c "layout lock: IT_LAYOUT blocked and correct layout can be returned"
2715
2716 test_51d() {
2717         dd if=/dev/zero of=/$DIR1/$tfile bs=1M count=1
2718         cancel_lru_locks mdc
2719
2720         # open should grant LAYOUT lock, mmap and read will install pages
2721         $MULTIOP $DIR1/$tfile oO_RDWR:SMR_Uc &
2722         local PID=$!
2723         sleep 1
2724
2725         # rss before revoking
2726         local br=$(grep -A 10 $tfile /proc/$PID/smaps | awk '/^Rss/{print $2}')
2727         echo "Before revoking layout lock: $br KB mapped"
2728
2729         # cancel layout lock manually
2730         cancel_lru_locks mdc
2731
2732         # rss after revoking
2733         local ar=$(grep -A 10 $tfile /proc/$PID/smaps | awk '/^Rss/{print $2}')
2734
2735         kill -USR1 $PID
2736         wait $PID || error "wait PID $PID failed"
2737
2738         [ $ar -eq 0 ] || error "rss before: $br, after $ar, some pages remained"
2739 }
2740 run_test 51d "layout lock: losing layout lock should clean up memory map region"
2741
2742 test_54_part1()
2743 {
2744         echo "==> rename vs getattr vs setxattr should not deadlock"
2745         mkdir -p $DIR/d1/d2/d3 || error "(1) mkdir failed"
2746
2747         do_facet mds1 $LCTL set_param fail_loc=$1
2748
2749         mv -T $DIR/d1/d2/d3 $DIR/d1/d3 &
2750         PID1=$!
2751         sleep 1
2752
2753         stat $DIR/d1/d2 &
2754         PID2=$!
2755         sleep 1
2756
2757         setfattr -n user.attr1 -v value1 $DIR2/d1 || error "(2) setfattr failed"
2758         wait $PID1 || error "(3) mv failed"
2759         wait $PID2 || error "(4) stat failed"
2760         echo
2761
2762         rm -rf $DIR/d1
2763 }
2764
2765 test_54_part2() {
2766         echo "==> rename vs getattr vs open vs getattr should not deadlock"
2767         mkdir -p $DIR/d1/d2/d3 || error "(1) mkdir failed"
2768
2769         do_facet mds1 $LCTL set_param fail_loc=$1
2770
2771         mv -T $DIR/d1/d2/d3 $DIR/d1/d3 &
2772         PID1=$!
2773         sleep 1
2774
2775         stat $DIR/d1/d2 &
2776         PID2=$!
2777         sleep 1
2778
2779         $MULTIOP $DIR2/d1/d2 Oc &
2780         PID3=$!
2781         sleep 1
2782
2783         stat $DIR/d1 || error "(2) stat failed"
2784
2785         wait $PID1 || error "(3) mv failed"
2786         wait $PID2 || error "(4) stat failed"
2787         wait $PID3 && error "(5) multiop failed"
2788         echo
2789         rm -rf $DIR/d1
2790 }
2791
2792 test_54() {
2793         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
2794         save_lustre_params client "llite.*.xattr_cache" > $p
2795         lctl set_param llite.*.xattr_cache 1 ||
2796                 { skip "xattr cache is not supported"; return 0; }
2797
2798 #define OBD_FAIL_MDS_RENAME              0x153
2799 #define OBD_FAIL_MDS_RENAME2             0x154
2800         test_54_part1 0x80000153 || error 10
2801         test_54_part1 0x80000154 || error 11
2802         test_54_part2 0x80000153 || error 12
2803         test_54_part2 0x80000154 || error 13
2804
2805         restore_lustre_params < $p
2806         rm -f $p
2807 }
2808 run_test 54 "rename locking"
2809
2810 test_55a() {
2811         mkdir -p $DIR/d1/d2 $DIR/d3 || error "(1) mkdir failed"
2812
2813 #define OBD_FAIL_MDS_RENAME4              0x156
2814         do_facet mds1 $LCTL set_param fail_loc=0x80000156
2815
2816         mv -T $DIR/d1/d2 $DIR/d3/d2 &
2817         PID1=$!
2818         sleep 1
2819
2820         rm -r $DIR2/d3
2821         wait $PID1 && error "(2) mv succeeded"
2822
2823         rm -rf $DIR/d1
2824 }
2825 run_test 55a "rename vs unlink target dir"
2826
2827 test_55b()
2828 {
2829         mkdir -p $DIR/d1/d2 $DIR/d3 || error "(1) mkdir failed"
2830
2831 #define OBD_FAIL_MDS_RENAME4             0x156
2832         do_facet mds1 $LCTL set_param fail_loc=0x80000156
2833
2834         mv -T $DIR/d1/d2 $DIR/d3/d2 &
2835         PID1=$!
2836         sleep 1
2837
2838         rm -r $DIR2/d1
2839         wait $PID1 && error "(2) mv succeeded"
2840
2841         rm -rf $DIR/d3
2842 }
2843 run_test 55b "rename vs unlink source dir"
2844
2845 test_55c()
2846 {
2847         mkdir -p $DIR/d1/d2 $DIR/d3 || error "(1) mkdir failed"
2848
2849 #define OBD_FAIL_MDS_RENAME4              0x156
2850         do_facet mds1 $LCTL set_param fail_loc=0x156
2851
2852         mv -T $DIR/d1/d2 $DIR/d3/d2 &
2853         PID1=$!
2854         sleep 1
2855
2856         # while rename is sleeping, open and remove d3
2857         $MULTIOP $DIR2/d3 D_c &
2858         PID2=$!
2859         sleep 1
2860         rm -rf $DIR2/d3
2861         sleep 5
2862
2863         # while rename is sleeping 2nd time, close d3
2864         kill -USR1 $PID2
2865         wait $PID2 || error "(3) multiop failed"
2866
2867         wait $PID1 && error "(2) mv succeeded"
2868
2869         rm -rf $DIR/d1
2870 }
2871 run_test 55c "rename vs unlink orphan target dir"
2872
2873 test_55d()
2874 {
2875         touch $DIR/f1
2876
2877 #define OBD_FAIL_MDS_RENAME3              0x155
2878         do_facet mds1 $LCTL set_param fail_loc=0x155
2879         mv $DIR/f1 $DIR/$tdir &
2880         PID1=$!
2881         sleep 2
2882
2883         # while rename is sleeping, create $tdir, but as a directory
2884         mkdir -p $DIR2/$tdir || error "(1) mkdir failed"
2885
2886         # link in reverse locking order
2887         ln $DIR2/f1 $DIR2/$tdir/
2888
2889         wait $PID1 && error "(2) mv succeeded"
2890         rm -rf $DIR/f1
2891 }
2892 run_test 55d "rename file vs link"
2893
2894 test_60() {
2895         local MDSVER=$(lustre_build_version $SINGLEMDS)
2896         [ $(version_code $MDSVER) -lt $(version_code 2.3.0) ] &&
2897                 skip "MDS version $MDSVER must be >= 2.3.0" && return 0
2898
2899         # Create a file
2900         test_mkdir $DIR1/$tdir
2901         file1=$DIR1/$tdir/file
2902         file2=$DIR2/$tdir/file
2903
2904         echo orig > $file2 || error "Could not create $file2"
2905         version=$($LFS data_version $file1)
2906
2907         # Append data
2908         echo append >> $file2 || error "Could not append to $file2"
2909         version2=$($LFS data_version $file1)
2910         [ "$version" != "$version2" ] ||
2911             error "append did not change data version: $version"
2912
2913         # Overwrite data
2914         echo overwrite > $file2 || error "Could not overwrite $file2"
2915         version3=$($LFS data_version $file1)
2916         [ "$version2" != "$version3" ] ||
2917             error "overwrite did not change data version: $version2"
2918
2919         # Truncate before EOF
2920         $TRUNCATE $file2 3 || error "Could not truncate $file2"
2921         version4=$($LFS data_version $file1)
2922         [ "$version3" != "$version4" ] ||
2923             error "truncate did not change data version: $version3"
2924
2925         # Truncate after EOF
2926         $TRUNCATE $file2 123456 || error "Could not truncate $file2"
2927         version5=$($LFS data_version $file1)
2928         [ "$version4" != "$version5" ] ||
2929             error "truncate did not change data version: $version4"
2930
2931         # Chmod do not change version
2932         chmod 400 $file2 || error "Could not chmod 400 $file2"
2933         version6=$($LFS data_version $file1)
2934         [ "$version5" == "$version6" ] ||
2935             error "chmod should not change data version: $version5 != $version6"
2936
2937         # Chown do not change version
2938         chown $RUNAS_ID $file2 || error "Could not chown $RUNAS_ID $file2"
2939         version7=$($LFS data_version $file1)
2940         [ "$version5" == "$version7" ] ||
2941             error "chown should not change data version: $version5 != $version7"
2942 }
2943 run_test 60 "Verify data_version behaviour"
2944
2945 test_70a() {
2946         local test_dir=$tdir/test_dir
2947
2948         mkdir -p $DIR1/$tdir
2949         if [ $MDSCOUNT -ge 2 ]; then
2950                 local MDTIDX=1
2951                 $LFS mkdir -i $MDTIDX $DIR1/$test_dir ||
2952                         error "Create remote directory failed"
2953         else
2954                 mkdir -p $DIR1/$test_dir
2955         fi
2956         cd $DIR2/$test_dir || error "cd directory failed"
2957         rm -rf $DIR1/$test_dir || error "unlink directory failed"
2958
2959         cd $DIR2/$tdir || error "exit directory"
2960 }
2961 run_test 70a "cd directory && rm directory"
2962
2963 test_70b() { # LU-2781
2964         local i
2965         mkdir -p $DIR1/$tdir
2966
2967         touch $DIR1/$tdir/file
2968         for ((i = 0; i < 32; i++)); do
2969             $LFS rm_entry $DIR1/$tdir/non_existent_dir &>/dev/null
2970         done
2971         rm $DIR1/$tdir/file || error "cannot remove file after rm_entry"
2972
2973         touch $DIR1/$tdir/file
2974         $LFS mkdir -i0 $DIR1/$tdir/test_dir
2975         $LFS rm_entry $DIR1/$tdir/test_dir &>/dev/null
2976         rm -rf $DIR1/$tdir/test_dir ||
2977                 error "cannot remove directory after rm_entry"
2978         rm $DIR1/$tdir/file || error "cannot remove file after rm_entry"
2979 }
2980 run_test 70b "remove files after calling rm_entry"
2981
2982 test_71a() {
2983         local server_version=$(lustre_version_code $SINGLEMDS)
2984
2985         [[ $server_version -lt $(version_code 2.1.6) ]] &&
2986                 skip "Need MDS version at least 2.1.6" && return
2987
2988         # Patch not applied to 2.2 and 2.3 branches
2989         [[ $server_version -ge $(version_code 2.2.0) ]] &&
2990         [[ $server_version -lt $(version_code 2.4.0) ]] &&
2991                 skip "Need MDS version earlier than 2.2.0 or at least 2.4.0" &&
2992                         return
2993
2994         checkfiemap --test ||
2995                 { skip "checkfiemap not runnable: $?" && return; }
2996         # write data this way: hole - data - hole - data
2997         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=1 count=1
2998         [ "$(facet_fstype ost$(($($LFS getstripe -i $DIR1/$tfile) + 1)))" = \
2999                 "zfs" ] &&
3000                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return 0
3001         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=3 count=1
3002         GET_STAT="lctl get_param -n ldlm.services.ldlm_cbd.stats"
3003         stat $DIR2/$tfile
3004         local can1=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
3005         echo $can1
3006         checkfiemap $DIR2/$tfile 81920 ||
3007                 error "data is not flushed from client"
3008         local can2=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
3009         echo $can2
3010
3011         # common case of "create file, copy file" on a single node
3012         # should not flush data from ost
3013         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=1 count=1
3014         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=3 count=1
3015         stat $DIR1/$tfile
3016         local can3=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
3017         echo $can3
3018         checkfiemap $DIR1/$tfile 81920 ||
3019         error 4
3020         local can4=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
3021         echo $can2
3022         [ $can3 -eq $can4 ] || error $((can2-can1)) "cancel RPC occured."
3023 }
3024 run_test 71a "correct file map just after write operation is finished"
3025
3026 test_71b() {
3027         local server_version=$(lustre_version_code $SINGLEMDS)
3028
3029         [[ $server_version -lt $(version_code 2.1.6) ]] &&
3030                 skip "Need MDS version at least 2.1.6" && return
3031
3032         # Patch not applied to 2.2 and 2.3 branches
3033         [[ $server_version -ge $(version_code 2.2.0) ]] &&
3034         [[ $server_version -lt $(version_code 2.4.0) ]] &&
3035                 skip "Need MDS version earlier than 2.2.0 or at least 2.4.0" &&
3036                         return
3037         [[ $OSTCOUNT -ge 2 ]] || { skip "needs >= 2 OSTs"; return; }
3038
3039         checkfiemap --test ||
3040                 { skip "error $?: checkfiemap failed" && return; }
3041
3042         mkdir -p $DIR1/$tdir
3043
3044         $LFS setstripe -c -1 $DIR1/$tdir || error "setstripe failed"
3045         dd if=/dev/urandom of=$DIR1/$tdir/$tfile bs=40K count=1
3046         [ "$(facet_fstype ost$(($($LFS getstripe -i $DIR1/$tdir/$tfile) + 1)))" = \
3047                 "zfs" ] &&
3048                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return 0
3049         checkfiemap $DIR1/$tdir/$tfile 40960 || error "checkfiemap failed"
3050 }
3051 run_test 71b "check fiemap support for stripecount > 1"
3052
3053 test_72() {
3054         local p="$TMP/sanityN-$TESTNAME.parameters"
3055         local tlink1
3056         local tlink2
3057         save_lustre_params client "llite.*.xattr_cache" > $p
3058         lctl set_param llite.*.xattr_cache 1 ||
3059                 { skip "xattr cache is not supported"; return 0; }
3060
3061         touch $DIR1/$tfile
3062         setfattr -n user.attr1 -v value1 $DIR1/$tfile ||
3063                 error "setfattr1 failed"
3064         getfattr -n user.attr1 $DIR2/$tfile | grep value1 ||
3065                 error "getfattr1 failed"
3066         setfattr -n user.attr1 -v value2 $DIR2/$tfile ||
3067                 error "setfattr2 failed"
3068         getfattr -n user.attr1 $DIR1/$tfile | grep value2 ||
3069                 error "getfattr2 failed"
3070
3071         # check that trusted.link is consistent
3072         tlink1=$(getfattr -n trusted.link $DIR1/$tfile | md5sum)
3073         ln $DIR2/$tfile $DIR2/$tfile-2 || error "failed to link"
3074         tlink2=$(getfattr -n trusted.link $DIR1/$tfile | md5sum)
3075         echo "$tlink1 $tlink2"
3076         [ "$tlink1" = "$tlink2" ] && error "trusted.link should have changed!"
3077
3078         rm -f $DIR2/$tfile
3079
3080         restore_lustre_params < $p
3081         rm -f $p
3082 }
3083 run_test 72 "getxattr/setxattr cache should be consistent between nodes"
3084
3085 test_73() {
3086         local p="$TMP/sanityN-$TESTNAME.parameters"
3087         save_lustre_params client "llite.*.xattr_cache" > $p
3088         lctl set_param llite.*.xattr_cache 1 ||
3089                 { skip "xattr cache is not supported"; return 0; }
3090
3091         touch $DIR1/$tfile
3092         setfattr -n user.attr1 -v value1 $DIR1/$tfile ||
3093                 error "setfattr1 failed"
3094         getfattr -n user.attr1 $DIR2/$tfile || error "getfattr1 failed"
3095         getfattr -n user.attr1 $DIR1/$tfile || error "getfattr2 failed"
3096         clear_stats llite.*.stats
3097         # PR lock should be cached by now on both clients
3098         getfattr -n user.attr1 $DIR1/$tfile || error "getfattr3 failed"
3099         # 2 hits for getfattr(0)+getfattr(size)
3100         [ $(calc_stats llite.*.stats getxattr_hits) -eq 2 ] ||
3101                 error "not cached in $DIR1"
3102         getfattr -n user.attr1 $DIR2/$tfile || error "getfattr4 failed"
3103         # 4 hits for more getfattr(0)+getfattr(size)
3104         [ $(calc_stats llite.*.stats getxattr_hits) -eq 4 ] ||
3105                 error "not cached in $DIR2"
3106         rm -f $DIR2/$tfile
3107
3108         restore_lustre_params < $p
3109         rm -f $p
3110 }
3111 run_test 73 "getxattr should not cause xattr lock cancellation"
3112
3113 test_74() {
3114         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.93) ] &&
3115                 skip "Need MDS version at least 2.4.93" && return
3116
3117         dd if=/dev/zero of=$DIR1/$tfile-1 bs=1K count=1
3118         dd if=/dev/zero of=$DIR1/$tfile-2 bs=1K count=1
3119         flocks_test 4 $DIR1/$tfile-1 $DIR2/$tfile-2
3120 }
3121 run_test 74 "flock deadlock: different mounts =============="
3122
3123 # LU-3889
3124 test_75() {
3125         $LFS setstripe -c 2 -S 1m -i 0 $DIR1/$tfile
3126         dd if=/dev/zero of=$DIR1/$tfile bs=1M count=2
3127         cancel_lru_locks osc
3128
3129         dd of=$DIR1/$tfile if=/dev/zero bs=1M count=1 seek=1 conv=notrunc
3130         sync
3131
3132         # define OBD_FAIL_LDLM_ENQUEUE_HANG 0x31d
3133         $LCTL set_param fail_loc=0x31d
3134         stat -c %s $DIR1/$tfile &
3135         local pid=$!
3136         sleep 1
3137         kill -9 $pid
3138
3139         # For bad lock error handler we should ASSERT and got kernel panic here
3140         sleep 4
3141         $LCTL set_param fail_loc=0
3142 }
3143 run_test 75 "osc: upcall after unuse lock==================="
3144
3145 test_76() { #LU-946
3146         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
3147                 skip "Need MDS version at least 2.5.53" && return
3148
3149         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3150         local fcount=$((MDSCOUNT * 256))
3151         declare -a fd_list
3152         declare -a fid_list
3153
3154         if remote_mds; then
3155                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
3156         else
3157                 nid="0@lo"
3158         fi
3159
3160         rm -rf $DIR/$tdir
3161         test_mkdir $DIR/$tdir
3162
3163         # drop all open locks and close any cached "open" files on the client
3164         cancel_lru_locks mdc
3165
3166         local open_fids_cmd="$LCTL get_param -n mdt.*.exports.'$nid'.open_files"
3167         local fid_list=($(do_nodes $(comma_list $(mdts_nodes)) $open_fids_cmd))
3168         local already=${#fid_list[@]}
3169         for (( i = 0; i < $already; i++ )) ; do
3170                 log "already open[$i]: $($LFS fid2path $DIR2 ${fid_list[i]})"
3171         done
3172
3173         echo -n "opening files: "
3174         ulimit -n $((fcount + 50))
3175         for ((i = 0; i < $fcount; i++)); do
3176                 touch $DIR/$tdir/f_$i
3177                 local fd=$(free_fd ${fd_list[i]})
3178                 local open_cmd="exec $fd<$DIR/$tdir/f_$i"
3179                 eval $open_cmd
3180
3181                 fd_list[i]=$fd
3182
3183                 (( $i % 32 == 0 )) && echo -n "."
3184         done
3185         echo
3186
3187         fid_list=($(do_nodes $(comma_list $(mdts_nodes)) $open_fids_cmd))
3188
3189         # Possible errors in openfiles FID list.
3190         # 1. Missing FIDs. Check 1
3191         # 2. Extra FIDs. Check 1
3192         # 3. Duplicated FID. Check 2
3193         # 4. Invalid FIDs. Check 2
3194         # 5. Valid FID, points to some other file. Check 3
3195
3196         # Check 1
3197         [ ${#fid_list[@]} -ne $((fcount + already)) ] &&
3198                 error "${#fid_list[@]} != $fcount (+$already old) open files"
3199
3200         echo -n "closing files: "
3201         for (( fd = 0, fid = 0; fd < $fcount; fd++, fid++ )) ; do
3202                 local close_cmd="exec ${fd_list[fd]}<&-"
3203                 eval $close_cmd
3204                 filename=$($LFS fid2path $DIR2 ${fid_list[fid]})
3205
3206                 while [[ ! "$filename" =~ "$DIR2/$tdir/f_" ]]; do
3207                         echo "skip old open file $filename"
3208                         ((fid++))
3209                         filename=$($LFS fid2path $DIR2 ${fid_list[fid]})
3210                 done
3211
3212                 # Check 2
3213                 rm --interactive=no $filename
3214                 [ $? -ne 0 ] &&
3215                         error "Nonexisting fid ${fid_list[fid]} listed."
3216                 (( $fd % 32 == 0 )) && echo -n "."
3217         done
3218         echo
3219
3220         # Check 3
3221         ls_op=$(ls $DIR2/$tdir | wc -l)
3222         [ $ls_op -ne 0 ] &&
3223                 error "Some openfiles are missing in lproc output"
3224
3225         rm -rf $DIR/$tdir
3226 }
3227 run_test 76 "Verify MDT open_files listing"
3228
3229 nrs_write_read() {
3230         local n=16
3231         local dir=$DIR/$tdir
3232         local myRUNAS="$1"
3233
3234         mkdir $dir || error "mkdir $dir failed"
3235         $LFS setstripe -c $OSTCOUNT $dir || error "setstripe to $dir failed"
3236         chmod 777 $dir
3237
3238         do_nodes $CLIENTS $myRUNAS \
3239                 dd if=/dev/zero of="$dir/nrs_r_\$HOSTNAME" bs=1M count=$n ||
3240                 error "dd at 0 on client failed (1)"
3241
3242         do_nodes $CLIENTS $myRUNAS \
3243                 "declare -a pids_w;
3244                 for ((i = 0; i < $n; i++)); do
3245                         dd if=/dev/zero of=$dir/nrs_w_\$HOSTNAME bs=1M \
3246 seek=\\\$i count=1 conv=notrunc &
3247                         pids_w[\\\$i]=\\\$!;
3248                 done;
3249                 rc_w=0;
3250                 for ((i = 0; i < $n; i++)); do
3251                         wait \\\${pids_w[\\\$i]};
3252                         newrc=\\\$?;
3253                         [ \\\$newrc -gt \\\$rc_w ] && rc_w=\\\$newrc;
3254                 done;
3255                 exit \\\$rc_w" &
3256         local pid_w=$!
3257         do_nodes $CLIENTS sync;
3258         cancel_lru_locks osc
3259
3260         do_nodes $CLIENTS $myRUNAS \
3261                 "declare -a pids_r;
3262                 for ((i = 0; i < $n; i++)); do
3263                         dd if=$dir/nrs_r_\$HOSTNAME bs=1M of=/dev/null \
3264 seek=\\\$i count=1 &
3265                         pids_r[\\\$i]=\\\$!;
3266                 done;
3267                 rc_r=0;
3268                 for ((i = 0; i < $n; i++)); do
3269                         wait \\\${pids_r[\\\$i]};
3270                         newrc=\\\$?;
3271                         [ \\\$newrc -gt \\\$rc_r ] && rc_r=\\\$newrc;
3272                 done;
3273                 exit \\\$rc_r" &
3274         local pid_r=$!
3275         cancel_lru_locks osc
3276
3277         wait $pid_w || error "dd (write) failed (2)"
3278         wait $pid_r || error "dd (read) failed (3)"
3279         rm -rvf $dir || error "rm -rf $dir failed"
3280 }
3281
3282 test_77a() { #LU-3266
3283         local rc
3284
3285         oss=$(comma_list $(osts_nodes))
3286         do_nodes $oss lctl set_param ost.OSS.*.nrs_policies="fifo" ||
3287                 rc=$?
3288         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3289         [[ $rc -ne 0 ]] && error "failed to set fifo policy"
3290         nrs_write_read
3291
3292         return 0
3293 }
3294 run_test 77a "check FIFO NRS policy"
3295
3296 test_77b() { #LU-3266
3297         local rc
3298
3299         oss=$(comma_list $(osts_nodes))
3300
3301         do_nodes $oss lctl set_param ost.OSS.*.nrs_policies="crrn" \
3302                 ost.OSS.*.nrs_crrn_quantum=1 || rc=$?
3303         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3304         [[ $rc -ne 0 ]] && error "failed to set crrn_quantum to 1"
3305
3306         echo "policy: crr-n, crrn_quantum 1"
3307         nrs_write_read
3308
3309         do_nodes $oss lctl set_param \
3310                 ost.OSS.*.nrs_crrn_quantum=64 || rc=$?
3311         [[ $rc -ne 0 ]] && error "failed to set crrn_quantum to 64"
3312
3313         echo "policy: crr-n, crrn_quantum 64"
3314         nrs_write_read
3315
3316         # cleanup
3317         do_nodes $oss lctl set_param \
3318                 ost.OSS.ost_io.nrs_policies="fifo" || rc=$?
3319         [[ $rc -ne 0 ]] && error "failed to set fifo policy"
3320         return 0
3321 }
3322 run_test 77b "check CRR-N NRS policy"
3323
3324 orr_trr() {
3325         local policy=$1
3326
3327         oss=$(comma_list $(osts_nodes))
3328
3329         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies=$policy \
3330                 ost.OSS.*.nrs_"$policy"_quantum=1 \
3331                 ost.OSS.*.nrs_"$policy"_offset_type="physical" \
3332                 ost.OSS.*.nrs_"$policy"_supported="reads" || return $?
3333
3334         echo "policy: $policy, ${policy}_quantum 1, ${policy}_offset_type " \
3335                 "physical, ${policy}_supported reads"
3336         nrs_write_read
3337
3338         do_nodes $oss lctl set_param \
3339                 ost.OSS.*.nrs_${policy}_supported="writes" \
3340                 ost.OSS.*.nrs_${policy}_quantum=64 || return $?
3341
3342         echo "policy: $policy, ${policy}_quantum 64, ${policy}_offset_type " \
3343                 "physical, ${policy}_supported writes"
3344         nrs_write_read
3345
3346         do_nodes $oss lctl set_param \
3347                 ost.OSS.*.nrs_${policy}_supported="reads_and_writes" \
3348                 ost.OSS.*.nrs_${policy}_offset_type="logical" || return $?
3349         echo "policy: $policy, ${policy}_quantum 64, ${policy}_offset_type " \
3350                 "logical, ${policy}_supported reads_and_writes"
3351         nrs_write_read
3352
3353         # cleanup
3354         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo" ||
3355                 return $?
3356         return 0
3357 }
3358
3359 test_77c() { #LU-3266
3360         local rc
3361         orr_trr "orr" || rc=$?
3362         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3363         [[ $rc -ne 0 ]] && error "orr_trr failed rc:$rc"
3364         return 0
3365 }
3366 run_test 77c "check ORR NRS policy"
3367
3368 test_77d() { #LU-3266
3369         local rc
3370         orr_trr "trr" || rc=$?
3371         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3372         [[ $rc -ne 0 ]] && error "orr_trr failed rc:$rc"
3373         return 0
3374 }
3375 run_test 77d "check TRR nrs policy"
3376
3377 tbf_rule_operate()
3378 {
3379         local facet=$1
3380         shift 1
3381
3382         do_facet $facet lctl set_param \
3383                 ost.OSS.ost_io.nrs_tbf_rule="$*"
3384         [ $? -ne 0 ] &&
3385                 error "failed to run operate '$*' on TBF rules"
3386 }
3387
3388 cleanup_tbf_verify()
3389 {
3390         local rc=0
3391         trap 0
3392         echo "cleanup_tbf $DIR/$tdir"
3393         rm -rf $DIR/$tdir
3394         rc=$?
3395         wait_delete_completed
3396         return $rc
3397 }
3398
3399 tbf_verify() {
3400         local dir=$DIR/$tdir
3401         local client1=${CLIENT1:-$(hostname)}
3402         local myRUNAS="$3"
3403
3404         local np=$(check_cpt_number ost1)
3405         [ $np -gt 0 ] || error "CPU partitions should not be $np."
3406         echo "cpu_npartitions on ost1 is $np"
3407
3408         mkdir $dir || error "mkdir $dir failed"
3409         $LFS setstripe -c 1 -i 0 $dir || error "setstripe to $dir failed"
3410         chmod 777 $dir
3411
3412         trap cleanup_tbf_verify EXIT
3413         echo "Limited write rate: $1, read rate: $2"
3414         echo "Verify the write rate is under TBF control"
3415         local start=$SECONDS
3416         do_node $client1 $myRUNAS dd if=/dev/zero of=$dir/tbf \
3417                 bs=1M count=100 oflag=direct 2>&1
3418         local runtime=$((SECONDS - start + 1))
3419         local rate=$(bc <<< "scale=6; 100 / $runtime")
3420         echo "Write runtime is $runtime s, speed is $rate IOPS"
3421
3422         # verify the write rate does not exceed TBF rate limit
3423         [ $(bc <<< "$rate < 1.1 * $np * $1") -eq 1 ] ||
3424                 error "The write rate ($rate) exceeds 110% of rate limit ($1 * $np)"
3425
3426         cancel_lru_locks osc
3427
3428         echo "Verify the read rate is under TBF control"
3429         start=$SECONDS
3430         do_node $client1 $myRUNAS dd if=$dir/tbf of=/dev/null \
3431                 bs=1M count=100 iflag=direct 2>&1
3432         runtime=$((SECONDS - start + 1))
3433         rate=$(bc <<< "scale=6; 100 / $runtime")
3434         echo "Read runtime is $runtime s, speed is $rate IOPS"
3435
3436         # verify the read rate does not exceed TBF rate limit
3437         [ $(bc <<< "$rate < 1.1 * $np * $2") -eq 1 ] ||
3438                 error "The read rate ($rate) exceeds 110% of rate limit ($2 * $np)"
3439
3440         cancel_lru_locks osc
3441         cleanup_tbf_verify || error "rm -rf $dir failed"
3442 }
3443
3444 test_77e() {
3445         local rc
3446
3447         oss=$(comma_list $(osts_nodes))
3448
3449         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ nid" ||
3450                 rc=$?
3451         [[ $rc -eq 3 ]] && skip "no NRS TBF exists" && return
3452         [[ $rc -ne 0 ]] && error "failed to set TBF NID policy"
3453
3454         local idis
3455         local rateis
3456         if [ $(lustre_version_code ost1) -ge $(version_code 2.8.54) ]; then
3457                 idis="nid="
3458                 rateis="rate="
3459         fi
3460
3461         # Only operate rules on ost1 since OSTs might run on the same OSS
3462         # Add some rules
3463         tbf_rule_operate ost1 "start\ localhost\ ${idis}{0@lo}\ ${rateis}1000"
3464         local address=$(comma_list "$(host_nids_address $CLIENTS $NETTYPE)")
3465         local client_nids=$(nids_list $address "\\")
3466         tbf_rule_operate ost1 "start\ clients\ ${idis}{$client_nids}\ ${rateis}100"
3467         tbf_rule_operate ost1 "start\ others\ ${idis}{*.*.*.*@$NETTYPE}\ ${rateis}50"
3468         nrs_write_read
3469
3470         # Change the rules
3471         tbf_rule_operate ost1 "change\ localhost\ ${rateis}1001"
3472         tbf_rule_operate ost1 "change\ clients\ ${rateis}101"
3473         tbf_rule_operate ost1 "change\ others\ ${rateis}51"
3474         nrs_write_read
3475
3476         # Stop the rules
3477         tbf_rule_operate ost1 "stop\ localhost"
3478         tbf_rule_operate ost1 "stop\ clients"
3479         tbf_rule_operate ost1 "stop\ others"
3480         nrs_write_read
3481
3482         # Cleanup the TBF policy
3483         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3484         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3485         nrs_write_read
3486         return 0
3487 }
3488 run_test 77e "check TBF NID nrs policy"
3489
3490 test_77f() {
3491         local rc
3492
3493         oss=$(comma_list $(osts_nodes))
3494
3495         do_nodes $oss $LCTL set_param \
3496                 ost.OSS.ost_io.nrs_policies="tbf\ jobid" || rc=$?
3497         [[ $rc -eq 3 ]] && skip "no NRS TBF exists" && return
3498         [[ $rc -ne 0 ]] && error "failed to set TBF JOBID policy"
3499
3500         # Configure jobid_var
3501         local saved_jobid_var=$($LCTL get_param -n jobid_var)
3502         rc=$?
3503         [[ $rc -eq 3 ]] && skip "jobid_var not found" && return
3504         [[ $rc -ne 0 ]] && error "failed to get param jobid_var"
3505         if [ $saved_jobid_var != procname_uid ]; then
3506                 set_persistent_param_and_check client \
3507                         "jobid_var" "$FSNAME.sys.jobid_var" procname_uid
3508         fi
3509
3510         local idis
3511         local rateis
3512         if [ $(lustre_version_code ost1) -ge $(version_code 2.8.54) ]; then
3513                 idis="jobid="
3514                 rateis="rate="
3515         fi
3516
3517         # Only operate rules on ost1 since OSTs might run on the same OSS
3518         # Add some rules
3519         tbf_rule_operate ost1 "start\ runas\ ${idis}{iozone.$RUNAS_ID\ dd.$RUNAS_ID\ tiotest.$RUNAS_ID}\ ${rateis}1000"
3520         tbf_rule_operate ost1 "start\ iozone_runas\ ${idis}{iozone.$RUNAS_ID}\ ${rateis}100"
3521         tbf_rule_operate ost1 "start\ dd_runas\ ${idis}{dd.$RUNAS_ID}\ ${rateis}50"
3522         nrs_write_read "$RUNAS"
3523
3524         # Change the rules
3525         tbf_rule_operate ost1 "change\ runas\ ${rateis}1001"
3526         tbf_rule_operate ost1 "change\ iozone_runas\ ${rateis}101"
3527         tbf_rule_operate ost1 "change\ dd_runas\ ${rateis}51"
3528         nrs_write_read "$RUNAS"
3529
3530         # Stop the rules
3531         tbf_rule_operate ost1 "stop\ runas"
3532         tbf_rule_operate ost1 "stop\ iozone_runas"
3533         tbf_rule_operate ost1 "stop\ dd_runas"
3534         nrs_write_read "$RUNAS"
3535
3536         # Cleanup the TBF policy
3537         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3538         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3539         nrs_write_read "$RUNAS"
3540
3541         local current_jobid_var=$($LCTL get_param -n jobid_var)
3542         [[ $? -ne 0 ]] && error "failed to get param jobid_var"
3543         if [ $saved_jobid_var != $current_jobid_var ]; then
3544                 set_persistent_param_and_check client \
3545                         "jobid_var" "$FSNAME.sys.jobid_var" $saved_jobid_var
3546         fi
3547         return 0
3548 }
3549 run_test 77f "check TBF JobID nrs policy"
3550
3551 test_77g() {
3552         local rc=0
3553
3554         oss=$(comma_list $(osts_nodes))
3555
3556         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ nid" ||
3557                 rc=$?
3558         [[ $rc -eq 3 ]] && skip "no NRS TBF exists" && return
3559         [[ $rc -ne 0 ]] && error "failed to set TBF NID policy"
3560
3561         do_nodes $oss lctl set_param \
3562                 ost.OSS.ost_io.nrs_policies="tbf\ jobid" || rc=$?
3563         [[ $rc -ne 0 ]] && error "failed to set TBF JOBID policy"
3564
3565         local idis
3566         local rateis
3567         if [ $(lustre_version_code ost1) -ge $(version_code 2.8.54) ]; then
3568                 idis="jobid="
3569                 rateis="rate="
3570         fi
3571
3572         # Add a rule that only valid for Jobid TBF. If direct change between
3573         # TBF types is not supported, this operation will fail.
3574         tbf_rule_operate ost1 "start\ dd_runas\ ${idis}{dd.$RUNAS_ID}\ ${rateis}50"
3575
3576         # Cleanup the TBF policy
3577         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3578         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3579         return 0
3580 }
3581 run_test 77g "Change TBF type directly"
3582
3583 test_77h() {
3584         [ $(lustre_version_code ost1) -ge $(version_code 2.8.55) ] ||
3585                 { skip "Need OST version at least 2.8.55"; return 0; }
3586
3587         local old_policy=$(do_facet ost1 \
3588                 lctl get_param ost.OSS.ost_io.nrs_policies)
3589         local new_policy
3590
3591         do_facet ost1 lctl set_param \
3592                 ost.OSS.ost_io.nrs_policies="abc"
3593         [ $? -eq 0 ] && error "should return error"
3594
3595         do_facet ost1 lctl set_param \
3596                 ost.OSS.ost_io.nrs_policies="tbf\ abc"
3597         [ $? -eq 0 ] && error "should return error"
3598
3599         do_facet ost1 lctl set_param \
3600                 ost.OSS.ost_io.nrs_policies="tbf\ reg\ abc"
3601         [ $? -eq 0 ] && error "should return error"
3602
3603         do_facet ost1 lctl set_param \
3604                 ost.OSS.ost_io.nrs_policies="tbf\ abc\ efg"
3605         [ $? -eq 0 ] && error "should return error"
3606
3607         new_policy=$(do_facet ost1 lctl get_param ost.OSS.ost_io.nrs_policies)
3608         [ $? -eq 0 ] || error "shouldn't LBUG"
3609
3610         [ "$old_policy" = "$new_policy" ] || error "NRS policy should be same"
3611
3612         return 0
3613 }
3614 run_test 77h "Wrong policy name should report error, not LBUG"
3615
3616 tbf_rule_check()
3617 {
3618         local facet=$1
3619         local expected=$2
3620         local error_message=$3
3621         local rule_number=0
3622         for rule in $expected; do
3623                 rule_number=$((rule_number + 1))
3624         done
3625         local stop_line=$(($rule_number + 3))
3626         local awk_command="awk 'NR >= 4 && NR <= $stop_line {print \$1}'"
3627
3628         local output=$(do_facet $facet lctl get_param \
3629                 ost.OSS.ost_io.nrs_tbf_rule |
3630                 eval $awk_command |
3631                 tr "\n" " " |
3632                 sed 's/[ ]*$//')
3633         if [ "$output" != "$expected" ]; then
3634                 error "$error_message, expected '$expected', got '$output'"
3635         fi
3636 }
3637
3638 test_77i() {
3639         [ $(lustre_version_code ost1) -ge $(version_code 2.8.55) ] ||
3640                 { skip "Need OST version at least 2.8.55"; return 0; }
3641
3642         for i in $(seq 1 $OSTCOUNT)
3643         do
3644                 do_facet ost"$i" lctl set_param \
3645                         ost.OSS.ost_io.nrs_policies="tbf\ jobid"
3646                 [ $? -ne 0 ] &&
3647                         error "failed to set TBF policy"
3648         done
3649
3650         tbf_rule_check ost1 "default" "error before inserting any rule"
3651
3652         tbf_rule_operate ost1 "start\ before\ jobid={jobid}\ rate=1000"
3653         tbf_rule_check ost1 "before default" \
3654                 "error when inserting rule 'before'"
3655
3656         tbf_rule_operate ost1 "start\ after\ jobid={jobid}\ rate=1000\ rank=default"
3657         tbf_rule_check ost1 "before after default" \
3658                 "error when inserting rule 'after'"
3659
3660         tbf_rule_operate ost1 "start\ target\ jobid={jobid}\ rate=1000\ rank=after"
3661         tbf_rule_check ost1 "before target after default" \
3662                 "error when inserting rule 'target'"
3663
3664         echo "Move before itself"
3665         tbf_rule_operate ost1 "change\ target\ rank=target"
3666         tbf_rule_check ost1 "before target after default" \
3667                 "error when moving before itself"
3668
3669         echo "Move to higher rank"
3670         tbf_rule_operate ost1 "change\ target\ rank=before"
3671         tbf_rule_check ost1 "target before after default" \
3672                 "error when moving to higher rank"
3673
3674         echo "Move to lower rank"
3675         tbf_rule_operate ost1 "change\ target\ rank=after"
3676         tbf_rule_check ost1 "before target after default" \
3677                 "error when moving to lower rank"
3678
3679         echo "Move before default"
3680         tbf_rule_operate ost1 "change\ target\ rank=default"
3681         tbf_rule_check ost1 "before after target default" \
3682                 error "error when moving before default"
3683
3684         # Cleanup the TBF policy
3685         do_nodes $(comma_list $(osts_nodes)) \
3686                 $LCTL set_param ost.OSS.ost_io.nrs_policies=fifo
3687         return 0
3688 }
3689 run_test 77i "Change rank of TBF rule"
3690
3691 test_77j() {
3692         local idis
3693         local rateis
3694         local ost_version=$(lustre_version_code ost1)
3695
3696         [ $ost_version -ge $(version_code 2.9.53) ] ||
3697                 { skip "Need OST version at least 2.9.53"; return 0; }
3698         if [ $ost_version -ge $(version_code 2.8.60) ]; then
3699                 idis="opcode="
3700                 rateis="rate="
3701         fi
3702
3703         do_nodes $(comma_list $(osts_nodes)) \
3704                 lctl set_param jobid_var=procname_uid \
3705                         ost.OSS.ost_io.nrs_policies="tbf\ opcode" \
3706                         ost.OSS.ost_io.nrs_tbf_rule="start\ ost_r\ ${idis}{ost_read}\ ${rateis}5" \
3707                         ost.OSS.ost_io.nrs_tbf_rule="start\ ost_w\ ${idis}{ost_write}\ ${rateis}20"
3708         [ $? -ne 0 ] && error "failed to set TBF OPCode policy"
3709
3710         nrs_write_read
3711         tbf_verify 20 5
3712
3713         do_nodes $(comma_list $(osts_nodes)) \
3714                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ost_r" \
3715                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ost_w" \
3716                         ost.OSS.ost_io.nrs_policies="fifo"
3717
3718         # sleep 3 seconds to wait the tbf policy stop completely,
3719         # or the next test case is possible get -EAGAIN when
3720         # setting the tbf policy
3721         sleep 3
3722 }
3723 run_test 77j "check TBF-OPCode NRS policy"
3724
3725 test_id() {
3726         local idstr="${1}id"
3727         local policy="${idstr}={$2}"
3728         local rate="rate=$3"
3729
3730         do_nodes $(comma_list $(osts_nodes)) \
3731                 lctl set_param jobid_var=procname_uid \
3732                         ost.OSS.ost_io.nrs_policies="tbf\ ${idstr}" \
3733                         ost.OSS.ost_io.nrs_tbf_rule="start\ ost_${idstr}\ ${policy}\ ${rate}"
3734         [ $? -ne 0 ] && error "failed to set tbf ${idstr} policy"
3735
3736         nrs_write_read "runas $4"
3737         tbf_verify $3 $3 "runas $4"
3738
3739         do_nodes $(comma_list $(osts_nodes)) \
3740                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ost_${idstr}" \
3741                         ost.OSS.ost_io.nrs_policies="fifo"
3742
3743         # sleep 3 seconds to wait the tbf policy stop completely,
3744         # or the next test case is possible get -eagain when
3745         # setting the tbf policy
3746         sleep 3
3747 }
3748
3749 test_77ja(){
3750         if [ $(lustre_version_code ost1) -lt $(version_code 2.11.50) ]; then
3751                 skip "Need OST version at least 2.11.50"
3752                 return 0
3753         fi
3754         test_id "u" "500" "5" "-u 500"
3755         test_id "g" "500" "5" "-u 500 -g 500"
3756 }
3757 run_test 77ja "check TBF-UID/GID NRS policy"
3758
3759 cleanup_77k()
3760 {
3761         local rule_lists=$1
3762         local old_nrs=$2
3763
3764         trap 0
3765         for rule in $rule_lists; do
3766                 do_nodes $(comma_list $(osts_nodes)) \
3767                         lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ $rule"
3768         done
3769
3770         do_nodes $(comma_list $(osts_nodes)) \
3771                 lctl set_param ost.OSS.ost_io.nrs_policies="$old_nrs"
3772
3773         sleep 3
3774 }
3775
3776 test_77k() {
3777         [[ $(lustre_version_code ost1) -ge $(version_code 2.9.53) ]] ||
3778                 { skip "Need OST version at least 2.9.53"; return 0; }
3779
3780         do_nodes $(comma_list $(osts_nodes)) \
3781                 lctl set_param ost.OSS.ost_io.nrs_policies="tbf" \
3782                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_w\ jobid={dd.$RUNAS_ID}\&opcode={ost_write}\ rate=20" \
3783                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_r\ jobid={dd.$RUNAS_ID}\&opcode={ost_read}\ rate=10"
3784
3785         nrs_write_read "$RUNAS"
3786         tbf_verify 20 10 "$RUNAS"
3787
3788         local address=$(comma_list "$(host_nids_address $CLIENTS $NETTYPE)")
3789         local client_nids=$(nids_list $address "\\")
3790         do_nodes $(comma_list $(osts_nodes)) \
3791                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_w" \
3792                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_r" \
3793                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_w\ nid={0@lo\ $client_nids}\&opcode={ost_write}\ rate=20" \
3794                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_r\ nid={0@lo\ $client_nids}\&opcode={ost_read}\ rate=10"
3795
3796         nrs_write_read
3797         tbf_verify 20 10
3798
3799         do_nodes $(comma_list $(osts_nodes)) \
3800                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_w" \
3801                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_r" \
3802                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext\ nid={0@lo\ $client_nids}\&jobid={dd.$RUNAS_ID}\ rate=20"
3803
3804         nrs_write_read "$RUNAS"
3805         tbf_verify 20 20 "$RUNAS"
3806
3807         do_nodes $(comma_list $(osts_nodes)) \
3808                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext" \
3809                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_a\ jobid={dd.$RUNAS_ID},opcode={ost_write}\ rate=20" \
3810                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_b\ jobid={dd.$RUNAS_ID},opcode={ost_read}\ rate=10"
3811
3812         nrs_write_read "$RUNAS"
3813         # with parameter "RUNAS", it will match the latest rule
3814         # "ext_b" first, so the limited write rate is 10.
3815         tbf_verify 10 10 "$RUNAS"
3816         tbf_verify 20 10
3817
3818         trap "cleanup_77k \"ext_a ext_b\" \"fifo\"" EXIT
3819
3820         [[ $(lustre_version_code ost1) -ge $(version_code 2.10.58) ]] ||
3821                 { skip "Need OST version at least 2.10.58"; return 0; }
3822
3823         do_nodes $(comma_list $(osts_nodes)) \
3824                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_a" \
3825                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_b" \
3826                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_ug\ uid={500}\&gid={1000}\ rate=5"
3827         nrs_write_read "runas -u 500 -g 1000"
3828         tbf_verify 5 5 "runas -u 500 -g 1000"
3829
3830         do_nodes $(comma_list $(osts_nodes)) \
3831                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_ug" \
3832                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_uw\ uid={500}\&opcode={ost_write}\ rate=20" \
3833                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_ur\ uid={500}\&opcode={ost_read}\ rate=10"
3834
3835         nrs_write_read "runas -u 500"
3836         tbf_verify 20 10 "runas -u 500"
3837
3838         do_nodes $(comma_list $(osts_nodes)) \
3839                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_uw" \
3840                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_ur" \
3841                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_a\ uid={500},opcode={ost_write}\ rate=20" \
3842                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_b\ uid={500},opcode={ost_read}\ rate=10"
3843         nrs_write_read "runas -u 500"
3844         tbf_verify 10 10 "runas -u 500"
3845         tbf_verify 20 10 "runas -u 500"
3846         cleanup_77k "ext_a ext_b" "fifo"
3847 }
3848 run_test 77k "check TBF policy with NID/JobID/OPCode expression"
3849
3850 test_77l() {
3851         [[ $(lustre_version_code ost1) -ge $(version_code 2.10.56) ]] ||
3852                 { skip "Need OST version at least 2.10.56"; return 0; }
3853
3854         do_facet ost1 lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ nid"
3855         do_facet ost1 lctl set_param ost.OSS.ost_io.nrs_policies="tbf"
3856
3857         local output=$(do_facet ost1 lctl get_param \
3858                         ost.OSS.ost_io.nrs_policies | \
3859                         awk '/name: tbf/ {print;exit}' | \
3860                         awk -F ': ' '{print $2}')
3861
3862         if [ "$output" != "tbf" ]; then
3863                 error "The generic TBF output is '$output', not 'tbf'"
3864         fi
3865
3866         do_facet ost1 lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3867 }
3868 run_test 77l "check the output of NRS policies for generic TBF"
3869
3870 test_77m() {
3871         if [ $(lustre_version_code ost1) -lt $(version_code 2.9.54) ]; then
3872                 skip "Need OST version at least 2.9.54"
3873                 return 0
3874         fi
3875
3876         local dir=$DIR/$tdir
3877
3878         mkdir $dir || error "mkdir $dir failed"
3879         $LFS setstripe -c $OSTCOUNT $dir || error "setstripe to $dir failed"
3880         chmod 777 $dir
3881
3882         local nodes=$(comma_list $(osts_nodes))
3883         do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies=delay \
3884                                        ost.OSS.ost_io.nrs_delay_min=4 \
3885                                        ost.OSS.ost_io.nrs_delay_max=4 \
3886                                        ost.OSS.ost_io.nrs_delay_pct=100
3887         [ $? -ne 0 ] && error "Failed to set delay policy"
3888
3889         local start=$SECONDS
3890         do_nodes "${SINGLECLIENT:-$HOSTNAME}" "$RUNAS" \
3891                  dd if=/dev/zero of="$dir/nrs_delay_$HOSTNAME" bs=1M count=1 \
3892                    oflag=direct conv=fdatasync ||
3893                 { do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo";
3894                   error "dd on client failed (1)"; }
3895         local elapsed=$((SECONDS - start))
3896
3897         # NRS delay doesn't do sub-second timing, so a request enqueued at
3898         # 0.9 seconds can be dequeued at 4.0
3899         [ $elapsed -lt 3 ] &&
3900                 { do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo";
3901                   error "Single 1M write should take at least 3 seconds"; }
3902
3903         start=$SECONDS
3904         do_nodes "${SINGLECLIENT:-$HOSTNAME}" "$RUNAS" \
3905                  dd if=/dev/zero of="$dir/nrs_delay_$HOSTNAME" bs=1M count=10 \
3906                    oflag=direct conv=fdatasync ||
3907                 { do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo";
3908                   error "dd on client failed (2)"; }
3909         elapsed=$((SECONDS - start))
3910
3911         [ $elapsed -lt 30 ] &&
3912                 { do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo";
3913                   error "Ten 1M writes should take at least 30 seconds"; }
3914
3915         do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3916         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3917
3918         return 0
3919 }
3920 run_test 77m "check NRS Delay slows write RPC processing"
3921
3922 test_77n() { #LU-10802
3923         if [ $(lustre_version_code ost1) -lt $(version_code 2.10.58) ]; then
3924                 skip "Need OST version at least 2.10.58"
3925                 return 0
3926         fi
3927
3928         # Configure jobid_var
3929         local saved_jobid_var=$($LCTL get_param -n jobid_var)
3930         if [ $saved_jobid_var != procname_uid ]; then
3931                 set_persistent_param_and_check client \
3932                         "jobid_var" "$FSNAME.sys.jobid_var" procname_uid
3933         fi
3934
3935         do_nodes $(comma_list $(osts_nodes)) \
3936                 lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ jobid" \
3937                         ost.OSS.ost_io.nrs_tbf_rule="stop\ dd_runas" \
3938                         ost.OSS.ost_io.nrs_tbf_rule="start\ dd_runas\ jobid={*.$RUNAS_ID}\ rate=20"
3939
3940         nrs_write_read
3941         tbf_verify 20 20 "$RUNAS"
3942
3943         do_nodes $(comma_list $(osts_nodes)) \
3944                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ dd_runas" \
3945                         ost.OSS.ost_io.nrs_tbf_rule="start\ dd_runas\ jobid={dd.*}\ rate=20"
3946
3947         nrs_write_read
3948         tbf_verify 20 20
3949
3950         do_nodes $(comma_list $(osts_nodes)) \
3951                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ dd_runas" \
3952                         ost.OSS.ost_io.nrs_policies="fifo"
3953
3954         sleep 3
3955
3956         local current_jobid_var=$($LCTL get_param -n jobid_var)
3957         if [ $saved_jobid_var != $current_jobid_var ]; then
3958                 set_persistent_param_and_check client \
3959                         "jobid_var" "$FSNAME.sys.jobid_var" $saved_jobid_var
3960         fi
3961 }
3962 run_test 77n "check wildcard support for TBF JobID NRS policy"
3963
3964 test_78() { #LU-6673
3965         local rc
3966
3967         oss=$(comma_list $(osts_nodes))
3968         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="orr" &
3969         do_nodes $oss lctl set_param ost.OSS.*.nrs_orr_quantum=1
3970         rc=$?
3971         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3972         # Valid return codes are:
3973         # 0: Tuning succeeded
3974         # ENODEV: Policy is still stopped
3975         # EAGAIN: Policy is being initialized
3976         [ $rc -eq 0 -o $rc -eq 19 -o $rc -eq 11 ] ||
3977                 error "Expected set_param to return 0|ENODEV|EAGAIN"
3978
3979         # Cleanup the ORR policy
3980         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3981         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3982         return 0
3983 }
3984 run_test 78 "Enable policy and specify tunings right away"
3985
3986 test_79() {
3987         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3988         test_mkdir $DIR/$tdir
3989
3990         # Prevent interference from layout intent RPCs due to
3991         # asynchronous writeback. These will be tested in 130c below.
3992         do_nodes ${CLIENTS:-$HOSTNAME} sync
3993
3994         setfattr -n trusted.name1 -v value1 $DIR/$tdir ||
3995                 error "setfattr -n trusted.name1=value1 $DIR/$tdir failed"
3996
3997 #define OBD_FAIL_MDS_INTENT_DELAY               0x160
3998         local mdtidx=$($LFS getstripe -m $DIR/$tdir)
3999         local facet=mds$((mdtidx + 1))
4000         stat $DIR/$tdir
4001         set_nodes_failloc $(facet_active_host $facet) 0x80000160
4002         getfattr -n trusted.name1 $DIR/$tdir 2> /dev/null  &
4003         local pid=$!
4004         sleep 2
4005
4006 #define OBD_FAIL_MDS_GETXATTR_PACK       0x131
4007         set_nodes_failloc $(facet_active_host $facet) 0x80000131
4008
4009         wait $pid
4010         return 0
4011 }
4012 run_test 79 "xattr: intent error"
4013
4014 test_80a() {
4015         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4016         local MDTIDX=1
4017         local mdt_index
4018         local i
4019         local file
4020         local pid
4021
4022         mkdir -p $DIR1/$tdir/dir
4023         createmany -o $DIR1/$tdir/dir/f 10 ||
4024                 error "create files under remote dir failed $i"
4025
4026         cp /etc/passwd $DIR1/$tdir/$tfile
4027
4028         #migrate open file should fails
4029         multiop_bg_pause $DIR2/$tdir/$tfile O_c || error "open $file failed"
4030         pid=$!
4031         # give multiop a chance to open
4032         sleep 1
4033
4034         $LFS migrate -m $MDTIDX $DIR1/$tdir &&
4035                 error "migrate open files should failed with open files"
4036
4037         kill -USR1 $pid
4038
4039         $LFS migrate -m $MDTIDX $DIR1/$tdir ||
4040                         error "migrate remote dir error"
4041
4042         echo "Finish migration, then checking.."
4043         for file in $(find $DIR1/$tdir); do
4044                 mdt_index=$($LFS getstripe -m $file)
4045                 [ $mdt_index == $MDTIDX ] ||
4046                         error "$file is not on MDT${MDTIDX}"
4047         done
4048
4049         diff /etc/passwd $DIR1/$tdir/$tfile ||
4050                 error "file different after migration"
4051
4052         rm -rf $DIR1/$tdir || error "rm dir failed after migration"
4053 }
4054 run_test 80a "migrate directory when some children is being opened"
4055
4056 cleanup_80b() {
4057         trap 0
4058         kill -9 $migrate_pid
4059 }
4060
4061 test_80b() {
4062         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4063         local migrate_dir1=$DIR1/$tdir/migrate_dir
4064         local migrate_dir2=$DIR2/$tdir/migrate_dir
4065         local migrate_run=$LUSTRE/tests/migrate.sh
4066         local start_time
4067         local end_time
4068         local show_time=1
4069         local mdt_idx
4070         local rc=0
4071         local rc1=0
4072
4073         trap cleanup_80b EXIT
4074         #prepare migrate directory
4075         mkdir -p $migrate_dir1
4076         for F in {1,2,3,4,5}; do
4077                 echo "$F$F$F$F$F" > $migrate_dir1/file$F
4078                 echo "$F$F$F$F$F" > $DIR/$tdir/file$F
4079         done
4080
4081         #migrate the directories among MDTs
4082         (
4083                 while true; do
4084                         mdt_idx=$((RANDOM % MDSCOUNT))
4085                         $LFS migrate -m $mdt_idx $migrate_dir1 &>/dev/null ||
4086                                 rc=$?
4087                         [ $rc -ne 0 -o $rc -ne 16 ] || break
4088                 done
4089         ) &
4090         migrate_pid=$!
4091
4092         echo "start migration thread $migrate_pid"
4093         #Access the files at the same time
4094         start_time=$(date +%s)
4095         echo "accessing the migrating directory for 5 minutes..."
4096         while true; do
4097                 ls $migrate_dir2 > /dev/null || {
4098                         echo "read dir fails"
4099                         break
4100                 }
4101                 diff -u $DIR2/$tdir/file1 $migrate_dir2/file1 || {
4102                         echo "access file1 fails"
4103                         break
4104                 }
4105
4106                 cat $migrate_dir2/file2 > $migrate_dir2/file3 || {
4107                         echo "access file2/3 fails"
4108                         break
4109                 }
4110
4111                 echo "aaaaa" > $migrate_dir2/file4 > /dev/null || {
4112                         echo "access file4 fails"
4113                         break
4114                 }
4115
4116                 stat $migrate_dir2/file5 > /dev/null || {
4117                         echo "stat file5 fails"
4118                         break
4119                 }
4120
4121                 touch $migrate_dir2/source_file > /dev/null || rc1=$?
4122                 [ $rc1 -ne 0 -o $rc1 -ne 1 ] || {
4123                         echo "touch file failed with $rc1"
4124                         break;
4125                 }
4126
4127                 if [ -e $migrate_dir2/source_file ]; then
4128                         ln $migrate_dir2/source_file $migrate_dir2/link_file \
4129                                         &>/dev/null || rc1=$?
4130                         if [ -e $migrate_dir2/link_file ]; then
4131                                 rm -rf $migrate_dir2/link_file
4132                         fi
4133
4134                         mrename $migrate_dir2/source_file \
4135                                 $migrate_dir2/target_file &>/dev/null || rc1=$?
4136                         [ $rc1 -ne 0 -o $rc1 -ne 1 ] || {
4137                                 echo "rename failed with $rc1"
4138                                 break
4139                         }
4140
4141                         if [ -e $migrate_dir2/target_file ]; then
4142                                 rm -rf $migrate_dir2/target_file &>/dev/null ||
4143                                                                 rc1=$?
4144                         else
4145                                 rm -rf $migrate_dir2/source_file &>/dev/null ||
4146                                                                 rc1=$?
4147                         fi
4148                         [ $rc1 -ne 0 -o $rc1 -ne 1 ] || {
4149                                 echo "unlink failed with $rc1"
4150                                 break
4151                         }
4152                 fi
4153
4154                 end_time=$(date +%s)
4155                 duration=$((end_time - start_time))
4156                 if [ $((duration % 10)) -eq 0 ]; then
4157                         if [ $show_time -eq 1 ]; then
4158                                 echo "...$duration seconds"
4159                                 show_time=0
4160                         fi
4161                 else
4162                         show_time=1
4163                 fi
4164
4165                 kill -0 $migrate_pid || {
4166                         echo "migration stopped 1"
4167                         break
4168                 }
4169
4170                 [ $duration -ge 300 ] && break
4171         done
4172
4173         #check migration are still there
4174         kill -0 $migrate_pid || error "migration stopped 2"
4175         cleanup_80b
4176 }
4177 run_test 80b "Accessing directory during migration"
4178
4179 test_81a() {
4180         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4181
4182         rm -rf $DIR1/$tdir
4183
4184         mkdir -p $DIR1/$tdir
4185
4186         $LFS setdirstripe -i0 -c$MDSCOUNT  $DIR1/$tdir/d0
4187         $LFS setdirstripe -i0 -c$MDSCOUNT  $DIR1/$tdir/d1
4188
4189         cd $DIR1/$tdir
4190         touch d0/0      || error "create 0 failed"
4191         mv d0/0 d1/0    || error "rename d0/0 d1/0 failed"
4192         stat d0/0       && error "stat mv filed succeed"
4193         mv $DIR2/$tdir/d1/0 $DIR2/$tdir/d0/0 || error "rename d1/0 d0/0 failed"
4194         stat d0/0       || error "stat failed"
4195
4196         local t=$(ls -ai $DIR1/$tdir/d0 | sort -u | wc -l)
4197
4198         if [ $t -ne 3 ]; then
4199                 ls -ai $DIR1/$tdir/d0
4200                 error "expect 3 get $t"
4201         fi
4202
4203         return 0
4204 }
4205 run_test 81a "rename and stat under striped directory"
4206
4207 test_81b() {
4208         [ $MDSCOUNT -lt 2 ] &&
4209                 skip "We need at least 2 MDTs for this test"
4210
4211         local total
4212         local setattr_pid
4213
4214         total=1000
4215
4216         $LFS mkdir -c $MDSCOUNT $DIR1/$tdir || error "$LFS mkdir"
4217         createmany -o $DIR1/$tdir/$tfile. $total || error "createmany"
4218
4219         (
4220                 while true; do
4221                         touch $DIR1/$tdir
4222                 done
4223         ) &
4224         setattr_pid=$!
4225
4226         for i in $(seq $total); do
4227                 mrename $DIR2/$tdir/$tfile.$i $DIR2/$tdir/$tfile-new.$i \
4228                         > /dev/null
4229         done
4230
4231         kill -9 $setattr_pid
4232 }
4233 run_test 81b "rename under striped directory doesn't deadlock"
4234
4235 test_82() {
4236         [[ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.6.91) ]] ||
4237                 { skip "Need MDS version at least 2.6.92"; return 0; }
4238
4239         # Client 1 creates a file.
4240         multiop_bg_pause $DIR1/$tfile O_ac || error "multiop_bg_pause 1"
4241         pid1=$!
4242         # Client 2 opens the file.
4243         multiop_bg_pause $DIR2/$tfile o_Ac || error "multiop_bg_pause 2"
4244         pid2=$!
4245         # Client 1 makes the file an orphan.
4246         rm $DIR1/$tfile || error "rm"
4247         # Client 2 sets EA "user.multiop".
4248         kill -s USR1 $pid2
4249         wait $pid2 || error "multiop 2"
4250         # Client 1 gets EA "user.multiop".  This used to fail because the EA
4251         # cache refill would get "trusted.link" from mdd_xattr_list() but
4252         # -ENOENT when trying to get "trusted.link"'s value.  See also sanity
4253         # 102q.
4254         kill -s USR1 $pid1
4255         wait $pid1 || error "multiop 1"
4256 }
4257 run_test 82 "fsetxattr and fgetxattr on orphan files"
4258
4259 test_83() {
4260         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4261         local pid1
4262         local pid2
4263
4264         (
4265                 cd $DIR1
4266                 while true; do
4267                         $LFS mkdir -i1 -c2 $tdir
4268                         rmdir $tdir
4269                 done
4270         ) &
4271         pid1=$!
4272         echo "start pid $pid1 to create/unlink striped directory"
4273
4274         # Access the directory at the same time
4275         (
4276                 cd $DIR2
4277                 while true; do
4278                         stat $tdir > /dev/null 2>&1
4279                 done
4280         ) &
4281         pid2=$!
4282         echo "start pid $pid2 to stat striped directory"
4283
4284         sleep 120
4285         kill $pid1 $pid2
4286         wait $pid1 $pid2
4287
4288         return 0
4289 }
4290 run_test 83 "access striped directory while it is being created/unlinked"
4291
4292 test_90() {
4293         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4294         local pid1
4295         local pid2
4296         local duration=180
4297
4298         [ "$SLOW" = "yes" ] && duration=600
4299         # Open/Create under striped directory
4300         (
4301                 cd $DIR1
4302                 while true; do
4303                         $LFS mkdir -c$MDSCOUNT $tdir > /dev/null 2>&1
4304                         touch $tdir/f{0..3} > /dev/null 2>&1
4305                 done
4306         ) &
4307         pid1=$!
4308         echo "start pid $pid1 to open/create under striped directory"
4309
4310         # unlink the striped directory at the same time
4311         (
4312                 cd $DIR2
4313                 while true; do
4314                         rm -rf $tdir > /dev/null 2>&1
4315                 done
4316         ) &
4317         pid2=$!
4318         echo "start pid $pid2 to unlink striped directory"
4319
4320         sleep $duration
4321
4322         kill $pid1 $pid2
4323         wait $pid1 $pid2
4324
4325         return 0
4326 }
4327 run_test 90 "open/create and unlink striped directory"
4328
4329 test_91() {
4330         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4331         local pid1
4332         local pid2
4333         local duration=180
4334
4335         [ "$SLOW" = "yes" ] && duration=600
4336         # chmod striped directory
4337         (
4338                 cd $DIR1
4339                 while true; do
4340                         $LFS mkdir -c$MDSCOUNT $tdir > /dev/null 2>&1
4341                         chmod go+w $tdir > /dev/null 2>&1
4342                 done
4343         ) &
4344         pid1=$!
4345         echo "start pid $pid1 to chmod striped directory"
4346
4347         # unlink the striped directory at the same time
4348         (
4349                 cd $DIR2
4350                 while true; do
4351                         rm -rf $tdir > /dev/null 2>&1
4352                 done
4353         ) &
4354         pid2=$!
4355         echo "start pid $pid2 to unlink striped directory"
4356
4357         sleep $duration
4358
4359         kill $pid1 $pid2
4360         wait $pid1 $pid2
4361
4362         return 0
4363 }
4364 run_test 91 "chmod and unlink striped directory"
4365
4366 test_92() {
4367         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4368
4369         local fd=$(free_fd)
4370         local cmd="exec $fd<$DIR1/$tdir"
4371         $LFS setdirstripe -c$MDSCOUNT $DIR1/$tdir || error "mkdir $tdir fails"
4372         eval $cmd
4373         cmd="exec $fd<&-"
4374         trap "eval $cmd" EXIT
4375         cd $DIR1/$tdir || error "cd $DIR1/$tdir fails"
4376         rmdir ../$tdir || error "rmdir ../$tdir fails"
4377
4378         #define OBD_FAIL_LLITE_NO_CHECK_DEAD  0x1408
4379         $LCTL set_param fail_loc=0x1408
4380         mkdir $DIR2/$tdir/dir && error "create dir succeeds"
4381         $LFS setdirstripe -i1 $DIR2/$tdir/remote_dir &&
4382                 error "create remote dir succeeds"
4383         $LCTL set_param fail_loc=0
4384         eval $cmd
4385         return 0
4386 }
4387 run_test 92 "create remote directory under orphan directory"
4388
4389 test_93() {
4390         local rc1=0
4391         local rc2=0
4392         local old_rr
4393
4394         mkdir -p $DIR1/$tfile-1/
4395         mkdir -p $DIR2/$tfile-2/
4396         local old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
4397                 'lod.lustre-MDT*/qos_threshold_rr' | sed -e 's/%//')
4398         do_facet $SINGLEMDS lctl set_param -n \
4399                 'lod.lustre-MDT*/qos_threshold_rr' 100
4400         #define OBD_FAIL_MDS_LOV_CREATE_RACE     0x163
4401         do_facet $SINGLEMDS "lctl set_param fail_loc=0x00000163"
4402
4403         $LFS setstripe -c -1 $DIR1/$tfile-1/file1 &
4404         local PID1=$!
4405         sleep 1
4406         $LFS setstripe -c -1 $DIR2/$tfile-2/file2 &
4407         local PID2=$!
4408         wait $PID2
4409         wait $PID1
4410         do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
4411         do_facet $SINGLEMDS "lctl set_param -n \
4412                 'lod.lustre-MDT*/qos_threshold_rr' $old_rr"
4413
4414         $LFS getstripe $DIR1/$tfile-1/file1
4415         rc1=$($LFS getstripe -q $DIR1/$tfile-1/file1 |
4416                 awk '{if (/[0-9]/) print $1 }' | sort | uniq -d | wc -l)
4417         $LFS getstripe $DIR2/$tfile-2/file2
4418         rc2=$($LFS getstripe -q $DIR2/$tfile-2/file2 |
4419                 awk '{if (/[0-9]/) print $1 }' | sort | uniq -d | wc -l)
4420         echo "rc1=$rc1 and rc2=$rc2 "
4421         [ $rc1 -eq 0 ] && [ $rc2 -eq 0 ] ||
4422                 error "object allocate on same ost detected"
4423 }
4424 run_test 93 "alloc_rr should not allocate on same ost"
4425
4426 # Data-on-MDT tests
4427 test_100a() {
4428         skip "Reserved for glimpse-ahead" && return
4429         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4430                 skip "Need MDS version at least 2.10.55" && return
4431
4432         mkdir -p $DIR/$tdir
4433
4434         $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
4435
4436         lctl set_param -n mdc.*.stats=clear
4437         dd if=/dev/zero of=$DIR2/$tdir/dom bs=4096 count=1 || return 1
4438
4439         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #1"
4440         # first stat from server should return size data and save glimpse
4441         local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
4442         [ $gls -eq 0 ] || error "Unexpected $gls glimpse RPCs"
4443         # second stat to check size is NOT cached on client without IO lock
4444         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #2"
4445
4446         local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
4447         [ $gls -ge 1 ] || error "Expect glimpse RPCs but none"
4448         rm -f $dom
4449 }
4450 run_test 100a "DoM: glimpse RPCs for stat without IO lock (DoM only file)"
4451
4452 test_100b() {
4453         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4454                 skip "Need MDS version at least 2.10.55" && return
4455
4456         mkdir -p $DIR/$tdir
4457
4458         $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
4459
4460         lctl set_param -n mdc.*.stats=clear
4461         dd if=/dev/zero of=$DIR2/$tdir/dom bs=4096 count=1 || return 1
4462         cancel_lru_locks mdc
4463         # first stat data from server should have size
4464         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #1"
4465         # second stat to check size is cached on client
4466         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #2"
4467
4468         local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
4469         # both stats should cause no glimpse requests
4470         [ $gls == 0 ] || error "Unexpected $gls glimpse RPCs"
4471         rm -f $dom
4472 }
4473 run_test 100b "DoM: no glimpse RPC for stat with IO lock (DoM only file)"
4474
4475 test_100c() {
4476         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4477                 skip "Need MDS version at least 2.10.55" && return
4478
4479         mkdir -p $DIR/$tdir
4480
4481         $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
4482
4483         lctl set_param -n mdc.*.stats=clear
4484         lctl set_param -n osc.*.stats=clear
4485         dd if=/dev/zero of=$DIR2/$tdir/dom bs=2048K count=1 || return 1
4486
4487         # check that size is merged from MDT and OST correctly
4488         $CHECKSTAT -t file -s 2097152 $DIR/$tdir/dom ||
4489                 error "Wrong size from stat #1"
4490
4491         local gls=$(lctl get_param -n osc.*.stats | grep -c ldlm_glimpse)
4492         [ $gls -eq 0 ] && error "Expect OST glimpse RPCs but got none"
4493
4494         rm -f $dom
4495 }
4496 run_test 100c "DoM: write vs stat without IO lock (combined file)"
4497
4498 test_100d() {
4499         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4500                 skip "Need MDS version at least 2.10.55" && return
4501
4502         mkdir -p $DIR/$tdir
4503
4504         $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
4505
4506
4507         dd if=/dev/zero of=$DIR2/$tdir/dom bs=2048K count=1 || return 1
4508         lctl set_param -n mdc.*.stats=clear
4509         $TRUNCATE $DIR2/$tdir/dom 4096
4510
4511         # check that reported size is valid after file grows to OST and
4512         # is truncated back to MDT stripe size
4513         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom ||
4514                 error "Wrong size from stat #1"
4515
4516         local gls=$(lctl get_param -n osc.*.stats | grep -c ldlm_glimpse)
4517         [ $gls -eq 0 ] && error "Expect OST glimpse but got none"
4518
4519         rm -f $dom
4520 }
4521 run_test 100d "DoM: write+truncate vs stat without IO lock (combined file)"
4522
4523 test_101a() {
4524         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4525                 skip "Need MDS version at least 2.10.55" && return
4526
4527         $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
4528         # to get layout
4529         $CHECKSTAT -t file $DIR1/$tfile
4530
4531         local old_wb=$(sysctl -n vm.dirty_writeback_centisecs)
4532         sysctl -wq vm.dirty_writeback_centisecs=0
4533
4534         trap "sysctl -wq vm.dirty_writeback_centisecs=$old_wb" EXIT
4535
4536         # open + IO lock
4537         dd if=/dev/zero of=$DIR1/$tfile bs=4096 count=1 ||
4538                 error_noexit "Write fails"
4539         # must discard pages
4540         lctl set_param -n mdc.*.stats=clear
4541         rm $DIR2/$tfile || error "Unlink fails"
4542
4543         local writes=$(lctl get_param -n mdc.*.stats | grep -c ost_write)
4544         [ $writes -eq 0 ] || error "Found WRITE RPC but expect none"
4545 }
4546 run_test 101a "Discard DoM data on unlink"
4547
4548 test_101b() {
4549         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4550                 skip "Need MDS version at least 2.10.55" && return
4551
4552         $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
4553         touch $DIR1/${tfile}_2
4554         # to get layout
4555         $CHECKSTAT -t file $DIR1/$tfile
4556
4557         local old_wb=$(sysctl -n vm.dirty_writeback_centisecs)
4558         sysctl -wq vm.dirty_writeback_centisecs=0
4559
4560         trap "sysctl -wq vm.dirty_writeback_centisecs=$old_wb" EXIT
4561
4562         # open + IO lock
4563         dd if=/dev/zero of=$DIR1/$tfile bs=4096 count=1 || error "Write fails"
4564         # must discard pages
4565         lctl set_param -n mdc.*.stats=clear
4566         mv $DIR2/${tfile}_2 $DIR2/$tfile || error "Rename fails"
4567
4568         local writes=$(lctl get_param -n mdc.*.stats | grep -c ost_write)
4569         [ $writes -eq 0 ] || error "Found WRITE RPC but expect none"
4570 }
4571 run_test 101b "Discard DoM data on rename"
4572
4573 test_101c() {
4574         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4575                 skip "Need MDS version at least 2.10.55" && return
4576
4577         $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
4578         # to get layout
4579         $CHECKSTAT -t file $DIR1/$tfile
4580
4581         local old_wb=$(sysctl -n vm.dirty_writeback_centisecs)
4582         sysctl -wq vm.dirty_writeback_centisecs=0
4583
4584         trap "sysctl -wq vm.dirty_writeback_centisecs=$old_wb" EXIT
4585
4586         # open + IO lock
4587         dd if=/dev/zero of=$DIR1/$tfile bs=4096 count=1 || error "Write fails"
4588         $MULTIOP $DIR1/$tfile O_c &
4589         MULTIOP_PID=$!
4590         sleep 1
4591         lctl set_param -n mdc.*.stats=clear
4592         rm $DIR2/$tfile > /dev/null || error "Unlink fails for opened file"
4593         kill -USR1 $MULTIOP_PID && wait $MULTIOP_PID || error "multiop failure"
4594
4595         local writes=$(lctl get_param -n mdc.*.stats | grep -c ost_write)
4596         [ $writes -eq 0 ] || error "Found WRITE RPC but expect none"
4597 }
4598 run_test 101c "Discard DoM data on close-unlink"
4599
4600 # test to verify file handle related system calls
4601 # (name_to_handle_at/open_by_handle_at)
4602 # The new system calls are supported in glibc >= 2.14.
4603
4604 # test to verify we can open by handle an unlinked file from > 1 client
4605 # This test opens the file normally on $DIR1, which is on one mount, and then
4606 # opens it by handle on $DIR2, which is on a different mount.
4607 test_102() {
4608         [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
4609                 skip "Needs MDS version 2.11.57 or later"
4610
4611         echo "Test file_handle syscalls" > $DIR/$tfile ||
4612                 error "write failed"
4613         check_fhandle_syscalls $DIR/$tfile $DIR2 ||
4614                 error "check_fhandle_syscalls failed"
4615         rm -f $DIR2/$tfile
4616 }
4617 run_test 102 "Test open by handle of unlinked file"
4618
4619 log "cleanup: ======================================================"
4620
4621 # kill and wait in each test only guarentee script finish, but command in script
4622 # like 'rm' 'chmod' may still be running, wait for all commands to finish
4623 # otherwise umount below will fail
4624 [ "$(mount | grep $MOUNT2)" ] && wait_update $HOSTNAME "fuser -m $MOUNT2" "" ||
4625         true
4626
4627 complete $SECONDS
4628 rm -f $SAMPLE_FILE
4629 check_and_cleanup_lustre
4630 exit_status