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