Whamcloud - gitweb
01d7293dd8c7b2c2e9df4ea762e0eead628bf706
[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 p="$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" > $p
810         cancel_lru_locks $OSC
811         enable_lockless_truncate 1
812         rm -f $DIR1/$tfile
813         lfs setstripe -c -1 $DIR1/$tfile
814         dd if=/dev/zero of=$DIR1/$tfile count=$OSTCOUNT bs=$stripe_size > \
815                 /dev/null 2>&1
816         clear_stats $OSC.*.${OSC}_stats
817
818         log "checking cached lockless truncate"
819         $TRUNCATE $DIR1/$tfile 8000000
820         $CHECKSTAT -s 8000000 $DIR2/$tfile || error "wrong file size"
821         [ $(calc_stats $OSC.*.${OSC}_stats lockless_truncate) -ne 0 ] ||
822                 error "cached truncate isn't lockless"
823
824         log "checking not cached lockless truncate"
825         $TRUNCATE $DIR2/$tfile 5000000
826         $CHECKSTAT -s 5000000 $DIR1/$tfile || error "wrong file size"
827         [ $(calc_stats $OSC.*.${OSC}_stats lockless_truncate) -ne 0 ] ||
828                 error "not cached truncate isn't lockless"
829
830         log "disabled lockless truncate"
831         enable_lockless_truncate 0
832         clear_stats $OSC.*.${OSC}_stats
833         $TRUNCATE $DIR2/$tfile 3000000
834         $CHECKSTAT -s 3000000 $DIR1/$tfile || error "wrong file size"
835         [ $(calc_stats $OSC.*.${OSC}_stats lockless_truncate) -eq 0 ] ||
836                 error "lockless truncate disabling failed"
837         rm $DIR1/$tfile
838         # restore lockless_truncate default values
839         restore_lustre_params < $p
840         rm -f $p
841 }
842 run_test 32a "lockless truncate"
843
844 test_32b() { # bug 11270
845         remote_ost_nodsh && skip "remote OST with nodsh" && return
846
847         local node
848         local facets=$(get_facets OST)
849         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
850
851         save_lustre_params client "osc.*.contention_seconds" > $p
852         save_lustre_params $facets \
853                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
854         save_lustre_params $facets \
855                 "ldlm.namespaces.filter-*.contended_locks" >> $p
856         save_lustre_params $facets \
857                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
858         clear_stats $OSC.*.${OSC}_stats
859
860         # agressive lockless i/o settings
861         do_nodes $(comma_list $(osts_nodes)) \
862                 "lctl set_param -n ldlm.namespaces.*.max_nolock_bytes=2000000 \
863                         ldlm.namespaces.filter-*.contended_locks=0 \
864                         ldlm.namespaces.filter-*.contention_seconds=60"
865         lctl set_param -n $OSC.*.contention_seconds=60
866         for i in {1..5}; do
867                 dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1 conv=notrunc > \
868                         /dev/null 2>&1
869                 dd if=/dev/zero of=$DIR2/$tfile bs=4k count=1 conv=notrunc > \
870                         /dev/null 2>&1
871         done
872         [ $(calc_stats $OSC.*.${OSC}_stats lockless_write_bytes) -ne 0 ] ||
873                 error "lockless i/o was not triggered"
874         # disable lockless i/o (it is disabled by default)
875         do_nodes $(comma_list $(osts_nodes)) \
876                 "lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes=0 \
877                         ldlm.namespaces.filter-*.contended_locks=32 \
878                         ldlm.namespaces.filter-*.contention_seconds=0"
879         # set contention_seconds to 0 at client too, otherwise Lustre still
880         # remembers lock contention
881         lctl set_param -n $OSC.*.contention_seconds=0
882         clear_stats $OSC.*.${OSC}_stats
883         for i in {1..1}; do
884                 dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1 conv=notrunc > \
885                         /dev/null 2>&1
886                 dd if=/dev/zero of=$DIR2/$tfile bs=4k count=1 conv=notrunc > \
887                         /dev/null 2>&1
888         done
889         [ $(calc_stats $OSC.*.${OSC}_stats lockless_write_bytes) -eq 0 ] ||
890                 error "lockless i/o works when disabled"
891         rm -f $DIR1/$tfile
892         restore_lustre_params <$p
893         rm -f $p
894 }
895 run_test 32b "lockless i/o"
896
897 print_jbd_stat () {
898     local dev
899     local mdts=$(get_facets MDS)
900     local varcvs
901     local mds
902
903     local stat=0
904     for mds in ${mdts//,/ }; do
905         varsvc=${mds}_svc
906         dev=$(basename $(do_facet $mds "lctl get_param -n osd*.${!varsvc}.mntdev|\
907                 xargs readlink -f" ))
908         val=$(do_facet $mds "cat /proc/fs/jbd*/${dev}{,:*,-*}/info 2>/dev/null |
909                 head -n1")
910         val=${val%% *};
911         stat=$(( stat + val))
912     done
913     echo $stat
914 }
915
916 # commit on sharing tests
917 test_33a() {
918     remote_mds_nodsh && skip "remote MDS with nodsh" && return
919
920     [ -z "$CLIENTS" ] && skip "Need two or more clients, have $CLIENTS" && return 0
921     [ $CLIENTCOUNT -lt 2 ] &&
922         skip "Need two or more clients, have $CLIENTCOUNT" && return 0
923
924     local nfiles=${TEST33_NFILES:-10000}
925     local param_file=$TMP/$tfile-params
926     local fstype=$(facet_fstype $SINGLEMDS)
927
928         save_lustre_params $(get_facets MDS) \
929                 "mdt.*.commit_on_sharing" > $param_file
930
931     local COS
932     local jbdold="N/A"
933     local jbdnew="N/A"
934     local jbd
935
936     for COS in 0 1; do
937         do_facet $SINGLEMDS lctl set_param mdt.*.commit_on_sharing=$COS
938         avgjbd=0
939         avgtime=0
940         for i in 1 2 3; do
941             do_nodes $CLIENT1,$CLIENT2 "mkdir -p $DIR1/$tdir-\\\$(hostname)-$i"
942
943             [ $fstype = ldiskfs ] && jbdold=$(print_jbd_stat)
944             echo "=== START createmany old: $jbdold transaction"
945             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")
946             [ $fstype = ldiskfs ] && jbdnew=$(print_jbd_stat)
947             [ $fstype = ldiskfs ] && jbd=$(( jbdnew - jbdold ))
948             echo "=== END   createmany new: $jbdnew transaction :  $jbd transactions  nfiles $nfiles time $elapsed COS=$COS"
949             [ $fstype = ldiskfs ] && avgjbd=$(( avgjbd + jbd ))
950             avgtime=$(( avgtime + elapsed ))
951         done
952         eval cos${COS}_jbd=$((avgjbd / 3))
953         eval cos${COS}_time=$((avgtime / 3))
954     done
955
956     echo "COS=0 transactions (avg): $cos0_jbd  time (avg): $cos0_time"
957     echo "COS=1 transactions (avg): $cos1_jbd  time (avg): $cos1_time"
958     [ "$cos0_jbd" != 0 ] && echo "COS=1 vs COS=0 jbd:  $((((cos1_jbd/cos0_jbd - 1)) * 100 )) %"
959     [ "$cos0_time" != 0 ] && echo "COS=1 vs COS=0 time: $((((cos1_time/cos0_time - 1)) * 100 )) %"
960
961     restore_lustre_params < $param_file
962     rm -f $param_file
963     return 0
964 }
965 run_test 33a "commit on sharing, cross crete/delete, 2 clients, benchmark"
966
967 # commit on sharing tests
968 test_33b() {
969         remote_mds_nodsh && skip "remote MDS with nodsh" && return
970
971         [ -n "$CLIENTS" ] || { skip "Need two or more clients" && return 0; }
972         [ $CLIENTCOUNT -ge 2 ] ||
973                 { skip "Need two or more clients, have $CLIENTCOUNT" &&
974                                                                 return 0; }
975         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
976
977         local nfiles=${TEST33_NFILES:-10000}
978         local param_file=$TMP/$tfile-params
979
980         save_lustre_params $(get_facets MDS) \
981                 "mdt.*.commit_on_sharing" > $param_file
982
983         local COS
984         local jbdold
985         local jbdnew
986         local jbd
987         local MDTIDX=1
988
989         for COS in 0 1; do
990                 do_facet $SINGLEMDS lctl set_param mdt.*.commit_on_sharing=$COS
991                 avgjbd=0
992                 avgtime=0
993                 for i in 1 2 3; do
994                         do_node $CLIENT1 "$LFS mkdir -i $MDTIDX \
995                                           $DIR1/$tdir-\\\$(hostname)-$i"
996
997                         jbdold=$(print_jbd_stat)
998                         echo "=== START createmany old: $jbdold transaction"
999                         local elapsed=$(do_and_time "do_nodes $CLIENT1,$CLIENT2\
1000                                 createmany -o $DIR1/$tdir-\\\$(hostname)-$i/f- \
1001                                 -r$DIR2/$tdir-\\\$(hostname)-$i/f- $nfiles > \
1002                                                                 /dev/null 2>&1")
1003                         jbdnew=$(print_jbd_stat)
1004                         jbd=$(( jbdnew - jbdold ))
1005                         echo "=== END   createmany new: $jbdnew transaction : \
1006                         $jbd transactions nfiles $nfiles time $elapsed COS=$COS"
1007                         avgjbd=$(( avgjbd + jbd ))
1008                         avgtime=$(( avgtime + elapsed ))
1009                 done
1010                 eval cos${COS}_jbd=$((avgjbd / 3))
1011                 eval cos${COS}_time=$((avgtime / 3))
1012         done
1013
1014         echo "COS=0 transactions (avg): $cos0_jbd  time (avg): $cos0_time"
1015         echo "COS=1 transactions (avg): $cos1_jbd  time (avg): $cos1_time"
1016         [ "$cos0_jbd" != 0 ] &&
1017             echo "COS=1 vs COS=0 jbd: $(((cos1_jbd/cos0_jbd - 1) * 100)) %"
1018         [ "$cos0_time" != 0 ] &&
1019             echo "COS=1 vs COS=0 time: $(((cos1_time/cos0_time - 1) * 100)) %"
1020
1021         restore_lustre_params < $param_file
1022         rm -f $param_file
1023         return 0
1024 }
1025 run_test 33b "COS: cross create/delete, 2 clients, benchmark under remote dir"
1026
1027 test_33c() {
1028         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1029         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.63) ] &&
1030                 skip "DNE CoS not supported" && return
1031
1032         local sync_count
1033
1034         mkdir $DIR/$tdir
1035         sync_all_data
1036         do_facet mds1 "lctl set_param -n mdt.*.sync_count=0"
1037         # do twice in case transaction is committed before unlock, see LU-8200
1038         for i in 1 2; do
1039                 # remote dir is created on MDT1, which enqueued lock of $tdir on
1040                 # MDT0
1041                 $LFS mkdir -i 1 $DIR/$tdir/remote.$i
1042                 mkdir $DIR/$tdir/local.$i
1043         done
1044         sync_count=$(do_facet mds1 "lctl get_param -n mdt.*MDT0000.sync_count")
1045         echo "sync_count $sync_count"
1046         [ $sync_count -eq 0 ] && error "Sync-Lock-Cancel not triggered"
1047
1048         sync_all_data
1049         do_facet mds1 "lctl set_param -n mdt.*.sync_count=0"
1050         $LFS mkdir -i 1 $DIR/$tdir/remote.3
1051         # during sleep remote mkdir should have been committed and canceled
1052         # remote lock spontaneously, which shouldn't trigger sync
1053         sleep 6
1054         mkdir $DIR/$tdir/local.3
1055         sync_count=$(do_facet mds1 "lctl get_param -n mdt.*MDT0000.sync_count")
1056         echo "sync_count $sync_count"
1057         [ $sync_count -eq 0 ] || error "Sync-Lock-Cancel triggered"
1058 }
1059 run_test 33c "Cancel cross-MDT lock should trigger Sync-Lock-Cancel"
1060
1061 # arg1 is operations done before CoS, arg2 is the operation that triggers CoS
1062 op_trigger_cos() {
1063         local commit_nr
1064         local total=0
1065         local nodes=$(comma_list $(mdts_nodes))
1066
1067         sync_all_data
1068
1069         # trigger CoS twice in case transaction commit before unlock
1070         for i in 1 2; do
1071                 sh -c "$1"
1072                 do_nodes $nodes "lctl set_param -n mdt.*.async_commit_count=0"
1073                 sh -c "$2"
1074                 commit_nr=$(do_nodes $nodes \
1075                         "lctl get_param -n mdt.*.async_commit_count" | calc_sum)
1076                 total=$((total + commit_nr));
1077                 rm -rf $DIR/$tdir
1078                 sync_all_data
1079         done
1080
1081         echo "CoS count $total"
1082         [ $total -gt 0 ] || error "$2 didn't trigger CoS"
1083 }
1084
1085 test_33d() {
1086         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1087         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.63) ] &&
1088                 skip "DNE CoS not supported" && return
1089
1090         # remote directory create
1091         op_trigger_cos "mkdir $DIR/$tdir" "$LFS mkdir -i 1 $DIR/$tdir/subdir"
1092         # remote directory unlink
1093         op_trigger_cos "$LFS mkdir -i 1 $DIR/$tdir" "rmdir $DIR/$tdir"
1094         # striped directory create
1095         op_trigger_cos "mkdir $DIR/$tdir" "$LFS mkdir -c 2 $DIR/$tdir/subdir"
1096         # striped directory setattr
1097         op_trigger_cos "$LFS mkdir -c 2 $DIR/$tdir; touch $DIR/$tdir" \
1098                 "chmod 713 $DIR/$tdir"
1099         # striped directory unlink
1100         op_trigger_cos "$LFS mkdir -c 2 $DIR/$tdir; touch $DIR/$tdir" \
1101                 "rmdir $DIR/$tdir"
1102         # cross-MDT link
1103         op_trigger_cos "$LFS mkdir -c 2 $DIR/$tdir; \
1104                         $LFS mkdir -i 0 $DIR/$tdir/d1; \
1105                         $LFS mkdir -i 1 $DIR/$tdir/d2; \
1106                         touch $DIR/$tdir/d1/tgt" \
1107                 "ln $DIR/$tdir/d1/tgt $DIR/$tdir/d2/src"
1108         # cross-MDT rename
1109         op_trigger_cos "$LFS mkdir -c 2 $DIR/$tdir; \
1110                         $LFS mkdir -i 0 $DIR/$tdir/d1; \
1111                         $LFS mkdir -i 1 $DIR/$tdir/d2; \
1112                         touch $DIR/$tdir/d1/src" \
1113                 "mv $DIR/$tdir/d1/src $DIR/$tdir/d2/tgt"
1114         # migrate
1115         op_trigger_cos "$LFS mkdir -i 0 $DIR/$tdir" \
1116                 "$LFS migrate -m 1 $DIR/$tdir"
1117
1118         return 0
1119 }
1120 run_test 33d "DNE distributed operation should trigger COS"
1121
1122 test_33e() {
1123         [ -n "$CLIENTS" ] || { skip "Need two or more clients" && return 0; }
1124         [ $CLIENTCOUNT -ge 2 ] ||
1125                 { skip "Need two or more clients, have $CLIENTCOUNT" &&
1126                                                                 return 0; }
1127         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1128         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.63) ] &&
1129                 skip "DNE CoS not supported" && return
1130
1131         local client2=${CLIENT2:-$(hostname)}
1132
1133         sync
1134
1135         local nodes=$(comma_list $(mdts_nodes))
1136         do_nodes $nodes "lctl set_param -n mdt.*.async_commit_count=0"
1137
1138         $LFS mkdir -c 2 $DIR/$tdir
1139         mkdir $DIR/$tdir/subdir
1140         echo abc > $DIR/$tdir/$tfile
1141         do_node $client2 echo dfg >> $DIR/$tdir/$tfile
1142         do_node $client2 touch $DIR/$tdir/subdir
1143
1144         local async_commit_count=$(do_nodes $nodes \
1145                 "lctl get_param -n mdt.*.async_commit_count" | calc_sum)
1146         [ $async_commit_count -gt 0 ] && error "CoS triggerred"
1147
1148         return 0
1149 }
1150 run_test 33e "DNE local operation shouldn't trigger COS"
1151
1152 # End commit on sharing tests
1153
1154 get_ost_lock_timeouts() {
1155     local nodes=${1:-$(comma_list $(osts_nodes))}
1156
1157     local locks=$(do_nodes $nodes \
1158         "lctl get_param -n ldlm.namespaces.filter-*.lock_timeouts" | calc_sum)
1159
1160     echo $locks
1161 }
1162
1163 cleanup_34() {
1164         local i
1165         trap 0
1166         do_nodes $(comma_list $(osts_nodes)) \
1167                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
1168         for i in $(seq $OSTCOUNT); do
1169                 wait_osc_import_ready client ost$i
1170         done
1171 }
1172
1173 test_34() { #16129
1174         remote_ost_nodsh && skip "remote OST with nodsh" && return
1175         local OPER
1176         local lock_in
1177         local lock_out
1178         trap cleanup_34 EXIT RETURN
1179         for OPER in notimeout timeout ; do
1180                 rm $DIR1/$tfile 2>/dev/null
1181                 lock_in=$(get_ost_lock_timeouts)
1182                 if [ $OPER == "timeout" ] ; then
1183                         for j in `seq $OSTCOUNT`; do
1184                                 #define OBD_FAIL_PTLRPC_HPREQ_TIMEOUT    0x511
1185                                 do_facet ost$j lctl set_param fail_loc=0x511
1186                         done
1187                         echo lock should expire
1188                 else
1189                         for j in `seq $OSTCOUNT`; do
1190                                 #define OBD_FAIL_PTLRPC_HPREQ_NOTIMEOUT  0x512
1191                                 do_facet ost$j lctl set_param fail_loc=0x512
1192                         done
1193                         echo lock should not expire
1194                 fi
1195                 echo writing on client1
1196                 dd if=/dev/zero of=$DIR1/$tfile count=100 conv=notrunc > /dev/null 2>&1
1197                 sync &
1198                 echo reading on client2
1199                 dd of=/dev/null if=$DIR2/$tfile > /dev/null 2>&1
1200                 # wait for a lock timeout
1201                 sleep 4
1202                 lock_out=$(get_ost_lock_timeouts)
1203                 if [ $OPER == "timeout" ] ; then
1204                         if [ $lock_in == $lock_out ]; then
1205                                 error "no lock timeout happened"
1206                         else
1207                                 echo "success"
1208                         fi
1209                 else
1210                         if [ $lock_in != $lock_out ]; then
1211                                 error "lock timeout happened"
1212                         else
1213                                 echo "success"
1214                         fi
1215                 fi
1216         done
1217         cleanup_34
1218 }
1219 run_test 34 "no lock timeout under IO"
1220
1221 test_35() { # bug 17645
1222         local generation=[]
1223         local count=0
1224         gen=$(lctl get_param mdc.$FSNAME-MDT*-mdc-*.import | grep generation |
1225               awk '/generation/{print $2}')
1226         for g in $gen; do
1227                 generation[count]=$g
1228                 let count=count+1
1229         done
1230
1231         test_mkdir $MOUNT1/$tdir
1232         cancel_lru_locks mdc
1233
1234         # Let's initiate -EINTR situation by setting fail_loc and take
1235         # write lock on same file from same client. This will not cause
1236         # bl_ast yet as lock is already in local cache.
1237         #define OBD_FAIL_LDLM_INTR_CP_AST        0x317
1238         do_facet client "lctl set_param fail_loc=0x80000317"
1239         local timeout=$(do_facet $SINGLEMDS lctl get_param  -n timeout)
1240         let timeout=timeout*3
1241         local nr=0
1242         while test $nr -lt 10; do
1243                 log "Race attempt $nr"
1244                 local blk1=$(lctl get_param -n ldlm.services.ldlm_cbd.stats |
1245                              awk '/ldlm_bl_callback/ { print $2 }')
1246                 test "x$blk1" = "x" && blk1=0
1247                 createmany -o $MOUNT2/$tdir/a 4000 &
1248                 pid1=$!
1249                 sleep 1
1250
1251                 # Let's make conflict and bl_ast
1252                 ls -la $MOUNT1/$tdir > /dev/null &
1253                 pid2=$!
1254
1255                 log "Wait for $pid1 $pid2 for $timeout sec..."
1256                 sleep $timeout
1257                 kill -9 $pid1 $pid2 > /dev/null 2>&1
1258                 wait
1259                 local blk2=$(lctl get_param -n ldlm.services.ldlm_cbd.stats |
1260                              awk '/ldlm_bl_callback/ { print $2 }')
1261                 test "x$blk2" = "x" && blk2=0
1262                 test $blk2 -gt $blk1 && break
1263                 rm -fr $MOUNT1/$tdir
1264                 cancel_lru_locks mdc
1265                 let nr=nr+1
1266         done
1267         do_facet client "lctl set_param fail_loc=0x0"
1268         df -h $MOUNT1 $MOUNT2
1269         count=0
1270         gen=$(lctl get_param mdc.$FSNAME-MDT*-mdc-*.import | grep generation |
1271                 awk '/generation/{print $2}')
1272         for g in $gen; do
1273             if ! test "$g" -eq "${generation[count]}"; then
1274                 list=$(lctl list_param mdc.$FSNAME-MDT*-mdc-*.import)
1275                 local c=0
1276                 for imp in $list; do
1277                         if [ $c = $count ]; then
1278                                 break
1279                         fi
1280                         c=c+1
1281                 done
1282                 imp=$(echo "$imp" | awk -F"." '{print $2}')
1283                 error "Eviction happened on import $imp"
1284             fi
1285             let count=count+1
1286         done
1287 }
1288 run_test 35 "-EINTR cp_ast vs. bl_ast race does not evict client"
1289
1290 test_36() { #bug 16417
1291         local SIZE
1292         local SIZE_B
1293         local i
1294
1295         test_mkdir $DIR1/$tdir
1296         $LFS setstripe -c -1 $DIR1/$tdir
1297         i=0
1298         SIZE=50
1299         let SIZE_B=SIZE*1024*1024
1300         sync; sleep 2; sync # wait for delete thread
1301         wait_mds_ost_sync || error "wait_mds_ost_sync failed"
1302         wait_destroy_complete || error "wait_destroy_complete failed"
1303
1304         while [ $i -le 10 ]; do
1305                 lctl mark "start test - cycle ($i)"
1306                 local before=$(lfs_df $MOUNT1 | awk '/^filesystem/{ print $4; exit }')
1307                 dd if=/dev/zero of=$DIR1/$tdir/$tfile bs=1M count=$SIZE ||
1308                         error "dd $DIR1/$tdir/$tfile ${SIZE}MB failed"
1309                 sync          # sync data from client cache
1310                 sync_all_data # sync data from server cache (delayed allocation)
1311                 sleep 2
1312                 local after_dd=$(lfs_df $MOUNT1 | awk '/^filesystem/{ print $4; exit }')
1313                 multiop_bg_pause $DIR2/$tdir/$tfile O_r${SIZE_B}c || return 3
1314                 read_pid=$!
1315                 rm -f $DIR1/$tdir/$tfile
1316                 kill -USR1 $read_pid
1317                 wait $read_pid
1318                 sync; sleep 2; sync # Ensure new statfs
1319                 wait_delete_completed
1320                 local after=$(lfs_df $MOUNT1 | awk '/^filesystem/{ print $4; exit }')
1321                 echo "*** cycle($i) *** before($before) after_dd($after_dd)" \
1322                         "after($after)"
1323                 # this free space! not used
1324                 (( $after_dd <= $after)) ||
1325                         error "space leaked after_dd:$after_dd > after:$after"
1326                 let i=i+1
1327         done
1328 }
1329 run_test 36 "handle ESTALE/open-unlink correctly"
1330
1331 test_37() { # bug 18695
1332         test_mkdir $DIR1/$tdir
1333         multiop_bg_pause $DIR1/$tdir D_c || return 1
1334         MULTIPID=$!
1335         # create large directory (32kB seems enough from e2fsck, ~= 1000 files)
1336         createmany -m $DIR2/$tdir/f 10000
1337         # set mtime/atime backward
1338         touch -t 198001010000 $DIR2/$tdir
1339         kill -USR1 $MULTIPID
1340         nr_files=`lfs find $DIR1/$tdir -type f | wc -l`
1341         [ $nr_files -eq 10000 ] || error "$nr_files != 10000 truncated directory?"
1342
1343 }
1344 run_test 37 "check i_size is not updated for directory on close (bug 18695) =============="
1345
1346 # this should be set to past
1347 TEST_39_MTIME=`date -d "1 year ago" +%s`
1348
1349 # bug 11063
1350 test_39a() {
1351         local client1=${CLIENT1:-`hostname`}
1352         local client2=${CLIENT2:-`hostname`}
1353
1354         do_node $client1 "touch $DIR1/$tfile"
1355
1356         do_node $client1 "touch -m -d @$TEST_39_MTIME $DIR1/$tfile"
1357         local mtime1=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1358         [ "$mtime1" = $TEST_39_MTIME ] || \
1359                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
1360
1361         local d1=`do_node $client1 date +%s`
1362         do_node $client1 'echo hello >> '$DIR1/$tfile
1363         local d2=`do_node $client1 date +%s`
1364
1365         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1366         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
1367                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
1368
1369         do_node $client1 "mv $DIR1/$tfile $DIR1/$tfile-1"
1370
1371         for (( i=0; i < 2; i++ )) ; do
1372                 local mtime3=`do_node $client2 "stat -c %Y $DIR1/$tfile-1"`
1373                 [ "$mtime2" = "$mtime3" ] || \
1374                         error "mtime ($mtime2) changed (to $mtime3) on rename"
1375
1376                 cancel_lru_locks osc
1377                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1378         done
1379 }
1380 run_test 39a "test from 11063 =================================="
1381
1382 test_39b() {
1383         local client1=${CLIENT1:-`hostname`}
1384         local client2=${CLIENT2:-`hostname`}
1385
1386         touch $DIR1/$tfile
1387
1388         local mtime1=`stat -c %Y $DIR1/$tfile`
1389         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1390
1391         sleep 1
1392         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
1393
1394         for (( i=0; i < 2; i++ )) ; do
1395                 local mtime3=`stat -c %Y $DIR1/$tfile`
1396                 local mtime4=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1397
1398                 [ "$mtime3" = "$mtime4" ] || \
1399                         error "different mtime on clients: $mtime3, $mtime4"
1400                 [ "$mtime3" = $TEST_39_MTIME ] || \
1401                         error "lost mtime: $mtime3, should be $TEST_39_MTIME"
1402
1403                 cancel_lru_locks osc
1404                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1405         done
1406 }
1407 run_test 39b "11063 problem 1 =================================="
1408
1409 test_39c() {
1410         local client1=${CLIENT1:-`hostname`}
1411         local client2=${CLIENT2:-`hostname`}
1412
1413         echo hello > $DIR1/$tfile
1414
1415         local mtime1=`stat -c %Y $DIR1/$tfile`
1416         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1417         [ "$mtime1" = "$mtime2" ] || \
1418                 error "create: different mtime on clients: $mtime1, $mtime2"
1419
1420         sleep 1
1421         $TRUNCATE $DIR1/$tfile 1
1422
1423         for (( i=0; i < 2; i++ )) ; do
1424                 local mtime3=`stat -c %Y $DIR1/$tfile`
1425                 local mtime4=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1426
1427                 [ "$mtime3" = "$mtime4" ] || \
1428                         error "different mtime on clients: $mtime3, $mtime4"
1429                 [ "$mtime3" -gt $mtime2 ] || \
1430                         error "truncate did not update mtime: $mtime2, $mtime3"
1431
1432                 cancel_lru_locks osc
1433                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1434         done
1435 }
1436 run_test 39c "check truncate mtime update ======================"
1437
1438 test_39d() { # LU-7310
1439         touch $DIR1/$tfile
1440         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
1441
1442         local mtime1=$(stat -c %Y $DIR2/$tfile)
1443         [ "$mtime1" = $TEST_39_MTIME ] ||
1444                 error "mtime: $mtime1, should be $TEST_39_MTIME"
1445
1446         # force sync write
1447         # define OBD_FAIL_OSC_NO_GRANT 0x411
1448         $LCTL set_param fail_loc=0x411
1449
1450         local d1=$(date +%s)
1451         echo hello >> $DIR1/$tfile
1452         local d2=$(date +%s)
1453
1454         $LCTL set_param fail_loc=0
1455
1456         cancel_lru_locks $OSC
1457
1458         local mtime2=$(stat -c %Y $DIR2/$tfile)
1459         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] ||
1460                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
1461 }
1462 run_test 39d "sync write should update mtime"
1463
1464 # for pdo testing, we must cancel MDT-MDT locks as well as client locks to
1465 # avoid unexpected delays due to previous tests
1466 pdo_lru_clear() {
1467         cancel_lru_locks mdc
1468         do_nodes $(comma_list $(mdts_nodes)) \
1469                 $LCTL set_param -n ldlm.namespaces.*mdt*.lru_size=clear
1470         do_nodes $(comma_list $(mdts_nodes)) \
1471                 $LCTL get_param ldlm.namespaces.*mdt*.lock_unused_count \
1472                         ldlm.namespaces.*mdt*.lock_count | grep -v '=0'
1473 }
1474
1475 # check that pid exists hence second operation wasn't blocked by first one
1476 # if it is so then there is no conflict, return 0
1477 # else second operation is conflicting with first one, return 1
1478 check_pdo_conflict() {
1479         local pid=$1
1480         local conflict=0
1481         sleep 1 # to ensure OP1 is finished on client if OP2 is blocked by OP1
1482         if [[ `ps --pid $pid | wc -l` == 1 ]]; then
1483                 conflict=1
1484                 echo "Conflict"
1485         else
1486                 echo "No conflict"
1487         fi
1488         return $conflict
1489 }
1490
1491 # pdirop tests
1492 # test 40: check non-blocking operations
1493 test_40a() {
1494         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1495         pdo_lru_clear
1496 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1497         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1498         touch $DIR2
1499         mkdir $DIR1/$tfile &
1500         PID1=$!
1501         sleep 1
1502         touch $DIR2/$tfile-2
1503         check_pdo_conflict $PID1 || error "create is blocked"
1504         mkdir $DIR2/$tfile-3
1505         check_pdo_conflict $PID1 || error "mkdir is blocked"
1506         link $DIR2/$tfile-2 $DIR2/$tfile-4
1507         check_pdo_conflict $PID1 || error "link is blocked"
1508         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1509         check_pdo_conflict $PID1 || error "rename is blocked"
1510         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1511         check_pdo_conflict $PID1 || error "getattr is blocked"
1512         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1513         rmdir $DIR2/$tfile-3
1514         check_pdo_conflict $PID1 || error "unlink is blocked"
1515
1516         #  all operations above shouldn't wait the first one
1517         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1518         wait $PID1
1519         rm -rf $DIR/$tfile*
1520         return 0
1521 }
1522 run_test 40a "pdirops: create vs others =============="
1523
1524 test_40b() {
1525         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1526         pdo_lru_clear
1527 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1528         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1529         touch $DIR1/$tfile &
1530         PID1=$!
1531         sleep 1
1532         # open|create
1533         touch $DIR2/$tfile-2
1534         check_pdo_conflict $PID1 || error "create is blocked"
1535         mkdir $DIR2/$tfile-3
1536         check_pdo_conflict $PID1 || error "mkdir is blocked"
1537         link $DIR2/$tfile-2 $DIR2/$tfile-4
1538         check_pdo_conflict $PID1 || error "link is blocked"
1539         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1540         check_pdo_conflict $PID1 || error "rename is blocked"
1541         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1542         check_pdo_conflict $PID1 || error "getattr is blocked"
1543         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1544         rmdir $DIR2/$tfile-3
1545         check_pdo_conflict $PID1 || error "unlink is blocked"
1546         # all operations above shouldn't wait the first one
1547
1548         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1549         wait $PID1
1550         rm -rf $DIR/$tfile*
1551         return 0
1552 }
1553 run_test 40b "pdirops: open|create and others =============="
1554
1555 test_40c() {
1556         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1557         pdo_lru_clear
1558         touch $DIR1/$tfile
1559 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1560         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1561         link $DIR1/$tfile $DIR1/$tfile-0 &
1562         PID1=$!
1563         sleep 1
1564         # open|create
1565         touch $DIR2/$tfile-2
1566         check_pdo_conflict $PID1 || error "create is blocked"
1567         mkdir $DIR2/$tfile-3
1568         check_pdo_conflict $PID1 || error "mkdir is blocked"
1569         link $DIR2/$tfile-2 $DIR2/$tfile-4
1570         check_pdo_conflict $PID1 || error "link is blocked"
1571         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1572         check_pdo_conflict $PID1 || error "rename is blocked"
1573         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1574         check_pdo_conflict $PID1 || error "getattr is blocked"
1575         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1576         rmdir $DIR2/$tfile-3
1577         check_pdo_conflict $PID1 || error "unlink is blocked"
1578
1579         # all operations above shouldn't wait the first one
1580         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1581         wait $PID1
1582         rm -rf $DIR/$tfile*
1583         return 0
1584 }
1585 run_test 40c "pdirops: link and others =============="
1586
1587 test_40d() {
1588         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1589         pdo_lru_clear
1590         touch $DIR1/$tfile
1591 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1592         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1593         rm $DIR1/$tfile &
1594         PID1=$!
1595         sleep 1
1596         # open|create
1597         touch $DIR2/$tfile-2
1598         check_pdo_conflict $PID1 || error "create is blocked"
1599         mkdir $DIR2/$tfile-3
1600         check_pdo_conflict $PID1 || error "mkdir is blocked"
1601         link $DIR2/$tfile-2 $DIR2/$tfile-4
1602         check_pdo_conflict $PID1 || error "link is blocked"
1603         mv $DIR2/$tfile-2 $DIR2/$tfile-5
1604         check_pdo_conflict $PID1 || error "rename is blocked"
1605         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1606         check_pdo_conflict $PID1 || error "getattr is blocked"
1607         rm $DIR2/$tfile-4 $DIR2/$tfile-5
1608         rmdir $DIR2/$tfile-3
1609         check_pdo_conflict $PID1 || error "unlink is blocked"
1610
1611         # all operations above shouldn't wait the first one
1612         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1613         wait $PID1
1614         return 0
1615 }
1616 run_test 40d "pdirops: unlink and others =============="
1617
1618 test_40e() {
1619         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1620         pdo_lru_clear
1621         touch $DIR1/$tfile
1622 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1623         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1624         mv $DIR1/$tfile $DIR1/$tfile-0 &
1625         PID1=$!
1626         sleep 1
1627         # open|create
1628         touch $DIR2/$tfile-2
1629         check_pdo_conflict $PID1 || error "create is blocked"
1630         mkdir $DIR2/$tfile-3
1631         check_pdo_conflict $PID1 || error "mkdir is blocked"
1632         link $DIR2/$tfile-2 $DIR2/$tfile-4
1633         check_pdo_conflict $PID1 || error "link is blocked"
1634         stat $DIR2/$tfile-3 $DIR2/$tfile-4 > /dev/null
1635         check_pdo_conflict $PID1 || error "getattr is blocked"
1636         rm $DIR2/$tfile-4 $DIR2/$tfile-2
1637         rmdir $DIR2/$tfile-3
1638         check_pdo_conflict $PID1 || error "unlink is blocked"
1639
1640        # all operations above shouldn't wait the first one
1641         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1642         wait $PID1
1643         rm -rf $DIR/$tfile*
1644         return 0
1645 }
1646 run_test 40e "pdirops: rename and others =============="
1647
1648 # test 41: create blocking operations
1649 test_41a() {
1650         pdo_lru_clear
1651 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1652         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1653         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1654         PID1=$!
1655         sleep 1
1656         mkdir $DIR2/$tfile && error "mkdir must fail"
1657         check_pdo_conflict $PID1 && { wait $PID1; echo "mkdir isn't blocked"; }
1658         rm -rf $DIR/$tfile*
1659         return 0
1660 }
1661 run_test 41a "pdirops: create vs mkdir =============="
1662
1663 test_41b() {
1664         pdo_lru_clear
1665 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1666         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1667         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1668         PID1=$!
1669         sleep 1
1670         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
1671         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1672         rm -rf $DIR/$tfile*
1673         return 0
1674 }
1675 run_test 41b "pdirops: create vs create =============="
1676
1677 test_41c() {
1678         pdo_lru_clear
1679         touch $DIR1/$tfile-2
1680 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1681         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1682         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1683         PID1=$!
1684         sleep 1
1685         link $DIR2/$tfile-2 $DIR2/$tfile && error "link must fail"
1686         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1687         rm -rf $DIR/$tfile*
1688         return 0
1689 }
1690 run_test 41c "pdirops: create vs link =============="
1691
1692 test_41d() {
1693         pdo_lru_clear
1694 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1695         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1696         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1697         PID1=$!
1698         sleep 1
1699         rm $DIR2/$tfile || error "unlink must succeed"
1700         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1701         rm -rf $DIR/$tfile*
1702         return 0
1703 }
1704 run_test 41d "pdirops: create vs unlink =============="
1705
1706 test_41e() {
1707         pdo_lru_clear
1708         touch $DIR1/$tfile-2
1709 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1710         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1711         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1712         PID1=$!
1713         sleep 1
1714         mv $DIR2/$tfile-2 $DIR2/$tfile || error "rename must succeed"
1715         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1716         rm -rf $DIR/$tfile*
1717         return 0
1718 }
1719 run_test 41e "pdirops: create and rename (tgt) =============="
1720
1721 test_41f() {
1722         pdo_lru_clear
1723 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1724         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1725         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1726         PID1=$!
1727         sleep 1
1728         mv $DIR2/$tfile $DIR2/$tfile-2 || error "rename must succeed"
1729         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1730         rm -rf $DIR/$tfile*
1731         return 0
1732 }
1733 run_test 41f "pdirops: create and rename (src) =============="
1734
1735 test_41g() {
1736         pdo_lru_clear
1737 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1738         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1739         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1740         PID1=$!
1741         sleep 1
1742         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
1743         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1744         rm -rf $DIR/$tfile*
1745         return 0
1746 }
1747 run_test 41g "pdirops: create vs getattr =============="
1748
1749 test_41h() {
1750         pdo_lru_clear
1751 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1752         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1753         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1754         PID1=$!
1755         sleep 1
1756         ls -lia $DIR2/ > /dev/null
1757         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1758         rm -rf $DIR/$tfile*
1759         return 0
1760 }
1761 run_test 41h "pdirops: create vs readdir =============="
1762
1763 # test 42: unlink and blocking operations
1764 test_42a() {
1765         pdo_lru_clear
1766 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1767         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1768         mkdir $DIR1/$tfile &
1769         PID1=$!
1770         sleep 1
1771         mkdir $DIR2/$tfile && error "mkdir must fail"
1772         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1773         rm -rf $DIR/$tfile*
1774         return 0
1775 }
1776 run_test 42a "pdirops: mkdir vs mkdir =============="
1777
1778 test_42b() {
1779         pdo_lru_clear
1780 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1781         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1782         mkdir $DIR1/$tfile &
1783         PID1=$!
1784         sleep 1
1785         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
1786         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1787         rm -rf $DIR/$tfile*
1788         return 0
1789 }
1790 run_test 42b "pdirops: mkdir vs create =============="
1791
1792 test_42c() {
1793         pdo_lru_clear
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=$!
1799         sleep 1
1800         link $DIR2/$tfile-2 $DIR2/$tfile && error "link must fail"
1801         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1802         rm -rf $DIR/$tfile*
1803         return 0
1804 }
1805 run_test 42c "pdirops: mkdir vs link =============="
1806
1807 test_42d() {
1808         pdo_lru_clear
1809 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1810         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1811         mkdir $DIR1/$tfile &
1812         PID1=$!
1813         sleep 1
1814         rmdir $DIR2/$tfile || error "unlink must succeed"
1815         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1816         rm -rf $DIR/$tfile*
1817         return 0
1818 }
1819 run_test 42d "pdirops: mkdir vs unlink =============="
1820
1821 test_42e() {
1822         pdo_lru_clear
1823         touch $DIR1/$tfile-2
1824 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1825         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1826         mkdir $DIR1/$tfile &
1827         PID1=$!
1828         sleep 1
1829         mv -T $DIR2/$tfile-2 $DIR2/$tfile && error "rename must fail"
1830         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1831         rm -rf $DIR/$tfile*
1832         return 0
1833 }
1834 run_test 42e "pdirops: mkdir and rename (tgt) =============="
1835
1836 test_42f() {
1837         pdo_lru_clear
1838 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1839         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1840         mkdir $DIR1/$tfile &
1841         PID1=$!
1842         sleep 1
1843         mv $DIR2/$tfile $DIR2/$tfile-2 || error "rename must succeed"
1844         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1845         rm -rf $DIR/$tfile*
1846         return 0
1847 }
1848 run_test 42f "pdirops: mkdir and rename (src) =============="
1849
1850 test_42g() {
1851         pdo_lru_clear
1852 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1853         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1854         mkdir $DIR1/$tfile &
1855         PID1=$!
1856         sleep 1
1857         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
1858         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1859         rm -rf $DIR/$tfile*
1860         return 0
1861 }
1862 run_test 42g "pdirops: mkdir vs getattr =============="
1863
1864 test_42h() {
1865         pdo_lru_clear
1866 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1867         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1868         mkdir $DIR1/$tfile &
1869         PID1=$!
1870         sleep 1
1871         ls -lia $DIR2/ > /dev/null
1872         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1873         rm -rf $DIR/$tfile*
1874         return 0
1875 }
1876 run_test 42h "pdirops: mkdir vs readdir =============="
1877
1878 # test 43: unlink and blocking operations
1879 test_43a() {
1880         pdo_lru_clear
1881         touch $DIR1/$tfile
1882 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1883         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1884         rm $DIR1/$tfile &
1885         PID1=$!
1886         sleep 1
1887         mkdir $DIR2/$tfile || error "mkdir must succeed"
1888         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1889         rm -rf $DIR/$tfile*
1890         return 0
1891 }
1892 run_test 43a "pdirops: unlink vs mkdir =============="
1893
1894 test_43b() {
1895         pdo_lru_clear
1896         touch $DIR1/$tfile
1897 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1898         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1899         rm $DIR1/$tfile &
1900         PID1=$!
1901         sleep 1
1902         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c || error "create must succeed"
1903         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1904         rm -rf $DIR/$tfile*
1905         return 0
1906 }
1907 run_test 43b "pdirops: unlink vs create =============="
1908
1909 test_43c() {
1910         pdo_lru_clear
1911         touch $DIR1/$tfile
1912         touch $DIR1/$tfile-2
1913 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1914         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1915         rm $DIR1/$tfile &
1916         PID1=$!
1917         sleep 1
1918         link $DIR2/$tfile-2 $DIR2/$tfile || error "link must succeed"
1919         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1920         rm -rf $DIR/$tfile*
1921         return 0
1922 }
1923 run_test 43c "pdirops: unlink vs link =============="
1924
1925 test_43d() {
1926         pdo_lru_clear
1927         touch $DIR1/$tfile
1928 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1929         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1930         rm $DIR1/$tfile &
1931         PID1=$!
1932         sleep 1
1933         rm $DIR2/$tfile && error "unlink must fail"
1934         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1935         rm -rf $DIR/$tfile*
1936         return 0
1937 }
1938 run_test 43d "pdirops: unlink vs unlink =============="
1939
1940 test_43e() {
1941         pdo_lru_clear
1942         touch $DIR1/$tfile
1943         touch $DIR1/$tfile-2
1944 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1945         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1946         rm $DIR1/$tfile &
1947         PID1=$!
1948         sleep 1
1949         mv -u $DIR2/$tfile-2 $DIR2/$tfile || error "rename must succeed"
1950         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1951         rm -rf $DIR/$tfile*
1952         return 0
1953 }
1954 run_test 43e "pdirops: unlink and rename (tgt) =============="
1955
1956 test_43f() {
1957         pdo_lru_clear
1958         touch $DIR1/$tfile
1959 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1960         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1961         rm $DIR1/$tfile &
1962         PID1=$!
1963         sleep 1
1964         mv $DIR2/$tfile $DIR2/$tfile-2 && error "rename must fail"
1965         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1966         rm -rf $DIR/$tfile*
1967         return 0
1968 }
1969 run_test 43f "pdirops: unlink and rename (src) =============="
1970
1971 test_43g() {
1972         pdo_lru_clear
1973         touch $DIR1/$tfile
1974 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1975         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1976         rm $DIR1/$tfile &
1977         PID1=$!
1978         sleep 1
1979         stat $DIR2/$tfile > /dev/null && error "stat must fail"
1980         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1981         rm -rf $DIR/$tfile*
1982         return 0
1983 }
1984 run_test 43g "pdirops: unlink vs getattr =============="
1985
1986 test_43h() {
1987         pdo_lru_clear
1988         touch $DIR1/$tfile
1989 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1990         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
1991         rm $DIR1/$tfile &
1992         PID1=$!
1993         sleep 1
1994         ls -lia $DIR2/ > /dev/null
1995         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1996         rm -rf $DIR/$tfile*
1997         return 0
1998 }
1999 run_test 43h "pdirops: unlink vs readdir =============="
2000
2001 test_43i() {
2002         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2003         pdo_lru_clear
2004         touch $DIR1/$tfile
2005 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2006         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2007         rm $DIR1/$tfile &
2008         PID1=$!
2009         sleep 1
2010         $LFS mkdir -i 1 $DIR2/$tfile || error "remote mkdir must succeed"
2011         check_pdo_conflict $PID1 &&
2012                 { wait $PID1; error "remote mkdir isn't blocked"; }
2013         rm -rf $DIR/$tfile*
2014         return 0
2015 }
2016 run_test 43i "pdirops: unlink vs remote mkdir"
2017
2018 # test 44: rename tgt and blocking operations
2019 test_44a() {
2020         pdo_lru_clear
2021         touch $DIR1/$tfile-2
2022 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
2023         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2024         mv $DIR1/$tfile-2 $DIR1/$tfile &
2025         PID1=$!
2026         sleep 1
2027         mkdir $DIR2/$tfile && error "mkdir must fail"
2028         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
2029         rm -rf $DIR/$tfile*
2030         return 0
2031 }
2032 run_test 44a "pdirops: rename tgt vs mkdir =============="
2033
2034 test_44b() {
2035         pdo_lru_clear
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=$!
2041         sleep 1
2042         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
2043         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
2044         rm -rf $DIR/$tfile*
2045         return 0
2046 }
2047 run_test 44b "pdirops: rename tgt vs create =============="
2048
2049 test_44c() {
2050         pdo_lru_clear
2051         touch $DIR1/$tfile-2
2052         touch $DIR1/$tfile-3
2053 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2054         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2055         mv $DIR1/$tfile-2 $DIR1/$tfile &
2056         PID1=$!
2057         sleep 1
2058         link $DIR2/$tfile-3 $DIR2/$tfile && error "link must fail"
2059         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2060         rm -rf $DIR/$tfile*
2061         return 0
2062 }
2063 run_test 44c "pdirops: rename tgt vs link =============="
2064
2065 test_44d() {
2066         pdo_lru_clear
2067         touch $DIR1/$tfile-2
2068 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2069         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2070         mv $DIR1/$tfile-2 $DIR1/$tfile &
2071         PID1=$!
2072         sleep 1
2073         rm $DIR2/$tfile || error "unlink must succeed"
2074         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
2075         rm -rf $DIR/$tfile*
2076         return 0
2077 }
2078 run_test 44d "pdirops: rename tgt vs unlink =============="
2079
2080 test_44e() {
2081         pdo_lru_clear
2082         touch $DIR1/$tfile
2083         touch $DIR1/$tfile-2
2084         touch $DIR1/$tfile-3
2085 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2086         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2087         mv $DIR1/$tfile-2 $DIR1/$tfile &
2088         PID1=$!
2089         sleep 1
2090         mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
2091         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2092         rm -rf $DIR/$tfile*
2093         return 0
2094 }
2095 run_test 44e "pdirops: rename tgt and rename (tgt) =============="
2096
2097 test_44f() {
2098         pdo_lru_clear
2099         touch $DIR1/$tfile-2
2100         touch $DIR1/$tfile-3
2101 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2102         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2103         mv $DIR1/$tfile-2 $DIR1/$tfile &
2104         PID1=$!
2105         sleep 1
2106         mv $DIR2/$tfile $DIR2/$tfile-3 || error "rename must succeed"
2107         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2108         rm -rf $DIR/$tfile*
2109         return 0
2110 }
2111 run_test 44f "pdirops: rename tgt and rename (src) =============="
2112
2113 test_44g() {
2114         pdo_lru_clear
2115         touch $DIR1/$tfile-2
2116 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2117         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2118         mv $DIR1/$tfile-2 $DIR1/$tfile &
2119         PID1=$!
2120         sleep 1
2121         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
2122         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
2123         rm -rf $DIR/$tfile*
2124         return 0
2125 }
2126 run_test 44g "pdirops: rename tgt vs getattr =============="
2127
2128 test_44h() {
2129         pdo_lru_clear
2130         touch $DIR1/$tfile-2
2131 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2132         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2133         mv $DIR1/$tfile-2 $DIR1/$tfile &
2134         PID1=$!
2135         sleep 1
2136         ls -lia $DIR2/ > /dev/null
2137         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
2138         rm -rf $DIR/$tfile*
2139         return 0
2140 }
2141 run_test 44h "pdirops: rename tgt vs readdir =============="
2142
2143 # test 44: rename tgt and blocking operations
2144 test_44i() {
2145         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2146         pdo_lru_clear
2147         touch $DIR1/$tfile-2
2148 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
2149         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000146
2150         mv $DIR1/$tfile-2 $DIR1/$tfile &
2151         PID1=$!
2152         sleep 1
2153         $LFS mkdir -i 1 $DIR2/$tfile && error "remote mkdir must fail"
2154         check_pdo_conflict $PID1 && { wait $PID1;
2155                                 error "remote mkdir isn't blocked"; }
2156         rm -rf $DIR/$tfile*
2157         return 0
2158 }
2159 run_test 44i "pdirops: rename tgt vs remote mkdir"
2160
2161 # test 45: rename src and blocking operations
2162 test_45a() {
2163         pdo_lru_clear
2164         touch $DIR1/$tfile
2165 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2166         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2167         mv $DIR1/$tfile $DIR1/$tfile-2 &
2168         PID1=$!
2169         sleep 1
2170         mkdir $DIR2/$tfile || error "mkdir must succeed"
2171         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
2172         rm -rf $DIR/$tfile*
2173         return 0
2174 }
2175 run_test 45a "pdirops: rename src vs mkdir =============="
2176
2177 test_45b() {
2178         pdo_lru_clear
2179         touch $DIR1/$tfile
2180 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2181         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2182         mv $DIR1/$tfile $DIR1/$tfile-2 &
2183         PID1=$!
2184         sleep 1
2185         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c || error "create must succeed"
2186         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
2187         rm -rf $DIR/$tfile*
2188         return 0
2189 }
2190 run_test 45b "pdirops: rename src vs create =============="
2191
2192 test_45c() {
2193         pdo_lru_clear
2194         touch $DIR1/$tfile
2195         touch $DIR1/$tfile-3
2196 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2197         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2198         mv $DIR1/$tfile $DIR1/$tfile-2 &
2199         PID1=$!
2200         sleep 1
2201         link $DIR2/$tfile-3 $DIR2/$tfile || error "link must succeed"
2202         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2203         rm -rf $DIR/$tfile*
2204         return 0
2205 }
2206 run_test 45c "pdirops: rename src vs link =============="
2207
2208 test_45d() {
2209         pdo_lru_clear
2210         touch $DIR1/$tfile
2211 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2212         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2213         mv $DIR1/$tfile $DIR1/$tfile-2 &
2214         PID1=$!
2215         sleep 1
2216         rm $DIR2/$tfile && error "unlink must fail"
2217         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
2218         rm -rf $DIR/$tfile*
2219         return 0
2220 }
2221 run_test 45d "pdirops: rename src vs unlink =============="
2222
2223 test_45e() {
2224         pdo_lru_clear
2225         touch $DIR1/$tfile
2226         touch $DIR1/$tfile-3
2227 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2228         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2229         mv $DIR1/$tfile $DIR1/$tfile-2 &
2230         PID1=$!
2231         sleep 1
2232         mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
2233         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2234         rm -rf $DIR/$tfile*
2235         return 0
2236 }
2237 run_test 45e "pdirops: rename src and rename (tgt) =============="
2238
2239 test_45f() {
2240         pdo_lru_clear
2241         touch $DIR1/$tfile
2242 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2243         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2244         mv $DIR1/$tfile $DIR1/$tfile-2 &
2245         PID1=$!
2246         sleep 1
2247         mv $DIR2/$tfile $DIR2/$tfile-3 && error "rename must fail"
2248         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2249         rm -rf $DIR/$tfile*
2250         return 0
2251 }
2252 run_test 45f "pdirops: rename src and rename (src) =============="
2253
2254 test_45g() {
2255         pdo_lru_clear
2256         touch $DIR1/$tfile
2257 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2258         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2259         mv $DIR1/$tfile $DIR1/$tfile-2 &
2260         PID1=$!
2261         sleep 1
2262         stat $DIR2/$tfile > /dev/null && error "stat must fail"
2263         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
2264         rm -rf $DIR/$tfile*
2265         return 0
2266 }
2267 run_test 45g "pdirops: rename src vs getattr =============="
2268
2269 test_45h() {
2270         pdo_lru_clear
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=$!
2276         sleep 1
2277         ls -lia $DIR2/ > /dev/null
2278         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
2279         rm -rf $DIR/$tfile*
2280         return 0
2281 }
2282 run_test 45h "pdirops: unlink vs readdir =============="
2283
2284 test_45i() {
2285         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2286         pdo_lru_clear
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=$!
2292         sleep 1
2293         $LFS mkdir -i 1 $DIR2/$tfile || error "create remote dir must succeed"
2294         check_pdo_conflict $PID1 && { wait $PID1;
2295                                 error "create remote dir isn't blocked"; }
2296         rm -rf $DIR/$tfile*
2297         return 0
2298 }
2299 run_test 45i "pdirops: rename src vs remote mkdir"
2300
2301 # test 46: link and blocking operations
2302 test_46a() {
2303         pdo_lru_clear
2304         touch $DIR1/$tfile-2
2305 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2306         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2307         link $DIR1/$tfile-2 $DIR1/$tfile &
2308         PID1=$!
2309         sleep 1
2310         mkdir $DIR2/$tfile && error "mkdir must fail"
2311         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
2312         rm -rf $DIR/$tfile*
2313         return 0
2314 }
2315 run_test 46a "pdirops: link vs mkdir =============="
2316
2317 test_46b() {
2318         pdo_lru_clear
2319         touch $DIR1/$tfile-2
2320 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2321         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2322         link $DIR1/$tfile-2 $DIR1/$tfile &
2323         PID1=$!
2324         sleep 1
2325         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
2326         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
2327         rm -rf $DIR/$tfile*
2328         return 0
2329 }
2330 run_test 46b "pdirops: link vs create =============="
2331
2332 test_46c() {
2333         pdo_lru_clear
2334         touch $DIR1/$tfile-2
2335 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2336         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2337         link $DIR1/$tfile-2 $DIR1/$tfile &
2338         PID1=$!
2339         sleep 1
2340         link $DIR2/$tfile $DIR2/$tfile && error "link must fail"
2341         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2342         rm -rf $DIR/$tfile*
2343         return 0
2344 }
2345 run_test 46c "pdirops: link vs link =============="
2346
2347 test_46d() {
2348         pdo_lru_clear
2349         touch $DIR1/$tfile-2
2350 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2351         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2352         link $DIR1/$tfile-2 $DIR1/$tfile &
2353         PID1=$!
2354         sleep 1
2355         rm $DIR2/$tfile || error "unlink must succeed"
2356         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
2357         rm -rf $DIR/$tfile*
2358         return 0
2359 }
2360 run_test 46d "pdirops: link vs unlink =============="
2361
2362 test_46e() {
2363         pdo_lru_clear
2364         touch $DIR1/$tfile-2
2365         touch $DIR1/$tfile-3
2366 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2367         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2368         link $DIR1/$tfile-2 $DIR1/$tfile &
2369         PID1=$!
2370         sleep 1
2371         mv $DIR2/$tfile-3 $DIR2/$tfile || error "rename must succeed"
2372         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2373         rm -rf $DIR/$tfile*
2374         return 0
2375 }
2376 run_test 46e "pdirops: link and rename (tgt) =============="
2377
2378 test_46f() {
2379         pdo_lru_clear
2380         touch $DIR1/$tfile-2
2381         touch $DIR1/$tfile-3
2382 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2383         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2384         link $DIR1/$tfile-2 $DIR1/$tfile &
2385         PID1=$!
2386         sleep 1
2387         mv $DIR2/$tfile $DIR2/$tfile-3 || error "rename must succeed"
2388         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2389         rm -rf $DIR/$tfile*
2390         return 0
2391 }
2392 run_test 46f "pdirops: link and rename (src) =============="
2393
2394 test_46g() {
2395         pdo_lru_clear
2396         touch $DIR1/$tfile-2
2397 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2398         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2399         link $DIR1/$tfile-2 $DIR1/$tfile &
2400         PID1=$!
2401         sleep 1
2402         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
2403         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
2404         rm -rf $DIR/$tfile*
2405         return 0
2406 }
2407 run_test 46g "pdirops: link vs getattr =============="
2408
2409 test_46h() {
2410         pdo_lru_clear
2411         touch $DIR1/$tfile-2
2412 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2413         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2414         link $DIR1/$tfile-2 $DIR1/$tfile &
2415         PID1=$!
2416         sleep 1
2417         ls -lia $DIR2/ > /dev/null
2418         check_pdo_conflict $PID1 && { wait $PID1;
2419                         error "readdir isn't blocked"; }
2420         rm -rf $DIR/$tfile*
2421         return 0
2422 }
2423 run_test 46h "pdirops: link vs readdir =============="
2424
2425 test_46i() {
2426         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2427         pdo_lru_clear
2428         touch $DIR1/$tfile-2
2429 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2430         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2431         link $DIR1/$tfile-2 $DIR1/$tfile &
2432         PID1=$!
2433         sleep 1
2434         $LFS mkdir -i 1 $DIR2/$tfile && error "remote mkdir must fail"
2435         check_pdo_conflict $PID1 && { wait $PID1;
2436                                 error "remote mkdir isn't blocked"; }
2437         rm -rf $DIR/$tfile*
2438         return 0
2439 }
2440 run_test 46i "pdirops: link vs remote mkdir"
2441
2442 # test 47: remote mkdir and blocking operations
2443 test_47a() {
2444 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2445         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2446         pdo_lru_clear
2447         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2448         $LFS mkdir -i 1 $DIR1/$tfile &
2449         PID1=$!
2450         sleep 1
2451         mkdir $DIR2/$tfile && error "mkdir must fail"
2452         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
2453         rm -rf $DIR/$tfile*
2454         return 0
2455 }
2456 run_test 47a "pdirops: remote mkdir vs mkdir"
2457
2458 test_47b() {
2459 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2460         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2461         pdo_lru_clear
2462         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2463         $LFS mkdir -i 1 $DIR1/$tfile &
2464         PID1=$!
2465         sleep 1
2466         multiop $DIR2/$tfile oO_CREAT:O_EXCL:c && error "create must fail"
2467         check_pdo_conflict $PID1 && { wait $PID1;
2468                                         error "create isn't blocked"; }
2469         rm -rf $DIR/$tfile*
2470         return 0
2471 }
2472 run_test 47b "pdirops: remote mkdir vs create"
2473
2474 test_47c() {
2475         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2476         pdo_lru_clear
2477         touch $DIR1/$tfile-2
2478 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2479         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2480         $LFS mkdir -i 1 $DIR1/$tfile &
2481         PID1=$!
2482         sleep 1
2483         link $DIR2/$tfile-2 $DIR2/$tfile && error "link must fail"
2484         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2485         rm -rf $DIR/$tfile*
2486         return 0
2487 }
2488 run_test 47c "pdirops: remote mkdir vs link"
2489
2490 test_47d() {
2491         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2492         pdo_lru_clear
2493 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2494         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2495         $LFS mkdir -i 1 $DIR1/$tfile &
2496         PID1=$!
2497         sleep 1
2498         rmdir $DIR2/$tfile || error "unlink must succeed"
2499         check_pdo_conflict $PID1 && { wait $PID1;
2500                                         error "unlink isn't blocked"; }
2501         rm -rf $DIR/$tfile*
2502         return 0
2503 }
2504 run_test 47d "pdirops: remote mkdir vs unlink"
2505
2506 test_47e() {
2507         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2508         pdo_lru_clear
2509         touch $DIR1/$tfile-2
2510 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2511         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2512         $LFS mkdir -i 1 $DIR1/$tfile &
2513         PID1=$!
2514         sleep 1
2515         mv -T $DIR2/$tfile-2 $DIR2/$tfile && error "rename must fail"
2516         check_pdo_conflict $PID1 && { wait $PID1;
2517                                         error "rename isn't blocked"; }
2518         rm -rf $DIR/$tfile*
2519         return 0
2520 }
2521 run_test 47e "pdirops: remote mkdir and rename (tgt)"
2522
2523 test_47f() {
2524         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2525         pdo_lru_clear
2526 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2527         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2528         $LFS mkdir -i 1 $DIR1/$tfile &
2529         PID1=$!
2530         sleep 1
2531         mv $DIR2/$tfile $DIR2/$tfile-2 || error "rename must succeed"
2532         check_pdo_conflict $PID1 && { wait $PID1;
2533                                         error "rename isn't blocked"; }
2534         rm -rf $DIR/$tfile*
2535         return 0
2536 }
2537 run_test 47f "pdirops: remote mkdir and rename (src)"
2538
2539 test_47g() {
2540         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2541         sync
2542         sync_all_data
2543         pdo_lru_clear
2544 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2545         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000145
2546         $LFS mkdir -i 1 $DIR1/$tfile &
2547         PID1=$!
2548         sleep 2
2549         stat $DIR2/$tfile > /dev/null || error "stat must succeed"
2550         check_pdo_conflict $PID1 && { wait $PID1;
2551                                         error "getattr isn't blocked"; }
2552         rm -rf $DIR/$tfile*
2553         return 0
2554 }
2555 run_test 47g "pdirops: remote mkdir vs getattr"
2556
2557 test_50() {
2558         trunc_size=4096
2559         dd if=/dev/zero of=$DIR1/$tfile bs=1K count=10
2560 #define OBD_FAIL_OSC_CP_ENQ_RACE         0x410
2561         do_facet client "lctl set_param fail_loc=0x410"
2562         $TRUNCATE $DIR2/$tfile $trunc_size
2563         do_facet client "lctl set_param fail_loc=0x0"
2564         sleep 3
2565         size=`stat -c %s $DIR2/$tfile`
2566         [ $size -eq $trunc_size ] || error "wrong size"
2567 }
2568 run_test 50 "osc lvb attrs: enqueue vs. CP AST =============="
2569
2570 test_51a() {
2571         local filesize
2572         local origfile=/etc/hosts
2573
2574         filesize=$(stat -c %s $origfile)
2575
2576         # create an empty file
2577         $MCREATE $DIR1/$tfile || error "can't create $DIR1/$tfile"
2578         # cache layout lock on both mount point
2579         stat $DIR1/$tfile > /dev/null || error "stat $DIR1/$tfile failed"
2580         stat $DIR2/$tfile > /dev/null || error "stat $DIR2/$tfile failed"
2581
2582         # open and sleep 2 seconds then read
2583         $MULTIOP $DIR2/$tfile o_2r${filesize}c &
2584         local pid=$!
2585         sleep 1
2586
2587         # create the layout of testing file
2588         dd if=$origfile of=$DIR1/$tfile conv=notrunc > /dev/null ||
2589                 error "dd $DIR1/$tfile failed"
2590
2591         # MULTIOP proc should be able to read enough bytes and exit
2592         for ((i = 0; i < 6; i++)); do
2593                 sleep 1
2594                 kill -0 $pid || break
2595         done
2596         kill -0 $pid 2> /dev/null && error "multiop is still there"
2597         cmp $origfile $DIR2/$tfile || error "$origfile and $DIR2/$tfile differs"
2598
2599         rm -f $DIR1/$tfile
2600 }
2601 run_test 51a "layout lock: refresh layout should work"
2602
2603 test_51b() {
2604         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.59) ]] ||
2605                 { skip "Need MDS version at least 2.3.59"; return 0; }
2606
2607         local tmpfile=`mktemp`
2608
2609         # create an empty file
2610         $MCREATE $DIR1/$tfile || error "mcreate $DIR1/$tfile failed"
2611
2612         # delay glimpse so that layout has changed when glimpse finish
2613 #define OBD_FAIL_GLIMPSE_DELAY 0x1404
2614         $LCTL set_param fail_loc=0x1404
2615         stat -c %s $DIR2/$tfile |tee $tmpfile &
2616         local pid=$!
2617         sleep 1
2618
2619         # create layout of testing file
2620         dd if=/dev/zero of=$DIR1/$tfile bs=1k count=1 conv=notrunc >/dev/null ||
2621                 error "dd $DIR1/$tfile failed"
2622
2623         wait $pid
2624         local fsize=$(cat $tmpfile)
2625
2626         [ x$fsize = x1024 ] || error "file size is $fsize, should be 1024"
2627
2628         rm -f $DIR1/$tfile $tmpfile
2629 }
2630 run_test 51b "layout lock: glimpse should be able to restart if layout changed"
2631
2632 test_51c() {
2633         [ $OSTCOUNT -ge 2 ] || { skip "needs >= 2 osts"; return; }
2634
2635         # set default layout to have 1 stripe
2636         mkdir $DIR1/$tdir
2637         $LFS setstripe -c 1 $DIR1/$tdir
2638
2639         # create a file with empty layout
2640         $MCREATE $DIR1/$tdir/$tfile ||
2641                 error "$MCREATE $DIR1/$tdir/$tfile failed"
2642
2643 #define OBD_FAIL_MDS_LL_BLOCK 0x172
2644         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x172
2645
2646         # change the layout of testing file
2647         echo "Setting layout to have $OSTCOUNT stripes ..."
2648         $LFS setstripe -c $OSTCOUNT $DIR1/$tdir/$tfile &
2649         pid=$!
2650         sleep 1
2651
2652         # write something to the file, it should be blocked on fetching layout
2653         dd if=/dev/zero of=$DIR2/$tdir/$tfile bs=1k count=1 conv=notrunc
2654         local stripe_count=$($LFS getstripe -c $DIR2/$tdir/$tfile)
2655         wait $pid
2656
2657         # lod_qos.c::min_stripe_count() allows setstripe with a default stripe
2658         # count to succeed with only 3/4 of the number of stripes (rounded up),
2659         # so creating striped files does not fail if an OST is offline or full
2660         [ $stripe_count -ge $((OSTCOUNT - $OSTCOUNT / 4)) ] ||
2661                 error "bad layout: getstripe -c $stripe_count < $OSTCOUNT * 3/4"
2662
2663         rm -fr $DIR1/$tdir
2664 }
2665 run_test 51c "layout lock: IT_LAYOUT blocked and correct layout can be returned"
2666
2667 test_51d() {
2668         dd if=/dev/zero of=/$DIR1/$tfile bs=1M count=1
2669         cancel_lru_locks mdc
2670
2671         # open should grant LAYOUT lock, mmap and read will install pages
2672         $MULTIOP $DIR1/$tfile oO_RDWR:SMR_Uc &
2673         local PID=$!
2674         sleep 1
2675
2676         # rss before revoking
2677         local br=$(grep -A 10 $tfile /proc/$PID/smaps | awk '/^Rss/{print $2}')
2678         echo "Before revoking layout lock: $br KB mapped"
2679
2680         # cancel layout lock manually
2681         cancel_lru_locks mdc
2682
2683         # rss after revoking
2684         local ar=$(grep -A 10 $tfile /proc/$PID/smaps | awk '/^Rss/{print $2}')
2685
2686         kill -USR1 $PID
2687         wait $PID || error "wait PID $PID failed"
2688
2689         [ $ar -eq 0 ] || error "rss before: $br, after $ar, some pages remained"
2690 }
2691 run_test 51d "layout lock: losing layout lock should clean up memory map region"
2692
2693 test_54_part1()
2694 {
2695         echo "==> rename vs getattr vs setxattr should not deadlock"
2696         mkdir -p $DIR/d1/d2/d3 || error "(1) mkdir failed"
2697
2698         do_facet mds1 $LCTL set_param fail_loc=$1
2699
2700         mv -T $DIR/d1/d2/d3 $DIR/d1/d3 &
2701         PID1=$!
2702         sleep 1
2703
2704         stat $DIR/d1/d2 &
2705         PID2=$!
2706         sleep 1
2707
2708         setfattr -n user.attr1 -v value1 $DIR2/d1 || error "(2) setfattr failed"
2709         wait $PID1 || error "(3) mv failed"
2710         wait $PID2 || error "(4) stat failed"
2711         echo
2712
2713         rm -rf $DIR/d1
2714 }
2715
2716 test_54_part2() {
2717         echo "==> rename vs getattr vs open vs getattr should not deadlock"
2718         mkdir -p $DIR/d1/d2/d3 || error "(1) mkdir failed"
2719
2720         do_facet mds1 $LCTL set_param fail_loc=$1
2721
2722         mv -T $DIR/d1/d2/d3 $DIR/d1/d3 &
2723         PID1=$!
2724         sleep 1
2725
2726         stat $DIR/d1/d2 &
2727         PID2=$!
2728         sleep 1
2729
2730         $MULTIOP $DIR2/d1/d2 Oc &
2731         PID3=$!
2732         sleep 1
2733
2734         stat $DIR/d1 || error "(2) stat failed"
2735
2736         wait $PID1 || error "(3) mv failed"
2737         wait $PID2 || error "(4) stat failed"
2738         wait $PID3 && error "(5) multiop failed"
2739         echo
2740         rm -rf $DIR/d1
2741 }
2742
2743 test_54() {
2744         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
2745         save_lustre_params client "llite.*.xattr_cache" > $p
2746         lctl set_param llite.*.xattr_cache 1 ||
2747                 { skip "xattr cache is not supported"; return 0; }
2748
2749 #define OBD_FAIL_MDS_RENAME              0x153
2750 #define OBD_FAIL_MDS_RENAME2             0x154
2751         test_54_part1 0x80000153 || error 10
2752         test_54_part1 0x80000154 || error 11
2753         test_54_part2 0x80000153 || error 12
2754         test_54_part2 0x80000154 || error 13
2755
2756         restore_lustre_params < $p
2757         rm -f $p
2758 }
2759 run_test 54 "rename locking"
2760
2761 test_55a() {
2762         mkdir -p $DIR/d1/d2 $DIR/d3 || error "(1) mkdir failed"
2763
2764 #define OBD_FAIL_MDS_RENAME4              0x156
2765         do_facet mds1 $LCTL set_param fail_loc=0x80000156
2766
2767         mv -T $DIR/d1/d2 $DIR/d3/d2 &
2768         PID1=$!
2769         sleep 1
2770
2771         rm -r $DIR2/d3
2772         wait $PID1 && error "(2) mv succeeded"
2773
2774         rm -rf $DIR/d1
2775 }
2776 run_test 55a "rename vs unlink target dir"
2777
2778 test_55b()
2779 {
2780         mkdir -p $DIR/d1/d2 $DIR/d3 || error "(1) mkdir failed"
2781
2782 #define OBD_FAIL_MDS_RENAME4             0x156
2783         do_facet mds1 $LCTL set_param fail_loc=0x80000156
2784
2785         mv -T $DIR/d1/d2 $DIR/d3/d2 &
2786         PID1=$!
2787         sleep 1
2788
2789         rm -r $DIR2/d1
2790         wait $PID1 && error "(2) mv succeeded"
2791
2792         rm -rf $DIR/d3
2793 }
2794 run_test 55b "rename vs unlink source dir"
2795
2796 test_55c()
2797 {
2798         mkdir -p $DIR/d1/d2 $DIR/d3 || error "(1) mkdir failed"
2799
2800 #define OBD_FAIL_MDS_RENAME4              0x156
2801         do_facet mds1 $LCTL set_param fail_loc=0x156
2802
2803         mv -T $DIR/d1/d2 $DIR/d3/d2 &
2804         PID1=$!
2805         sleep 1
2806
2807         # while rename is sleeping, open and remove d3
2808         $MULTIOP $DIR2/d3 D_c &
2809         PID2=$!
2810         sleep 1
2811         rm -rf $DIR2/d3
2812         sleep 5
2813
2814         # while rename is sleeping 2nd time, close d3
2815         kill -USR1 $PID2
2816         wait $PID2 || error "(3) multiop failed"
2817
2818         wait $PID1 && error "(2) mv succeeded"
2819
2820         rm -rf $DIR/d1
2821 }
2822 run_test 55c "rename vs unlink orphan target dir"
2823
2824 test_55d()
2825 {
2826         touch $DIR/f1
2827
2828 #define OBD_FAIL_MDS_RENAME3              0x155
2829         do_facet mds1 $LCTL set_param fail_loc=0x155
2830         mv $DIR/f1 $DIR/$tdir &
2831         PID1=$!
2832         sleep 2
2833
2834         # while rename is sleeping, create $tdir, but as a directory
2835         mkdir -p $DIR2/$tdir || error "(1) mkdir failed"
2836
2837         # link in reverse locking order
2838         ln $DIR2/f1 $DIR2/$tdir/
2839
2840         wait $PID1 && error "(2) mv succeeded"
2841         rm -rf $DIR/f1
2842 }
2843 run_test 55d "rename file vs link"
2844
2845 test_60() {
2846         local MDSVER=$(lustre_build_version $SINGLEMDS)
2847         [ $(version_code $MDSVER) -lt $(version_code 2.3.0) ] &&
2848                 skip "MDS version $MDSVER must be >= 2.3.0" && return 0
2849
2850         # Create a file
2851         test_mkdir $DIR1/$tdir
2852         file1=$DIR1/$tdir/file
2853         file2=$DIR2/$tdir/file
2854
2855         echo orig > $file2 || error "Could not create $file2"
2856         version=$($LFS data_version $file1)
2857
2858         # Append data
2859         echo append >> $file2 || error "Could not append to $file2"
2860         version2=$($LFS data_version $file1)
2861         [ "$version" != "$version2" ] ||
2862             error "append did not change data version: $version"
2863
2864         # Overwrite data
2865         echo overwrite > $file2 || error "Could not overwrite $file2"
2866         version3=$($LFS data_version $file1)
2867         [ "$version2" != "$version3" ] ||
2868             error "overwrite did not change data version: $version2"
2869
2870         # Truncate before EOF
2871         $TRUNCATE $file2 3 || error "Could not truncate $file2"
2872         version4=$($LFS data_version $file1)
2873         [ "$version3" != "$version4" ] ||
2874             error "truncate did not change data version: $version3"
2875
2876         # Truncate after EOF
2877         $TRUNCATE $file2 123456 || error "Could not truncate $file2"
2878         version5=$($LFS data_version $file1)
2879         [ "$version4" != "$version5" ] ||
2880             error "truncate did not change data version: $version4"
2881
2882         # Chmod do not change version
2883         chmod 400 $file2 || error "Could not chmod 400 $file2"
2884         version6=$($LFS data_version $file1)
2885         [ "$version5" == "$version6" ] ||
2886             error "chmod should not change data version: $version5 != $version6"
2887
2888         # Chown do not change version
2889         chown $RUNAS_ID $file2 || error "Could not chown $RUNAS_ID $file2"
2890         version7=$($LFS data_version $file1)
2891         [ "$version5" == "$version7" ] ||
2892             error "chown should not change data version: $version5 != $version7"
2893 }
2894 run_test 60 "Verify data_version behaviour"
2895
2896 test_70a() {
2897         local test_dir=$tdir/test_dir
2898
2899         mkdir -p $DIR1/$tdir
2900         if [ $MDSCOUNT -ge 2 ]; then
2901                 local MDTIDX=1
2902                 $LFS mkdir -i $MDTIDX $DIR1/$test_dir ||
2903                         error "Create remote directory failed"
2904         else
2905                 mkdir -p $DIR1/$test_dir
2906         fi
2907         cd $DIR2/$test_dir || error "cd directory failed"
2908         rm -rf $DIR1/$test_dir || error "unlink directory failed"
2909
2910         cd $DIR2/$tdir || error "exit directory"
2911 }
2912 run_test 70a "cd directory && rm directory"
2913
2914 test_70b() { # LU-2781
2915         local i
2916         mkdir -p $DIR1/$tdir
2917
2918         touch $DIR1/$tdir/file
2919         for ((i = 0; i < 32; i++)); do
2920             $LFS rm_entry $DIR1/$tdir/non_existent_dir &>/dev/null
2921         done
2922         rm $DIR1/$tdir/file || error "cannot remove file after rm_entry"
2923
2924         touch $DIR1/$tdir/file
2925         $LFS mkdir -i0 $DIR1/$tdir/test_dir
2926         $LFS rm_entry $DIR1/$tdir/test_dir &>/dev/null
2927         rm -rf $DIR1/$tdir/test_dir ||
2928                 error "cannot remove directory after rm_entry"
2929         rm $DIR1/$tdir/file || error "cannot remove file after rm_entry"
2930 }
2931 run_test 70b "remove files after calling rm_entry"
2932
2933 test_71a() {
2934         local server_version=$(lustre_version_code $SINGLEMDS)
2935
2936         [[ $server_version -lt $(version_code 2.1.6) ]] &&
2937                 skip "Need MDS version at least 2.1.6" && return
2938
2939         # Patch not applied to 2.2 and 2.3 branches
2940         [[ $server_version -ge $(version_code 2.2.0) ]] &&
2941         [[ $server_version -lt $(version_code 2.4.0) ]] &&
2942                 skip "Need MDS version earlier than 2.2.0 or at least 2.4.0" &&
2943                         return
2944
2945         checkfiemap --test ||
2946                 { skip "checkfiemap not runnable: $?" && return; }
2947         # write data this way: hole - data - hole - data
2948         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=1 count=1
2949         [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR1/$tfile) + 1)))" = \
2950                 "zfs" ] &&
2951                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return 0
2952         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=3 count=1
2953         GET_STAT="lctl get_param -n ldlm.services.ldlm_cbd.stats"
2954         stat $DIR2/$tfile
2955         local can1=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
2956         echo $can1
2957         checkfiemap $DIR2/$tfile 81920 ||
2958                 error "data is not flushed from client"
2959         local can2=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
2960         echo $can2
2961
2962         # common case of "create file, copy file" on a single node
2963         # should not flush data from ost
2964         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=1 count=1
2965         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=3 count=1
2966         stat $DIR1/$tfile
2967         local can3=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
2968         echo $can3
2969         checkfiemap $DIR1/$tfile 81920 ||
2970         error 4
2971         local can4=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
2972         echo $can2
2973         [ $can3 -eq $can4 ] || error $((can2-can1)) "cancel RPC occured."
2974 }
2975 run_test 71a "correct file map just after write operation is finished"
2976
2977 test_71b() {
2978         local server_version=$(lustre_version_code $SINGLEMDS)
2979
2980         [[ $server_version -lt $(version_code 2.1.6) ]] &&
2981                 skip "Need MDS version at least 2.1.6" && return
2982
2983         # Patch not applied to 2.2 and 2.3 branches
2984         [[ $server_version -ge $(version_code 2.2.0) ]] &&
2985         [[ $server_version -lt $(version_code 2.4.0) ]] &&
2986                 skip "Need MDS version earlier than 2.2.0 or at least 2.4.0" &&
2987                         return
2988         [[ $OSTCOUNT -ge 2 ]] || { skip "needs >= 2 OSTs"; return; }
2989
2990         checkfiemap --test ||
2991                 { skip "error $?: checkfiemap failed" && return; }
2992
2993         mkdir -p $DIR1/$tdir
2994
2995         $LFS setstripe -c -1 $DIR1/$tdir || error "setstripe failed"
2996         dd if=/dev/urandom of=$DIR1/$tdir/$tfile bs=40K count=1
2997         [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR1/$tdir/$tfile) + 1)))" = \
2998                 "zfs" ] &&
2999                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return 0
3000         checkfiemap $DIR1/$tdir/$tfile 40960 || error "checkfiemap failed"
3001 }
3002 run_test 71b "check fiemap support for stripecount > 1"
3003
3004 test_72() {
3005         local p="$TMP/sanityN-$TESTNAME.parameters"
3006         local tlink1
3007         local tlink2
3008         save_lustre_params client "llite.*.xattr_cache" > $p
3009         lctl set_param llite.*.xattr_cache 1 ||
3010                 { skip "xattr cache is not supported"; return 0; }
3011
3012         touch $DIR1/$tfile
3013         setfattr -n user.attr1 -v value1 $DIR1/$tfile ||
3014                 error "setfattr1 failed"
3015         getfattr -n user.attr1 $DIR2/$tfile | grep value1 ||
3016                 error "getfattr1 failed"
3017         setfattr -n user.attr1 -v value2 $DIR2/$tfile ||
3018                 error "setfattr2 failed"
3019         getfattr -n user.attr1 $DIR1/$tfile | grep value2 ||
3020                 error "getfattr2 failed"
3021
3022         # check that trusted.link is consistent
3023         tlink1=$(getfattr -n trusted.link $DIR1/$tfile | md5sum)
3024         ln $DIR2/$tfile $DIR2/$tfile-2 || error "failed to link"
3025         tlink2=$(getfattr -n trusted.link $DIR1/$tfile | md5sum)
3026         echo "$tlink1 $tlink2"
3027         [ "$tlink1" = "$tlink2" ] && error "trusted.link should have changed!"
3028
3029         rm -f $DIR2/$tfile
3030
3031         restore_lustre_params < $p
3032         rm -f $p
3033 }
3034 run_test 72 "getxattr/setxattr cache should be consistent between nodes"
3035
3036 test_73() {
3037         local p="$TMP/sanityN-$TESTNAME.parameters"
3038         save_lustre_params client "llite.*.xattr_cache" > $p
3039         lctl set_param llite.*.xattr_cache 1 ||
3040                 { skip "xattr cache is not supported"; return 0; }
3041
3042         touch $DIR1/$tfile
3043         setfattr -n user.attr1 -v value1 $DIR1/$tfile ||
3044                 error "setfattr1 failed"
3045         getfattr -n user.attr1 $DIR2/$tfile || error "getfattr1 failed"
3046         getfattr -n user.attr1 $DIR1/$tfile || error "getfattr2 failed"
3047         clear_stats llite.*.stats
3048         # PR lock should be cached by now on both clients
3049         getfattr -n user.attr1 $DIR1/$tfile || error "getfattr3 failed"
3050         # 2 hits for getfattr(0)+getfattr(size)
3051         [ $(calc_stats llite.*.stats getxattr_hits) -eq 2 ] ||
3052                 error "not cached in $DIR1"
3053         getfattr -n user.attr1 $DIR2/$tfile || error "getfattr4 failed"
3054         # 4 hits for more getfattr(0)+getfattr(size)
3055         [ $(calc_stats llite.*.stats getxattr_hits) -eq 4 ] ||
3056                 error "not cached in $DIR2"
3057         rm -f $DIR2/$tfile
3058
3059         restore_lustre_params < $p
3060         rm -f $p
3061 }
3062 run_test 73 "getxattr should not cause xattr lock cancellation"
3063
3064 test_74() {
3065         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.93) ] &&
3066                 skip "Need MDS version at least 2.4.93" && return
3067
3068         dd if=/dev/zero of=$DIR1/$tfile-1 bs=1K count=1
3069         dd if=/dev/zero of=$DIR1/$tfile-2 bs=1K count=1
3070         flocks_test 4 $DIR1/$tfile-1 $DIR2/$tfile-2
3071 }
3072 run_test 74 "flock deadlock: different mounts =============="
3073
3074 # LU-3889
3075 test_75() {
3076         $LFS setstripe -c 2 -S 1m -i 0 $DIR1/$tfile
3077         dd if=/dev/zero of=$DIR1/$tfile bs=1M count=2
3078         cancel_lru_locks osc
3079
3080         dd of=$DIR1/$tfile if=/dev/zero bs=1M count=1 seek=1 conv=notrunc
3081         sync
3082
3083         # define OBD_FAIL_LDLM_ENQUEUE_HANG 0x31d
3084         $LCTL set_param fail_loc=0x31d
3085         stat -c %s $DIR1/$tfile &
3086         local pid=$!
3087         sleep 1
3088         kill -9 $pid
3089
3090         # For bad lock error handler we should ASSERT and got kernel panic here
3091         sleep 4
3092         $LCTL set_param fail_loc=0
3093 }
3094 run_test 75 "osc: upcall after unuse lock==================="
3095
3096 test_76() { #LU-946
3097         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
3098                 skip "Need MDS version at least 2.5.53" && return
3099
3100         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3101         local fcount=$((MDSCOUNT * 256))
3102         declare -a fd_list
3103         declare -a fid_list
3104
3105         if remote_mds; then
3106                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
3107         else
3108                 nid="0@lo"
3109         fi
3110
3111         rm -rf $DIR/$tdir
3112         test_mkdir $DIR/$tdir
3113
3114         # drop all open locks and close any cached "open" files on the client
3115         cancel_lru_locks mdc
3116
3117         local open_fids_cmd="$LCTL get_param -n mdt.*.exports.'$nid'.open_files"
3118         local fid_list=($(do_nodes $(comma_list $(mdts_nodes)) $open_fids_cmd))
3119         local already=${#fid_list[@]}
3120         for (( i = 0; i < $already; i++ )) ; do
3121                 log "already open[$i]: $($LFS fid2path $DIR2 ${fid_list[i]})"
3122         done
3123
3124         echo -n "opening files: "
3125         ulimit -n $((fcount + 50))
3126         for ((i = 0; i < $fcount; i++)); do
3127                 touch $DIR/$tdir/f_$i
3128                 local fd=$(free_fd ${fd_list[i]})
3129                 local open_cmd="exec $fd<$DIR/$tdir/f_$i"
3130                 eval $open_cmd
3131
3132                 fd_list[i]=$fd
3133
3134                 (( $i % 32 == 0 )) && echo -n "."
3135         done
3136         echo
3137
3138         fid_list=($(do_nodes $(comma_list $(mdts_nodes)) $open_fids_cmd))
3139
3140         # Possible errors in openfiles FID list.
3141         # 1. Missing FIDs. Check 1
3142         # 2. Extra FIDs. Check 1
3143         # 3. Duplicated FID. Check 2
3144         # 4. Invalid FIDs. Check 2
3145         # 5. Valid FID, points to some other file. Check 3
3146
3147         # Check 1
3148         [ ${#fid_list[@]} -ne $((fcount + already)) ] &&
3149                 error "${#fid_list[@]} != $fcount (+$already old) open files"
3150
3151         echo -n "closing files: "
3152         for (( fd = 0, fid = 0; fd < $fcount; fd++, fid++ )) ; do
3153                 local close_cmd="exec ${fd_list[fd]}<&-"
3154                 eval $close_cmd
3155                 filename=$($LFS fid2path $DIR2 ${fid_list[fid]})
3156
3157                 while [[ ! "$filename" =~ "$DIR2/$tdir/f_" ]]; do
3158                         echo "skip old open file $filename"
3159                         ((fid++))
3160                         filename=$($LFS fid2path $DIR2 ${fid_list[fid]})
3161                 done
3162
3163                 # Check 2
3164                 rm --interactive=no $filename
3165                 [ $? -ne 0 ] &&
3166                         error "Nonexisting fid ${fid_list[fid]} listed."
3167                 (( $fd % 32 == 0 )) && echo -n "."
3168         done
3169         echo
3170
3171         # Check 3
3172         ls_op=$(ls $DIR2/$tdir | wc -l)
3173         [ $ls_op -ne 0 ] &&
3174                 error "Some openfiles are missing in lproc output"
3175
3176         rm -rf $DIR/$tdir
3177 }
3178 run_test 76 "Verify MDT open_files listing"
3179
3180 nrs_write_read() {
3181         local n=16
3182         local dir=$DIR/$tdir
3183         local myRUNAS="$1"
3184
3185         mkdir $dir || error "mkdir $dir failed"
3186         $LFS setstripe -c $OSTCOUNT $dir || error "setstripe to $dir failed"
3187         chmod 777 $dir
3188
3189         do_nodes $CLIENTS $myRUNAS \
3190                 dd if=/dev/zero of="$dir/nrs_r_\$HOSTNAME" bs=1M count=$n ||
3191                 error "dd at 0 on client failed (1)"
3192
3193         do_nodes $CLIENTS $myRUNAS \
3194                 "declare -a pids_w;
3195                 for ((i = 0; i < $n; i++)); do
3196                         dd if=/dev/zero of=$dir/nrs_w_\$HOSTNAME bs=1M \
3197 seek=\\\$i count=1 conv=notrunc &
3198                         pids_w[\\\$i]=\\\$!;
3199                 done;
3200                 rc_w=0;
3201                 for ((i = 0; i < $n; i++)); do
3202                         wait \\\${pids_w[\\\$i]};
3203                         newrc=\\\$?;
3204                         [ \\\$newrc -gt \\\$rc_w ] && rc_w=\\\$newrc;
3205                 done;
3206                 exit \\\$rc_w" &
3207         local pid_w=$!
3208         do_nodes $CLIENTS sync;
3209         cancel_lru_locks osc
3210
3211         do_nodes $CLIENTS $myRUNAS \
3212                 "declare -a pids_r;
3213                 for ((i = 0; i < $n; i++)); do
3214                         dd if=$dir/nrs_r_\$HOSTNAME bs=1M of=/dev/null \
3215 seek=\\\$i count=1 &
3216                         pids_r[\\\$i]=\\\$!;
3217                 done;
3218                 rc_r=0;
3219                 for ((i = 0; i < $n; i++)); do
3220                         wait \\\${pids_r[\\\$i]};
3221                         newrc=\\\$?;
3222                         [ \\\$newrc -gt \\\$rc_r ] && rc_r=\\\$newrc;
3223                 done;
3224                 exit \\\$rc_r" &
3225         local pid_r=$!
3226         cancel_lru_locks osc
3227
3228         wait $pid_w || error "dd (write) failed (2)"
3229         wait $pid_r || error "dd (read) failed (3)"
3230         rm -rvf $dir || error "rm -rf $dir failed"
3231 }
3232
3233 test_77a() { #LU-3266
3234         local rc
3235
3236         oss=$(comma_list $(osts_nodes))
3237         do_nodes $oss lctl set_param ost.OSS.*.nrs_policies="fifo" ||
3238                 rc=$?
3239         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3240         [[ $rc -ne 0 ]] && error "failed to set fifo policy"
3241         nrs_write_read
3242
3243         return 0
3244 }
3245 run_test 77a "check FIFO NRS policy"
3246
3247 test_77b() { #LU-3266
3248         local rc
3249
3250         oss=$(comma_list $(osts_nodes))
3251
3252         do_nodes $oss lctl set_param ost.OSS.*.nrs_policies="crrn" \
3253                 ost.OSS.*.nrs_crrn_quantum=1 || rc=$?
3254         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3255         [[ $rc -ne 0 ]] && error "failed to set crrn_quantum to 1"
3256
3257         echo "policy: crr-n, crrn_quantum 1"
3258         nrs_write_read
3259
3260         do_nodes $oss lctl set_param \
3261                 ost.OSS.*.nrs_crrn_quantum=64 || rc=$?
3262         [[ $rc -ne 0 ]] && error "failed to set crrn_quantum to 64"
3263
3264         echo "policy: crr-n, crrn_quantum 64"
3265         nrs_write_read
3266
3267         # cleanup
3268         do_nodes $oss lctl set_param \
3269                 ost.OSS.ost_io.nrs_policies="fifo" || rc=$?
3270         [[ $rc -ne 0 ]] && error "failed to set fifo policy"
3271         return 0
3272 }
3273 run_test 77b "check CRR-N NRS policy"
3274
3275 orr_trr() {
3276         local policy=$1
3277
3278         oss=$(comma_list $(osts_nodes))
3279
3280         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies=$policy \
3281                 ost.OSS.*.nrs_"$policy"_quantum=1 \
3282                 ost.OSS.*.nrs_"$policy"_offset_type="physical" \
3283                 ost.OSS.*.nrs_"$policy"_supported="reads" || return $?
3284
3285         echo "policy: $policy, ${policy}_quantum 1, ${policy}_offset_type " \
3286                 "physical, ${policy}_supported reads"
3287         nrs_write_read
3288
3289         do_nodes $oss lctl set_param \
3290                 ost.OSS.*.nrs_${policy}_supported="writes" \
3291                 ost.OSS.*.nrs_${policy}_quantum=64 || return $?
3292
3293         echo "policy: $policy, ${policy}_quantum 64, ${policy}_offset_type " \
3294                 "physical, ${policy}_supported writes"
3295         nrs_write_read
3296
3297         do_nodes $oss lctl set_param \
3298                 ost.OSS.*.nrs_${policy}_supported="reads_and_writes" \
3299                 ost.OSS.*.nrs_${policy}_offset_type="logical" || return $?
3300         echo "policy: $policy, ${policy}_quantum 64, ${policy}_offset_type " \
3301                 "logical, ${policy}_supported reads_and_writes"
3302         nrs_write_read
3303
3304         # cleanup
3305         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo" ||
3306                 return $?
3307         return 0
3308 }
3309
3310 test_77c() { #LU-3266
3311         local rc
3312         orr_trr "orr" || rc=$?
3313         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3314         [[ $rc -ne 0 ]] && error "orr_trr failed rc:$rc"
3315         return 0
3316 }
3317 run_test 77c "check ORR NRS policy"
3318
3319 test_77d() { #LU-3266
3320         local rc
3321         orr_trr "trr" || rc=$?
3322         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3323         [[ $rc -ne 0 ]] && error "orr_trr failed rc:$rc"
3324         return 0
3325 }
3326 run_test 77d "check TRR nrs policy"
3327
3328 tbf_rule_operate()
3329 {
3330         local facet=$1
3331         shift 1
3332
3333         do_facet $facet lctl set_param \
3334                 ost.OSS.ost_io.nrs_tbf_rule="$*"
3335         [ $? -ne 0 ] &&
3336                 error "failed to run operate '$*' on TBF rules"
3337 }
3338
3339 cleanup_tbf_verify()
3340 {
3341         local rc=0
3342         trap 0
3343         echo "cleanup_tbf $DIR/$tdir"
3344         rm -rf $DIR/$tdir
3345         rc=$?
3346         wait_delete_completed
3347         return $rc
3348 }
3349
3350 tbf_verify() {
3351         local dir=$DIR/$tdir
3352         local client1=${CLIENT1:-$(hostname)}
3353         local myRUNAS="$3"
3354
3355         local np=$(check_cpt_number ost1)
3356         [ $np -gt 0 ] || error "CPU partitions should not be $np."
3357         echo "cpu_npartitions on ost1 is $np"
3358
3359         mkdir $dir || error "mkdir $dir failed"
3360         $LFS setstripe -c 1 -i 0 $dir || error "setstripe to $dir failed"
3361         chmod 777 $dir
3362
3363         trap cleanup_tbf_verify EXIT
3364         echo "Limited write rate: $1, read rate: $2"
3365         echo "Verify the write rate is under TBF control"
3366         local start=$SECONDS
3367         do_node $client1 $myRUNAS dd if=/dev/zero of=$dir/tbf \
3368                 bs=1M count=100 oflag=direct 2>&1
3369         local runtime=$((SECONDS - start + 1))
3370         local rate=$(bc <<< "scale=6; 100 / $runtime")
3371         echo "Write runtime is $runtime s, speed is $rate IOPS"
3372
3373         # verify the write rate does not exceed TBF rate limit
3374         [ $(bc <<< "$rate < 1.1 * $np * $1") -eq 1 ] ||
3375                 error "The write rate ($rate) exceeds 110% of rate limit ($1 * $np)"
3376
3377         cancel_lru_locks osc
3378
3379         echo "Verify the read rate is under TBF control"
3380         start=$SECONDS
3381         do_node $client1 $myRUNAS dd if=$dir/tbf of=/dev/null \
3382                 bs=1M count=100 iflag=direct 2>&1
3383         runtime=$((SECONDS - start + 1))
3384         rate=$(bc <<< "scale=6; 100 / $runtime")
3385         echo "Read runtime is $runtime s, speed is $rate IOPS"
3386
3387         # verify the read rate does not exceed TBF rate limit
3388         [ $(bc <<< "$rate < 1.1 * $np * $2") -eq 1 ] ||
3389                 error "The read rate ($rate) exceeds 110% of rate limit ($2 * $np)"
3390
3391         cancel_lru_locks osc
3392         cleanup_tbf_verify || error "rm -rf $dir failed"
3393 }
3394
3395 test_77e() {
3396         local rc
3397
3398         oss=$(comma_list $(osts_nodes))
3399
3400         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ nid" ||
3401                 rc=$?
3402         [[ $rc -eq 3 ]] && skip "no NRS TBF exists" && return
3403         [[ $rc -ne 0 ]] && error "failed to set TBF NID policy"
3404
3405         local idis
3406         local rateis
3407         if [ $(lustre_version_code ost1) -ge $(version_code 2.8.54) ]; then
3408                 idis="nid="
3409                 rateis="rate="
3410         fi
3411
3412         # Only operate rules on ost1 since OSTs might run on the same OSS
3413         # Add some rules
3414         tbf_rule_operate ost1 "start\ localhost\ ${idis}{0@lo}\ ${rateis}1000"
3415         local address=$(comma_list "$(host_nids_address $CLIENTS $NETTYPE)")
3416         local client_nids=$(nids_list $address "\\")
3417         tbf_rule_operate ost1 "start\ clients\ ${idis}{$client_nids}\ ${rateis}100"
3418         tbf_rule_operate ost1 "start\ others\ ${idis}{*.*.*.*@$NETTYPE}\ ${rateis}50"
3419         nrs_write_read
3420
3421         # Change the rules
3422         tbf_rule_operate ost1 "change\ localhost\ ${rateis}1001"
3423         tbf_rule_operate ost1 "change\ clients\ ${rateis}101"
3424         tbf_rule_operate ost1 "change\ others\ ${rateis}51"
3425         nrs_write_read
3426
3427         # Stop the rules
3428         tbf_rule_operate ost1 "stop\ localhost"
3429         tbf_rule_operate ost1 "stop\ clients"
3430         tbf_rule_operate ost1 "stop\ others"
3431         nrs_write_read
3432
3433         # Cleanup the TBF policy
3434         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3435         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3436         nrs_write_read
3437         return 0
3438 }
3439 run_test 77e "check TBF NID nrs policy"
3440
3441 test_77f() {
3442         local rc
3443
3444         oss=$(comma_list $(osts_nodes))
3445
3446         do_nodes $oss $LCTL set_param \
3447                 ost.OSS.ost_io.nrs_policies="tbf\ jobid" || rc=$?
3448         [[ $rc -eq 3 ]] && skip "no NRS TBF exists" && return
3449         [[ $rc -ne 0 ]] && error "failed to set TBF JOBID policy"
3450
3451         # Configure jobid_var
3452         local saved_jobid_var=$($LCTL get_param -n jobid_var)
3453         rc=$?
3454         [[ $rc -eq 3 ]] && skip "jobid_var not found" && return
3455         [[ $rc -ne 0 ]] && error "failed to get param jobid_var"
3456         if [ $saved_jobid_var != procname_uid ]; then
3457                 set_persistent_param_and_check client \
3458                         "jobid_var" "$FSNAME.sys.jobid_var" procname_uid
3459         fi
3460
3461         local idis
3462         local rateis
3463         if [ $(lustre_version_code ost1) -ge $(version_code 2.8.54) ]; then
3464                 idis="jobid="
3465                 rateis="rate="
3466         fi
3467
3468         # Only operate rules on ost1 since OSTs might run on the same OSS
3469         # Add some rules
3470         tbf_rule_operate ost1 "start\ runas\ ${idis}{iozone.$RUNAS_ID\ dd.$RUNAS_ID\ tiotest.$RUNAS_ID}\ ${rateis}1000"
3471         tbf_rule_operate ost1 "start\ iozone_runas\ ${idis}{iozone.$RUNAS_ID}\ ${rateis}100"
3472         tbf_rule_operate ost1 "start\ dd_runas\ ${idis}{dd.$RUNAS_ID}\ ${rateis}50"
3473         nrs_write_read "$RUNAS"
3474
3475         # Change the rules
3476         tbf_rule_operate ost1 "change\ runas\ ${rateis}1001"
3477         tbf_rule_operate ost1 "change\ iozone_runas\ ${rateis}101"
3478         tbf_rule_operate ost1 "change\ dd_runas\ ${rateis}51"
3479         nrs_write_read "$RUNAS"
3480
3481         # Stop the rules
3482         tbf_rule_operate ost1 "stop\ runas"
3483         tbf_rule_operate ost1 "stop\ iozone_runas"
3484         tbf_rule_operate ost1 "stop\ dd_runas"
3485         nrs_write_read "$RUNAS"
3486
3487         # Cleanup the TBF policy
3488         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3489         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3490         nrs_write_read "$RUNAS"
3491
3492         local current_jobid_var=$($LCTL get_param -n jobid_var)
3493         [[ $? -ne 0 ]] && error "failed to get param jobid_var"
3494         if [ $saved_jobid_var != $current_jobid_var ]; then
3495                 set_persistent_param_and_check client \
3496                         "jobid_var" "$FSNAME.sys.jobid_var" $saved_jobid_var
3497         fi
3498         return 0
3499 }
3500 run_test 77f "check TBF JobID nrs policy"
3501
3502 test_77g() {
3503         local rc=0
3504
3505         oss=$(comma_list $(osts_nodes))
3506
3507         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ nid" ||
3508                 rc=$?
3509         [[ $rc -eq 3 ]] && skip "no NRS TBF exists" && return
3510         [[ $rc -ne 0 ]] && error "failed to set TBF NID policy"
3511
3512         do_nodes $oss lctl set_param \
3513                 ost.OSS.ost_io.nrs_policies="tbf\ jobid" || rc=$?
3514         [[ $rc -ne 0 ]] && error "failed to set TBF JOBID policy"
3515
3516         local idis
3517         local rateis
3518         if [ $(lustre_version_code ost1) -ge $(version_code 2.8.54) ]; then
3519                 idis="jobid="
3520                 rateis="rate="
3521         fi
3522
3523         # Add a rule that only valid for Jobid TBF. If direct change between
3524         # TBF types is not supported, this operation will fail.
3525         tbf_rule_operate ost1 "start\ dd_runas\ ${idis}{dd.$RUNAS_ID}\ ${rateis}50"
3526
3527         # Cleanup the TBF policy
3528         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3529         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3530         return 0
3531 }
3532 run_test 77g "Change TBF type directly"
3533
3534 test_77h() {
3535         [ $(lustre_version_code ost1) -ge $(version_code 2.8.55) ] ||
3536                 { skip "Need OST version at least 2.8.55"; return 0; }
3537
3538         local old_policy=$(do_facet ost1 \
3539                 lctl get_param ost.OSS.ost_io.nrs_policies)
3540         local new_policy
3541
3542         do_facet ost1 lctl set_param \
3543                 ost.OSS.ost_io.nrs_policies="abc"
3544         [ $? -eq 0 ] && error "should return error"
3545
3546         do_facet ost1 lctl set_param \
3547                 ost.OSS.ost_io.nrs_policies="tbf\ abc"
3548         [ $? -eq 0 ] && error "should return error"
3549
3550         do_facet ost1 lctl set_param \
3551                 ost.OSS.ost_io.nrs_policies="tbf\ reg\ abc"
3552         [ $? -eq 0 ] && error "should return error"
3553
3554         do_facet ost1 lctl set_param \
3555                 ost.OSS.ost_io.nrs_policies="tbf\ abc\ efg"
3556         [ $? -eq 0 ] && error "should return error"
3557
3558         new_policy=$(do_facet ost1 lctl get_param ost.OSS.ost_io.nrs_policies)
3559         [ $? -eq 0 ] || error "shouldn't LBUG"
3560
3561         [ "$old_policy" = "$new_policy" ] || error "NRS policy should be same"
3562
3563         return 0
3564 }
3565 run_test 77h "Wrong policy name should report error, not LBUG"
3566
3567 tbf_rule_check()
3568 {
3569         local facet=$1
3570         local expected=$2
3571         local error_message=$3
3572         local rule_number=0
3573         for rule in $expected; do
3574                 rule_number=$((rule_number + 1))
3575         done
3576         local stop_line=$(($rule_number + 3))
3577         local awk_command="awk 'NR >= 4 && NR <= $stop_line {print \$1}'"
3578
3579         local output=$(do_facet $facet lctl get_param \
3580                 ost.OSS.ost_io.nrs_tbf_rule |
3581                 eval $awk_command |
3582                 tr "\n" " " |
3583                 sed 's/[ ]*$//')
3584         if [ "$output" != "$expected" ]; then
3585                 error "$error_message, expected '$expected', got '$output'"
3586         fi
3587 }
3588
3589 test_77i() {
3590         [ $(lustre_version_code ost1) -ge $(version_code 2.8.55) ] ||
3591                 { skip "Need OST version at least 2.8.55"; return 0; }
3592
3593         for i in $(seq 1 $OSTCOUNT)
3594         do
3595                 do_facet ost"$i" lctl set_param \
3596                         ost.OSS.ost_io.nrs_policies="tbf\ jobid"
3597                 [ $? -ne 0 ] &&
3598                         error "failed to set TBF policy"
3599         done
3600
3601         tbf_rule_check ost1 "default" "error before inserting any rule"
3602
3603         tbf_rule_operate ost1 "start\ before\ jobid={jobid}\ rate=1000"
3604         tbf_rule_check ost1 "before default" \
3605                 "error when inserting rule 'before'"
3606
3607         tbf_rule_operate ost1 "start\ after\ jobid={jobid}\ rate=1000\ rank=default"
3608         tbf_rule_check ost1 "before after default" \
3609                 "error when inserting rule 'after'"
3610
3611         tbf_rule_operate ost1 "start\ target\ jobid={jobid}\ rate=1000\ rank=after"
3612         tbf_rule_check ost1 "before target after default" \
3613                 "error when inserting rule 'target'"
3614
3615         echo "Move before itself"
3616         tbf_rule_operate ost1 "change\ target\ rank=target"
3617         tbf_rule_check ost1 "before target after default" \
3618                 "error when moving before itself"
3619
3620         echo "Move to higher rank"
3621         tbf_rule_operate ost1 "change\ target\ rank=before"
3622         tbf_rule_check ost1 "target before after default" \
3623                 "error when moving to higher rank"
3624
3625         echo "Move to lower rank"
3626         tbf_rule_operate ost1 "change\ target\ rank=after"
3627         tbf_rule_check ost1 "before target after default" \
3628                 "error when moving to lower rank"
3629
3630         echo "Move before default"
3631         tbf_rule_operate ost1 "change\ target\ rank=default"
3632         tbf_rule_check ost1 "before after target default" \
3633                 error "error when moving before default"
3634
3635         # Cleanup the TBF policy
3636         do_nodes $(comma_list $(osts_nodes)) \
3637                 $LCTL set_param ost.OSS.ost_io.nrs_policies=fifo
3638         return 0
3639 }
3640 run_test 77i "Change rank of TBF rule"
3641
3642 test_77j() {
3643         local idis
3644         local rateis
3645         local ost_version=$(lustre_version_code ost1)
3646
3647         [ $ost_version -ge $(version_code 2.9.53) ] ||
3648                 { skip "Need OST version at least 2.9.53"; return 0; }
3649         if [ $ost_version -ge $(version_code 2.8.60) ]; then
3650                 idis="opcode="
3651                 rateis="rate="
3652         fi
3653
3654         do_nodes $(comma_list $(osts_nodes)) \
3655                 lctl set_param jobid_var=procname_uid \
3656                         ost.OSS.ost_io.nrs_policies="tbf\ opcode" \
3657                         ost.OSS.ost_io.nrs_tbf_rule="start\ ost_r\ ${idis}{ost_read}\ ${rateis}5" \
3658                         ost.OSS.ost_io.nrs_tbf_rule="start\ ost_w\ ${idis}{ost_write}\ ${rateis}20"
3659         [ $? -ne 0 ] && error "failed to set TBF OPCode policy"
3660
3661         nrs_write_read
3662         tbf_verify 20 5
3663
3664         do_nodes $(comma_list $(osts_nodes)) \
3665                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ost_r" \
3666                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ost_w" \
3667                         ost.OSS.ost_io.nrs_policies="fifo"
3668
3669         # sleep 3 seconds to wait the tbf policy stop completely,
3670         # or the next test case is possible get -EAGAIN when
3671         # setting the tbf policy
3672         sleep 3
3673 }
3674 run_test 77j "check TBF-OPCode NRS policy"
3675
3676 test_id() {
3677         local idstr="${1}id"
3678         local policy="${idstr}={$2}"
3679         local rate="rate=$3"
3680
3681         do_nodes $(comma_list $(osts_nodes)) \
3682                 lctl set_param jobid_var=procname_uid \
3683                         ost.OSS.ost_io.nrs_policies="tbf\ ${idstr}" \
3684                         ost.OSS.ost_io.nrs_tbf_rule="start\ ost_${idstr}\ ${policy}\ ${rate}"
3685         [ $? -ne 0 ] && error "failed to set tbf ${idstr} policy"
3686
3687         nrs_write_read "runas $4"
3688         tbf_verify $3 $3 "runas $4"
3689
3690         do_nodes $(comma_list $(osts_nodes)) \
3691                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ost_${idstr}" \
3692                         ost.OSS.ost_io.nrs_policies="fifo"
3693
3694         # sleep 3 seconds to wait the tbf policy stop completely,
3695         # or the next test case is possible get -eagain when
3696         # setting the tbf policy
3697         sleep 3
3698 }
3699
3700 test_77ja(){
3701         if [ $(lustre_version_code ost1) -lt $(version_code 2.11.50) ]; then
3702                 skip "Need OST version at least 2.11.50"
3703                 return 0
3704         fi
3705         test_id "u" "500" "5" "-u 500"
3706         test_id "g" "500" "5" "-u 500 -g 500"
3707 }
3708 run_test 77ja "check TBF-UID/GID NRS policy"
3709
3710 cleanup_77k()
3711 {
3712         local rule_lists=$1
3713         local old_nrs=$2
3714
3715         trap 0
3716         for rule in $rule_lists; do
3717                 do_nodes $(comma_list $(osts_nodes)) \
3718                         lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ $rule"
3719         done
3720
3721         do_nodes $(comma_list $(osts_nodes)) \
3722                 lctl set_param ost.OSS.ost_io.nrs_policies="$old_nrs"
3723
3724         sleep 3
3725 }
3726
3727 test_77k() {
3728         [[ $(lustre_version_code ost1) -ge $(version_code 2.9.53) ]] ||
3729                 { skip "Need OST version at least 2.9.53"; return 0; }
3730
3731         do_nodes $(comma_list $(osts_nodes)) \
3732                 lctl set_param ost.OSS.ost_io.nrs_policies="tbf" \
3733                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_w\ jobid={dd.$RUNAS_ID}\&opcode={ost_write}\ rate=20" \
3734                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_r\ jobid={dd.$RUNAS_ID}\&opcode={ost_read}\ rate=10"
3735
3736         nrs_write_read "$RUNAS"
3737         tbf_verify 20 10 "$RUNAS"
3738
3739         local address=$(comma_list "$(host_nids_address $CLIENTS $NETTYPE)")
3740         local client_nids=$(nids_list $address "\\")
3741         do_nodes $(comma_list $(osts_nodes)) \
3742                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_w" \
3743                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_r" \
3744                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_w\ nid={0@lo\ $client_nids}\&opcode={ost_write}\ rate=20" \
3745                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_r\ nid={0@lo\ $client_nids}\&opcode={ost_read}\ rate=10"
3746
3747         nrs_write_read
3748         tbf_verify 20 10
3749
3750         do_nodes $(comma_list $(osts_nodes)) \
3751                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_w" \
3752                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_r" \
3753                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext\ nid={0@lo\ $client_nids}\&jobid={dd.$RUNAS_ID}\ rate=20"
3754
3755         nrs_write_read "$RUNAS"
3756         tbf_verify 20 20 "$RUNAS"
3757
3758         do_nodes $(comma_list $(osts_nodes)) \
3759                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext" \
3760                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_a\ jobid={dd.$RUNAS_ID},opcode={ost_write}\ rate=20" \
3761                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_b\ jobid={dd.$RUNAS_ID},opcode={ost_read}\ rate=10"
3762
3763         nrs_write_read "$RUNAS"
3764         # with parameter "RUNAS", it will match the latest rule
3765         # "ext_b" first, so the limited write rate is 10.
3766         tbf_verify 10 10 "$RUNAS"
3767         tbf_verify 20 10
3768
3769         trap "cleanup_77k \"ext_a ext_b\" \"fifo\"" EXIT
3770
3771         [[ $(lustre_version_code ost1) -ge $(version_code 2.10.58) ]] ||
3772                 { skip "Need OST version at least 2.10.58"; return 0; }
3773
3774         do_nodes $(comma_list $(osts_nodes)) \
3775                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_a" \
3776                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_b" \
3777                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_ug\ uid={500}\&gid={1000}\ rate=5"
3778         nrs_write_read "runas -u 500 -g 1000"
3779         tbf_verify 5 5 "runas -u 500 -g 1000"
3780
3781         do_nodes $(comma_list $(osts_nodes)) \
3782                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_ug" \
3783                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_uw\ uid={500}\&opcode={ost_write}\ rate=20" \
3784                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_ur\ uid={500}\&opcode={ost_read}\ rate=10"
3785
3786         nrs_write_read "runas -u 500"
3787         tbf_verify 20 10 "runas -u 500"
3788
3789         do_nodes $(comma_list $(osts_nodes)) \
3790                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_uw" \
3791                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_ur" \
3792                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_a\ uid={500},opcode={ost_write}\ rate=20" \
3793                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_b\ uid={500},opcode={ost_read}\ rate=10"
3794         nrs_write_read "runas -u 500"
3795         tbf_verify 10 10 "runas -u 500"
3796         tbf_verify 20 10 "runas -u 500"
3797         cleanup_77k "ext_a ext_b" "fifo"
3798 }
3799 run_test 77k "check TBF policy with NID/JobID/OPCode expression"
3800
3801 test_77l() {
3802         [[ $(lustre_version_code ost1) -ge $(version_code 2.10.56) ]] ||
3803                 { skip "Need OST version at least 2.10.56"; return 0; }
3804
3805         do_facet ost1 lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ nid"
3806         do_facet ost1 lctl set_param ost.OSS.ost_io.nrs_policies="tbf"
3807
3808         local output=$(do_facet ost1 lctl get_param \
3809                         ost.OSS.ost_io.nrs_policies | \
3810                         awk '/name: tbf/ {print;exit}' | \
3811                         awk -F ': ' '{print $2}')
3812
3813         if [ "$output" != "tbf" ]; then
3814                 error "The generic TBF output is '$output', not 'tbf'"
3815         fi
3816
3817         do_facet ost1 lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3818 }
3819 run_test 77l "check the output of NRS policies for generic TBF"
3820
3821 test_77m() {
3822         if [ $(lustre_version_code ost1) -lt $(version_code 2.9.54) ]; then
3823                 skip "Need OST version at least 2.9.54"
3824                 return 0
3825         fi
3826
3827         local dir=$DIR/$tdir
3828
3829         mkdir $dir || error "mkdir $dir failed"
3830         $LFS setstripe -c $OSTCOUNT $dir || error "setstripe to $dir failed"
3831         chmod 777 $dir
3832
3833         local nodes=$(comma_list $(osts_nodes))
3834         do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies=delay \
3835                                        ost.OSS.ost_io.nrs_delay_min=4 \
3836                                        ost.OSS.ost_io.nrs_delay_max=4 \
3837                                        ost.OSS.ost_io.nrs_delay_pct=100
3838         [ $? -ne 0 ] && error "Failed to set delay policy"
3839
3840         local start=$SECONDS
3841         do_nodes "${SINGLECLIENT:-$HOSTNAME}" "$RUNAS" \
3842                  dd if=/dev/zero of="$dir/nrs_delay_$HOSTNAME" bs=1M count=1 \
3843                    oflag=direct conv=fdatasync ||
3844                 { do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo";
3845                   error "dd on client failed (1)"; }
3846         local elapsed=$((SECONDS - start))
3847
3848         # NRS delay doesn't do sub-second timing, so a request enqueued at
3849         # 0.9 seconds can be dequeued at 4.0
3850         [ $elapsed -lt 3 ] &&
3851                 { do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo";
3852                   error "Single 1M write should take at least 3 seconds"; }
3853
3854         start=$SECONDS
3855         do_nodes "${SINGLECLIENT:-$HOSTNAME}" "$RUNAS" \
3856                  dd if=/dev/zero of="$dir/nrs_delay_$HOSTNAME" bs=1M count=10 \
3857                    oflag=direct conv=fdatasync ||
3858                 { do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo";
3859                   error "dd on client failed (2)"; }
3860         elapsed=$((SECONDS - start))
3861
3862         [ $elapsed -lt 30 ] &&
3863                 { do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo";
3864                   error "Ten 1M writes should take at least 30 seconds"; }
3865
3866         do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3867         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3868
3869         return 0
3870 }
3871 run_test 77m "check NRS Delay slows write RPC processing"
3872
3873 test_77n() { #LU-10802
3874         if [ $(lustre_version_code ost1) -lt $(version_code 2.10.58) ]; then
3875                 skip "Need OST version at least 2.10.58"
3876                 return 0
3877         fi
3878
3879         # Configure jobid_var
3880         local saved_jobid_var=$($LCTL get_param -n jobid_var)
3881         if [ $saved_jobid_var != procname_uid ]; then
3882                 set_persistent_param_and_check client \
3883                         "jobid_var" "$FSNAME.sys.jobid_var" procname_uid
3884         fi
3885
3886         do_nodes $(comma_list $(osts_nodes)) \
3887                 lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ jobid" \
3888                         ost.OSS.ost_io.nrs_tbf_rule="stop\ dd_runas" \
3889                         ost.OSS.ost_io.nrs_tbf_rule="start\ dd_runas\ jobid={*.$RUNAS_ID}\ rate=20"
3890
3891         nrs_write_read
3892         tbf_verify 20 20 "$RUNAS"
3893
3894         do_nodes $(comma_list $(osts_nodes)) \
3895                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ dd_runas" \
3896                         ost.OSS.ost_io.nrs_tbf_rule="start\ dd_runas\ jobid={dd.*}\ rate=20"
3897
3898         nrs_write_read
3899         tbf_verify 20 20
3900
3901         do_nodes $(comma_list $(osts_nodes)) \
3902                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ dd_runas" \
3903                         ost.OSS.ost_io.nrs_policies="fifo"
3904
3905         sleep 3
3906
3907         local current_jobid_var=$($LCTL get_param -n jobid_var)
3908         if [ $saved_jobid_var != $current_jobid_var ]; then
3909                 set_persistent_param_and_check client \
3910                         "jobid_var" "$FSNAME.sys.jobid_var" $saved_jobid_var
3911         fi
3912 }
3913 run_test 77n "check wildcard support for TBF JobID NRS policy"
3914
3915 test_78() { #LU-6673
3916         local rc
3917
3918         oss=$(comma_list $(osts_nodes))
3919         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="orr" &
3920         do_nodes $oss lctl set_param ost.OSS.*.nrs_orr_quantum=1
3921         rc=$?
3922         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3923         # Valid return codes are:
3924         # 0: Tuning succeeded
3925         # ENODEV: Policy is still stopped
3926         # EAGAIN: Policy is being initialized
3927         [ $rc -eq 0 -o $rc -eq 19 -o $rc -eq 11 ] ||
3928                 error "Expected set_param to return 0|ENODEV|EAGAIN"
3929
3930         # Cleanup the ORR policy
3931         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3932         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3933         return 0
3934 }
3935 run_test 78 "Enable policy and specify tunings right away"
3936
3937 test_79() {
3938         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3939         test_mkdir $DIR/$tdir
3940
3941         # Prevent interference from layout intent RPCs due to
3942         # asynchronous writeback. These will be tested in 130c below.
3943         do_nodes ${CLIENTS:-$HOSTNAME} sync
3944
3945         setfattr -n trusted.name1 -v value1 $DIR/$tdir ||
3946                 error "setfattr -n trusted.name1=value1 $DIR/$tdir failed"
3947
3948 #define OBD_FAIL_MDS_INTENT_DELAY               0x160
3949         local mdtidx=$($LFS getstripe -m $DIR/$tdir)
3950         local facet=mds$((mdtidx + 1))
3951         stat $DIR/$tdir
3952         set_nodes_failloc $(facet_active_host $facet) 0x80000160
3953         getfattr -n trusted.name1 $DIR/$tdir 2> /dev/null  &
3954         local pid=$!
3955         sleep 2
3956
3957 #define OBD_FAIL_MDS_GETXATTR_PACK       0x131
3958         set_nodes_failloc $(facet_active_host $facet) 0x80000131
3959
3960         wait $pid
3961         return 0
3962 }
3963 run_test 79 "xattr: intent error"
3964
3965 test_80a() {
3966         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3967         local MDTIDX=1
3968         local mdt_index
3969         local i
3970         local file
3971         local pid
3972
3973         mkdir -p $DIR1/$tdir/dir
3974         createmany -o $DIR1/$tdir/dir/f 10 ||
3975                 error "create files under remote dir failed $i"
3976
3977         cp /etc/passwd $DIR1/$tdir/$tfile
3978
3979         #migrate open file should fails
3980         multiop_bg_pause $DIR2/$tdir/$tfile O_c || error "open $file failed"
3981         pid=$!
3982         # give multiop a chance to open
3983         sleep 1
3984
3985         $LFS migrate -m $MDTIDX $DIR1/$tdir &&
3986                 error "migrate open files should failed with open files"
3987
3988         kill -USR1 $pid
3989
3990         $LFS migrate -m $MDTIDX $DIR1/$tdir ||
3991                         error "migrate remote dir error"
3992
3993         echo "Finish migration, then checking.."
3994         for file in $(find $DIR1/$tdir); do
3995                 mdt_index=$($LFS getstripe -m $file)
3996                 [ $mdt_index == $MDTIDX ] ||
3997                         error "$file is not on MDT${MDTIDX}"
3998         done
3999
4000         diff /etc/passwd $DIR1/$tdir/$tfile ||
4001                 error "file different after migration"
4002
4003         rm -rf $DIR1/$tdir || error "rm dir failed after migration"
4004 }
4005 run_test 80a "migrate directory when some children is being opened"
4006
4007 cleanup_80b() {
4008         trap 0
4009         kill -9 $migrate_pid
4010 }
4011
4012 test_80b() {
4013         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4014         local migrate_dir1=$DIR1/$tdir/migrate_dir
4015         local migrate_dir2=$DIR2/$tdir/migrate_dir
4016         local migrate_run=$LUSTRE/tests/migrate.sh
4017         local start_time
4018         local end_time
4019         local show_time=1
4020         local mdt_idx
4021         local rc=0
4022         local rc1=0
4023
4024         trap cleanup_80b EXIT
4025         #prepare migrate directory
4026         mkdir -p $migrate_dir1
4027         for F in {1,2,3,4,5}; do
4028                 echo "$F$F$F$F$F" > $migrate_dir1/file$F
4029                 echo "$F$F$F$F$F" > $DIR/$tdir/file$F
4030         done
4031
4032         #migrate the directories among MDTs
4033         (
4034                 while true; do
4035                         mdt_idx=$((RANDOM % MDSCOUNT))
4036                         $LFS migrate -m $mdt_idx $migrate_dir1 &>/dev/null ||
4037                                 rc=$?
4038                         [ $rc -ne 0 -o $rc -ne 16 ] || break
4039                 done
4040         ) &
4041         migrate_pid=$!
4042
4043         echo "start migration thread $migrate_pid"
4044         #Access the files at the same time
4045         start_time=$(date +%s)
4046         echo "accessing the migrating directory for 5 minutes..."
4047         while true; do
4048                 ls $migrate_dir2 > /dev/null || {
4049                         echo "read dir fails"
4050                         break
4051                 }
4052                 diff -u $DIR2/$tdir/file1 $migrate_dir2/file1 || {
4053                         echo "access file1 fails"
4054                         break
4055                 }
4056
4057                 cat $migrate_dir2/file2 > $migrate_dir2/file3 || {
4058                         echo "access file2/3 fails"
4059                         break
4060                 }
4061
4062                 echo "aaaaa" > $migrate_dir2/file4 > /dev/null || {
4063                         echo "access file4 fails"
4064                         break
4065                 }
4066
4067                 stat $migrate_dir2/file5 > /dev/null || {
4068                         echo "stat file5 fails"
4069                         break
4070                 }
4071
4072                 touch $migrate_dir2/source_file > /dev/null || rc1=$?
4073                 [ $rc1 -ne 0 -o $rc1 -ne 1 ] || {
4074                         echo "touch file failed with $rc1"
4075                         break;
4076                 }
4077
4078                 if [ -e $migrate_dir2/source_file ]; then
4079                         ln $migrate_dir2/source_file $migrate_dir2/link_file \
4080                                         &>/dev/null || rc1=$?
4081                         if [ -e $migrate_dir2/link_file ]; then
4082                                 rm -rf $migrate_dir2/link_file
4083                         fi
4084
4085                         mrename $migrate_dir2/source_file \
4086                                 $migrate_dir2/target_file &>/dev/null || rc1=$?
4087                         [ $rc1 -ne 0 -o $rc1 -ne 1 ] || {
4088                                 echo "rename failed with $rc1"
4089                                 break
4090                         }
4091
4092                         if [ -e $migrate_dir2/target_file ]; then
4093                                 rm -rf $migrate_dir2/target_file &>/dev/null ||
4094                                                                 rc1=$?
4095                         else
4096                                 rm -rf $migrate_dir2/source_file &>/dev/null ||
4097                                                                 rc1=$?
4098                         fi
4099                         [ $rc1 -ne 0 -o $rc1 -ne 1 ] || {
4100                                 echo "unlink failed with $rc1"
4101                                 break
4102                         }
4103                 fi
4104
4105                 end_time=$(date +%s)
4106                 duration=$((end_time - start_time))
4107                 if [ $((duration % 10)) -eq 0 ]; then
4108                         if [ $show_time -eq 1 ]; then
4109                                 echo "...$duration seconds"
4110                                 show_time=0
4111                         fi
4112                 else
4113                         show_time=1
4114                 fi
4115
4116                 kill -0 $migrate_pid || {
4117                         echo "migration stopped 1"
4118                         break
4119                 }
4120
4121                 [ $duration -ge 300 ] && break
4122         done
4123
4124         #check migration are still there
4125         kill -0 $migrate_pid || error "migration stopped 2"
4126         cleanup_80b
4127 }
4128 run_test 80b "Accessing directory during migration"
4129
4130 test_81a() {
4131         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4132
4133         rm -rf $DIR1/$tdir
4134
4135         mkdir -p $DIR1/$tdir
4136
4137         $LFS setdirstripe -i0 -c$MDSCOUNT  $DIR1/$tdir/d0
4138         $LFS setdirstripe -i0 -c$MDSCOUNT  $DIR1/$tdir/d1
4139
4140         cd $DIR1/$tdir
4141         touch d0/0      || error "create 0 failed"
4142         mv d0/0 d1/0    || error "rename d0/0 d1/0 failed"
4143         stat d0/0       && error "stat mv filed succeed"
4144         mv $DIR2/$tdir/d1/0 $DIR2/$tdir/d0/0 || error "rename d1/0 d0/0 failed"
4145         stat d0/0       || error "stat failed"
4146
4147         local t=$(ls -ai $DIR1/$tdir/d0 | sort -u | wc -l)
4148
4149         if [ $t -ne 3 ]; then
4150                 ls -ai $DIR1/$tdir/d0
4151                 error "expect 3 get $t"
4152         fi
4153
4154         return 0
4155 }
4156 run_test 81a "rename and stat under striped directory"
4157
4158 test_81b() {
4159         [ $MDSCOUNT -lt 2 ] &&
4160                 skip "We need at least 2 MDTs for this test"
4161
4162         local total
4163         local setattr_pid
4164
4165         total=1000
4166
4167         $LFS mkdir -c $MDSCOUNT $DIR1/$tdir || error "$LFS mkdir"
4168         createmany -o $DIR1/$tdir/$tfile. $total || error "createmany"
4169
4170         (
4171                 while true; do
4172                         touch $DIR1/$tdir
4173                 done
4174         ) &
4175         setattr_pid=$!
4176
4177         for i in $(seq $total); do
4178                 mrename $DIR2/$tdir/$tfile.$i $DIR2/$tdir/$tfile-new.$i \
4179                         > /dev/null
4180         done
4181
4182         kill -9 $setattr_pid
4183 }
4184 run_test 81b "rename under striped directory doesn't deadlock"
4185
4186 test_82() {
4187         [[ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.6.91) ]] ||
4188                 { skip "Need MDS version at least 2.6.92"; return 0; }
4189
4190         # Client 1 creates a file.
4191         multiop_bg_pause $DIR1/$tfile O_ac || error "multiop_bg_pause 1"
4192         pid1=$!
4193         # Client 2 opens the file.
4194         multiop_bg_pause $DIR2/$tfile o_Ac || error "multiop_bg_pause 2"
4195         pid2=$!
4196         # Client 1 makes the file an orphan.
4197         rm $DIR1/$tfile || error "rm"
4198         # Client 2 sets EA "user.multiop".
4199         kill -s USR1 $pid2
4200         wait $pid2 || error "multiop 2"
4201         # Client 1 gets EA "user.multiop".  This used to fail because the EA
4202         # cache refill would get "trusted.link" from mdd_xattr_list() but
4203         # -ENOENT when trying to get "trusted.link"'s value.  See also sanity
4204         # 102q.
4205         kill -s USR1 $pid1
4206         wait $pid1 || error "multiop 1"
4207 }
4208 run_test 82 "fsetxattr and fgetxattr on orphan files"
4209
4210 test_83() {
4211         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4212         local pid1
4213         local pid2
4214
4215         (
4216                 cd $DIR1
4217                 while true; do
4218                         $LFS mkdir -i1 -c2 $tdir
4219                         rmdir $tdir
4220                 done
4221         ) &
4222         pid1=$!
4223         echo "start pid $pid1 to create/unlink striped directory"
4224
4225         # Access the directory at the same time
4226         (
4227                 cd $DIR2
4228                 while true; do
4229                         stat $tdir > /dev/null 2>&1
4230                 done
4231         ) &
4232         pid2=$!
4233         echo "start pid $pid2 to stat striped directory"
4234
4235         sleep 120
4236         kill $pid1 $pid2
4237         wait $pid1 $pid2
4238
4239         return 0
4240 }
4241 run_test 83 "access striped directory while it is being created/unlinked"
4242
4243 test_84() {
4244         [ $MDS1_VERSION -lt $(version_code 2.12.55) ] &&
4245                 skip "lustre < 2.12.55 does not contain LU-12485 fix"
4246
4247         local mtime
4248
4249         $MULTIOP $DIR/$tfile oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:c ||
4250                 error "create $tfile failed"
4251         mtime=$(stat -c%Y $DIR/$tfile)
4252         mtime=$((mtime + 200))
4253
4254         #define OBD_FAIL_OBD_0NLINK_RACE  0x60b
4255         do_facet mds1 $LCTL set_param fail_loc=0x8000060b
4256
4257         touch -c -m $mtime $DIR/$tfile &
4258         setattr_pid=$!
4259         # sleep a while to let 'touch' run first
4260         sleep 5
4261         rm -f $DIR2/$tfile || error "unlink $tfile failed"
4262
4263         # touch may fail
4264         wait $setattr_pid || true
4265 }
4266 run_test 84 "0-nlink race in lu_object_find()"
4267
4268 test_90() {
4269         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4270         local pid1
4271         local pid2
4272         local duration=180
4273
4274         [ "$SLOW" = "yes" ] && duration=600
4275         # Open/Create under striped directory
4276         (
4277                 cd $DIR1
4278                 while true; do
4279                         $LFS mkdir -c$MDSCOUNT $tdir > /dev/null 2>&1
4280                         touch $tdir/f{0..3} > /dev/null 2>&1
4281                 done
4282         ) &
4283         pid1=$!
4284         echo "start pid $pid1 to open/create under striped directory"
4285
4286         # unlink the striped directory at the same time
4287         (
4288                 cd $DIR2
4289                 while true; do
4290                         rm -rf $tdir > /dev/null 2>&1
4291                 done
4292         ) &
4293         pid2=$!
4294         echo "start pid $pid2 to unlink striped directory"
4295
4296         sleep $duration
4297
4298         kill $pid1 $pid2
4299         wait $pid1 $pid2
4300
4301         return 0
4302 }
4303 run_test 90 "open/create and unlink striped directory"
4304
4305 test_91() {
4306         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4307         local pid1
4308         local pid2
4309         local duration=180
4310
4311         [ "$SLOW" = "yes" ] && duration=600
4312         # chmod striped directory
4313         (
4314                 cd $DIR1
4315                 while true; do
4316                         $LFS mkdir -c$MDSCOUNT $tdir > /dev/null 2>&1
4317                         chmod go+w $tdir > /dev/null 2>&1
4318                 done
4319         ) &
4320         pid1=$!
4321         echo "start pid $pid1 to chmod striped directory"
4322
4323         # unlink the striped directory at the same time
4324         (
4325                 cd $DIR2
4326                 while true; do
4327                         rm -rf $tdir > /dev/null 2>&1
4328                 done
4329         ) &
4330         pid2=$!
4331         echo "start pid $pid2 to unlink striped directory"
4332
4333         sleep $duration
4334
4335         kill $pid1 $pid2
4336         wait $pid1 $pid2
4337
4338         return 0
4339 }
4340 run_test 91 "chmod and unlink striped directory"
4341
4342 test_92() {
4343         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4344
4345         local fd=$(free_fd)
4346         local cmd="exec $fd<$DIR1/$tdir"
4347         $LFS setdirstripe -c$MDSCOUNT $DIR1/$tdir || error "mkdir $tdir fails"
4348         eval $cmd
4349         cmd="exec $fd<&-"
4350         trap "eval $cmd" EXIT
4351         cd $DIR1/$tdir || error "cd $DIR1/$tdir fails"
4352         rmdir ../$tdir || error "rmdir ../$tdir fails"
4353
4354         #define OBD_FAIL_LLITE_NO_CHECK_DEAD  0x1408
4355         $LCTL set_param fail_loc=0x1408
4356         mkdir $DIR2/$tdir/dir && error "create dir succeeds"
4357         $LFS setdirstripe -i1 $DIR2/$tdir/remote_dir &&
4358                 error "create remote dir succeeds"
4359         $LCTL set_param fail_loc=0
4360         eval $cmd
4361         return 0
4362 }
4363 run_test 92 "create remote directory under orphan directory"
4364
4365 test_93() {
4366         local rc1=0
4367         local rc2=0
4368         local old_rr
4369
4370         mkdir -p $DIR1/$tfile-1/
4371         mkdir -p $DIR2/$tfile-2/
4372         local old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
4373                 'lod.lustre-MDT*/qos_threshold_rr' | sed -e 's/%//')
4374         do_facet $SINGLEMDS lctl set_param -n \
4375                 'lod.lustre-MDT*/qos_threshold_rr' 100
4376         #define OBD_FAIL_MDS_LOV_CREATE_RACE     0x163
4377         do_facet $SINGLEMDS "lctl set_param fail_loc=0x00000163"
4378
4379         $SETSTRIPE -c -1 $DIR1/$tfile-1/file1 &
4380         local PID1=$!
4381         sleep 1
4382         $SETSTRIPE -c -1 $DIR2/$tfile-2/file2 &
4383         local PID2=$!
4384         wait $PID2
4385         wait $PID1
4386         do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
4387         do_facet $SINGLEMDS "lctl set_param -n \
4388                 'lod.lustre-MDT*/qos_threshold_rr' $old_rr"
4389
4390         $GETSTRIPE $DIR1/$tfile-1/file1
4391         rc1=$($GETSTRIPE -q $DIR1/$tfile-1/file1 |
4392                 awk '{if (/[0-9]/) print $1 }' | sort | uniq -d | wc -l)
4393         $GETSTRIPE $DIR2/$tfile-2/file2
4394         rc2=$($GETSTRIPE -q $DIR2/$tfile-2/file2 |
4395                 awk '{if (/[0-9]/) print $1 }' | sort | uniq -d | wc -l)
4396         echo "rc1=$rc1 and rc2=$rc2 "
4397         [ $rc1 -eq 0 ] && [ $rc2 -eq 0 ] ||
4398                 error "object allocate on same ost detected"
4399 }
4400 run_test 93 "alloc_rr should not allocate on same ost"
4401
4402 # Data-on-MDT tests
4403 test_100a() {
4404         skip "Reserved for glimpse-ahead" && return
4405         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4406                 skip "Need MDS version at least 2.10.55" && return
4407
4408         mkdir -p $DIR/$tdir
4409
4410         $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
4411
4412         lctl set_param -n mdc.*.stats=clear
4413         dd if=/dev/zero of=$DIR2/$tdir/dom bs=4096 count=1 || return 1
4414
4415         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #1"
4416         # first stat from server should return size data and save glimpse
4417         local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
4418         [ $gls -eq 0 ] || error "Unexpected $gls glimpse RPCs"
4419         # second stat to check size is NOT cached on client without IO lock
4420         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #2"
4421
4422         local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
4423         [ $gls -ge 1 ] || error "Expect glimpse RPCs but none"
4424         rm -f $dom
4425 }
4426 run_test 100a "DoM: glimpse RPCs for stat without IO lock (DoM only file)"
4427
4428 test_100b() {
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         cancel_lru_locks mdc
4439         # first stat data from server should have size
4440         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #1"
4441         # second stat to check size is cached on client
4442         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #2"
4443
4444         local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
4445         # both stats should cause no glimpse requests
4446         [ $gls == 0 ] || error "Unexpected $gls glimpse RPCs"
4447         rm -f $dom
4448 }
4449 run_test 100b "DoM: no glimpse RPC for stat with IO lock (DoM only file)"
4450
4451 test_100c() {
4452         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4453                 skip "Need MDS version at least 2.10.55" && return
4454
4455         mkdir -p $DIR/$tdir
4456
4457         $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
4458
4459         lctl set_param -n mdc.*.stats=clear
4460         lctl set_param -n osc.*.stats=clear
4461         dd if=/dev/zero of=$DIR2/$tdir/dom bs=2048K count=1 || return 1
4462
4463         # check that size is merged from MDT and OST correctly
4464         $CHECKSTAT -t file -s 2097152 $DIR/$tdir/dom ||
4465                 error "Wrong size from stat #1"
4466
4467         local gls=$(lctl get_param -n osc.*.stats | grep -c ldlm_glimpse)
4468         [ $gls -eq 0 ] && error "Expect OST glimpse RPCs but got none"
4469
4470         rm -f $dom
4471 }
4472 run_test 100c "DoM: write vs stat without IO lock (combined file)"
4473
4474 test_100d() {
4475         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4476                 skip "Need MDS version at least 2.10.55" && return
4477
4478         mkdir -p $DIR/$tdir
4479
4480         $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
4481
4482
4483         dd if=/dev/zero of=$DIR2/$tdir/dom bs=2048K count=1 || return 1
4484         lctl set_param -n mdc.*.stats=clear
4485         $TRUNCATE $DIR2/$tdir/dom 4096
4486
4487         # check that reported size is valid after file grows to OST and
4488         # is truncated back to MDT stripe size
4489         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom ||
4490                 error "Wrong size from stat #1"
4491
4492         local gls=$(lctl get_param -n osc.*.stats | grep -c ldlm_glimpse)
4493         [ $gls -eq 0 ] && error "Expect OST glimpse but got none"
4494
4495         rm -f $dom
4496 }
4497 run_test 100d "DoM: write+truncate vs stat without IO lock (combined file)"
4498
4499 test_101a() {
4500         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4501                 skip "Need MDS version at least 2.10.55" && return
4502
4503         $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
4504         # to get layout
4505         $CHECKSTAT -t file $DIR1/$tfile
4506
4507         local old_wb=$(sysctl -n vm.dirty_writeback_centisecs)
4508         sysctl -wq vm.dirty_writeback_centisecs=0
4509
4510         trap "sysctl -wq vm.dirty_writeback_centisecs=$old_wb" EXIT
4511
4512         # open + IO lock
4513         dd if=/dev/zero of=$DIR1/$tfile bs=4096 count=1 ||
4514                 error_noexit "Write fails"
4515         # must discard pages
4516         lctl set_param -n mdc.*.stats=clear
4517         rm $DIR2/$tfile || error "Unlink fails"
4518
4519         local writes=$(lctl get_param -n mdc.*.stats | grep -c ost_write)
4520         [ $writes -eq 0 ] || error "Found WRITE RPC but expect none"
4521 }
4522 run_test 101a "Discard DoM data on unlink"
4523
4524 test_101b() {
4525         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4526                 skip "Need MDS version at least 2.10.55" && return
4527
4528         $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
4529         touch $DIR1/${tfile}_2
4530         # to get layout
4531         $CHECKSTAT -t file $DIR1/$tfile
4532
4533         local old_wb=$(sysctl -n vm.dirty_writeback_centisecs)
4534         sysctl -wq vm.dirty_writeback_centisecs=0
4535
4536         trap "sysctl -wq vm.dirty_writeback_centisecs=$old_wb" EXIT
4537
4538         # open + IO lock
4539         dd if=/dev/zero of=$DIR1/$tfile bs=4096 count=1 || error "Write fails"
4540         # must discard pages
4541         lctl set_param -n mdc.*.stats=clear
4542         mv $DIR2/${tfile}_2 $DIR2/$tfile || error "Rename fails"
4543
4544         local writes=$(lctl get_param -n mdc.*.stats | grep -c ost_write)
4545         [ $writes -eq 0 ] || error "Found WRITE RPC but expect none"
4546 }
4547 run_test 101b "Discard DoM data on rename"
4548
4549 test_101c() {
4550         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
4551                 skip "Need MDS version at least 2.10.55" && return
4552
4553         $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
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         $MULTIOP $DIR1/$tfile O_c &
4565         MULTIOP_PID=$!
4566         sleep 1
4567         lctl set_param -n mdc.*.stats=clear
4568         rm $DIR2/$tfile > /dev/null || error "Unlink fails for opened file"
4569         kill -USR1 $MULTIOP_PID && wait $MULTIOP_PID || error "multiop failure"
4570
4571         local writes=$(lctl get_param -n mdc.*.stats | grep -c ost_write)
4572         [ $writes -eq 0 ] || error "Found WRITE RPC but expect none"
4573 }
4574 run_test 101c "Discard DoM data on close-unlink"
4575
4576 # test to verify file handle related system calls
4577 # (name_to_handle_at/open_by_handle_at)
4578 # The new system calls are supported in glibc >= 2.14.
4579
4580 # test to verify we can open by handle an unlinked file from > 1 client
4581 # This test opens the file normally on $DIR1, which is on one mount, and then
4582 # opens it by handle on $DIR2, which is on a different mount.
4583 test_102() {
4584         [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
4585                 skip "Needs MDS version 2.11.57 or later"
4586
4587         echo "Test file_handle syscalls" > $DIR/$tfile ||
4588                 error "write failed"
4589         check_fhandle_syscalls $DIR/$tfile $DIR2 ||
4590                 error "check_fhandle_syscalls failed"
4591         rm -f $DIR2/$tfile
4592 }
4593 run_test 102 "Test open by handle of unlinked file"
4594
4595 # Compare file size between first & second mount, ensuring the client correctly
4596 # glimpses even with unused speculative locks - LU-11670
4597 test_103() {
4598         [ $(lustre_version_code $ost1) -lt $(version_code 2.10.50) ] &&
4599                 skip "Lockahead needs OST version at least 2.10.50"
4600
4601         local testnum=23
4602
4603         test_mkdir -p $DIR/$tdir
4604
4605         # Force file on to OST0
4606         $LFS setstripe -i 0 $DIR/$tdir
4607
4608         # Do not check multiple locks on glimpse
4609         # OBD_FAIL_OSC_NO_SIZE_DATA 0x415
4610         $LCTL set_param fail_loc=0x415
4611
4612         # Delay write commit by 2 seconds to guarantee glimpse wins race
4613         # The same fail_loc is used on client & server so it can work in the
4614         # single node sanity setup
4615         do_facet ost1 $LCTL set_param fail_loc=0x415 fail_val=2
4616
4617         echo "Incorrect size expected (no glimpse fix):"
4618         lockahead_test -d $DIR/$tdir -D $DIR2/$tdir -t $testnum -f $tfile
4619         rc=$?
4620         if [ $rc -eq 0 ]; then
4621                 echo "This doesn't work 100%, but this is just reproducing the bug, not testing the fix, so OK to not fail test."
4622         fi
4623
4624         # guarantee write commit timeout has expired
4625         sleep 2
4626
4627         # Clear fail_loc on client
4628         $LCTL set_param fail_loc=0
4629
4630         # Delay write commit by 2 seconds to guarantee glimpse wins race
4631         # OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
4632         do_facet ost1 $LCTL set_param fail_loc=0x214 fail_val=2
4633
4634         # Write commit is still delayed by 2 seconds
4635         lockahead_test -d $DIR/$tdir -D $DIR2/$tdir -t $testnum -f $tfile
4636         rc=$?
4637         [ $rc -eq 0 ] || error "Lockahead test${testnum} failed, ${rc}"
4638
4639         # guarantee write commit timeout has expired
4640         sleep 2
4641
4642         rm -f $DIR/$tfile || error "unable to delete $DIR/$tfile"
4643 }
4644 run_test 103 "Test size correctness with lockahead"
4645
4646 get_stat_xtimes()
4647 {
4648         local xtimes
4649
4650         xtimes=$(stat -c "%X %Y %Z" $DIR/$tfile)
4651
4652         echo ${xtimes[*]}
4653 }
4654
4655 get_mdt_xtimes()
4656 {
4657         local mdtdev=$1
4658         local output
4659         local xtimes
4660
4661         output=$(do_facet mds1 "$DEBUGFS -c -R 'stat ROOT/$tfile' $mdtdev")
4662         ((xtimes[0]=$(awk -F ':' /atime/'{ print $2 }' <<< "$output")))
4663         ((xtimes[1]=$(awk -F ':' /mtime/'{ print $2 }' <<< "$output")))
4664         ((xtimes[2]=$(awk -F ':' /ctime/'{ print $2 }' <<< "$output")))
4665
4666         echo ${xtimes[*]}
4667 }
4668
4669 check_mdt_xtimes()
4670 {
4671         local mdtdev=$1
4672         local xtimes=($(get_stat_xtimes))
4673         local mdt_xtimes=($(get_mdt_xtimes $mdtdev))
4674
4675         echo "STAT a|m|ctime ${xtimes[*]}"
4676         echo "MDT a|m|ctime ${xtimes[*]}"
4677         [[ ${xtimes[0]} == ${mdt_xtimes[0]} ]] ||
4678                 error "$DIR/$tfile atime (${xtimes[0]}:${mdt_xtimes[0]}) diff"
4679         [[ ${xtimes[1]} == ${mdt_xtimes[1]} ]] ||
4680                 error "$DIR/$tfile mtime (${xtimes[1]}:${mdt_xtimes[1]}) diff"
4681         [[ ${xtimes[2]} == ${mdt_xtimes[2]} ]] ||
4682                 error "$DIR/$tfile ctime (${xtimes[2]}:${mdt_xtimes[2]}) diff"
4683 }
4684
4685 test_104() {
4686         [ "$mds1_FSTYPE" == "ldiskfs" ] || skip_env "ldiskfs only test"
4687
4688         local pid
4689         local mdtdev=$(mdsdevname ${SINGLEMDS//mds/})
4690         local atime_diff=$(do_facet $SINGLEMDS \
4691                 lctl get_param -n mdd.*MDT0000*.atime_diff)
4692
4693         do_facet $SINGLEMDS \
4694                 lctl set_param -n mdd.*MDT0000*.atime_diff=0
4695
4696         stack_trap "do_facet $SINGLEMDS \
4697                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff" EXIT
4698
4699         dd if=/dev/zero of=$DIR/$tfile bs=1k count=1 conv=notrunc
4700         check_mdt_xtimes $mdtdev
4701         sleep 2
4702
4703         dd if=/dev/zero of=$DIR/$tfile bs=1k count=1 conv=notrunc
4704         check_mdt_xtimes $mdtdev
4705         sleep 2
4706         $MULTIOP $DIR2/$tfile Oz8192w8192_c &
4707         pid=$!
4708         sleep 2
4709         dd if=/dev/zero of=$DIR/$tfile bs=1k count=1 conv=notrunc
4710         sleep 2
4711         kill -USR1 $pid && wait $pid || error "multiop failure"
4712         check_mdt_xtimes $mdtdev
4713
4714         local xtimes
4715         local mdt_xtimes
4716
4717         # Verify mtime/ctime is NOT upated on MDS when there is no modification
4718         # on the client side
4719         xtimes=($(get_stat_xtimes))
4720         $MULTIOP $DIR/$tfile O_c &
4721         pid=$!
4722         sleep 2
4723         kill -USR1 $pid && wait $pid || error "multiop failure"
4724         mdt_xtimes=($(get_mdt_xtimes $mdtdev))
4725         [[ ${xtimes[1]} == ${mdt_xtimes[1]} ]] ||
4726                 error "$DIR/$tfile mtime (${xtimes[1]}:${mdt_xtimes[1]}) diff"
4727         [[ ${xtimes[2]} == ${mdt_xtimes[2]} ]] ||
4728                 error "$DIR/$tfile ctime (${xtimes[2]}:${mdt_xtimes[2]}) diff"
4729         check_mdt_xtimes $mdtdev
4730
4731         sleep 2
4732         # Change ctime via chmod
4733         $MULTIOP $DIR/$tfile o_tc &
4734         pid=$!
4735         sleep 2
4736         kill -USR1 $pid && wait $pid || error "multiop failure"
4737         check_mdt_xtimes $mdtdev
4738 }
4739 run_test 104 "Verify that MDS stores atime/mtime/ctime during close"
4740
4741 log "cleanup: ======================================================"
4742
4743 # kill and wait in each test only guarentee script finish, but command in script
4744 # like 'rm' 'chmod' may still be running, wait for all commands to finish
4745 # otherwise umount below will fail
4746 [ "$(mount | grep $MOUNT2)" ] && wait_update $HOSTNAME "fuser -m $MOUNT2" "" ||
4747         true
4748
4749 complete $SECONDS
4750 rm -f $SAMPLE_FILE
4751 check_and_cleanup_lustre
4752 exit_status