Whamcloud - gitweb
a520b27746973d4957f48221a325c931512f54b9
[fs/lustre-release.git] / lustre / tests / sanityn.sh
1 #!/bin/bash
2
3 set -e
4
5 ONLY=${ONLY:-"$*"}
6
7 SIZE=${SIZE:-40960}
8 OPENFILE=${OPENFILE:-openfile}
9 OPENUNLINK=${OPENUNLINK:-openunlink}
10 export TMP=${TMP:-/tmp}
11 MOUNT_2=${MOUNT_2:-"yes"}
12 CHECK_GRANT=${CHECK_GRANT:-"yes"}
13 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
14
15 LUSTRE=${LUSTRE:-$(dirname $0)/..}
16 . $LUSTRE/tests/test-framework.sh
17 init_test_env $@
18 init_logging
19
20 ALWAYS_EXCEPT="$SANITYN_EXCEPT "
21 # bug number for skipped test:  LU-7105
22 ALWAYS_EXCEPT+="                28 "
23 # bug number for skipped test:  LU-14541
24 ALWAYS_EXCEPT+="                16f"
25 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
26
27 # skip tests for PPC until they are fixed
28 if [[ $(uname -m) = ppc64 ]]; then
29         # bug number:    LU-11787
30         ALWAYS_EXCEPT+=" 71a"
31 fi
32
33 if [ $mds1_FSTYPE = "zfs" ]; then
34         # bug number:    LU-15757 (test_102() causes crash in umount later)
35         ALWAYS_EXCEPT+=" 102"
36         # LU-2829 / LU-2887 - make allowances for ZFS slowness
37         TEST33_NFILES=${TEST33_NFILES:-1000}
38 fi
39
40 #                                  23   (min)"
41 [ "$SLOW" = "no" ] && EXCEPT_SLOW="33a"
42
43 build_test_filter
44
45 FAIL_ON_ERROR=false
46
47 SETUP=${SETUP:-:}
48 TRACE=${TRACE:-""}
49
50 check_and_setup_lustre
51
52 OSC=${OSC:-"osc"}
53
54 assert_DIR
55 rm -rf $DIR1/[df][0-9]* $DIR1/lnk $DIR/[df].${TESTSUITE}*
56
57 SAMPLE_FILE=$TMP/$(basename $0 .sh).junk
58 dd if=/dev/urandom of=$SAMPLE_FILE bs=1M count=1
59
60 # $RUNAS_ID may get set incorrectly somewhere else
61 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
62
63 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
64
65 test_1() {
66         touch $DIR1/$tfile
67         [ -f $DIR2/$tfile ] || error "Check create"
68         chmod 777 $DIR2/$tfile
69         $CHECKSTAT -t file -p 0777 $DIR1/$tfile ||
70                 error "Check attribute update for 0777"
71
72         chmod a-x $DIR2/$tfile
73         $CHECKSTAT -t file -p 0666 $DIR1/$tfile ||
74                 error "Check attribute update for 0666"
75
76         rm $DIR2/$tfile
77         $CHECKSTAT -a $DIR1/$tfile ||
78                 error "Check unlink - removes file on other mountpoint"
79 }
80 run_test 1 "Check attribute updates on 2 mount points"
81
82 test_2a() {
83         touch $DIR1/f2a
84         ls -l $DIR2/f2a
85         chmod 777 $DIR2/f2a
86         $CHECKSTAT -t file -p 0777 $DIR1/f2a ||
87                 error "Either not file type or perms not 0777"
88 }
89 run_test 2a "check cached attribute updates on 2 mtpt's ========"
90
91 test_2b() {
92         touch $DIR1/f2b
93         ls -l $DIR2/f2b
94         chmod 777 $DIR1/f2b
95         $CHECKSTAT -t file -p 0777 $DIR2/f2b ||
96                 error "Either not file type or perms not 0777"
97 }
98 run_test 2b "check cached attribute updates on 2 mtpt's ========"
99
100 # NEED TO SAVE ROOT DIR MODE
101 test_2c() {
102         chmod 777 $DIR1
103         $CHECKSTAT -t dir -p 0777 $DIR2 ||
104                 error "Either not dir type or perms not 0777"
105 }
106 run_test 2c "check cached attribute updates on 2 mtpt's root ==="
107
108 test_2d() {
109         chmod 755 $DIR1
110         $CHECKSTAT -t dir -p 0755 $DIR2 ||
111                 error "Either not file type or perms not 0775"
112 }
113 run_test 2d "check cached attribute updates on 2 mtpt's root ==="
114
115 test_2e() {
116         chmod 755 $DIR1
117         ls -l $DIR1
118         ls -l $DIR2
119         chmod 777 $DIR1
120                 $RUNAS dd if=/dev/zero of=$DIR2/$tfile count=1 ||
121                         error "dd failed"
122 }
123 run_test 2e "check chmod on root is propagated to others"
124
125 test_2f() {
126         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
127         local MDTIDX=1
128         local remote_dir=$tdir/remote_dir
129
130         mkdir -p $DIR1/$tdir
131         $LFS mkdir -i $MDTIDX $DIR1/$remote_dir ||
132                    error "Create remote directory failed"
133
134         touch $DIR1/$remote_dir/$tfile ||
135                 error "Create file under remote directory failed"
136         chmod 777 $DIR1/$remote_dir/$tfile ||
137                 error "Chmod file under remote directory failed"
138
139         $CHECKSTAT -t file -p 0777 $DIR2/$remote_dir/$tfile ||
140                 error "Check attr of file under remote directory failed"
141
142         chown $RUNAS_ID:$RUNAS_GID $DIR1/$remote_dir/$tfile ||
143                 error "Chown file under remote directory failed"
144
145         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR2/$remote_dir/$tfile ||
146                 error "Check owner of file under remote directory failed"
147
148         cd $DIR2/$remote_dir || error "enter remote dir"
149         rm -rf $DIR1/$remote_dir/$tfile ||
150                 error "Unlink remote directory failed"
151
152         $CHECKSTAT -t file $DIR2/$remote_dir/$tfile &&
153                 error "unlink file still exists!"
154
155         cd $DIR2/$tdir || error "exit remote dir"
156         rm -rf $DIR1/$tdir || error "unlink directory failed"
157 }
158 run_test 2f "check attr/owner updates on DNE with 2 mtpt's"
159
160 test_2g() {
161         dd if=/dev/zero of=$DIR1/$tfile oflag=sync bs=1M count=2
162
163         local block1=$(stat $DIR1/$tfile | awk '/Blocks/ {print $4} ')
164         cancel_lru_locks osc
165         local block2=$(stat $DIR2/$tfile | awk '/Blocks/ {print $4} ')
166         echo "$DIR1/$tfile has $block1 blocks"
167         echo "$DIR2/$tfile has $block2 blocks"
168         [ $block1 -eq $block2 ] || error "$block1 not equal to $block2"
169 }
170 run_test 2g "check blocks update on sync write"
171
172 test_3() {
173         local target="this/is/good"
174         ln -s $target $DIR1/$tfile || error "ln -s $target $DIR1/$tfile failed"
175         [ "$(ls -l $DIR2/$tfile | sed -e 's/.* -> //')" = "$target" ] ||
176                 error "link $DIR2/$tfile not as expected"
177 }
178 run_test 3 "symlink on one mtpt, readlink on another ==========="
179
180 test_4() {
181         multifstat $DIR1/f4 $DIR2/f4
182 }
183 run_test 4 "fstat validation on multiple mount points =========="
184
185 test_5() {
186         mcreate $DIR1/f5
187         $TRUNCATE $DIR2/f5 100
188         $CHECKSTAT -t file -s 100 $DIR1/f5 ||
189                 error "Either not file type or size not equal to 100 bytes"
190         rm $DIR1/f5
191 }
192 run_test 5 "create a file on one mount, truncate it on the other"
193
194 test_6() {
195         openunlink $DIR1/$tfile $DIR2/$tfile || \
196                 error "openunlink $DIR1/$tfile $DIR2/$tfile"
197 }
198 run_test 6 "remove of open file on other node =================="
199
200 test_7() {
201         local dir=d7
202         opendirunlink $DIR1/$dir $DIR2/$dir || \
203                 error "opendirunlink $DIR1/$dir $DIR2/$dir"
204 }
205 run_test 7 "remove of open directory on other node ============="
206
207 test_8() {
208         opendevunlink $DIR1/$tfile $DIR2/$tfile || \
209                 error "opendevunlink $DIR1/$tfile $DIR2/$tfile"
210 }
211 run_test 8 "remove of open special file on other node =========="
212
213 test_9a() {
214         MTPT=1
215         local dir
216         > $DIR2/f9
217         for C in a b c d e f g h i j k l; do
218                 dir=`eval echo \\$DIR$MTPT`
219                 echo -n $C >> $dir/f9
220                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
221         done
222         [ "`cat $DIR1/f9`" = "abcdefghijkl" ] || \
223                 error "`od -a $DIR1/f9` != abcdefghijkl"
224 }
225 run_test 9a "append of file with sub-page size on multiple mounts"
226
227 #LU-10681 - tiny writes & appending to sparse striped file
228 test_9b() {
229         [[ $OSTCOUNT -ge 2 ]] || { skip "needs >= 2 OSTs"; return; }
230
231         $LFS setstripe -c 2 -S 1M $DIR/$tfile
232         echo "foo" >> $DIR/$tfile
233         dd if=/dev/zero of=$DIR2/$tfile bs=1M count=1 seek=1 conv=notrunc ||
234                 error "sparse dd $DIR2/$tfile failed"
235         echo "foo" >> $DIR/$tfile
236
237         data=$(dd if=$DIR2/$tfile bs=1 count=3 skip=$((2 * 1048576)) conv=notrunc)
238         echo "Data read (expecting 'foo')": $data
239         [ "$data" = "foo" ] || error "append to sparse striped file failed"
240 }
241 run_test 9b "append to striped sparse file"
242
243 test_10a() {
244         MTPT=1
245         local dir
246         OFFSET=0
247         > $DIR2/f10
248         for C in a b c d e f g h i j k l; do
249                 dir=`eval echo \\$DIR$MTPT`
250                 echo -n $C | dd of=$dir/f10 bs=1 seek=$OFFSET count=1
251                 [ "$MTPT" -eq 1 ] && MTPT=2 || MTPT=1
252                 OFFSET=`expr $OFFSET + 1`
253         done
254         [ "`cat $DIR1/f10`" = "abcdefghijkl" ] || \
255                 error "`od -a $DIR1/f10` != abcdefghijkl"
256 }
257 run_test 10a "write of file with sub-page size on multiple mounts "
258
259 test_10b() {
260         # create a seed file
261         yes "R" | head -c 4000 >$TMP/f10b-seed
262         dd if=$TMP/f10b-seed of=$DIR1/f10b bs=3k count=1 || error "dd $DIR1"
263
264         $TRUNCATE $DIR1/f10b 4096 || error "truncate 4096"
265
266         dd if=$DIR2/f10b of=$TMP/f10b-lustre bs=4k count=1 || error "dd $DIR2"
267
268         # create a test file locally to compare
269         dd if=$TMP/f10b-seed of=$TMP/f10b bs=3k count=1 || error "dd random"
270         $TRUNCATE $TMP/f10b 4096 || error "truncate 4096"
271         cmp $TMP/f10b $TMP/f10b-lustre || error "file miscompare"
272         rm $TMP/f10b $TMP/f10b-lustre $TMP/f10b-seed
273 }
274 run_test 10b "write of file with sub-page size on multiple mounts "
275
276 test_11() {
277         test_mkdir $DIR1/d11
278         multiop_bg_pause $DIR1/d11/f O_c || return 1
279         MULTIPID=$!
280         cp -p /bin/ls $DIR1/d11/f
281         $DIR2/d11/f
282         RC=$?
283         kill -USR1 $MULTIPID
284         wait $MULTIPID || error "wait for PID $MULTIPID failed"
285         [ $RC -eq 0 ] && error || true
286 }
287 run_test 11 "execution of file opened for write should return error ===="
288
289 test_12() {
290         DIR=$DIR DIR2=$DIR2 bash lockorder.sh
291 }
292 run_test 12 "test lock ordering (link, stat, unlink)"
293
294 test_13() {     # bug 2451 - directory coherency
295         test_mkdir $DIR1/d13
296         cd $DIR1/d13 || error "cd to $DIR1/d13 failed"
297         ls
298         ( touch $DIR1/d13/f13 ) # needs to be a separate shell
299         ls
300         rm -f $DIR2/d13/f13 || error "Cannot remove $DIR2/d13/f13"
301         ls 2>&1 | grep f13 && error "f13 shouldn't return an error (1)" || true
302         # need to run it twice
303         ( touch $DIR1/d13/f13 ) # needs to be a separate shell
304         ls
305         rm -f $DIR2/d13/f13 || error "Cannot remove $DIR2/d13/f13"
306         ls 2>&1 | grep f13 && error "f13 shouldn't return an error (2)" || true
307 }
308 run_test 13 "test directory page revocation"
309
310 test_14aa() {
311         test_mkdir $DIR1/$tdir
312         cp -p /bin/ls $DIR1/$tdir/$tfile
313         multiop_bg_pause $DIR1/$tdir/$tfile Ow_c || return 1
314         MULTIPID=$!
315
316         $DIR2/$tdir/$tfile && error || true
317         kill $MULTIPID
318 }
319 run_test 14aa "execution of file open for write returns -ETXTBSY"
320
321 test_14ab() {
322         test_mkdir $DIR1/$tdir
323         cp -p $(which sleep) $DIR1/$tdir/sleep || error "cp failed"
324         $DIR1/$tdir/sleep 60 &
325         SLEEP_PID=$!
326         $MULTIOP $DIR2/$tdir/sleep Oc && error "expected error, got success"
327         kill $SLEEP_PID
328 }
329 run_test 14ab "open(RDWR) of executing file returns -ETXTBSY"
330
331 test_14b() { # bug 3192, 7040
332         test_mkdir $DIR1/$tdir
333         cp -p $(which sleep) $DIR1/$tdir/sleep || error "cp failed"
334         $DIR1/$tdir/sleep 60 &
335         SLEEP_PID=$!
336         $TRUNCATE $DIR2/$tdir/sleep 60 && kill -9 $SLEEP_PID && \
337                 error "expected truncate error, got success"
338         kill $SLEEP_PID
339         cmp $(which sleep) $DIR1/$tdir/sleep || error "binary changed"
340 }
341 run_test 14b "truncate of executing file returns -ETXTBSY ======"
342
343 test_14c() { # bug 3430, 7040
344         test_mkdir $DIR1/$tdir
345         cp -p $(which sleep) $DIR1/$tdir/sleep || error "cp failed"
346         $DIR1/$tdir/sleep 60 &
347         SLEEP_PID=$!
348         cp /etc/hosts $DIR2/$tdir/sleep && error "expected error, got success"
349         kill $SLEEP_PID
350         cmp $(which sleep) $DIR1/$tdir/sleep || error "binary changed"
351 }
352 run_test 14c "open(O_TRUNC) of executing file return -ETXTBSY =="
353
354 test_14d() { # bug 10921
355         test_mkdir $DIR1/$tdir
356         cp -p $(which sleep) $DIR1/$tdir/sleep || error "cp failed"
357         $DIR1/$tdir/sleep 60 &
358         SLEEP_PID=$!
359         log chmod
360         chmod 600 $DIR1/$tdir/sleep || error "chmod failed"
361         kill $SLEEP_PID
362         cmp $(which sleep) $DIR1/$tdir/sleep || error "binary changed"
363 }
364 run_test 14d "chmod of executing file is still possible ========"
365
366 test_15() {     # bug 974 - ENOSPC
367         echo "PATH=$PATH"
368         bash oos2.sh $MOUNT1 $MOUNT2
369         wait_delete_completed
370         grant_error=$(dmesg | grep "< tot_grant")
371         [ -z "$grant_error" ] || error "$grant_error"
372 }
373 run_test 15 "test out-of-space with multiple writers ==========="
374
375 COUNT=${COUNT:-2500}
376 # The FSXNUM reduction for ZFS is needed until ORI-487 is fixed.
377 # We don't want to skip it entirely, but ZFS is VERY slow and cannot
378 # pass a 2500 operation dual-mount run within the time limit.
379 if [ "$ost1_FSTYPE" = "zfs" ]; then
380         FSXNUM=$((COUNT / 5))
381         FSXP=1
382 elif [ "$SLOW" = "yes" ]; then
383         FSXNUM=$((COUNT * 5))
384         FSXP=500
385 else
386         FSXNUM=$COUNT
387         FSXP=100
388 fi
389
390 test_16a() {
391         local file1=$DIR1/$tfile
392         local file2=$DIR2/$tfile
393         local stripe_size=$(do_facet $SINGLEMDS \
394                 "$LCTL get_param -n lod.$(facet_svc $SINGLEMDS)*.stripesize")
395
396         check_set_fallocate
397
398         # to allocate grant because it may run out due to test_15.
399         $LFS setstripe -c -1 $file1
400         dd if=/dev/zero of=$file1 bs=$stripe_size count=$OSTCOUNT oflag=sync
401         dd if=/dev/zero of=$file2 bs=$stripe_size count=$OSTCOUNT oflag=sync
402         rm -f $file1
403
404         $LFS setstripe -c -1 $file1 # b=10919
405         $FSX -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -S 0 $file1 $file2 ||
406                 error "fsx failed"
407         rm -f $file1
408
409         # O_DIRECT reads and writes must be aligned to the PAGE_SIZE.
410         $FSX -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -S 0 -Z -r $PAGE_SIZE \
411                 -w $PAGE_SIZE $file1 $file2 || error "fsx with O_DIRECT failed."
412 }
413 run_test 16a "$FSXNUM iterations of dual-mount fsx"
414
415 # Consistency check for tiny writes, LU-9409
416 test_16b() {
417         local file1=$DIR1/$tfile
418         local file2=$DIR2/$tfile
419         local stripe_size=($($LFS getstripe -S $DIR))
420
421         check_set_fallocate
422
423         # to allocate grant because it may run out due to test_15.
424         lfs setstripe -c -1 $file1
425         dd if=/dev/zero of=$file1 bs=$stripe_size count=$OSTCOUNT oflag=sync ||
426                 error "dd failed writing to file=$file1"
427         dd if=/dev/zero of=$file2 bs=$stripe_size count=$OSTCOUNT oflag=sync ||
428                 error "dd failed writing to file=$file2"
429         rm -f $file1
430
431         lfs setstripe -c -1 $file1 # b=10919
432         # -o is set to 8192 because writes < 1 page and between 1 and 2 pages
433         # create a mix of tiny writes & normal writes
434         $FSX -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -o 8192 -S 0 \
435                 $file1 $file2 || error "fsx with tiny write failed."
436 }
437 run_test 16b "$FSXNUM iterations of dual-mount fsx at small size"
438
439 test_16c() {
440         local file1=$DIR1/$tfile
441         local file2=$DIR2/$tfile
442         local stripe_size=$(do_facet $SINGLEMDS \
443                 "$LCTL get_param -n lod.$(facet_svc $SINGLEMDS)*.stripesize")
444
445         [ "$ost1_FSTYPE" != ldiskfs ] && skip "dio on ldiskfs only"
446
447         check_set_fallocate
448
449         # to allocate grant because it may run out due to test_15.
450         $LFS setstripe -c -1 $file1
451         dd if=/dev/zero of=$file1 bs=$stripe_size count=$OSTCOUNT oflag=sync
452         dd if=/dev/zero of=$file2 bs=$stripe_size count=$OSTCOUNT oflag=sync
453         rm -f $file1
454         wait_delete_completed
455
456         local list=$(comma_list $(osts_nodes))
457         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
458                 skip "not cache-capable obdfilter"
459         fi
460
461         set_osd_param $list '' read_cache_enable 0
462         set_osd_param $list '' writethrough_cache_enable 0
463
464         $LFS setstripe -c -1 $file1 # b=10919
465         $FSX -c 50 -p $FSXP -N $FSXNUM -l $((SIZE * 256)) -S 0 $file1 $file2 ||
466                 error "fsx failed"
467         rm -f $file1
468
469         set_osd_param $list '' read_cache_enable 1
470         set_osd_param $list '' writethrough_cache_enable 1
471
472         return 0
473 }
474 run_test 16c "verify data consistency on ldiskfs with cache disabled (b=17397)"
475
476 test_16d() {
477         local file1=$DIR1/$tfile
478         local file2=$DIR2/$tfile
479         local file3=$DIR1/file
480         local tmpfile=$(mktemp)
481         local stripe_size=$(do_facet $SINGLEMDS \
482                 "$LCTL get_param -n lod.$(facet_svc $SINGLEMDS)*.stripesize")
483
484         # to allocate grant because it may run out due to test_15.
485         $LFS setstripe -c -1 $file1
486         stack_trap "rm -f $file1 $file2 $file3 $tmpfile"
487         dd if=/dev/zero of=$file1 bs=$stripe_size count=$OSTCOUNT oflag=sync
488         dd if=/dev/zero of=$file2 bs=$stripe_size count=$OSTCOUNT oflag=sync
489         rm -f $file1
490
491         $LFS setstripe -c -1 $file1 # b=10919
492         $LCTL set_param ldlm.namespaces.*.lru_size=clear
493         
494         # direct write on one client and direct read from another
495         dd if=/dev/urandom of=$file1 bs=1M count=100 oflag=direct
496         dd if=$file2 of=$tmpfile iflag=direct bs=1M
497         diff $file1 $tmpfile || error "file different(1)"
498         rm -f $file1
499
500         # buffer write on one client, but direct read from another
501         dd if=$tmpfile of=$file1 bs=1M count=100
502         dd if=$file2 of=$file3 bs=1M iflag=direct count=100
503         diff $file3 $tmpfile || error "file different(2)"
504
505         rm -f $file3 $file2 $file1
506         # direct write on one client
507         dd if=$tmpfile of=$file1 bs=1M count=100 oflag=direct
508         # buffer read from another client
509         dd if=$file2 of=$file3 bs=1M count=100
510         diff $file3 $tmpfile || error "file different(3)"
511 }
512 run_test 16d "Verify DIO and buffer IO with two clients"
513
514 test_16e() { # LU-13227
515         # issue:        LU-14314
516
517         (( "$MDS1_VERSION" >= $(version_code 2.13.53) )) ||
518                 skip "Need MDS version at least 2.13.53"
519
520         local file1=$DIR1/$tfile
521         local file2=$DIR2/$tfile
522
523         # client1 write 10M data
524         dd if=/dev/zero of=$file1 bs=1M count=10
525         # drop locks
526         cancel_lru_locks osc > /dev/null
527         # use lockahead to generate one PW lock to keep LVB loaded.
528         $LFS ladvise -a lockahead --start 0 --length 1M \
529                 --mode WRITE $file1
530         # direct write to extend file size on client2
531         dd if=/dev/zero of=$file2 bs=1M seek=20 count=1 \
532                 oflag=direct conv=notrunc
533         local filesize=$(stat -c %s $file2)
534         [ "$filesize" -eq 22020096 ] ||
535                 error "expected filesize 22020096 got $filesize"
536         rm -f $file1
537 }
538 run_test 16e "Verify size consistency for O_DIRECT write"
539
540 test_16f() { # LU-14541
541         local file1=$DIR1/$tfile
542         local file2=$DIR2/$tfile
543         local duration=20
544         local status
545
546         timeout --preserve-status --signal=USR1 $duration \
547                 rw_seq_cst_vs_drop_caches $file1 $file2
548         status=$?
549
550         case $((status & 0x7f)) in
551                 0)
552                         echo OK # Computers must be fast now.
553                         ;;
554                 6) # SIGABRT
555                         error "sequential consistency violation detected"
556                         ;;
557                 10) # SIGUSR1
558                         echo TIMEOUT # This is fine.
559                         ;;
560                 *)
561                         error "strange status '$status'"
562                         ;;
563         esac
564
565         rm -f $file1
566 }
567 run_test 16f "rw sequential consistency vs drop_caches"
568
569 test_17() { # bug 3513, 3667
570         remote_ost_nodsh && skip "remote OST with nodsh" && return
571
572         lfs setstripe $DIR1/$tfile -i 0 -c 1
573         cp $SAMPLE_FILE $DIR1/$tfile
574         cancel_lru_locks osc > /dev/null
575         #define OBD_FAIL_ONCE|OBD_FAIL_LDLM_CREATE_RESOURCE    0x30a
576         do_facet ost1 lctl set_param fail_loc=0x8000030a
577         ls -ls $DIR1/$tfile | awk '{ print $1,$6 }' > $DIR1/$tfile-1 & \
578         ls -ls $DIR2/$tfile | awk '{ print $1,$6 }' > $DIR2/$tfile-2
579         wait
580         diff -u $DIR1/$tfile-1 $DIR2/$tfile-2 || error "files are different"
581 }
582 run_test 17 "resource creation/LVB creation race ==============="
583
584 test_18() {
585         # turn e.g. ALWAYS_EXCEPT="18c" into "-e 3"
586         local idx
587         local excepts=
588         for idx in {a..z}; do
589                 local ptr=EXCEPT_ALWAYS_18$idx
590                 [ x${!ptr} = xtrue ] || continue
591
592                 excepts="$excepts -e $(($(printf %d \'$idx)-96))"
593         done
594
595         excepts="$excepts -e 7 -e 8 -e 9"
596         $LUSTRE/tests/mmap_sanity -d $MOUNT1 -m $MOUNT2 $excepts ||
597                 error "mmap_sanity test failed"
598         sync; sleep 1; sync
599 }
600 run_test 18 "mmap sanity check ================================="
601
602 test_19() { # bug3811
603         local node=$(facet_active_host ost1)
604         local device="$FSNAME-OST*"
605
606         [ "x$DOM" = "xyes" ] && node=$(facet_active_host $SINGLEMDS) &&
607                 device="$FSNAME-MDT*"
608
609         # check whether obdfilter is cache capable at all
610         get_osd_param $node $device read_cache_enable >/dev/null ||
611                 skip "not cache-capable obdfilter"
612
613         local max=$(get_osd_param $node $device readcache_max_filesize |\
614                 head -n 1)
615         set_osd_param $node $device readcache_max_filesize 4096
616         dd if=/dev/urandom of=$TMP/$tfile bs=512k count=32
617         local SUM=$(cksum $TMP/$tfile | cut -d" " -f 1,2)
618         cp $TMP/$tfile $DIR1/$tfile
619         for i in `seq 1 20`; do
620                 [ $((i % 5)) -eq 0 ] && log "$testname loop $i"
621                 cancel_lru_locks $OSC > /dev/null
622                 cksum $DIR1/$tfile | cut -d" " -f 1,2 > $TMP/sum1 & \
623                 cksum $DIR2/$tfile | cut -d" " -f 1,2 > $TMP/sum2
624                 wait
625                 [ "$(cat $TMP/sum1)" = "$SUM" ] || \
626                         error "$DIR1/$tfile $(cat $TMP/sum1) != $SUM"
627                 [ "$(cat $TMP/sum2)" = "$SUM" ] || \
628                         error "$DIR2/$tfile $(cat $TMP/sum2) != $SUM"
629         done
630         set_osd_param $node $device readcache_max_filesize $max
631         rm $DIR1/$tfile
632 }
633 run_test 19 "test concurrent uncached read races ==============="
634
635 test_20() {
636         test_mkdir $DIR1/$tdir
637         cancel_lru_locks
638         CNT=$($LCTL get_param -n llite.*.dump_page_cache | wc -l)
639         $MULTIOP $DIR1/$tdir/$tfile Ow8190c
640         $MULTIOP $DIR2/$tdir/$tfile Oz8194w8190c
641         $MULTIOP $DIR1/$tdir/$tfile Oz0r8190c
642         cancel_lru_locks
643         CNT2=$($LCTL get_param -n llite.*.dump_page_cache | wc -l)
644         [[ $CNT2 == $CNT ]] ||
645                 error $((CNT2 - CNT))" page left in cache after lock cancel"
646 }
647 run_test 20 "test extra readahead page left in cache ===="
648
649 cleanup_21() {
650         trap 0
651         umount $DIR1/$tdir
652 }
653
654 test_21() { # Bug 5907
655         test_mkdir $DIR1/$tdir
656         mount /etc $DIR1/$tdir --bind || error "mount failed" # Poor man's mount.
657         trap cleanup_21 EXIT
658         rmdir -v $DIR1/$tdir && error "Removed mounted directory"
659         rmdir -v $DIR2/$tdir && echo "Removed mounted directory from another mountpoint, needs to be fixed"
660         test -d $DIR1/$tdir || error "Mounted directory disappeared"
661         cleanup_21
662         test -d $DIR2/$tdir || test -d $DIR1/$tdir && error "Removed dir still visible after umount"
663         true
664 }
665 run_test 21 " Try to remove mountpoint on another dir ===="
666
667 test_23() { # Bug 5972
668         local at_diff=$(do_facet $SINGLEMDS \
669                 $LCTL get_param -n mdd.*MDT0000*.atime_diff | head -n1)
670         echo "atime should be updated while another read" > $DIR1/$tfile
671
672         # clear the lock(mode: LCK_PW) gotten from creating operation
673         cancel_lru_locks $OSC
674         time1=$(date +%s)
675         echo "now is $time1"
676         sleep $((at_diff + 1))
677
678         echo "starting reads"
679         multiop_bg_pause $DIR1/$tfile or20_c || return 1
680         # with SOM and opencache enabled, we need to close a file and cancel
681         # open lock to get atime propogated to MDS
682         kill -USR1 $! || return 2
683         cancel_lru_locks mdc
684
685         time2=$(stat -c "%X" $DIR/$tfile)
686         echo "new atime is $time2"
687
688         [ $time2 -gt $time1 ] || error "atime was not updated"
689         rm -f $DIR1/$tfile || error "rm -f $DIR1/$tfile failed"
690         true
691 }
692 run_test 23 " others should see updated atime while another read===="
693
694 test_24a() {
695         touch $DIR1/$tfile
696         lfs df || error "lfs df failed"
697         lfs df -ih || error "lfs df -ih failed"
698         lfs df -h $DIR1 || error "lfs df -h $DIR1 failed"
699         lfs df -i $DIR2 || error "lfs df -i $DIR2 failed"
700         lfs df $DIR1/$tfile || error "lfs df $DIR1/$tfile failed"
701         lfs df -ih $DIR2/$tfile || error "lfs df -ih $DIR2/$tfile failed"
702
703         OSC=`lctl dl | awk '/-osc-|OSC.*MNT/ {print $4}' | head -n 1`
704 #       OSC=`lctl dl | awk '/-osc-/ {print $4}' | head -n 1`
705         lctl --device %osc deactivate
706         lfs df -i || error "lfs df -i with deactivated OSC failed"
707         lctl --device %osc activate
708         lfs df || error "lfs df with reactivated OSC failed"
709 }
710 run_test 24a "lfs df [-ih] [path] test ========================="
711
712 test_24b() {
713         touch $DIR1/$tfile
714         fsnum=$(lfs_df | grep -c "summary")
715         [ $fsnum -eq 2 ] || error "lfs df shows $fsnum != 2 filesystems."
716 }
717 run_test 24b "lfs df should show both filesystems ==============="
718
719 test_25a() {
720         local acl=$(lctl get_param -n mdc.*MDT0000-mdc-*.connect_flags |
721                                                                 grep -c acl)
722         [ "$acl" -lt 1 ] && skip "must have acl, skipping" && return
723
724         mkdir -p $DIR1/$tdir
725         touch $DIR1/$tdir/f1 || error "touch $DIR1/$tdir/f1"
726         chmod 0755 $DIR1/$tdir/f1 || error "chmod 0755 $DIR1/$tdir/f1"
727
728         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #1"
729         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
730                 error "setfacl $DIR2/$tdir #1"
731         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #2"
732         setfacl -m u:$RUNAS_ID:r-x -m g:$RUNAS_GID:r-x $DIR1/$tdir ||
733                 error "setfacl $DIR2/$tdir #2"
734         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #3"
735         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
736                 error "setfacl $DIR2/$tdir #3"
737         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #4"
738         setfacl -x u:$RUNAS_ID: -x g:$RUNAS_GID: $DIR1/$tdir ||
739                 error "setfacl $DIR2/$tdir #4"
740         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #5"
741
742         rm -rf $DIR1/$tdir
743 }
744 run_test 25a "change ACL on one mountpoint be seen on another ==="
745
746 test_25b() {
747         local acl=$(lctl get_param -n mdc.*MDT0000-mdc-*.connect_flags |
748                                                         grep -c acl)
749         [ "$acl" -lt 1 ] && skip "must have acl, skipping" && return
750
751         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
752
753         rm -rf $DIR1/$tdir
754         $LFS mkdir -i 1 $DIR1/$tdir
755         touch $DIR1/$tdir/f1 || error "touch $DIR1/$tdir/f1"
756         chmod 0755 $DIR1/$tdir/f1 || error "chmod 0755 $DIR1/$tdir/f1"
757
758         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #1"
759         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
760                 error "setfacl $DIR2/$tdir #1"
761         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #2"
762         setfacl -m u:$RUNAS_ID:r-x -m g:$RUNAS_GID:r-x $DIR1/$tdir ||
763                 error "setfacl $DIR2/$tdir #2"
764         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #3"
765         setfacl -m u:$RUNAS_ID:--- -m g:$RUNAS_GID:--- $DIR1/$tdir ||
766                 error "setfacl $DIR2/$tdir #3"
767         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 && error "checkstat $DIR2/$tdir/f1 #4"
768         setfacl -x u:$RUNAS_ID: -x g:$RUNAS_GID: $DIR1/$tdir ||
769                 error "setfacl $DIR2/$tdir #4"
770         $RUNAS $CHECKSTAT $DIR2/$tdir/f1 || error "checkstat $DIR2/$tdir/f1 #5"
771
772         rm -rf $DIR1/$tdir
773 }
774 run_test 25b "change ACL under remote dir on one mountpoint be seen on another"
775
776 test_26a() {
777         utime $DIR1/f26a -s $DIR2/f26a || error "utime failed for $DIR1/f26a"
778 }
779 run_test 26a "allow mtime to get older"
780
781 test_26b() {
782         touch $DIR1/$tfile
783         sleep 1
784         echo "aaa" >> $DIR1/$tfile
785         sleep 1
786         chmod a+x $DIR2/$tfile
787         mt1=`stat -c %Y $DIR1/$tfile`
788         mt2=`stat -c %Y $DIR2/$tfile`
789
790         if [ x"$mt1" != x"$mt2" ]; then
791                 error "not equal mtime, client1: "$mt1", client2: "$mt2"."
792         fi
793 }
794 run_test 26b "sync mtime between ost and mds"
795
796 test_27() {
797         cancel_lru_locks $OSC
798         lctl clear
799         dd if=/dev/zero of=$DIR2/$tfile bs=$((4096+4))k conv=notrunc count=4 seek=3 &
800         DD2_PID=$!
801         sleep 0.5
802         log "dd 1 started"
803
804         dd if=/dev/zero of=$DIR1/$tfile bs=$((16384-1024))k conv=notrunc count=1 seek=4 &
805         DD1_PID=$!
806         log "dd 2 started"
807
808         sleep 1
809         dd if=/dev/zero of=$DIR1/$tfile bs=8k conv=notrunc count=1 seek=0
810         log "dd 3 finished"
811         lctl set_param -n ldlm.dump_namespaces ""
812         wait $DD1_PID $DD2_PID
813         [ $? -ne 0 ] && lctl dk $TMP/debug || true
814 }
815 run_test 27 "align non-overlapping extent locks from request ==="
816
817 test_28() { # bug 9977
818         ECHO_UUID="ECHO_osc1_UUID"
819         tOST=$($LCTL dl | awk '/-osc-|OSC.*MNT/ { print $4 }' | head -n1)
820
821         $LFS setstripe $DIR1/$tfile -S 1048576 -i 0 -c 2
822         tOBJID=`$LFS getstripe $DIR1/$tfile | awk '$1 == 1 {print $2}'`
823         dd if=/dev/zero of=$DIR1/$tfile bs=1024k count=2
824
825         $LCTL <<-EOF
826                 newdev
827                 attach echo_client ECHO_osc1 $ECHO_UUID
828                 setup $tOST
829         EOF
830
831         tECHOID=`$LCTL dl | grep $ECHO_UUID | awk '{ print $1 }'`
832         $LCTL --device $tECHOID destroy "${tOBJID}:0"
833
834         $LCTL <<-EOF
835                 cfg_device ECHO_osc1
836                 cleanup
837                 detach
838         EOF
839
840         # reading of 1st stripe should pass
841         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 || error "dd failed"
842         # reading of 2nd stripe should fail (this stripe was destroyed)
843         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 skip=1 && error
844
845         # now, recreating test file
846         dd if=/dev/zero of=$DIR1/$tfile bs=1024k count=2 || error "dd failed"
847         # reading of 1st stripe should pass
848         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 || error "dd failed"
849         # reading of 2nd stripe should pass
850         dd if=$DIR2/$tfile of=/dev/null bs=1024k count=1 skip=1 ||
851                 error "dd failed"
852 }
853 run_test 28 "read/write/truncate file with lost stripes"
854
855 test_30() { #b=11110, LU-2523
856         test_mkdir $DIR1/$tdir
857         cp -f /bin/bash $DIR1/$tdir/bash
858         bash -c 'sleep 1; rm -f $DIR2/$tdir/bash; cp /bin/bash $DIR2/$tdir' &
859         $DIR1/$tdir/bash -c 'sleep 2;
860                 openfile -f O_RDONLY /proc/$$/exe >& /dev/null; echo $?'
861         wait
862         true
863 }
864 run_test 30 "recreate file race"
865
866 test_31a() {
867         test_mkdir $DIR1/$tdir
868         local writes=$(LANG=C dd if=/dev/zero of=$DIR/$tdir/$tfile \
869                        count=1 2>&1 | awk 'BEGIN { FS="+" } /out/ {print $1}')
870         #define OBD_FAIL_LDLM_CANCEL_BL_CB_RACE   0x314
871         lctl set_param fail_loc=0x314
872         local reads=$(LANG=C dd if=$DIR2/$tdir/$tfile of=/dev/null 2>&1 |
873                       awk 'BEGIN { FS="+" } /in/ {print $1}')
874         [ $reads -eq $writes ] || error "read" $reads "blocks, must be" $writes
875 }
876 run_test 31a "voluntary cancel / blocking ast race=============="
877
878 test_31b() {
879         remote_ost || { skip "local OST" && return 0; }
880         remote_ost_nodsh && skip "remote OST w/o dsh" && return 0
881
882         # make sure there is no local locks due to destroy
883         wait_mds_ost_sync || error "wait_mds_ost_sync()"
884         wait_delete_completed || error "wait_delete_completed()"
885
886         test_mkdir $DIR1/$tdir
887         lfs setstripe $DIR/$tdir/$tfile -i 0 -c 1
888         cp /etc/hosts $DIR/$tdir/$tfile
889         #define OBD_FAIL_LDLM_CANCEL_BL_CB_RACE   0x314
890         lctl set_param fail_loc=0x314
891         #define OBD_FAIL_LDLM_OST_FAIL_RACE      0x316
892         do_facet ost1 lctl set_param fail_loc=0x316
893         # Don't crash kernel
894         cat $DIR2/$tdir/$tfile > /dev/null 2>&1
895         lctl set_param fail_loc=0
896         do_facet ost1 lctl set_param fail_loc=0
897         # cleanup: reconnect the client back
898         df $DIR2
899 }
900 run_test 31b "voluntary OST cancel / blocking ast race=============="
901
902 #LU-14949 - multi-client version of the test 31r in sanity.
903 test_31r() {
904         touch $DIR/$tfile.target
905         touch $DIR/$tfile.source
906
907         ls -l $DIR/$tfile.target # cache it for sure
908
909         #OBD_FAIL_LLITE_OPEN_DELAY 0x1419
910         $LCTL set_param fail_loc=0x1419 fail_val=3
911         cat $DIR/$tfile.target &
912         CATPID=$!
913
914         # Guarantee open is waiting before we get here
915         sleep 1
916         mv $DIR2/$tfile.source $DIR2/$tfile.target
917
918         wait $CATPID
919         RC=$?
920         if [[ $RC -ne 0 ]]; then
921                 error "open with cat failed, rc=$RC"
922         fi
923 }
924 run_test 31r "open-rename(replace) race"
925
926 test_32b() { # bug 11270
927         remote_ost_nodsh && skip "remote OST with nodsh" && return
928
929         local node
930         local facets=$(get_facets OST)
931         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
932
933         save_lustre_params client "osc.*.contention_seconds" > $p
934         save_lustre_params $facets \
935                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
936         save_lustre_params $facets \
937                 "ldlm.namespaces.filter-*.contended_locks" >> $p
938         save_lustre_params $facets \
939                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
940         clear_stats $OSC.*.${OSC}_stats
941
942         # agressive lockless i/o settings
943         do_nodes $(comma_list $(osts_nodes)) \
944                 "lctl set_param -n ldlm.namespaces.*.max_nolock_bytes=2000000 \
945                         ldlm.namespaces.filter-*.contended_locks=0 \
946                         ldlm.namespaces.filter-*.contention_seconds=60"
947         lctl set_param -n $OSC.*.contention_seconds=60
948         for i in {1..5}; do
949                 dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1 conv=notrunc > \
950                         /dev/null 2>&1
951                 dd if=/dev/zero of=$DIR2/$tfile bs=4k count=1 conv=notrunc > \
952                         /dev/null 2>&1
953         done
954         [ $(calc_stats $OSC.*.${OSC}_stats lockless_write_bytes) -ne 0 ] ||
955                 error "lockless i/o was not triggered"
956         # disable lockless i/o (it is disabled by default)
957         do_nodes $(comma_list $(osts_nodes)) \
958                 "lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes=0 \
959                         ldlm.namespaces.filter-*.contended_locks=32 \
960                         ldlm.namespaces.filter-*.contention_seconds=0"
961         # set contention_seconds to 0 at client too, otherwise Lustre still
962         # remembers lock contention
963         lctl set_param -n $OSC.*.contention_seconds=0
964         clear_stats $OSC.*.${OSC}_stats
965         for i in {1..1}; do
966                 dd if=/dev/zero of=$DIR1/$tfile bs=4k count=1 conv=notrunc > \
967                         /dev/null 2>&1
968                 dd if=/dev/zero of=$DIR2/$tfile bs=4k count=1 conv=notrunc > \
969                         /dev/null 2>&1
970         done
971         [ $(calc_stats $OSC.*.${OSC}_stats lockless_write_bytes) -eq 0 ] ||
972                 error "lockless i/o works when disabled"
973         rm -f $DIR1/$tfile
974         restore_lustre_params <$p
975         rm -f $p
976 }
977 # Disable test 32b prior to full removal
978 #run_test 32b "lockless i/o"
979
980 print_jbd_stat () {
981         local mdts=$(get_facets MDS)
982         local stat=0
983         local varsvc
984         local dev
985         local mds
986
987         for mds in ${mdts//,/ }; do
988                 varsvc=${mds}_svc
989
990                 dev=$(basename $(do_facet $mds "lctl get_param -n \
991                         osd*.${!varsvc}.mntdev | xargs readlink -f"))
992                 val=$(do_facet $mds "cat /proc/fs/jbd*/${dev}{,:*,-*}/info \
993                         2>/dev/null | head -n1")
994                 val=${val%% *};
995                 stat=$((stat + val))
996         done
997         echo $stat
998 }
999
1000 # commit on sharing tests
1001 test_33a() {
1002         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1003
1004         [ -z "$CLIENTS" ] && skip "Need two or more clients, have $CLIENTS"
1005         [ $CLIENTCOUNT -lt 2 ] &&
1006                 skip "Need two or more clients, have $CLIENTCOUNT"
1007
1008         local nfiles=${TEST33_NFILES:-10000}
1009         local param_file=$TMP/$tfile-params
1010         local COS
1011         local jbdold="N/A"
1012         local jbdnew="N/A"
1013         local jbd
1014
1015         save_lustre_params $(get_facets MDS) \
1016                 "mdt.*.commit_on_sharing" > $param_file
1017
1018         for COS in 0 1; do
1019                 do_facet $SINGLEMDS lctl set_param mdt.*.commit_on_sharing=$COS
1020                 avgjbd=0
1021                 avgtime=0
1022                 for i in 1 2 3; do
1023                         do_nodes $CLIENT1,$CLIENT2 "mkdir -p $DIR1/$tdir-\\\$(hostname)-$i"
1024
1025                 [ "$mds1_FSTYPE" = ldiskfs ] && jbdold=$(print_jbd_stat)
1026                 echo "=== START createmany old: $jbdold transaction"
1027                 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")
1028                 [ "$mds1_FSTYPE" = ldiskfs ] && jbdnew=$(print_jbd_stat)
1029                 [ "$mds1_FSTYPE" = ldiskfs ] && jbd=$(( jbdnew - jbdold ))
1030                 echo "=== END   createmany new: $jbdnew transaction :  $jbd transactions  nfiles $nfiles time $elapsed COS=$COS"
1031                 [ "$mds1_FSTYPE" = ldiskfs ] && avgjbd=$(( avgjbd + jbd ))
1032                 avgtime=$(( avgtime + elapsed ))
1033                 done
1034         eval cos${COS}_jbd=$((avgjbd / 3))
1035         eval cos${COS}_time=$((avgtime / 3))
1036         done
1037
1038         echo "COS=0 transactions (avg): $cos0_jbd  time (avg): $cos0_time"
1039         echo "COS=1 transactions (avg): $cos1_jbd  time (avg): $cos1_time"
1040         [ "$cos0_jbd" != 0 ] &&
1041                 echo "COS=1 vs COS=0 jbd:  $((((cos1_jbd/cos0_jbd - 1)) * 100 )) %"
1042         [ "$cos0_time" != 0 ] &&
1043                 echo "COS=1 vs COS=0 time: $((((cos1_time/cos0_time - 1)) * 100 )) %"
1044
1045         restore_lustre_params < $param_file
1046         rm -f $param_file
1047         return 0
1048 }
1049 run_test 33a "commit on sharing, cross crete/delete, 2 clients, benchmark"
1050
1051 # commit on sharing tests
1052 test_33b() {
1053         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1054
1055         [ -n "$CLIENTS" ] || { skip "Need two or more clients" && return 0; }
1056         [ $CLIENTCOUNT -ge 2 ] ||
1057                 { skip "Need two or more clients, have $CLIENTCOUNT" &&
1058                                                                 return 0; }
1059         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1060
1061         local nfiles=${TEST33_NFILES:-10000}
1062         local param_file=$TMP/$tfile-params
1063
1064         save_lustre_params $(get_facets MDS) \
1065                 "mdt.*.commit_on_sharing" > $param_file
1066
1067         local COS
1068         local jbdold
1069         local jbdnew
1070         local jbd
1071         local MDTIDX=1
1072
1073         for COS in 0 1; do
1074                 do_facet $SINGLEMDS lctl set_param mdt.*.commit_on_sharing=$COS
1075                 avgjbd=0
1076                 avgtime=0
1077                 for i in 1 2 3; do
1078                         do_node $CLIENT1 "$LFS mkdir -i $MDTIDX \
1079                                           $DIR1/$tdir-\\\$(hostname)-$i"
1080
1081                         jbdold=$(print_jbd_stat)
1082                         echo "=== START createmany old: $jbdold transaction"
1083                         local elapsed=$(do_and_time "do_nodes $CLIENT1,$CLIENT2\
1084                                 createmany -o $DIR1/$tdir-\\\$(hostname)-$i/f- \
1085                                 -r$DIR2/$tdir-\\\$(hostname)-$i/f- $nfiles > \
1086                                                                 /dev/null 2>&1")
1087                         jbdnew=$(print_jbd_stat)
1088                         jbd=$(( jbdnew - jbdold ))
1089                         echo "=== END   createmany new: $jbdnew transaction : \
1090                         $jbd transactions nfiles $nfiles time $elapsed COS=$COS"
1091                         avgjbd=$(( avgjbd + jbd ))
1092                         avgtime=$(( avgtime + elapsed ))
1093                 done
1094                 eval cos${COS}_jbd=$((avgjbd / 3))
1095                 eval cos${COS}_time=$((avgtime / 3))
1096         done
1097
1098         echo "COS=0 transactions (avg): $cos0_jbd  time (avg): $cos0_time"
1099         echo "COS=1 transactions (avg): $cos1_jbd  time (avg): $cos1_time"
1100         [ "$cos0_jbd" != 0 ] &&
1101             echo "COS=1 vs COS=0 jbd: $(((cos1_jbd/cos0_jbd - 1) * 100)) %"
1102         [ "$cos0_time" != 0 ] &&
1103             echo "COS=1 vs COS=0 time: $(((cos1_time/cos0_time - 1) * 100)) %"
1104
1105         restore_lustre_params < $param_file
1106         rm -f $param_file
1107         return 0
1108 }
1109 run_test 33b "COS: cross create/delete, 2 clients, benchmark under remote dir"
1110
1111 test_33c() {
1112         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
1113         [ "$MDS1_VERSION" -lt $(version_code 2.7.63) ] &&
1114                 skip "DNE CoS not supported"
1115
1116         # LU-13522
1117         stop mds1
1118         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS || error "start mds1 failed"
1119
1120         local sync_count
1121
1122         mkdir_on_mdt0 $DIR/$tdir
1123         sync_all_data
1124         do_facet mds1 "lctl set_param -n mdt.*.sync_count=0"
1125         # do twice in case transaction is committed before unlock, see LU-8200
1126         for i in 1 2; do
1127                 # remote dir is created on MDT1, which enqueued lock of $tdir on
1128                 # MDT0
1129                 $LFS mkdir -i 1 $DIR/$tdir/remote.$i
1130                 mkdir $DIR/$tdir/local.$i
1131         done
1132         sync_count=$(do_facet mds1 "lctl get_param -n mdt.*MDT0000.sync_count")
1133         echo "sync_count $sync_count"
1134         [ $sync_count -eq 0 ] && error "Sync-Lock-Cancel not triggered"
1135
1136         sync_all_data
1137         do_facet mds1 "lctl set_param -n mdt.*.sync_count=0"
1138         $LFS mkdir -i 1 $DIR/$tdir/remote.3
1139         # during sleep remote mkdir should have been committed and canceled
1140         # remote lock spontaneously, which shouldn't trigger sync
1141         sleep 6
1142         mkdir $DIR/$tdir/local.3
1143         sync_count=$(do_facet mds1 "lctl get_param -n mdt.*MDT0000.sync_count")
1144         echo "sync_count $sync_count"
1145         [ $sync_count -eq 0 ] || error "Sync-Lock-Cancel triggered"
1146 }
1147 run_test 33c "Cancel cross-MDT lock should trigger Sync-Lock-Cancel"
1148
1149 # arg1 is operations done before CoS, arg2 is the operation that triggers CoS
1150 op_trigger_cos() {
1151         local commit_nr
1152         local total=0
1153         local nodes=$(comma_list $(mdts_nodes))
1154
1155         sync_all_data
1156
1157         # trigger CoS twice in case transaction commit before unlock
1158         for i in 1 2; do
1159                 bash -c "$1"
1160                 do_nodes $nodes "lctl set_param -n mdt.*.async_commit_count=0"
1161                 bash -c "$2"
1162                 commit_nr=$(do_nodes $nodes \
1163                         "lctl get_param -n mdt.*.async_commit_count" | calc_sum)
1164                 total=$((total + commit_nr));
1165                 rm -rf $DIR/$tdir
1166                 sync_all_data
1167         done
1168
1169         echo "CoS count $total"
1170         [ $total -gt 0 ] || error "$2 didn't trigger CoS"
1171 }
1172
1173 test_33d() {
1174         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
1175         [ "$MDS1_VERSION" -lt $(version_code 2.7.63) ] &&
1176                 skip "DNE CoS not supported"
1177
1178         # remote directory create
1179         op_trigger_cos "$LFS mkdir -i 0 $DIR/$tdir" "$LFS mkdir -i 1 $DIR/$tdir/subdir"
1180         # remote directory unlink
1181         op_trigger_cos "$LFS mkdir -i 1 $DIR/$tdir" "rmdir $DIR/$tdir"
1182         # striped directory create
1183         op_trigger_cos "mkdir $DIR/$tdir" "$LFS mkdir -c 2 $DIR/$tdir/subdir"
1184         # striped directory setattr
1185         op_trigger_cos "$LFS mkdir -c 2 $DIR/$tdir; touch $DIR/$tdir" \
1186                 "chmod 713 $DIR/$tdir"
1187         # striped directory unlink
1188         op_trigger_cos "$LFS mkdir -c 2 $DIR/$tdir; touch $DIR/$tdir" \
1189                 "rmdir $DIR/$tdir"
1190         # cross-MDT link
1191         op_trigger_cos "$LFS mkdir -c 2 $DIR/$tdir; \
1192                         $LFS mkdir -i 0 $DIR/$tdir/d1; \
1193                         $LFS mkdir -i 1 $DIR/$tdir/d2; \
1194                         touch $DIR/$tdir/d1/tgt" \
1195                 "ln $DIR/$tdir/d1/tgt $DIR/$tdir/d2/src"
1196         # cross-MDT rename
1197         op_trigger_cos "$LFS mkdir -c 2 $DIR/$tdir; \
1198                         $LFS mkdir -i 0 $DIR/$tdir/d1; \
1199                         $LFS mkdir -i 1 $DIR/$tdir/d2; \
1200                         touch $DIR/$tdir/d1/src" \
1201                 "mv $DIR/$tdir/d1/src $DIR/$tdir/d2/tgt"
1202         # migrate
1203         op_trigger_cos "$LFS mkdir -i 0 $DIR/$tdir" \
1204                 "$LFS migrate -m 1 $DIR/$tdir"
1205
1206         return 0
1207 }
1208 run_test 33d "DNE distributed operation should trigger COS"
1209
1210 test_33e() {
1211         [ -n "$CLIENTS" ] || skip "Need two or more clients"
1212         [ $CLIENTCOUNT -ge 2 ] ||
1213                 skip "Need two or more clients, have $CLIENTCOUNT"
1214         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
1215         [ "$MDS1_VERSION" -lt $(version_code 2.7.63) ] &&
1216                 skip "DNE CoS not supported"
1217
1218         local client2=${CLIENT2:-$(hostname)}
1219
1220         sync
1221
1222         local nodes=$(comma_list $(mdts_nodes))
1223         do_nodes $nodes "lctl set_param -n mdt.*.async_commit_count=0"
1224
1225         $LFS mkdir -c 2 $DIR/$tdir
1226         mkdir $DIR/$tdir/subdir
1227         echo abc > $DIR/$tdir/$tfile
1228         do_node $client2 echo dfg >> $DIR/$tdir/$tfile
1229         do_node $client2 touch $DIR/$tdir/subdir
1230
1231         local async_commit_count=$(do_nodes $nodes \
1232                 "lctl get_param -n mdt.*.async_commit_count" | calc_sum)
1233         [ $async_commit_count -gt 0 ] && error "CoS triggerred"
1234
1235         return 0
1236 }
1237 run_test 33e "DNE local operation shouldn't trigger COS"
1238
1239 # End commit on sharing tests
1240
1241 get_ost_lock_timeouts() {
1242     local nodes=${1:-$(comma_list $(osts_nodes))}
1243
1244     local locks=$(do_nodes $nodes \
1245         "lctl get_param -n ldlm.namespaces.filter-*.lock_timeouts" | calc_sum)
1246
1247     echo $locks
1248 }
1249
1250 cleanup_34() {
1251         local i
1252         trap 0
1253         do_nodes $(comma_list $(osts_nodes)) \
1254                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
1255         for i in $(seq $OSTCOUNT); do
1256                 wait_osc_import_ready client ost$i
1257         done
1258 }
1259
1260 test_34() { #16129
1261         remote_ost_nodsh && skip "remote OST with nodsh" && return
1262         local OPER
1263         local lock_in
1264         local lock_out
1265         trap cleanup_34 EXIT RETURN
1266         for OPER in notimeout timeout ; do
1267                 rm $DIR1/$tfile 2>/dev/null
1268                 lock_in=$(get_ost_lock_timeouts)
1269                 if [ $OPER == "timeout" ] ; then
1270                         for j in `seq $OSTCOUNT`; do
1271                                 #define OBD_FAIL_PTLRPC_HPREQ_TIMEOUT    0x511
1272                                 do_facet ost$j lctl set_param fail_loc=0x511
1273                         done
1274                         echo lock should expire
1275                 else
1276                         for j in `seq $OSTCOUNT`; do
1277                                 #define OBD_FAIL_PTLRPC_HPREQ_NOTIMEOUT  0x512
1278                                 do_facet ost$j lctl set_param fail_loc=0x512
1279                         done
1280                         echo lock should not expire
1281                 fi
1282                 echo writing on client1
1283                 dd if=/dev/zero of=$DIR1/$tfile count=100 conv=notrunc > /dev/null 2>&1
1284                 sync &
1285                 echo reading on client2
1286                 dd of=/dev/null if=$DIR2/$tfile > /dev/null 2>&1
1287                 # wait for a lock timeout
1288                 sleep 4
1289                 lock_out=$(get_ost_lock_timeouts)
1290                 if [ $OPER == "timeout" ] ; then
1291                         if [ $lock_in == $lock_out ]; then
1292                                 error "no lock timeout happened"
1293                         else
1294                                 echo "success"
1295                         fi
1296                 else
1297                         if [ $lock_in != $lock_out ]; then
1298                                 error "lock timeout happened"
1299                         else
1300                                 echo "success"
1301                         fi
1302                 fi
1303         done
1304         cleanup_34
1305 }
1306 run_test 34 "no lock timeout under IO"
1307
1308 test_35() { # bug 17645
1309         local generation=[]
1310         local count=0
1311         gen=$(lctl get_param mdc.$FSNAME-MDT*-mdc-*.import | grep generation |
1312               awk '/generation/{print $2}')
1313         for g in $gen; do
1314                 generation[count]=$g
1315                 let count=count+1
1316         done
1317
1318         test_mkdir $MOUNT1/$tdir
1319         cancel_lru_locks mdc
1320
1321         # Let's initiate -EINTR situation by setting fail_loc and take
1322         # write lock on same file from same client. This will not cause
1323         # bl_ast yet as lock is already in local cache.
1324         #define OBD_FAIL_LDLM_INTR_CP_AST        0x317
1325         do_facet client "lctl set_param fail_loc=0x80000317"
1326         local timeout=$(do_facet $SINGLEMDS lctl get_param  -n timeout)
1327         let timeout=timeout*3
1328         local nr=0
1329         while test $nr -lt 10; do
1330                 log "Race attempt $nr"
1331                 local blk1=$(lctl get_param -n ldlm.services.ldlm_cbd.stats |
1332                              awk '/ldlm_bl_callback/ { print $2 }')
1333                 test "x$blk1" = "x" && blk1=0
1334                 createmany -o $MOUNT2/$tdir/a 4000 &
1335                 pid1=$!
1336                 sleep 1
1337
1338                 # Let's make conflict and bl_ast
1339                 ls -la $MOUNT1/$tdir > /dev/null &
1340                 pid2=$!
1341
1342                 log "Wait for $pid1 $pid2 for $timeout sec..."
1343                 sleep $timeout
1344                 kill -9 $pid1 $pid2 > /dev/null 2>&1
1345                 wait
1346                 local blk2=$(lctl get_param -n ldlm.services.ldlm_cbd.stats |
1347                              awk '/ldlm_bl_callback/ { print $2 }')
1348                 test "x$blk2" = "x" && blk2=0
1349                 test $blk2 -gt $blk1 && break
1350                 rm -fr $MOUNT1/$tdir
1351                 cancel_lru_locks mdc
1352                 let nr=nr+1
1353         done
1354         do_facet client "lctl set_param fail_loc=0x0"
1355         df -h $MOUNT1 $MOUNT2
1356         count=0
1357         gen=$(lctl get_param mdc.$FSNAME-MDT*-mdc-*.import | grep generation |
1358                 awk '/generation/{print $2}')
1359         for g in $gen; do
1360             if ! test "$g" -eq "${generation[count]}"; then
1361                 list=$(lctl list_param mdc.$FSNAME-MDT*-mdc-*.import)
1362                 local c=0
1363                 for imp in $list; do
1364                         if [ $c = $count ]; then
1365                                 break
1366                         fi
1367                         c=c+1
1368                 done
1369                 imp=$(echo "$imp" | awk -F"." '{print $2}')
1370                 error "Eviction happened on import $imp"
1371             fi
1372             let count=count+1
1373         done
1374 }
1375 run_test 35 "-EINTR cp_ast vs. bl_ast race does not evict client"
1376
1377 test_36() { #bug 16417
1378         local SIZE
1379         local SIZE_B
1380         local i
1381
1382         test_mkdir $DIR1/$tdir
1383         $LFS setstripe -c -1 $DIR1/$tdir
1384         i=0
1385         SIZE=50
1386         let SIZE_B=SIZE*1024*1024
1387         sync; sleep 2; sync # wait for delete thread
1388         wait_mds_ost_sync || error "wait_mds_ost_sync failed"
1389         wait_destroy_complete || error "wait_destroy_complete failed"
1390
1391         while [ $i -le 10 ]; do
1392                 lctl mark "start test - cycle ($i)"
1393                 local before=$(lfs_df $MOUNT1 | awk '/^filesystem/{ print $4; exit }')
1394                 dd if=/dev/zero of=$DIR1/$tdir/$tfile bs=1M count=$SIZE ||
1395                         error "dd $DIR1/$tdir/$tfile ${SIZE}MB failed"
1396                 sync          # sync data from client cache
1397                 sync_all_data # sync data from server cache (delayed allocation)
1398                 sleep 2
1399                 local after_dd=$(lfs_df $MOUNT1 | awk '/^filesystem/{ print $4; exit }')
1400                 multiop_bg_pause $DIR2/$tdir/$tfile O_r${SIZE_B}c || return 3
1401                 read_pid=$!
1402                 rm -f $DIR1/$tdir/$tfile
1403                 kill -USR1 $read_pid
1404                 wait $read_pid
1405                 sync; sleep 2; sync # Ensure new statfs
1406                 wait_delete_completed
1407                 local after=$(lfs_df $MOUNT1 | awk '/^filesystem/{ print $4; exit }')
1408                 echo "*** cycle($i) *** before($before) after_dd($after_dd)" \
1409                         "after($after)"
1410                 # this free space! not used
1411                 (( $after_dd <= $after)) ||
1412                         error "space leaked after_dd:$after_dd > after:$after"
1413                 let i=i+1
1414         done
1415 }
1416 run_test 36 "handle ESTALE/open-unlink correctly"
1417
1418 test_37() { # bug 18695
1419         test_mkdir $DIR1/$tdir
1420         multiop_bg_pause $DIR1/$tdir D_c || return 1
1421         MULTIPID=$!
1422         # create large directory (32kB seems enough from e2fsck, ~= 1000 files)
1423         createmany -m $DIR2/$tdir/f 10000
1424         # set mtime/atime backward
1425         touch -t 198001010000 $DIR2/$tdir
1426         kill -USR1 $MULTIPID
1427         nr_files=`lfs find $DIR1/$tdir -type f | wc -l`
1428         [ $nr_files -eq 10000 ] || error "$nr_files != 10000 truncated directory?"
1429
1430 }
1431 run_test 37 "check i_size is not updated for directory on close (bug 18695) =============="
1432
1433 # this should be set to past
1434 TEST_39_MTIME=`date -d "1 year ago" +%s`
1435
1436 # bug 11063
1437 test_39a() {
1438         local client1=${CLIENT1:-`hostname`}
1439         local client2=${CLIENT2:-`hostname`}
1440
1441         do_node $client1 "touch $DIR1/$tfile"
1442
1443         do_node $client1 "touch -m -d @$TEST_39_MTIME $DIR1/$tfile"
1444         local mtime1=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1445         [ "$mtime1" = $TEST_39_MTIME ] || \
1446                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
1447
1448         local d1=`do_node $client1 date +%s`
1449         do_node $client1 'echo hello >> '$DIR1/$tfile
1450         local d2=`do_node $client1 date +%s`
1451
1452         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1453         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
1454                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
1455
1456         do_node $client1 "mv $DIR1/$tfile $DIR1/$tfile-1"
1457
1458         for (( i=0; i < 2; i++ )) ; do
1459                 local mtime3=`do_node $client2 "stat -c %Y $DIR1/$tfile-1"`
1460                 [ "$mtime2" = "$mtime3" ] || \
1461                         error "mtime ($mtime2) changed (to $mtime3) on rename"
1462
1463                 cancel_lru_locks osc
1464                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1465         done
1466 }
1467 run_test 39a "test from 11063 =================================="
1468
1469 test_39b() {
1470         local client1=${CLIENT1:-`hostname`}
1471         local client2=${CLIENT2:-`hostname`}
1472
1473         touch $DIR1/$tfile
1474
1475         local mtime1=`stat -c %Y $DIR1/$tfile`
1476         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1477
1478         sleep 1
1479         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
1480
1481         for (( i=0; i < 2; i++ )) ; do
1482                 local mtime3=`stat -c %Y $DIR1/$tfile`
1483                 local mtime4=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1484
1485                 [ "$mtime3" = "$mtime4" ] || \
1486                         error "different mtime on clients: $mtime3, $mtime4"
1487                 [ "$mtime3" = $TEST_39_MTIME ] || \
1488                         error "lost mtime: $mtime3, should be $TEST_39_MTIME"
1489
1490                 cancel_lru_locks osc
1491                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1492         done
1493 }
1494 run_test 39b "11063 problem 1 =================================="
1495
1496 test_39c() {
1497         local client1=${CLIENT1:-`hostname`}
1498         local client2=${CLIENT2:-`hostname`}
1499
1500         echo hello > $DIR1/$tfile
1501
1502         local mtime1=`stat -c %Y $DIR1/$tfile`
1503         local mtime2=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1504         [ "$mtime1" = "$mtime2" ] || \
1505                 error "create: different mtime on clients: $mtime1, $mtime2"
1506
1507         sleep 1
1508         $TRUNCATE $DIR1/$tfile 1
1509
1510         for (( i=0; i < 2; i++ )) ; do
1511                 local mtime3=`stat -c %Y $DIR1/$tfile`
1512                 local mtime4=`do_node $client2 "stat -c %Y $DIR1/$tfile"`
1513
1514                 [ "$mtime3" = "$mtime4" ] || \
1515                         error "different mtime on clients: $mtime3, $mtime4"
1516                 [ "$mtime3" -gt $mtime2 ] || \
1517                         error "truncate did not update mtime: $mtime2, $mtime3"
1518
1519                 cancel_lru_locks osc
1520                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
1521         done
1522 }
1523 run_test 39c "check truncate mtime update ======================"
1524
1525 test_39d() { # LU-7310
1526         touch $DIR1/$tfile
1527         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
1528
1529         local mtime1=$(stat -c %Y $DIR2/$tfile)
1530         [ "$mtime1" = $TEST_39_MTIME ] ||
1531                 error "mtime: $mtime1, should be $TEST_39_MTIME"
1532
1533         # force sync write
1534         # define OBD_FAIL_OSC_NO_GRANT 0x411
1535         $LCTL set_param fail_loc=0x411
1536
1537         local d1=$(date +%s)
1538         echo hello >> $DIR1/$tfile
1539         local d2=$(date +%s)
1540
1541         $LCTL set_param fail_loc=0
1542
1543         cancel_lru_locks $OSC
1544
1545         local mtime2=$(stat -c %Y $DIR2/$tfile)
1546         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] ||
1547                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
1548 }
1549 run_test 39d "sync write should update mtime"
1550
1551 pdo_sched() {
1552         # how long 40-47 take with specific delay
1553         # sleep 0.1 # 78s
1554         # sleep 0.2 # 103s
1555         # sleep 0.3 # 124s
1556         sleep 0.5 # 164s
1557 }
1558
1559 # for pdo testing, we must cancel MDT-MDT locks as well as client locks to
1560 # avoid unexpected delays due to previous tests
1561 pdo_lru_clear() {
1562         cancel_lru_locks mdc
1563         do_nodes $(comma_list $(mdts_nodes)) \
1564                 $LCTL set_param -n ldlm.namespaces.*mdt*.lru_size=clear
1565         do_nodes $(comma_list $(mdts_nodes)) \
1566                 $LCTL get_param ldlm.namespaces.*mdt*.lock_unused_count \
1567                         ldlm.namespaces.*mdt*.lock_count | grep -v '=0'
1568 }
1569
1570 # check that pid exists hence second operation wasn't blocked by first one
1571 # if it is so then there is no conflict, return 0
1572 # else second operation is conflicting with first one, return 1
1573 check_pdo_conflict() {
1574         local pid=$1
1575         local conflict=0
1576         pdo_sched # to ensure OP1 is finished on client if OP2 is blocked by OP1
1577         if [[ `ps --pid $pid | wc -l` == 1 ]]; then
1578                 conflict=1
1579                 echo "Conflict"
1580         else
1581                 echo "No conflict"
1582         fi
1583         return $conflict
1584 }
1585
1586 # pdirop tests
1587 # test 40: check non-blocking operations
1588 test_40a() {
1589         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1590
1591         mkdir_on_mdt0 $DIR2/$tdir
1592         pdo_lru_clear
1593 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1594         do_nodes $(comma_list $(mdts_nodes)) \
1595                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
1596         mkdir $DIR1/$tdir/$tfile &
1597         PID1=$!; pdo_sched
1598         touch $DIR2/$tdir/$tfile-2
1599         check_pdo_conflict $PID1 || error "create is blocked"
1600         mkdir $DIR2/$tdir/$tfile-3
1601         check_pdo_conflict $PID1 || error "mkdir is blocked"
1602         link $DIR2/$tdir/$tfile-2 $DIR2/$tdir/$tfile-4
1603         check_pdo_conflict $PID1 || error "link is blocked"
1604         mv $DIR2/$tdir/$tfile-2 $DIR2/$tdir/$tfile-5
1605         check_pdo_conflict $PID1 || error "rename is blocked"
1606         stat $DIR2/$tdir/$tfile-3 $DIR2/$tdir/$tfile-4 > /dev/null
1607         check_pdo_conflict $PID1 || error "getattr is blocked"
1608         rm $DIR2/$tdir/$tfile-4 $DIR2/$tdir/$tfile-5
1609         rmdir $DIR2/$tdir/$tfile-3
1610         check_pdo_conflict $PID1 || error "unlink is blocked"
1611
1612         #  all operations above shouldn't wait the first one
1613         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1614         do_nodes $(comma_list $(mdts_nodes)) \
1615                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
1616         wait $PID1
1617         rm -rf $DIR/$tdir
1618         return 0
1619 }
1620 run_test 40a "pdirops: create vs others =============="
1621
1622 test_40b() {
1623         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1624
1625         mkdir_on_mdt0 $DIR2/$tdir
1626         pdo_lru_clear
1627 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1628         do_nodes $(comma_list $(mdts_nodes)) \
1629                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
1630         touch $DIR1/$tdir/$tfile &
1631         PID1=$!; pdo_sched
1632         # open|create
1633         touch $DIR2/$tdir/$tfile-2
1634         check_pdo_conflict $PID1 || error "create is blocked"
1635         mkdir $DIR2/$tdir/$tfile-3
1636         check_pdo_conflict $PID1 || error "mkdir is blocked"
1637         link $DIR2/$tdir/$tfile-2 $DIR2/$tdir/$tfile-4
1638         check_pdo_conflict $PID1 || error "link is blocked"
1639         mv $DIR2/$tdir/$tfile-2 $DIR2/$tdir/$tfile-5
1640         check_pdo_conflict $PID1 || error "rename is blocked"
1641         stat $DIR2/$tdir/$tfile-3 $DIR2/$tdir/$tfile-4 > /dev/null
1642         check_pdo_conflict $PID1 || error "getattr is blocked"
1643         rm $DIR2/$tdir/$tfile-4 $DIR2/$tdir/$tfile-5
1644         rmdir $DIR2/$tdir/$tfile-3
1645         check_pdo_conflict $PID1 || error "unlink is blocked"
1646         # all operations above shouldn't wait the first one
1647
1648         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1649         do_nodes $(comma_list $(mdts_nodes)) \
1650                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
1651         wait $PID1
1652         rm -rf $DIR/$tdir
1653         return 0
1654 }
1655 run_test 40b "pdirops: open|create and others =============="
1656
1657 test_40c() {
1658         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1659
1660         mkdir_on_mdt0 $DIR2/$tdir
1661         pdo_lru_clear
1662         touch $DIR1/$tdir/$tfile
1663 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1664         do_nodes $(comma_list $(mdts_nodes)) \
1665                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
1666         link $DIR1/$tdir/$tfile $DIR1/$tdir/$tfile-0 &
1667         PID1=$!; pdo_sched
1668         # open|create
1669         touch $DIR2/$tdir/$tfile-2
1670         check_pdo_conflict $PID1 || error "create is blocked"
1671         mkdir $DIR2/$tdir/$tfile-3
1672         check_pdo_conflict $PID1 || error "mkdir is blocked"
1673         link $DIR2/$tdir/$tfile-2 $DIR2/$tdir/$tfile-4
1674         check_pdo_conflict $PID1 || error "link is blocked"
1675         mv $DIR2/$tdir/$tfile-2 $DIR2/$tdir/$tfile-5
1676         check_pdo_conflict $PID1 || error "rename is blocked"
1677         stat $DIR2/$tdir/$tfile-3 $DIR2/$tdir/$tfile-4 > /dev/null
1678         check_pdo_conflict $PID1 || error "getattr is blocked"
1679         rm $DIR2/$tdir/$tfile-4 $DIR2/$tdir/$tfile-5
1680         rmdir $DIR2/$tdir/$tfile-3
1681         check_pdo_conflict $PID1 || error "unlink is blocked"
1682
1683         # all operations above shouldn't wait the first one
1684         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1685         do_nodes $(comma_list $(mdts_nodes)) \
1686                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
1687         wait $PID1
1688         rm -rf $DIR/$tdir
1689         return 0
1690 }
1691 run_test 40c "pdirops: link and others =============="
1692
1693 test_40d() {
1694         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1695
1696         mkdir_on_mdt0 $DIR2/$tdir
1697         pdo_lru_clear
1698         touch $DIR1/$tdir/$tfile
1699 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1700         do_nodes $(comma_list $(mdts_nodes)) \
1701                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
1702         rm $DIR1/$tdir/$tfile &
1703         PID1=$!; pdo_sched
1704         # open|create
1705         touch $DIR2/$tdir/$tfile-2
1706         check_pdo_conflict $PID1 || error "create is blocked"
1707         mkdir $DIR2/$tdir/$tfile-3
1708         check_pdo_conflict $PID1 || error "mkdir is blocked"
1709         link $DIR2/$tdir/$tfile-2 $DIR2/$tdir/$tfile-4
1710         check_pdo_conflict $PID1 || error "link is blocked"
1711         mv $DIR2/$tdir/$tfile-2 $DIR2/$tdir/$tfile-5
1712         check_pdo_conflict $PID1 || error "rename is blocked"
1713         stat $DIR2/$tdir/$tfile-3 $DIR2/$tdir/$tfile-4 > /dev/null
1714         check_pdo_conflict $PID1 || error "getattr is blocked"
1715         rm $DIR2/$tdir/$tfile-4 $DIR2/$tdir/$tfile-5
1716         rmdir $DIR2/$tdir/$tfile-3
1717         check_pdo_conflict $PID1 || error "unlink is blocked"
1718
1719         # all operations above shouldn't wait the first one
1720         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1721         do_nodes $(comma_list $(mdts_nodes)) \
1722                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
1723         wait $PID1
1724         return 0
1725 }
1726 run_test 40d "pdirops: unlink and others =============="
1727
1728 test_40e() {
1729         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1730
1731         mkdir_on_mdt0 $DIR2/$tdir
1732         pdo_lru_clear
1733         touch $DIR1/$tdir/$tfile
1734 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1735         do_nodes $(comma_list $(mdts_nodes)) \
1736                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
1737         mv $DIR1/$tdir/$tfile $DIR1/$tdir/$tfile-0 &
1738         PID1=$!; pdo_sched
1739         # open|create
1740         touch $DIR2/$tdir/$tfile-2
1741         check_pdo_conflict $PID1 || error "create is blocked"
1742         mkdir $DIR2/$tdir/$tfile-3
1743         check_pdo_conflict $PID1 || error "mkdir is blocked"
1744         link $DIR2/$tdir/$tfile-2 $DIR2/$tdir/$tfile-4
1745         check_pdo_conflict $PID1 || error "link is blocked"
1746         stat $DIR2/$tdir/$tfile-3 $DIR2/$tdir/$tfile-4 > /dev/null
1747         check_pdo_conflict $PID1 || error "getattr is blocked"
1748         rm $DIR2/$tdir/$tfile-4 $DIR2/$tdir/$tfile-2
1749         rmdir $DIR2/$tdir/$tfile-3
1750         check_pdo_conflict $PID1 || error "unlink is blocked"
1751
1752        # all operations above shouldn't wait the first one
1753         check_pdo_conflict $PID1 || error "parallel operation is blocked"
1754         do_nodes $(comma_list $(mdts_nodes)) \
1755                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
1756         wait $PID1
1757         rm -rf $DIR/$tdir
1758         return 0
1759 }
1760 run_test 40e "pdirops: rename and others =============="
1761
1762 # test 41: create blocking operations
1763 test_41a() {
1764         pdo_lru_clear
1765 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1766         do_nodes $(comma_list $(mdts_nodes)) \
1767                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
1768         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1769         PID1=$! ; pdo_sched
1770         mkdir $DIR2/$tfile &
1771         PID2=$! ; pdo_sched
1772         do_nodes $(comma_list $(mdts_nodes)) \
1773                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
1774         check_pdo_conflict $PID1 && { wait $PID1; echo "mkdir isn't blocked"; }
1775         wait $PID2 ; [ $? -ne 0 ] || error "mkdir must fail"
1776         rm -rf $DIR/$tfile*
1777         return 0
1778 }
1779 run_test 41a "pdirops: create vs mkdir =============="
1780
1781 test_41b() {
1782         pdo_lru_clear
1783 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1784         do_nodes $(comma_list $(mdts_nodes)) \
1785                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
1786         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1787         PID1=$! ; pdo_sched
1788         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
1789         PID2=$! ; pdo_sched
1790         do_nodes $(comma_list $(mdts_nodes)) \
1791                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
1792         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1793         wait $PID2 ; [ $? -ne 0 ] || error "create must fail"
1794         rm -rf $DIR/$tfile*
1795         return 0
1796 }
1797 run_test 41b "pdirops: create vs create =============="
1798
1799 test_41c() {
1800         pdo_lru_clear
1801         touch $DIR1/$tfile-2
1802 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1803         do_nodes $(comma_list $(mdts_nodes)) \
1804                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
1805         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1806         PID1=$! ; pdo_sched
1807         link $DIR2/$tfile-2 $DIR2/$tfile &
1808         PID2=$! ; pdo_sched
1809         do_nodes $(comma_list $(mdts_nodes)) \
1810                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
1811         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
1812         wait $PID2 ; [ $? -ne 0 ] || error "link must fail"
1813         rm -rf $DIR/$tfile*
1814         return 0
1815 }
1816 run_test 41c "pdirops: create vs link =============="
1817
1818 test_41d() {
1819         pdo_lru_clear
1820 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1821         do_nodes $(comma_list $(mdts_nodes)) \
1822                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
1823         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1824         PID1=$! ; pdo_sched
1825         rm $DIR2/$tfile &
1826         PID2=$! ; pdo_sched
1827         do_nodes $(comma_list $(mdts_nodes)) \
1828                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
1829         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
1830         wait $PID2 ; [ $? -eq 0 ] || error "unlink must succeed"
1831         rm -rf $DIR/$tfile*
1832         return 0
1833 }
1834 run_test 41d "pdirops: create vs unlink =============="
1835
1836 test_41e() {
1837         pdo_lru_clear
1838         touch $DIR1/$tfile-2
1839 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1840         do_nodes $(comma_list $(mdts_nodes)) \
1841                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
1842         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1843         PID1=$! ; pdo_sched
1844         mv $DIR2/$tfile-2 $DIR2/$tfile &
1845         PID2=$! ; pdo_sched
1846         do_nodes $(comma_list $(mdts_nodes)) \
1847                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
1848         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1849         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
1850         rm -rf $DIR/$tfile*
1851         return 0
1852 }
1853 run_test 41e "pdirops: create and rename (tgt) =============="
1854
1855 test_41f() {
1856         pdo_lru_clear
1857 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1858         do_nodes $(comma_list $(mdts_nodes)) \
1859                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
1860         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1861         PID1=$! ; pdo_sched
1862         mv $DIR2/$tfile $DIR2/$tfile-2 &
1863         PID2=$! ; pdo_sched
1864         do_nodes $(comma_list $(mdts_nodes)) \
1865                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
1866         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
1867         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
1868         rm -rf $DIR/$tfile*
1869         return 0
1870 }
1871 run_test 41f "pdirops: create and rename (src) =============="
1872
1873 test_41g() {
1874         pdo_lru_clear
1875 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1876         do_nodes $(comma_list $(mdts_nodes)) \
1877                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
1878         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1879         PID1=$! ; pdo_sched
1880         stat $DIR2/$tfile > /dev/null &
1881         PID2=$! ; pdo_sched
1882         do_nodes $(comma_list $(mdts_nodes)) \
1883                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
1884         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
1885         wait $PID2 ; [ $? -eq 0 ] || error "stat must succeed"
1886         rm -rf $DIR/$tfile*
1887         return 0
1888 }
1889 run_test 41g "pdirops: create vs getattr =============="
1890
1891 test_41h() {
1892         pdo_lru_clear
1893 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1894         do_nodes $(comma_list $(mdts_nodes)) \
1895                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
1896         $MULTIOP $DIR1/$tfile oO_CREAT:O_RDWR:c &
1897         PID1=$! ; pdo_sched
1898         ls -lia $DIR2/ > /dev/null &
1899         PID2=$! ; pdo_sched
1900         do_nodes $(comma_list $(mdts_nodes)) \
1901                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
1902         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
1903         wait $PID2
1904         rm -rf $DIR/$tfile*
1905         return 0
1906 }
1907 run_test 41h "pdirops: create vs readdir =============="
1908
1909 sub_test_41i() {
1910         local PID1 PID2
1911         local fail_loc="$1"
1912         local ret=0
1913
1914         do_nodes $(comma_list $(mdts_nodes)) \
1915                 "lctl set_param -n fail_loc=${fail_loc} || true" &>/dev/null
1916
1917         $MULTIOP $DIR1/$tfile oO_CREAT:O_EXCL:c 2>/dev/null &
1918         PID1=$!
1919         sleep 0.2
1920         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c 2>/dev/null &
1921         PID2=$!
1922
1923         if ! wait $PID1 && ! wait $PID2; then
1924                 echo "Both creates failed (1 should fail, 1 should succeed)"
1925                 ret=1
1926         elif wait $PID1 && wait $PID2; then
1927                 echo "Both creates succeeded (1 should fail, 1 should succeed)"
1928                 ret=2
1929         fi
1930
1931         #Clean
1932         do_nodes $(comma_list $(mdts_nodes)) \
1933                 "lctl set_param -n fail_loc=0x0 || true" &>/dev/null
1934         rm -f $DIR/$tfile
1935
1936         return $ret
1937 }
1938
1939 test_41i() {
1940         (( $MDS1_VERSION >= $(version_code 2.13.56) )) ||
1941                 skip "Need MDS version newer than 2.13.56"
1942         local msg fail_loc
1943
1944 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_REINT_OPEN         0x169
1945 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_REINT_OPEN2        0x16a
1946         for fail_loc in "0x80000169" "0x8000016a"; do
1947                 echo "Begin 100 tests with fail_loc=$fail_loc"
1948                 printf "Progress: "
1949                 for i in {1..100}; do
1950                         printf "*"
1951                         msg=$(sub_test_41i "$fail_loc") ||
1952                                 { echo; error "iter=$i : $msg"; }
1953                 done
1954                 echo
1955         done
1956 }
1957 run_test 41i "reint_open: create vs create"
1958
1959
1960 # test 42: unlink and blocking operations
1961 test_42a() {
1962         pdo_lru_clear
1963 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1964         do_nodes $(comma_list $(mdts_nodes)) \
1965                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
1966         mkdir $DIR1/$tfile &
1967         PID1=$! ; pdo_sched
1968         mkdir $DIR2/$tfile &
1969         PID2=$! ; pdo_sched
1970         do_nodes $(comma_list $(mdts_nodes)) \
1971                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
1972         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
1973         wait $PID2 ; [ $? -ne 0 ] || error "mkdir must fail"
1974         rm -rf $DIR/$tfile*
1975         return 0
1976 }
1977 run_test 42a "pdirops: mkdir vs mkdir =============="
1978
1979 test_42b() {
1980         pdo_lru_clear
1981 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
1982         do_nodes $(comma_list $(mdts_nodes)) \
1983                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
1984         mkdir $DIR1/$tfile &
1985         PID1=$! ; pdo_sched
1986         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
1987         PID2=$! ; pdo_sched
1988         do_nodes $(comma_list $(mdts_nodes)) \
1989                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
1990         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
1991         wait $PID2 ; [ $? -ne 0 ] || error "create must fail"
1992         rm -rf $DIR/$tfile*
1993         return 0
1994 }
1995 run_test 42b "pdirops: mkdir vs create =============="
1996
1997 test_42c() {
1998         pdo_lru_clear
1999         touch $DIR1/$tfile-2
2000 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2001         do_nodes $(comma_list $(mdts_nodes)) \
2002                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2003         mkdir $DIR1/$tfile &
2004         PID1=$! ; pdo_sched
2005         link $DIR2/$tfile-2 $DIR2/$tfile &
2006         PID2=$! ; pdo_sched
2007         do_nodes $(comma_list $(mdts_nodes)) \
2008                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2009         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2010         wait $PID2 ; [ $? -ne 0 ] || error "link must fail"
2011         rm -rf $DIR/$tfile*
2012         return 0
2013 }
2014 run_test 42c "pdirops: mkdir vs link =============="
2015
2016 test_42d() {
2017         pdo_lru_clear
2018 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2019         do_nodes $(comma_list $(mdts_nodes)) \
2020                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2021         mkdir $DIR1/$tfile &
2022         PID1=$! ; pdo_sched
2023         rmdir $DIR2/$tfile &
2024         PID2=$! ; pdo_sched
2025         do_nodes $(comma_list $(mdts_nodes)) \
2026                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2027         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
2028         wait $PID2 ; [ $? -eq 0 ] || error "unlink must succeed"
2029         rm -rf $DIR/$tfile*
2030         return 0
2031 }
2032 run_test 42d "pdirops: mkdir vs unlink =============="
2033
2034 test_42e() {
2035         pdo_lru_clear
2036         touch $DIR1/$tfile-2
2037 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2038         do_nodes $(comma_list $(mdts_nodes)) \
2039                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2040         mkdir $DIR1/$tfile &
2041         PID1=$! ; pdo_sched
2042         mv -T $DIR2/$tfile-2 $DIR2/$tfile &
2043         PID2=$! ; pdo_sched
2044         do_nodes $(comma_list $(mdts_nodes)) \
2045                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2046         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2047         wait $PID2 ; [ $? -ne 0 ] || error "rename must fail"
2048         rm -rf $DIR/$tfile*
2049         return 0
2050 }
2051 run_test 42e "pdirops: mkdir and rename (tgt) =============="
2052
2053 test_42f() {
2054         pdo_lru_clear
2055 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2056         do_nodes $(comma_list $(mdts_nodes)) \
2057                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2058         mkdir $DIR1/$tfile &
2059         PID1=$! ; pdo_sched
2060         mv $DIR2/$tfile $DIR2/$tfile-2 &
2061         PID2=$! ; pdo_sched
2062         do_nodes $(comma_list $(mdts_nodes)) \
2063                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2064         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2065         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
2066         rm -rf $DIR/$tfile*
2067         return 0
2068 }
2069 run_test 42f "pdirops: mkdir and rename (src) =============="
2070
2071 test_42g() {
2072         mkdir_on_mdt0 $DIR1/$tdir
2073         pdo_lru_clear
2074 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2075         do_nodes $(comma_list $(mdts_nodes)) \
2076                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2077         mkdir $DIR1/$tdir/$tfile &
2078         PID1=$! ; pdo_sched
2079         stat $DIR2/$tdir/$tfile > /dev/null &
2080         PID2=$! ; pdo_sched
2081         do_nodes $(comma_list $(mdts_nodes)) \
2082                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2083         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
2084         wait $PID2 ; [ $? -eq 0 ] || error "stat must succeed"
2085         rm -rf $DIR/$tdir
2086 }
2087 run_test 42g "pdirops: mkdir vs getattr =============="
2088
2089 test_42h() {
2090         pdo_lru_clear
2091 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2092         do_nodes $(comma_list $(mdts_nodes)) \
2093                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2094         mkdir $DIR1/$tfile &
2095         PID1=$! ; pdo_sched
2096         ls -lia $DIR2/ > /dev/null &
2097         PID2=$! ; pdo_sched
2098         do_nodes $(comma_list $(mdts_nodes)) \
2099                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2100         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
2101         wait $PID2
2102         rm -rf $DIR/$tfile*
2103         return 0
2104 }
2105 run_test 42h "pdirops: mkdir vs readdir =============="
2106
2107 # test 43: rmdir,mkdir won't return -EEXIST
2108 test_43a() {
2109         for i in {1..1000}; do
2110                 mkdir $DIR1/$tdir || error "mkdir $tdir failed"
2111                 rmdir $DIR2/$tdir || error "rmdir $tdir failed"
2112         done
2113         return 0
2114 }
2115 run_test 43a "rmdir,mkdir doesn't return -EEXIST =============="
2116
2117 test_43b() {
2118         pdo_lru_clear
2119         touch $DIR1/$tfile
2120 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2121         do_nodes $(comma_list $(mdts_nodes)) \
2122                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2123         rm $DIR1/$tfile &
2124         PID1=$! ; pdo_sched
2125         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
2126         PID2=$! ; pdo_sched
2127         do_nodes $(comma_list $(mdts_nodes)) \
2128                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2129         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
2130         wait $PID2 ; [ $? -eq 0 ] || error "create must succeed"
2131         rm -rf $DIR/$tfile*
2132         return 0
2133 }
2134 run_test 43b "pdirops: unlink vs create =============="
2135
2136 test_43c() {
2137         pdo_lru_clear
2138         touch $DIR1/$tfile
2139         touch $DIR1/$tfile-2
2140 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2141         do_nodes $(comma_list $(mdts_nodes)) \
2142                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2143         rm $DIR1/$tfile &
2144         PID1=$! ; pdo_sched
2145         link $DIR2/$tfile-2 $DIR2/$tfile &
2146         PID2=$! ; pdo_sched
2147         do_nodes $(comma_list $(mdts_nodes)) \
2148                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2149         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2150         wait $PID2 ; [ $? -eq 0 ] || error "link must succeed"
2151         rm -rf $DIR/$tfile*
2152         return 0
2153 }
2154 run_test 43c "pdirops: unlink vs link =============="
2155
2156 test_43d() {
2157         pdo_lru_clear
2158         touch $DIR1/$tfile
2159 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2160         do_nodes $(comma_list $(mdts_nodes)) \
2161                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2162         rm $DIR1/$tfile &
2163         PID1=$! ; pdo_sched
2164         rm $DIR2/$tfile &
2165         PID2=$! ; pdo_sched
2166         do_nodes $(comma_list $(mdts_nodes)) \
2167                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2168         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
2169         wait $PID2 ; [ $? -ne 0 ] || error "unlink must fail"
2170         rm -rf $DIR/$tfile*
2171         return 0
2172 }
2173 run_test 43d "pdirops: unlink vs unlink =============="
2174
2175 test_43e() {
2176         pdo_lru_clear
2177         touch $DIR1/$tfile
2178         touch $DIR1/$tfile-2
2179 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2180         do_nodes $(comma_list $(mdts_nodes)) \
2181                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2182         rm $DIR1/$tfile &
2183         PID1=$! ; pdo_sched
2184         mv -u $DIR2/$tfile-2 $DIR2/$tfile &
2185         PID2=$! ; pdo_sched
2186         do_nodes $(comma_list $(mdts_nodes)) \
2187                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2188         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2189         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
2190         rm -rf $DIR/$tfile*
2191         return 0
2192 }
2193 run_test 43e "pdirops: unlink and rename (tgt) =============="
2194
2195 test_43f() {
2196         pdo_lru_clear
2197         touch $DIR1/$tfile
2198 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2199         do_nodes $(comma_list $(mdts_nodes)) \
2200                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2201         rm $DIR1/$tfile &
2202         PID1=$! ; pdo_sched
2203         mv $DIR2/$tfile $DIR2/$tfile-2 &
2204         PID2=$! ; pdo_sched
2205         do_nodes $(comma_list $(mdts_nodes)) \
2206                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2207         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2208         wait $PID2 ; [ $? -ne 0 ] || error "rename must fail"
2209         rm -rf $DIR/$tfile*
2210         return 0
2211 }
2212 run_test 43f "pdirops: unlink and rename (src) =============="
2213
2214 test_43g() {
2215         pdo_lru_clear
2216         touch $DIR1/$tfile
2217 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2218         do_nodes $(comma_list $(mdts_nodes)) \
2219                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2220         rm $DIR1/$tfile &
2221         PID1=$! ; pdo_sched
2222         stat $DIR2/$tfile > /dev/null &
2223         PID2=$! ; pdo_sched
2224         do_nodes $(comma_list $(mdts_nodes)) \
2225                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2226         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
2227         wait $PID2 ; [ $? -ne 0 ] || error "stat must fail"
2228         rm -rf $DIR/$tfile*
2229         return 0
2230 }
2231 run_test 43g "pdirops: unlink vs getattr =============="
2232
2233 test_43h() {
2234         pdo_lru_clear
2235         touch $DIR1/$tfile
2236 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2237         do_nodes $(comma_list $(mdts_nodes)) \
2238                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2239         rm $DIR1/$tfile &
2240         PID1=$! ; pdo_sched
2241         ls -lia $DIR2/ > /dev/null &
2242         PID2=$! ; pdo_sched
2243         do_nodes $(comma_list $(mdts_nodes)) \
2244                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2245         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
2246         wait $PID2
2247         rm -rf $DIR/$tfile*
2248         return 0
2249 }
2250 run_test 43h "pdirops: unlink vs readdir =============="
2251
2252 test_43i() {
2253         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2254         pdo_lru_clear
2255         touch $DIR1/$tfile
2256 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2257         do_nodes $(comma_list $(mdts_nodes)) \
2258                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2259         rm $DIR1/$tfile &
2260         PID1=$! ; pdo_sched
2261         $LFS mkdir -i 1 $DIR2/$tfile &
2262         PID2=$! ; pdo_sched
2263         do_nodes $(comma_list $(mdts_nodes)) \
2264                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2265         check_pdo_conflict $PID1 &&
2266                 { wait $PID1; error "remote mkdir isn't blocked"; }
2267         wait $PID2 ; [ $? -eq 0 ] || error "remote mkdir must succeed"
2268         rm -rf $DIR/$tfile*
2269         return 0
2270 }
2271 run_test 43i "pdirops: unlink vs remote mkdir"
2272
2273 test_43j() {
2274         [[ $MDS1_VERSION -lt $(version_code 2.13.52) ]] &&
2275                 skip "Need MDS version newer than 2.13.52"
2276
2277         mkdir_on_mdt0 $DIR1/$tdir
2278         for i in {1..100}; do
2279 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_CREATE_RACE         0x167
2280                 do_nodes $(comma_list $(mdts_nodes)) \
2281                         "lctl set_param -n fail_loc=0x80000167 2>/dev/null ||
2282                                 true"
2283                 OK=0
2284                 mkdir $DIR1/$tdir/sub &
2285                 PID1=$!
2286                 mkdir $DIR2/$tdir/sub && ((OK++))
2287                 wait $PID1 && ((OK++))
2288                 (( OK == 1 )) || error "exactly one mkdir should succeed"
2289
2290                 rmdir $DIR1/$tdir/sub || error "rmdir failed"
2291         done
2292         return 0
2293 }
2294 run_test 43j "racy mkdir return EEXIST =============="
2295
2296 sub_test_43k() {
2297         local PID1 PID2
2298         local fail_loc="$1"
2299         local ret=0
2300
2301         # We test in a separate directory to be able to unblock server thread in
2302         # cfs_race() if LCK_PW is taken on the parent by mdt_reint_unlink.
2303         test_mkdir $DIR2/$tdir
2304         touch $DIR2/$tdir/$tfile
2305         pdo_lru_clear
2306
2307         do_nodes $(comma_list $(mdts_nodes)) \
2308                 "lctl set_param -n fail_loc=${fail_loc} || true" &>/dev/null
2309         echo content > $DIR1/$tdir/$tfile & PID1=$!
2310         pdo_sched
2311         multiop $DIR2/$tdir/$tfile u & PID2=$!
2312
2313         wait $PID1 ||
2314                 { ret=$?; \
2315                 echo -n "overwriting $tfile should succeed (err=$ret); "; }
2316         wait $PID2 ||
2317                 { ret=$?; \
2318                 echo -n "unlinking $tfile should succeed (err=$ret);"; }
2319
2320         #Clean
2321         do_nodes $(comma_list $(mdts_nodes)) \
2322                 "lctl set_param -n fail_loc=0x0 || true" &>/dev/null
2323         rm -rf $DIR/$tdir
2324
2325         return $ret
2326 }
2327
2328 test_43k() {
2329         (( $MDS1_VERSION >= $(version_code 2.13.56) )) ||
2330                 skip "Need MDS version newer than 2.13.56"
2331         local msg fail_loc
2332
2333 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_REINT_OPEN         0x169
2334 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_REINT_OPEN2        0x16a
2335         for fail_loc in "0x80000169" "0x8000016a"; do
2336                 echo "Begin 100 tests with fail_loc=$fail_loc"
2337                 printf "Progress: "
2338                 for i in {1..100}; do
2339                         printf "*"
2340                         msg=$(sub_test_43k "$fail_loc") ||
2341                                 { echo; error "iter=$i : $msg"; }
2342                 done
2343                 echo
2344         done
2345
2346         #Clean
2347         reset_fail_loc
2348
2349         return 0
2350 }
2351 run_test 43k "unlink vs create"
2352
2353 # test 44: rename tgt and blocking operations
2354 test_44a() {
2355         pdo_lru_clear
2356         touch $DIR1/$tfile-2
2357 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
2358         do_nodes $(comma_list $(mdts_nodes)) \
2359                 "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
2360         mv $DIR1/$tfile-2 $DIR1/$tfile &
2361         PID1=$! ; pdo_sched
2362         mkdir $DIR2/$tfile &
2363         PID2=$! ; pdo_sched
2364         do_nodes $(comma_list $(mdts_nodes)) \
2365                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2366         check_pdo_conflict $PID1 && { wait $PID1; date;error "mkdir isn't blocked"; }
2367         wait $PID2 ; [ $? -ne 0 ] || error "mkdir must fail"
2368         date
2369         rm -rf $DIR/$tfile*
2370         return 0
2371 }
2372 run_test 44a "pdirops: rename tgt vs mkdir =============="
2373
2374 test_44b() {
2375         pdo_lru_clear
2376         touch $DIR1/$tfile-2
2377 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2378         do_nodes $(comma_list $(mdts_nodes)) \
2379                 "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
2380         mv $DIR1/$tfile-2 $DIR1/$tfile &
2381         PID1=$! ; pdo_sched
2382         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
2383         PID2=$! ; pdo_sched
2384         do_nodes $(comma_list $(mdts_nodes)) \
2385                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2386         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
2387         wait $PID2 ; [ $? -ne 0 ] || error "create must fail"
2388         rm -rf $DIR/$tfile*
2389         return 0
2390 }
2391 run_test 44b "pdirops: rename tgt vs create =============="
2392
2393 test_44c() {
2394         pdo_lru_clear
2395         touch $DIR1/$tfile-2
2396         touch $DIR1/$tfile-3
2397 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2398         do_nodes $(comma_list $(mdts_nodes)) \
2399                 "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
2400         mv $DIR1/$tfile-2 $DIR1/$tfile &
2401         PID1=$! ; pdo_sched
2402         link $DIR2/$tfile-3 $DIR2/$tfile &
2403         PID2=$! ; pdo_sched
2404         do_nodes $(comma_list $(mdts_nodes)) \
2405                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2406         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2407         wait $PID2 ; [ $? -ne 0 ] || error "link must fail"
2408         rm -rf $DIR/$tfile*
2409         return 0
2410 }
2411 run_test 44c "pdirops: rename tgt vs link =============="
2412
2413 test_44d() {
2414         pdo_lru_clear
2415         touch $DIR1/$tfile-2
2416 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2417         do_nodes $(comma_list $(mdts_nodes)) \
2418                 "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
2419         mv $DIR1/$tfile-2 $DIR1/$tfile &
2420         PID1=$! ; pdo_sched
2421         rm $DIR2/$tfile &
2422         PID2=$! ; pdo_sched
2423         do_nodes $(comma_list $(mdts_nodes)) \
2424                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2425         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
2426         wait $PID2 ; [ $? -eq 0 ] || error "unlink must succeed"
2427         rm -rf $DIR/$tfile*
2428         return 0
2429 }
2430 run_test 44d "pdirops: rename tgt vs unlink =============="
2431
2432 test_44e() {
2433         pdo_lru_clear
2434         touch $DIR1/$tfile
2435         touch $DIR1/$tfile-2
2436         touch $DIR1/$tfile-3
2437 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2438         do_nodes $(comma_list $(mdts_nodes)) \
2439                 "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
2440         mv $DIR1/$tfile-2 $DIR1/$tfile &
2441         PID1=$! ; pdo_sched
2442         mv $DIR2/$tfile-3 $DIR2/$tfile &
2443         PID2=$! ; pdo_sched
2444         do_nodes $(comma_list $(mdts_nodes)) \
2445                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2446         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2447         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
2448         rm -rf $DIR/$tfile*
2449         return 0
2450 }
2451 run_test 44e "pdirops: rename tgt and rename (tgt) =============="
2452
2453 test_44f() {
2454         pdo_lru_clear
2455         touch $DIR1/$tfile-2
2456         touch $DIR1/$tfile-3
2457 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2458         do_nodes $(comma_list $(mdts_nodes)) \
2459                 "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
2460         mv $DIR1/$tfile-2 $DIR1/$tfile &
2461         PID1=$! ; pdo_sched
2462         mv $DIR2/$tfile $DIR2/$tfile-3 &
2463         PID2=$! ; pdo_sched
2464         do_nodes $(comma_list $(mdts_nodes)) \
2465                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2466         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2467         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
2468         rm -rf $DIR/$tfile*
2469         return 0
2470 }
2471 run_test 44f "pdirops: rename tgt and rename (src) =============="
2472
2473 test_44g() {
2474         pdo_lru_clear
2475         touch $DIR1/$tfile-2
2476 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2477         do_nodes $(comma_list $(mdts_nodes)) \
2478                 "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
2479         mv $DIR1/$tfile-2 $DIR1/$tfile &
2480         PID1=$! ; pdo_sched
2481         stat $DIR2/$tfile > /dev/null &
2482         PID2=$! ; pdo_sched
2483         do_nodes $(comma_list $(mdts_nodes)) \
2484                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2485         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
2486         wait $PID2 ; [ $? -eq 0 ] || error "stat must succeed"
2487         rm -rf $DIR/$tfile*
2488         return 0
2489 }
2490 run_test 44g "pdirops: rename tgt vs getattr =============="
2491
2492 test_44h() {
2493         pdo_lru_clear
2494         touch $DIR1/$tfile-2
2495 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2    0x146
2496         do_nodes $(comma_list $(mdts_nodes)) \
2497                 "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
2498         mv $DIR1/$tfile-2 $DIR1/$tfile &
2499         PID1=$! ; pdo_sched
2500         ls -lia $DIR2/ > /dev/null &
2501         PID2=$! ; pdo_sched
2502         do_nodes $(comma_list $(mdts_nodes)) \
2503                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2504         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
2505         wait $PID2
2506         rm -rf $DIR/$tfile*
2507         return 0
2508 }
2509 run_test 44h "pdirops: rename tgt vs readdir =============="
2510
2511 # test 44: rename tgt and blocking operations
2512 test_44i() {
2513         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2514         pdo_lru_clear
2515         touch $DIR1/$tfile-2
2516 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK2   0x146
2517         do_nodes $(comma_list $(mdts_nodes)) \
2518                 "lctl set_param -n fail_loc=0x80000146 2>/dev/null || true"
2519         mv $DIR1/$tfile-2 $DIR1/$tfile &
2520         PID1=$! ; pdo_sched
2521         $LFS mkdir -i 1 $DIR2/$tfile &
2522         PID2=$! ; pdo_sched
2523         do_nodes $(comma_list $(mdts_nodes)) \
2524                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2525         check_pdo_conflict $PID1 && { wait $PID1;
2526                                 error "remote mkdir isn't blocked"; }
2527         wait $PID2 ; [ $? -ne 0 ] || error "remote mkdir must fail"
2528         rm -rf $DIR/$tfile*
2529         return 0
2530 }
2531 run_test 44i "pdirops: rename tgt vs remote mkdir"
2532
2533 # test 45: rename,mkdir doesn't fail with -EEXIST
2534 test_45a() {
2535         for i in {1..1000}; do
2536                 mkdir $DIR1/$tdir || error "mkdir $tdir failed"
2537                 mrename $DIR2/$tdir $DIR2/$tdir.$i > /dev/null ||
2538                         error "mrename to $tdir.$i failed"
2539         done
2540         rm -rf $DIR/$tdir*
2541         return 0
2542 }
2543 run_test 45a "rename,mkdir doesn't return -EEXIST =============="
2544
2545 test_45b() {
2546         pdo_lru_clear
2547         touch $DIR1/$tfile
2548 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2549         do_nodes $(comma_list $(mdts_nodes)) \
2550                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2551         mv $DIR1/$tfile $DIR1/$tfile-2 &
2552         PID1=$! ; pdo_sched
2553         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
2554         PID2=$! ; pdo_sched
2555         do_nodes $(comma_list $(mdts_nodes)) \
2556                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2557         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
2558         wait $PID2 ; [ $? -eq 0 ] || error "create must succeed"
2559         rm -rf $DIR/$tfile*
2560         return 0
2561 }
2562 run_test 45b "pdirops: rename src vs create =============="
2563
2564 test_45c() {
2565         pdo_lru_clear
2566         touch $DIR1/$tfile
2567         touch $DIR1/$tfile-3
2568 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2569         do_nodes $(comma_list $(mdts_nodes)) \
2570                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2571         mv $DIR1/$tfile $DIR1/$tfile-2 &
2572         PID1=$! ; pdo_sched
2573         link $DIR2/$tfile-3 $DIR2/$tfile &
2574         PID2=$! ; pdo_sched
2575         do_nodes $(comma_list $(mdts_nodes)) \
2576                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2577         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2578         wait $PID2 ; [ $? -eq 0 ] || error "link must succeed"
2579         rm -rf $DIR/$tfile*
2580         return 0
2581 }
2582 run_test 45c "pdirops: rename src vs link =============="
2583
2584 test_45d() {
2585         pdo_lru_clear
2586         touch $DIR1/$tfile
2587 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2588         do_nodes $(comma_list $(mdts_nodes)) \
2589                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2590         mv $DIR1/$tfile $DIR1/$tfile-2 &
2591         PID1=$! ; pdo_sched
2592         rm $DIR2/$tfile &
2593         PID2=$! ; pdo_sched
2594         do_nodes $(comma_list $(mdts_nodes)) \
2595                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2596         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
2597         wait $PID2 ; [ $? -ne 0 ] || error "unlink must fail"
2598         rm -rf $DIR/$tfile*
2599         return 0
2600 }
2601 run_test 45d "pdirops: rename src vs unlink =============="
2602
2603 test_45e() {
2604         pdo_lru_clear
2605         touch $DIR1/$tfile
2606         touch $DIR1/$tfile-3
2607 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2608         do_nodes $(comma_list $(mdts_nodes)) \
2609                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2610         mv $DIR1/$tfile $DIR1/$tfile-2 &
2611         PID1=$! ; pdo_sched
2612         mv $DIR2/$tfile-3 $DIR2/$tfile &
2613         PID2=$! ; pdo_sched
2614         do_nodes $(comma_list $(mdts_nodes)) \
2615                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2616         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2617         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
2618         rm -rf $DIR/$tfile*
2619         return 0
2620 }
2621 run_test 45e "pdirops: rename src and rename (tgt) =============="
2622
2623 test_45f() {
2624         pdo_lru_clear
2625         touch $DIR1/$tfile
2626 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2627         do_nodes $(comma_list $(mdts_nodes)) \
2628                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2629         mv $DIR1/$tfile $DIR1/$tfile-2 &
2630         PID1=$! ; pdo_sched
2631         mv $DIR2/$tfile $DIR2/$tfile-3 &
2632         PID2=$! ; pdo_sched
2633         do_nodes $(comma_list $(mdts_nodes)) \
2634                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2635         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2636         wait $PID2 ; [ $? -ne 0 ] || error "rename must fail"
2637         rm -rf $DIR/$tfile*
2638         return 0
2639 }
2640 run_test 45f "pdirops: rename src and rename (src) =============="
2641
2642 test_45g() {
2643         pdo_lru_clear
2644         touch $DIR1/$tfile
2645 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2646         do_nodes $(comma_list $(mdts_nodes)) \
2647                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2648         mv $DIR1/$tfile $DIR1/$tfile-2 &
2649         PID1=$! ; pdo_sched
2650         stat $DIR2/$tfile > /dev/null &
2651         PID2=$! ; pdo_sched
2652         do_nodes $(comma_list $(mdts_nodes)) \
2653                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2654         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
2655         wait $PID2 ; [ $? -ne 0 ] || error "stat must fail"
2656         rm -rf $DIR/$tfile*
2657         return 0
2658 }
2659 run_test 45g "pdirops: rename src vs getattr =============="
2660
2661 test_45h() {
2662         pdo_lru_clear
2663         touch $DIR1/$tfile
2664 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2665         do_nodes $(comma_list $(mdts_nodes)) \
2666                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2667         mv $DIR1/$tfile $DIR1/$tfile-2 &
2668         PID1=$! ; pdo_sched
2669         ls -lia $DIR2/ > /dev/null &
2670         do_nodes $(comma_list $(mdts_nodes)) \
2671                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2672         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
2673         wait $PID2
2674         rm -rf $DIR/$tfile*
2675         return 0
2676 }
2677 run_test 45h "pdirops: unlink vs readdir =============="
2678
2679 test_45i() {
2680         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2681         pdo_lru_clear
2682         touch $DIR1/$tfile
2683 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2684         do_nodes $(comma_list $(mdts_nodes)) \
2685                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2686         mv $DIR1/$tfile $DIR1/$tfile-2 &
2687         PID1=$! ; pdo_sched
2688         $LFS mkdir -i 1 $DIR2/$tfile &
2689         PID2=$! ; pdo_sched
2690         do_nodes $(comma_list $(mdts_nodes)) \
2691                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2692         check_pdo_conflict $PID1 && { wait $PID1;
2693                                 error "create remote dir isn't blocked"; }
2694         wait $PID2 ; [ $? -eq 0 ] || error "create remote dir must succeed"
2695         rm -rf $DIR/$tfile*
2696         return 0
2697 }
2698 run_test 45i "pdirops: rename src vs remote mkdir"
2699
2700 sub_test_45j() {
2701         local PID1 PID2
2702         local fail_loc="$1"
2703         local ret=0
2704
2705         # We test in a sparate directory to be able to unblock server thread in
2706         # cfs_race if LCK_PW is taken on the parent by mdt_reint_rename.
2707         test_mkdir $DIR2/$tdir
2708         echo file1 > $DIR2/$tdir/$tfile
2709         echo file2 > $DIR2/$tdir/$tfile-2
2710         pdo_lru_clear
2711
2712         do_nodes $(comma_list $(mdts_nodes)) \
2713                 "lctl set_param -n fail_loc=${fail_loc} || true" &>/dev/null
2714
2715         cat $DIR1/$tdir/$tfile >/dev/null &
2716         PID1=$!
2717         pdo_sched
2718         mrename $DIR2/$tdir/$tfile-2 $DIR2/$tdir/$tfile > /dev/null &
2719         PID2=$!
2720
2721         wait $PID1 ||
2722                 { ret=$?; echo -n "cat $tfile should succeed (err=$ret); "; }
2723         wait $PID2 ||
2724                 { ret=$?; \
2725                 echo -n "mrename $tfile-2 to $tfile failed (err=$ret);"; }
2726
2727         #Clean
2728         do_nodes $(comma_list $(mdts_nodes)) \
2729                 "lctl set_param -n fail_loc=0x0 || true" &>/dev/null
2730         rm -rf $DIR/$tdir
2731
2732         return $ret
2733 }
2734
2735 test_45j() {
2736         (( $MDS1_VERSION >= $(version_code 2.13.56) )) ||
2737                 skip "Need MDS version newer than 2.13.56"
2738         local msg fail_loc
2739
2740 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_REINT_OPEN         0x169
2741 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_REINT_OPEN2        0x16a
2742         for fail_loc in "0x80000169" "0x8000016a"; do
2743                 echo "Begin 100 tests with fail_loc=$fail_loc"
2744                 printf "Progress: "
2745                 for i in {1..100}; do
2746                         printf "*"
2747                         msg=$(sub_test_45j "$fail_loc") ||
2748                                 { echo; error "iter=$i : $msg"; }
2749                 done
2750                 echo
2751         done
2752 }
2753 run_test 45j "read vs rename =============="
2754
2755 # test 46: link and blocking operations
2756 test_46a() {
2757         pdo_lru_clear
2758         touch $DIR1/$tfile-2
2759 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2760         do_nodes $(comma_list $(mdts_nodes)) \
2761                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2762         link $DIR1/$tfile-2 $DIR1/$tfile &
2763         PID1=$! ; pdo_sched
2764         mkdir $DIR2/$tfile &
2765         PID2=$! ; pdo_sched
2766         do_nodes $(comma_list $(mdts_nodes)) \
2767                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2768         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
2769         wait $PID2 ; [ $? -ne 0 ] || error "mkdir must fail"
2770         rm -rf $DIR/$tfile*
2771         return 0
2772 }
2773 run_test 46a "pdirops: link vs mkdir =============="
2774
2775 test_46b() {
2776         pdo_lru_clear
2777         touch $DIR1/$tfile-2
2778 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2779         do_nodes $(comma_list $(mdts_nodes)) \
2780                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2781         link $DIR1/$tfile-2 $DIR1/$tfile &
2782         PID1=$! ; pdo_sched
2783         $MULTIOP $DIR2/$tfile oO_CREAT:O_EXCL:c &
2784         PID2=$! ; pdo_sched
2785         do_nodes $(comma_list $(mdts_nodes)) \
2786                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2787         check_pdo_conflict $PID1 && { wait $PID1; error "create isn't blocked"; }
2788         wait $PID2 ; [ $? -ne 0 ] || error "create must fail"
2789         rm -rf $DIR/$tfile*
2790         return 0
2791 }
2792 run_test 46b "pdirops: link vs create =============="
2793
2794 test_46c() {
2795         pdo_lru_clear
2796         touch $DIR1/$tfile-2
2797 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2798         do_nodes $(comma_list $(mdts_nodes)) \
2799                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2800         link $DIR1/$tfile-2 $DIR1/$tfile &
2801         PID1=$! ; pdo_sched
2802         link $DIR2/$tfile $DIR2/$tfile &
2803         PID2=$! ; pdo_sched
2804         do_nodes $(comma_list $(mdts_nodes)) \
2805                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2806         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2807         wait $PID2 ; [ $? -ne 0 ] || error "link must fail"
2808         rm -rf $DIR/$tfile*
2809         return 0
2810 }
2811 run_test 46c "pdirops: link vs link =============="
2812
2813 test_46d() {
2814         pdo_lru_clear
2815         touch $DIR1/$tfile-2
2816 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2817         do_nodes $(comma_list $(mdts_nodes)) \
2818                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2819         link $DIR1/$tfile-2 $DIR1/$tfile &
2820         PID1=$! ; pdo_sched
2821         rm $DIR2/$tfile &
2822         PID2=$! ; pdo_sched
2823         do_nodes $(comma_list $(mdts_nodes)) \
2824                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2825         check_pdo_conflict $PID1 && { wait $PID1; error "unlink isn't blocked"; }
2826         wait $PID2 ; [ $? -eq 0 ] || error "unlink must succeed"
2827         rm -rf $DIR/$tfile*
2828         return 0
2829 }
2830 run_test 46d "pdirops: link vs unlink =============="
2831
2832 test_46e() {
2833         pdo_lru_clear
2834         touch $DIR1/$tfile-2
2835         touch $DIR1/$tfile-3
2836 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2837         do_nodes $(comma_list $(mdts_nodes)) \
2838                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2839         link $DIR1/$tfile-2 $DIR1/$tfile &
2840         PID1=$! ; pdo_sched
2841         mv $DIR2/$tfile-3 $DIR2/$tfile &
2842         PID2=$! ; pdo_sched
2843         do_nodes $(comma_list $(mdts_nodes)) \
2844                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2845         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2846         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
2847         rm -rf $DIR/$tfile*
2848         return 0
2849 }
2850 run_test 46e "pdirops: link and rename (tgt) =============="
2851
2852 test_46f() {
2853         pdo_lru_clear
2854         touch $DIR1/$tfile-2
2855         touch $DIR1/$tfile-3
2856 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2857         do_nodes $(comma_list $(mdts_nodes)) \
2858                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2859         link $DIR1/$tfile-2 $DIR1/$tfile &
2860         PID1=$! ; pdo_sched
2861         mv $DIR2/$tfile $DIR2/$tfile-3 &
2862         PID2=$! ; pdo_sched
2863         do_nodes $(comma_list $(mdts_nodes)) \
2864                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2865         check_pdo_conflict $PID1 && { wait $PID1; error "rename isn't blocked"; }
2866         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
2867         rm -rf $DIR/$tfile*
2868         return 0
2869 }
2870 run_test 46f "pdirops: link and rename (src) =============="
2871
2872 test_46g() {
2873         pdo_lru_clear
2874         touch $DIR1/$tfile-2
2875 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2876         do_nodes $(comma_list $(mdts_nodes)) \
2877                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2878         link $DIR1/$tfile-2 $DIR1/$tfile &
2879         PID1=$! ; pdo_sched
2880         stat $DIR2/$tfile > /dev/null &
2881         PID2=$! ; pdo_sched
2882         do_nodes $(comma_list $(mdts_nodes)) \
2883                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2884         check_pdo_conflict $PID1 && { wait $PID1; error "getattr isn't blocked"; }
2885         wait $PID2 ; [ $? -eq 0 ] || error "stat must succeed"
2886         rm -rf $DIR/$tfile*
2887         return 0
2888 }
2889 run_test 46g "pdirops: link vs getattr =============="
2890
2891 test_46h() {
2892         pdo_lru_clear
2893         touch $DIR1/$tfile-2
2894 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2895         do_nodes $(comma_list $(mdts_nodes)) \
2896                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2897         link $DIR1/$tfile-2 $DIR1/$tfile &
2898         PID1=$! ; pdo_sched
2899         ls -lia $DIR2/ > /dev/null &
2900         PID2=$! ; pdo_sched
2901         do_nodes $(comma_list $(mdts_nodes)) \
2902                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2903         check_pdo_conflict $PID1 && { wait $PID1; error "readdir isn't blocked"; }
2904         wait $PID2
2905         rm -rf $DIR/$tfile*
2906         return 0
2907 }
2908 run_test 46h "pdirops: link vs readdir =============="
2909
2910 test_46i() {
2911         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2912         pdo_lru_clear
2913         touch $DIR1/$tfile-2
2914 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2915         do_nodes $(comma_list $(mdts_nodes)) \
2916                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2917         link $DIR1/$tfile-2 $DIR1/$tfile &
2918         PID1=$! ; pdo_sched
2919         $LFS mkdir -i 1 $DIR2/$tfile &
2920         PID2=$! ; pdo_sched
2921         do_nodes $(comma_list $(mdts_nodes)) \
2922                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2923         check_pdo_conflict $PID1 && { wait $PID1;
2924                                 error "remote mkdir isn't blocked"; }
2925         wait $PID2 ; [ $? -ne 0 ] || error "remote mkdir must fail"
2926         rm -rf $DIR/$tfile*
2927         return 0
2928 }
2929 run_test 46i "pdirops: link vs remote mkdir"
2930
2931 # test 47: remote mkdir and blocking operations
2932 test_47a() {
2933 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2934         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2935         pdo_lru_clear
2936         do_nodes $(comma_list $(mdts_nodes)) \
2937                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2938         $LFS mkdir -i 1 $DIR1/$tfile &
2939         PID1=$! ; pdo_sched
2940         mkdir $DIR2/$tfile &
2941         PID2=$! ; pdo_sched
2942         do_nodes $(comma_list $(mdts_nodes)) \
2943                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2944         check_pdo_conflict $PID1 && { wait $PID1; error "mkdir isn't blocked"; }
2945         wait $PID2 ; [ $? -ne 0 ] || error "mkdir must fail"
2946         rm -rf $DIR/$tfile*
2947         return 0
2948 }
2949 run_test 47a "pdirops: remote mkdir vs mkdir"
2950
2951 test_47b() {
2952 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2953         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2954         pdo_lru_clear
2955         do_nodes $(comma_list $(mdts_nodes)) \
2956                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2957         $LFS mkdir -i 1 $DIR1/$tfile &
2958         PID1=$! ; pdo_sched
2959         sleep 1 # please do not remove this sleep, see LU-10754
2960         multiop $DIR2/$tfile oO_CREAT:O_EXCL:c &
2961         PID2=$! ; pdo_sched
2962         do_nodes $(comma_list $(mdts_nodes)) \
2963                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2964         check_pdo_conflict $PID1 && { wait $PID1;
2965                                         error "create isn't blocked"; }
2966         wait $PID2 ; [ $? -ne 0 ] || error "create must fail"
2967         rm -rf $DIR/$tfile*
2968         return 0
2969 }
2970 run_test 47b "pdirops: remote mkdir vs create"
2971
2972 test_47c() {
2973         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2974         pdo_lru_clear
2975         touch $DIR1/$tfile-2
2976 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2977         do_nodes $(comma_list $(mdts_nodes)) \
2978                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2979         $LFS mkdir -i 1 $DIR1/$tfile &
2980         PID1=$! ; pdo_sched
2981         link $DIR2/$tfile-2 $DIR2/$tfile &
2982         PID2=$! ; pdo_sched
2983         do_nodes $(comma_list $(mdts_nodes)) \
2984                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
2985         check_pdo_conflict $PID1 && { wait $PID1; error "link isn't blocked"; }
2986         wait $PID2 ; [ $? -ne 0 ] || error "link must fail"
2987         rm -rf $DIR/$tfile*
2988         return 0
2989 }
2990 run_test 47c "pdirops: remote mkdir vs link"
2991
2992 test_47d() {
2993         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2994         pdo_lru_clear
2995 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
2996         do_nodes $(comma_list $(mdts_nodes)) \
2997                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
2998         $LFS mkdir -i 1 $DIR1/$tfile &
2999         PID1=$! ; pdo_sched
3000         rmdir $DIR2/$tfile &
3001         PID2=$! ; pdo_sched
3002         do_nodes $(comma_list $(mdts_nodes)) \
3003                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
3004         check_pdo_conflict $PID1 && { wait $PID1;
3005                                         error "unlink isn't blocked"; }
3006         wait $PID2 ; [ $? -eq 0 ] || error "rmdir must succeed"
3007         rm -rf $DIR/$tfile*
3008         return 0
3009 }
3010 run_test 47d "pdirops: remote mkdir vs unlink"
3011
3012 test_47e() {
3013         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3014         pdo_lru_clear
3015         touch $DIR1/$tfile-2
3016 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
3017         do_nodes $(comma_list $(mdts_nodes)) \
3018                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
3019         $LFS mkdir -i 1 $DIR1/$tfile &
3020         PID1=$! ; pdo_sched
3021         mv -T $DIR2/$tfile-2 $DIR2/$tfile &
3022         PID2=$! ; pdo_sched
3023         do_nodes $(comma_list $(mdts_nodes)) \
3024                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
3025         check_pdo_conflict $PID1 && { wait $PID1;
3026                                         error "rename isn't blocked"; }
3027         wait $PID2 ; [ $? -ne 0 ] || error "rename must fail"
3028         rm -rf $DIR/$tfile*
3029         return 0
3030 }
3031 run_test 47e "pdirops: remote mkdir and rename (tgt)"
3032
3033 test_47f() {
3034         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3035         pdo_lru_clear
3036 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
3037         do_nodes $(comma_list $(mdts_nodes)) \
3038                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
3039         $LFS mkdir -i 1 $DIR1/$tfile &
3040         PID1=$! ; pdo_sched
3041         mv $DIR2/$tfile $DIR2/$tfile-2 &
3042         PID2=$! ; pdo_sched
3043         do_nodes $(comma_list $(mdts_nodes)) \
3044                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
3045         check_pdo_conflict $PID1 && { wait $PID1;
3046                                         error "rename isn't blocked"; }
3047         wait $PID2 ; [ $? -eq 0 ] || error "rename must succeed"
3048         rm -rf $DIR/$tfile*
3049         return 0
3050 }
3051 run_test 47f "pdirops: remote mkdir and rename (src)"
3052
3053 test_47g() {
3054         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3055         sync
3056         sync_all_data
3057         pdo_lru_clear
3058 #define OBD_FAIL_ONCE|OBD_FAIL_MDS_PDO_LOCK    0x145
3059         do_nodes $(comma_list $(mdts_nodes)) \
3060                 "lctl set_param -n fail_loc=0x80000145 2>/dev/null || true"
3061         $LFS mkdir -i 1 $DIR1/$tfile &
3062         PID1=$! ; pdo_sched
3063         stat $DIR2/$tfile > /dev/null &
3064         PID2=$! ; pdo_sched
3065         do_nodes $(comma_list $(mdts_nodes)) \
3066                 "lctl set_param -n fail_loc=0 2>/dev/null || true"
3067         check_pdo_conflict $PID1 && { wait $PID1;
3068                                         error "getattr isn't blocked"; }
3069         wait $PID2 ; [ $? -eq 0 ] || error "stat must succeed"
3070         rm -rf $DIR/$tfile*
3071         return 0
3072 }
3073 run_test 47g "pdirops: remote mkdir vs getattr"
3074
3075 test_50() {
3076         trunc_size=4096
3077         dd if=/dev/zero of=$DIR1/$tfile bs=1K count=10
3078 #define OBD_FAIL_OSC_CP_ENQ_RACE         0x410
3079         do_facet client "lctl set_param fail_loc=0x410"
3080         $TRUNCATE $DIR2/$tfile $trunc_size
3081         do_facet client "lctl set_param fail_loc=0x0"
3082         sleep 3
3083         size=`stat -c %s $DIR2/$tfile`
3084         [ $size -eq $trunc_size ] || error "wrong size"
3085 }
3086 run_test 50 "osc lvb attrs: enqueue vs. CP AST =============="
3087
3088 test_51a() {
3089         local filesize
3090         local origfile=/etc/hosts
3091
3092         filesize=$(stat -c %s $origfile)
3093
3094         # create an empty file
3095         $MCREATE $DIR1/$tfile || error "can't create $DIR1/$tfile"
3096         # cache layout lock on both mount point
3097         stat $DIR1/$tfile > /dev/null || error "stat $DIR1/$tfile failed"
3098         stat $DIR2/$tfile > /dev/null || error "stat $DIR2/$tfile failed"
3099
3100         # open and sleep 2 seconds then read
3101         $MULTIOP $DIR2/$tfile o_2r${filesize}c &
3102         local pid=$!
3103         sleep 1
3104
3105         # create the layout of testing file
3106         dd if=$origfile of=$DIR1/$tfile conv=notrunc > /dev/null ||
3107                 error "dd $DIR1/$tfile failed"
3108
3109         # MULTIOP proc should be able to read enough bytes and exit
3110         for ((i = 0; i < 6; i++)); do
3111                 sleep 1
3112                 kill -0 $pid || break
3113         done
3114         kill -0 $pid 2> /dev/null && error "multiop is still there"
3115         cmp $origfile $DIR2/$tfile || error "$origfile and $DIR2/$tfile differs"
3116
3117         rm -f $DIR1/$tfile
3118 }
3119 run_test 51a "layout lock: refresh layout should work"
3120
3121 test_51b() {
3122         (( $MDS1_VERSION >= $(version_code 2.3.59) )) ||
3123                 skip "Need MDS version at least 2.3.59"
3124
3125         local tmpfile=`mktemp`
3126
3127         $LFS setstripe -E 1m -S 1M -c 1 -E -1 -c 1 $DIR1/$tfile ||
3128                 error "Create $DIR1/$tfile failed"
3129
3130         dd if=/dev/zero of=$DIR1/$tfile bs=1k count=1 conv=notrunc ||
3131                 error "dd $DIR1/$tfile failed"
3132
3133         # delay glimpse so that layout has changed when glimpse finish
3134 #define OBD_FAIL_GLIMPSE_DELAY 0x1404
3135         $LCTL set_param fail_loc=0x1404 fail_val=4
3136         stat -c %s $DIR2/$tfile |tee $tmpfile &
3137         local pid=$!
3138         sleep 0.2
3139
3140         # extend layout of testing file
3141         dd if=/dev/zero of=$DIR1/$tfile bs=1M count=1 seek=2 conv=notrunc ||
3142                 error "dd $DIR1/$tfile failed"
3143
3144         wait $pid
3145         local fsize=$(cat $tmpfile)
3146
3147         [ x$fsize = x3145728 ] || error "file size is $fsize, should be 3145728"
3148
3149         rm -f $DIR1/$tfile $tmpfile
3150 }
3151 run_test 51b "layout lock: glimpse should be able to restart if layout changed"
3152
3153 test_51c() {
3154         [ $OSTCOUNT -ge 2 ] || { skip "needs >= 2 osts"; return; }
3155
3156         # set default layout to have 1 stripe
3157         mkdir $DIR1/$tdir
3158         $LFS setstripe -c 1 $DIR1/$tdir
3159
3160         # create a file with empty layout
3161         $MCREATE $DIR1/$tdir/$tfile ||
3162                 error "$MCREATE $DIR1/$tdir/$tfile failed"
3163
3164 #define OBD_FAIL_MDS_LL_BLOCK 0x172
3165         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x172
3166
3167         # change the layout of testing file
3168         echo "Setting layout to have $OSTCOUNT stripes ..."
3169         $LFS setstripe -c $OSTCOUNT $DIR1/$tdir/$tfile &
3170         pid=$!
3171         sleep 1
3172
3173         # write something to the file, it should be blocked on fetching layout
3174         dd if=/dev/zero of=$DIR2/$tdir/$tfile bs=1k count=1 conv=notrunc
3175         local stripe_count=$($LFS getstripe -c $DIR2/$tdir/$tfile)
3176         wait $pid
3177
3178         # lod_qos.c::min_stripe_count() allows setstripe with a default stripe
3179         # count to succeed with only 3/4 of the number of stripes (rounded up),
3180         # so creating striped files does not fail if an OST is offline or full
3181         [ $stripe_count -ge $((OSTCOUNT - $OSTCOUNT / 4)) ] ||
3182                 error "bad layout: getstripe -c $stripe_count < $OSTCOUNT * 3/4"
3183
3184         rm -fr $DIR1/$tdir
3185 }
3186 run_test 51c "layout lock: IT_LAYOUT blocked and correct layout can be returned"
3187
3188 test_51d() {
3189         dd if=/dev/zero of=/$DIR1/$tfile bs=1M count=1
3190         cancel_lru_locks mdc
3191
3192         # open should grant LAYOUT lock, mmap and read will install pages
3193         $MULTIOP $DIR1/$tfile oO_RDWR:SMR_Uc &
3194         local PID=$!
3195         sleep 1
3196
3197         # rss before revoking
3198         local br=$(grep -A 10 $tfile /proc/$PID/smaps | awk '/^Rss/{print $2}')
3199         echo "Before revoking layout lock: $br KB mapped"
3200
3201         # cancel layout lock manually
3202         cancel_lru_locks mdc
3203
3204         # rss after revoking
3205         local ar=$(grep -A 10 $tfile /proc/$PID/smaps | awk '/^Rss/{print $2}')
3206
3207         kill -USR1 $PID
3208         wait $PID || error "wait PID $PID failed"
3209
3210         [ $ar -eq 0 ] || error "rss before: $br, after $ar, some pages remained"
3211 }
3212 run_test 51d "layout lock: losing layout lock should clean up memory map region"
3213
3214 test_51e() {
3215         (( $MDS1_VERSION >= $(version_code 2.13.54.148) )) ||
3216                 skip "MDS version must be at least 2.13.54.148"
3217
3218         local pid
3219
3220         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eW_E+eUc &
3221         pid=$!
3222         sleep 1
3223
3224         $LFS getstripe $DIR2/$tfile
3225         kill -USR1 $pid
3226         wait $pid || error "multiop failed"
3227
3228         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
3229         pid=$!
3230         sleep 1
3231
3232         $LFS getstripe $DIR2/$tfile
3233         kill -USR1 $pid
3234         wait $pid || error "multiop failed"
3235 }
3236 run_test 51e "lfs getstripe does not break leases, part 2"
3237
3238 test_54_part1()
3239 {
3240         echo "==> rename vs getattr vs setxattr should not deadlock"
3241         mkdir -p $DIR/d1/d2/d3 || error "(1) mkdir failed"
3242
3243         do_facet mds1 $LCTL set_param fail_loc=$1
3244
3245         mv -T $DIR/d1/d2/d3 $DIR/d1/d3 &
3246         PID1=$!
3247         sleep 1
3248
3249         stat $DIR/d1/d2 &
3250         PID2=$!
3251         sleep 1
3252
3253         setfattr -n user.attr1 -v value1 $DIR2/d1 || error "(2) setfattr failed"
3254         wait $PID1 || error "(3) mv failed"
3255         wait $PID2 || error "(4) stat failed"
3256         echo
3257
3258         rm -rf $DIR/d1
3259 }
3260
3261 test_54_part2() {
3262         echo "==> rename vs getattr vs open vs getattr should not deadlock"
3263         mkdir -p $DIR/d1/d2/d3 || error "(1) mkdir failed"
3264
3265         do_facet mds1 $LCTL set_param fail_loc=$1
3266
3267         mv -T $DIR/d1/d2/d3 $DIR/d1/d3 &
3268         PID1=$!
3269         sleep 1
3270
3271         stat $DIR/d1/d2 &
3272         PID2=$!
3273         sleep 1
3274
3275         $MULTIOP $DIR2/d1/d2 Oc &
3276         PID3=$!
3277         sleep 1
3278
3279         stat $DIR/d1 || error "(2) stat failed"
3280
3281         wait $PID1 || error "(3) mv failed"
3282         wait $PID2 || error "(4) stat failed"
3283         wait $PID3 && error "(5) multiop failed"
3284         echo
3285         rm -rf $DIR/d1
3286 }
3287
3288 test_54() {
3289         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
3290         save_lustre_params client "llite.*.xattr_cache" > $p
3291         lctl set_param llite.*.xattr_cache 1 ||
3292                 { skip "xattr cache is not supported"; return 0; }
3293
3294 #define OBD_FAIL_MDS_RENAME              0x153
3295 #define OBD_FAIL_MDS_RENAME2             0x154
3296         test_54_part1 0x80000153 || error 10
3297         test_54_part1 0x80000154 || error 11
3298         test_54_part2 0x80000153 || error 12
3299         test_54_part2 0x80000154 || error 13
3300
3301         restore_lustre_params < $p
3302         rm -f $p
3303 }
3304 run_test 54 "rename locking"
3305
3306 test_55a() {
3307         mkdir_on_mdt0 $DIR/$tdir
3308         mkdir -p $DIR/$tdir/d1/d2 $DIR/$tdir/d3 || error "(1) mkdir failed"
3309
3310 #define OBD_FAIL_MDS_RENAME4              0x156
3311         do_facet mds1 $LCTL set_param fail_loc=0x80000156
3312
3313         mv -T $DIR/$tdir/d1/d2 $DIR/$tdir/d3/d2 &
3314         PID1=$!
3315         sleep 1
3316
3317         rm -r $DIR2/$tdir/d3
3318         wait $PID1 && error "(2) mv succeeded"
3319
3320         rm -rf $DIR/$tdir
3321 }
3322 run_test 55a "rename vs unlink target dir"
3323
3324 test_55b()
3325 {
3326         mkdir_on_mdt0 $DIR/$tdir
3327         mkdir -p $DIR/$tdir/d1/d2 $DIR/$tdir/d3 || error "(1) mkdir failed"
3328
3329 #define OBD_FAIL_MDS_RENAME4             0x156
3330         do_facet mds1 $LCTL set_param fail_loc=0x80000156
3331
3332         mv -T $DIR/$tdir/d1/d2 $DIR/$tdir/d3/d2 &
3333         PID1=$!
3334         sleep 1
3335
3336         rm -r $DIR2/$tdir/d1
3337         wait $PID1 && error "(2) mv succeeded"
3338
3339         rm -rf $DIR/$tdir
3340 }
3341 run_test 55b "rename vs unlink source dir"
3342
3343 test_55c()
3344 {
3345         mkdir_on_mdt0 $DIR/$tdir
3346         mkdir -p $DIR/$tdir/d1/d2 $DIR/$tdir/d3 || error "(1) mkdir failed"
3347
3348 #define OBD_FAIL_MDS_RENAME4              0x156
3349         do_facet mds1 $LCTL set_param fail_loc=0x156
3350
3351         mv -T $DIR/$tdir/d1/d2 $DIR/$tdir/d3/d2 &
3352         PID1=$!
3353         sleep 1
3354
3355         # while rename is sleeping, open and remove d3
3356         $MULTIOP $DIR2/$tdir/d3 D_c &
3357         PID2=$!
3358         sleep 1
3359         rm -rf $DIR2/$tdir/d3
3360         sleep 5
3361
3362         # while rename is sleeping 2nd time, close d3
3363         kill -USR1 $PID2
3364         wait $PID2 || error "(3) multiop failed"
3365
3366         wait $PID1 && error "(2) mv succeeded"
3367
3368         rm -rf $DIR/$tdir
3369 }
3370 run_test 55c "rename vs unlink orphan target dir"
3371
3372 test_55d()
3373 {
3374         mkdir_on_mdt0 $DIR/$tdir
3375
3376         touch $DIR/$tdir/f1
3377
3378 #define OBD_FAIL_MDS_RENAME3              0x155
3379         do_facet mds1 $LCTL set_param fail_loc=0x155
3380         mv $DIR/$tdir/f1 $DIR/$tdir/$tdir &
3381         PID1=$!
3382         sleep 2
3383
3384         # while rename is sleeping, create $tdir, but as a directory
3385         mkdir -p $DIR2/$tdir/$tdir || error "(1) mkdir failed"
3386
3387         # link in reverse locking order
3388         ln $DIR2/$tdir/f1 $DIR2/$tdir/$tdir/
3389
3390         wait $PID1 && error "(2) mv succeeded"
3391         rm -rf $DIR/$tdir
3392 }
3393 run_test 55d "rename file vs link"
3394
3395 test_60() {
3396         [ $MDS1_VERSION -lt $(version_code 2.3.0) ] &&
3397                 skip "MDS version must be >= 2.3.0"
3398
3399         # Create a file
3400         test_mkdir $DIR1/$tdir
3401         file1=$DIR1/$tdir/file
3402         file2=$DIR2/$tdir/file
3403
3404         echo orig > $file2 || error "Could not create $file2"
3405         version=$($LFS data_version $file1)
3406
3407         # Append data
3408         echo append >> $file2 || error "Could not append to $file2"
3409         version2=$($LFS data_version $file1)
3410         [ "$version" != "$version2" ] ||
3411             error "append did not change data version: $version"
3412
3413         # Overwrite data
3414         echo overwrite > $file2 || error "Could not overwrite $file2"
3415         version3=$($LFS data_version $file1)
3416         [ "$version2" != "$version3" ] ||
3417             error "overwrite did not change data version: $version2"
3418
3419         # Truncate before EOF
3420         $TRUNCATE $file2 3 || error "Could not truncate $file2"
3421         version4=$($LFS data_version $file1)
3422         [ "$version3" != "$version4" ] ||
3423             error "truncate did not change data version: $version3"
3424
3425         # Truncate after EOF
3426         $TRUNCATE $file2 123456 || error "Could not truncate $file2"
3427         version5=$($LFS data_version $file1)
3428         [ "$version4" != "$version5" ] ||
3429             error "truncate did not change data version: $version4"
3430
3431         # Chmod do not change version
3432         chmod 400 $file2 || error "Could not chmod 400 $file2"
3433         version6=$($LFS data_version $file1)
3434         [ "$version5" == "$version6" ] ||
3435             error "chmod should not change data version: $version5 != $version6"
3436
3437         # Chown do not change version
3438         chown $RUNAS_ID $file2 || error "Could not chown $RUNAS_ID $file2"
3439         version7=$($LFS data_version $file1)
3440         [ "$version5" == "$version7" ] ||
3441             error "chown should not change data version: $version5 != $version7"
3442 }
3443 run_test 60 "Verify data_version behaviour"
3444
3445 test_70a() {
3446         local test_dir=$tdir/test_dir
3447
3448         mkdir -p $DIR1/$tdir
3449         if [ $MDSCOUNT -ge 2 ]; then
3450                 local MDTIDX=1
3451                 $LFS mkdir -i $MDTIDX $DIR1/$test_dir ||
3452                         error "Create remote directory failed"
3453         else
3454                 mkdir -p $DIR1/$test_dir
3455         fi
3456         cd $DIR2/$test_dir || error "cd directory failed"
3457         rm -rf $DIR1/$test_dir || error "unlink directory failed"
3458
3459         cd $DIR2/$tdir || error "exit directory"
3460 }
3461 run_test 70a "cd directory && rm directory"
3462
3463 test_70b() { # LU-2781
3464         local i
3465         mkdir -p $DIR1/$tdir
3466
3467         touch $DIR1/$tdir/file
3468         for ((i = 0; i < 32; i++)); do
3469             $LFS rm_entry $DIR1/$tdir/non_existent_dir &>/dev/null
3470         done
3471         rm $DIR1/$tdir/file || error "cannot remove file after rm_entry"
3472
3473         touch $DIR1/$tdir/file
3474         $LFS mkdir -i0 $DIR1/$tdir/test_dir
3475         $LFS rm_entry $DIR1/$tdir/test_dir &>/dev/null
3476         rm -rf $DIR1/$tdir/test_dir ||
3477                 error "cannot remove directory after rm_entry"
3478         rm $DIR1/$tdir/file || error "cannot remove file after rm_entry"
3479 }
3480 run_test 70b "remove files after calling rm_entry"
3481
3482 test_71a() {
3483         [[ "$MDS1_VERSION" -lt $(version_code 2.1.6) ]] &&
3484                 skip "Need MDS version at least 2.1.6"
3485
3486         # Patch not applied to 2.2 and 2.3 branches
3487         [[ "$MDS1_VERSION" -ge $(version_code 2.2.0) ]] &&
3488         [[ "$MDS1_VERSION" -lt $(version_code 2.4.0) ]] &&
3489                 skip "Need MDS version earlier than 2.2.0 or at least 2.4.0"
3490
3491         checkfiemap --test ||
3492                 skip "checkfiemap not runnable: $?"
3493         # write data this way: hole - data - hole - data
3494         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=1 count=1
3495         [ "$(facet_fstype ost$(($($LFS getstripe -i $DIR1/$tfile) + 1)))" = \
3496                 "zfs" ] &&
3497                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return 0
3498         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=3 count=1
3499         GET_STAT="lctl get_param -n ldlm.services.ldlm_cbd.stats"
3500         stat $DIR2/$tfile
3501         local can1=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
3502         echo $can1
3503         checkfiemap $DIR2/$tfile 81920 ||
3504                 error "data is not flushed from client"
3505         local can2=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
3506         echo $can2
3507
3508         # common case of "create file, copy file" on a single node
3509         # should not flush data from ost
3510         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=1 count=1
3511         dd if=/dev/urandom of=$DIR1/$tfile bs=40K seek=3 count=1
3512         stat $DIR1/$tfile
3513         local can3=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
3514         echo $can3
3515         checkfiemap $DIR1/$tfile 81920 ||
3516         error 4
3517         local can4=$($GET_STAT | awk '/ldlm_bl_callback/ {print $2}')
3518         echo $can2
3519         [ $can3 -eq $can4 ] || error $((can2-can1)) "cancel RPC occured."
3520 }
3521 run_test 71a "correct file map just after write operation is finished"
3522
3523 test_71b() {
3524         [[ "$MDS1_VERSION" -lt $(version_code 2.1.6) ]] &&
3525                 skip "Need MDS version at least 2.1.6"
3526
3527         # Patch not applied to 2.2 and 2.3 branches
3528         [[ "$MDS1_VERSION" -ge $(version_code 2.2.0) ]] &&
3529         [[ "$MDS1_VERSION" -lt $(version_code 2.4.0) ]] &&
3530                 skip "Need MDS version earlier than 2.2.0 or at least 2.4.0"
3531         [[ $OSTCOUNT -ge 2 ]] || skip "needs >= 2 OSTs"
3532
3533         checkfiemap --test ||
3534                 skip "error $?: checkfiemap failed"
3535
3536         mkdir -p $DIR1/$tdir
3537
3538         $LFS setstripe -c -1 $DIR1/$tdir || error "setstripe failed"
3539         dd if=/dev/urandom of=$DIR1/$tdir/$tfile bs=40K count=1
3540         [ "$(facet_fstype ost$(($($LFS getstripe -i $DIR1/$tdir/$tfile) + 1)))" = \
3541                 "zfs" ] &&
3542                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return 0
3543         checkfiemap $DIR1/$tdir/$tfile 40960 || error "checkfiemap failed"
3544 }
3545 run_test 71b "check fiemap support for stripecount > 1"
3546
3547 test_72() {
3548         local p="$TMP/sanityN-$TESTNAME.parameters"
3549         local tlink1
3550         local tlink2
3551         save_lustre_params client "llite.*.xattr_cache" > $p
3552         lctl set_param llite.*.xattr_cache 1 ||
3553                 { skip "xattr cache is not supported"; return 0; }
3554
3555         touch $DIR1/$tfile
3556         setfattr -n user.attr1 -v value1 $DIR1/$tfile ||
3557                 error "setfattr1 failed"
3558         getfattr -n user.attr1 $DIR2/$tfile | grep value1 ||
3559                 error "getfattr1 failed"
3560         setfattr -n user.attr1 -v value2 $DIR2/$tfile ||
3561                 error "setfattr2 failed"
3562         getfattr -n user.attr1 $DIR1/$tfile | grep value2 ||
3563                 error "getfattr2 failed"
3564
3565         # check that trusted.link is consistent
3566         tlink1=$(getfattr -n trusted.link $DIR1/$tfile | md5sum)
3567         ln $DIR2/$tfile $DIR2/$tfile-2 || error "failed to link"
3568         tlink2=$(getfattr -n trusted.link $DIR1/$tfile | md5sum)
3569         echo "$tlink1 $tlink2"
3570         [ "$tlink1" = "$tlink2" ] && error "trusted.link should have changed!"
3571
3572         rm -f $DIR2/$tfile
3573
3574         restore_lustre_params < $p
3575         rm -f $p
3576 }
3577 run_test 72 "getxattr/setxattr cache should be consistent between nodes"
3578
3579 test_73() {
3580         local p="$TMP/sanityN-$TESTNAME.parameters"
3581         save_lustre_params client "llite.*.xattr_cache" > $p
3582         lctl set_param llite.*.xattr_cache 1 ||
3583                 { skip "xattr cache is not supported"; return 0; }
3584
3585         touch $DIR1/$tfile
3586         setfattr -n user.attr1 -v value1 $DIR1/$tfile ||
3587                 error "setfattr1 failed"
3588         getfattr -n user.attr1 $DIR2/$tfile || error "getfattr1 failed"
3589         getfattr -n user.attr1 $DIR1/$tfile || error "getfattr2 failed"
3590         clear_stats llite.*.stats
3591         # PR lock should be cached by now on both clients
3592         getfattr -n user.attr1 $DIR1/$tfile || error "getfattr3 failed"
3593         # 2 hits for getfattr(0)+getfattr(size)
3594         [ $(calc_stats llite.*.stats getxattr_hits) -eq 2 ] ||
3595                 error "not cached in $DIR1"
3596         getfattr -n user.attr1 $DIR2/$tfile || error "getfattr4 failed"
3597         # 4 hits for more getfattr(0)+getfattr(size)
3598         [ $(calc_stats llite.*.stats getxattr_hits) -eq 4 ] ||
3599                 error "not cached in $DIR2"
3600         rm -f $DIR2/$tfile
3601
3602         restore_lustre_params < $p
3603         rm -f $p
3604 }
3605 run_test 73 "getxattr should not cause xattr lock cancellation"
3606
3607 test_74() {
3608         [ "$MDS1_VERSION" -lt $(version_code 2.4.93) ] &&
3609                 skip "Need MDS version at least 2.4.93"
3610
3611         dd if=/dev/zero of=$DIR1/$tfile-1 bs=1K count=1
3612         dd if=/dev/zero of=$DIR1/$tfile-2 bs=1K count=1
3613         flocks_test 4 $DIR1/$tfile-1 $DIR2/$tfile-2
3614 }
3615 run_test 74 "flock deadlock: different mounts =============="
3616
3617 # LU-3889
3618 test_75() {
3619         $LFS setstripe -c 2 -S 1m -i 0 $DIR1/$tfile
3620         dd if=/dev/zero of=$DIR1/$tfile bs=1M count=2
3621         cancel_lru_locks osc
3622
3623         dd of=$DIR1/$tfile if=/dev/zero bs=1M count=1 seek=1 conv=notrunc
3624         sync
3625
3626         # define OBD_FAIL_LDLM_ENQUEUE_HANG 0x31d
3627         $LCTL set_param fail_loc=0x31d
3628         stat -c %s $DIR1/$tfile &
3629         local pid=$!
3630         sleep 1
3631         kill -9 $pid
3632
3633         # For bad lock error handler we should ASSERT and got kernel panic here
3634         sleep 4
3635         $LCTL set_param fail_loc=0
3636 }
3637 run_test 75 "osc: upcall after unuse lock==================="
3638
3639 test_76() { #LU-946
3640         [[ "$MDS1_VERSION" -lt $(version_code 2.5.53) ]] &&
3641                 skip "Need MDS version at least 2.5.53"
3642
3643         remote_mds_nodsh && skip "remote MDS with nodsh"
3644         local fcount=$((MDSCOUNT * 256))
3645         declare -a fd_list
3646         declare -a fid_list
3647
3648         if remote_mds; then
3649                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
3650         else
3651                 nid="0@lo"
3652         fi
3653
3654         rm -rf $DIR/$tdir
3655         test_mkdir $DIR/$tdir
3656
3657         # drop all open locks and close any cached "open" files on the client
3658         cancel_lru_locks mdc
3659
3660         local open_fids_cmd="$LCTL get_param -n mdt.*.exports.'$nid'.open_files"
3661         local fid_list=($(do_nodes $(comma_list $(mdts_nodes)) $open_fids_cmd))
3662         local already=${#fid_list[@]}
3663         for (( i = 0; i < $already; i++ )) ; do
3664                 log "already open[$i]: $($LFS fid2path $DIR2 ${fid_list[i]})"
3665         done
3666
3667         echo -n "opening files: "
3668         ulimit -n $((fcount + 50))
3669         for ((i = 0; i < $fcount; i++)); do
3670                 touch $DIR/$tdir/f_$i
3671                 local fd=$(free_fd ${fd_list[i]})
3672                 local open_cmd="exec $fd<$DIR/$tdir/f_$i"
3673                 eval $open_cmd
3674
3675                 fd_list[i]=$fd
3676
3677                 (( $i % 32 == 0 )) && echo -n "."
3678         done
3679         echo
3680
3681         fid_list=($(do_nodes $(comma_list $(mdts_nodes)) $open_fids_cmd))
3682
3683         # Possible errors in openfiles FID list.
3684         # 1. Missing FIDs. Check 1
3685         # 2. Extra FIDs. Check 1
3686         # 3. Duplicated FID. Check 2
3687         # 4. Invalid FIDs. Check 2
3688         # 5. Valid FID, points to some other file. Check 3
3689
3690         # Check 1
3691         [ ${#fid_list[@]} -ne $((fcount + already)) ] &&
3692                 error "${#fid_list[@]} != $fcount (+$already old) open files"
3693
3694         echo -n "closing files: "
3695         for (( fd = 0, fid = 0; fd < $fcount; fd++, fid++ )) ; do
3696                 local close_cmd="exec ${fd_list[fd]}<&-"
3697                 eval $close_cmd
3698                 filename=$($LFS fid2path $DIR2 ${fid_list[fid]})
3699
3700                 while [[ ! "$filename" =~ "$DIR2/$tdir/f_" ]]; do
3701                         echo "skip old open file $filename"
3702                         ((fid++))
3703                         filename=$($LFS fid2path $DIR2 ${fid_list[fid]})
3704                 done
3705
3706                 # Check 2
3707                 rm --interactive=no $filename
3708                 [ $? -ne 0 ] &&
3709                         error "Nonexisting fid ${fid_list[fid]} listed."
3710                 (( $fd % 32 == 0 )) && echo -n "."
3711         done
3712         echo
3713
3714         # Check 3
3715         ls_op=$(ls $DIR2/$tdir | wc -l)
3716         [ $ls_op -ne 0 ] &&
3717                 error "Some openfiles are missing in lproc output"
3718
3719         rm -rf $DIR/$tdir
3720 }
3721 run_test 76 "Verify MDT open_files listing"
3722
3723 nrs_write_read() {
3724         local n=16
3725         local dir=$DIR/$tdir
3726         local myRUNAS="$1"
3727
3728         mkdir $dir || error "mkdir $dir failed"
3729         $LFS setstripe -c $OSTCOUNT $dir || error "setstripe to $dir failed"
3730         chmod 777 $dir
3731
3732         do_nodes $CLIENTS $myRUNAS \
3733                 dd if=/dev/zero of="$dir/nrs_r_\$HOSTNAME" bs=1M count=$n ||
3734                 error "dd at 0 on client failed (1)"
3735
3736         do_nodes $CLIENTS $myRUNAS \
3737                 "declare -a pids_w;
3738                 for ((i = 0; i < $n; i++)); do
3739                         dd if=/dev/zero of=$dir/nrs_w_\$HOSTNAME bs=1M \
3740 seek=\\\$i count=1 conv=notrunc &
3741                         pids_w[\\\$i]=\\\$!;
3742                 done;
3743                 rc_w=0;
3744                 for ((i = 0; i < $n; i++)); do
3745                         wait \\\${pids_w[\\\$i]};
3746                         newrc=\\\$?;
3747                         [ \\\$newrc -gt \\\$rc_w ] && rc_w=\\\$newrc;
3748                 done;
3749                 exit \\\$rc_w" &
3750         local pid_w=$!
3751         do_nodes $CLIENTS sync;
3752         cancel_lru_locks osc
3753
3754         do_nodes $CLIENTS $myRUNAS \
3755                 "declare -a pids_r;
3756                 for ((i = 0; i < $n; i++)); do
3757                         dd if=$dir/nrs_r_\$HOSTNAME bs=1M of=/dev/null \
3758 seek=\\\$i count=1 &
3759                         pids_r[\\\$i]=\\\$!;
3760                 done;
3761                 rc_r=0;
3762                 for ((i = 0; i < $n; i++)); do
3763                         wait \\\${pids_r[\\\$i]};
3764                         newrc=\\\$?;
3765                         [ \\\$newrc -gt \\\$rc_r ] && rc_r=\\\$newrc;
3766                 done;
3767                 exit \\\$rc_r" &
3768         local pid_r=$!
3769         cancel_lru_locks osc
3770
3771         wait $pid_w || error "dd (write) failed (2)"
3772         wait $pid_r || error "dd (read) failed (3)"
3773         rm -rvf $dir || error "rm -rf $dir failed"
3774 }
3775
3776 test_77a() { #LU-3266
3777         local rc
3778
3779         oss=$(comma_list $(osts_nodes))
3780         do_nodes $oss lctl set_param ost.OSS.*.nrs_policies="fifo" ||
3781                 rc=$?
3782         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3783         [[ $rc -ne 0 ]] && error "failed to set fifo policy"
3784         nrs_write_read
3785
3786         return 0
3787 }
3788 run_test 77a "check FIFO NRS policy"
3789
3790 test_77b() { #LU-3266
3791         local rc
3792
3793         oss=$(comma_list $(osts_nodes))
3794
3795         do_nodes $oss lctl set_param ost.OSS.*.nrs_policies="crrn" \
3796                 ost.OSS.*.nrs_crrn_quantum=1 || rc=$?
3797         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3798         [[ $rc -ne 0 ]] && error "failed to set crrn_quantum to 1"
3799
3800         echo "policy: crr-n, crrn_quantum 1"
3801         nrs_write_read
3802
3803         do_nodes $oss lctl set_param \
3804                 ost.OSS.*.nrs_crrn_quantum=64 || rc=$?
3805         [[ $rc -ne 0 ]] && error "failed to set crrn_quantum to 64"
3806
3807         echo "policy: crr-n, crrn_quantum 64"
3808         nrs_write_read
3809
3810         # cleanup
3811         do_nodes $oss lctl set_param \
3812                 ost.OSS.ost_io.nrs_policies="fifo" || rc=$?
3813         [[ $rc -ne 0 ]] && error "failed to set fifo policy"
3814         return 0
3815 }
3816 run_test 77b "check CRR-N NRS policy"
3817
3818 orr_trr() {
3819         local policy=$1
3820
3821         oss=$(comma_list $(osts_nodes))
3822
3823         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies=$policy \
3824                 ost.OSS.*.nrs_"$policy"_quantum=1 \
3825                 ost.OSS.*.nrs_"$policy"_offset_type="physical" \
3826                 ost.OSS.*.nrs_"$policy"_supported="reads" || return $?
3827
3828         echo "policy: $policy, ${policy}_quantum 1, ${policy}_offset_type " \
3829                 "physical, ${policy}_supported reads"
3830         nrs_write_read
3831
3832         do_nodes $oss lctl set_param \
3833                 ost.OSS.*.nrs_${policy}_supported="writes" \
3834                 ost.OSS.*.nrs_${policy}_quantum=64 || return $?
3835
3836         echo "policy: $policy, ${policy}_quantum 64, ${policy}_offset_type " \
3837                 "physical, ${policy}_supported writes"
3838         nrs_write_read
3839
3840         do_nodes $oss lctl set_param \
3841                 ost.OSS.*.nrs_${policy}_supported="reads_and_writes" \
3842                 ost.OSS.*.nrs_${policy}_offset_type="logical" || return $?
3843         echo "policy: $policy, ${policy}_quantum 64, ${policy}_offset_type " \
3844                 "logical, ${policy}_supported reads_and_writes"
3845         nrs_write_read
3846
3847         # cleanup
3848         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo" ||
3849                 return $?
3850         return 0
3851 }
3852
3853 test_77c() { #LU-3266
3854         local rc
3855         orr_trr "orr" || rc=$?
3856         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3857         [[ $rc -ne 0 ]] && error "orr_trr failed rc:$rc"
3858         return 0
3859 }
3860 run_test 77c "check ORR NRS policy"
3861
3862 test_77d() { #LU-3266
3863         local rc
3864         orr_trr "trr" || rc=$?
3865         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
3866         [[ $rc -ne 0 ]] && error "orr_trr failed rc:$rc"
3867         return 0
3868 }
3869 run_test 77d "check TRR nrs policy"
3870
3871 tbf_rule_operate()
3872 {
3873         local facet=$1
3874         shift 1
3875
3876         do_facet $facet lctl set_param \
3877                 ost.OSS.ost_io.nrs_tbf_rule="$*"
3878         [ $? -ne 0 ] &&
3879                 error "failed to run operate '$*' on TBF rules"
3880 }
3881
3882 cleanup_tbf_verify()
3883 {
3884         local rc=0
3885         trap 0
3886         echo "cleanup_tbf $DIR/$tdir"
3887         rm -rf $DIR/$tdir
3888         rc=$?
3889         wait_delete_completed
3890         return $rc
3891 }
3892
3893 tbf_verify() {
3894         local dir=$DIR/$tdir
3895         local client1=${CLIENT1:-$(hostname)}
3896         local myRUNAS="$3"
3897
3898         local np=$(check_cpt_number ost1)
3899         [ $np -gt 0 ] || error "CPU partitions should not be $np."
3900         echo "cpu_npartitions on ost1 is $np"
3901
3902         mkdir $dir || error "mkdir $dir failed"
3903         $LFS setstripe -c 1 -i 0 $dir || error "setstripe to $dir failed"
3904         chmod 777 $dir
3905
3906         trap cleanup_tbf_verify EXIT
3907         echo "Limited write rate: $1, read rate: $2"
3908         echo "Verify the write rate is under TBF control"
3909         local start=$SECONDS
3910         do_node $client1 $myRUNAS dd if=/dev/zero of=$dir/tbf \
3911                 bs=1M count=100 oflag=direct 2>&1
3912         local runtime=$((SECONDS - start + 1))
3913         local rate=$(bc <<< "scale=6; 100 / $runtime")
3914         echo "Write runtime is $runtime s, speed is $rate IOPS"
3915
3916         # verify the write rate does not exceed TBF rate limit
3917         [ $(bc <<< "$rate < 1.1 * $np * $1") -eq 1 ] ||
3918                 error "The write rate ($rate) exceeds 110% of rate limit ($1 * $np)"
3919
3920         cancel_lru_locks osc
3921
3922         echo "Verify the read rate is under TBF control"
3923         start=$SECONDS
3924         do_node $client1 $myRUNAS dd if=$dir/tbf of=/dev/null \
3925                 bs=1M count=100 iflag=direct 2>&1
3926         runtime=$((SECONDS - start + 1))
3927         rate=$(bc <<< "scale=6; 100 / $runtime")
3928         echo "Read runtime is $runtime s, speed is $rate IOPS"
3929
3930         # verify the read rate does not exceed TBF rate limit
3931         [ $(bc <<< "$rate < 1.1 * $np * $2") -eq 1 ] ||
3932                 error "The read rate ($rate) exceeds 110% of rate limit ($2 * $np)"
3933
3934         cancel_lru_locks osc
3935         cleanup_tbf_verify || error "rm -rf $dir failed"
3936 }
3937
3938 test_77e() {
3939         local rc
3940
3941         oss=$(comma_list $(osts_nodes))
3942
3943         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ nid" ||
3944                 rc=$?
3945         [[ $rc -eq 3 ]] && skip "no NRS TBF exists" && return
3946         [[ $rc -ne 0 ]] && error "failed to set TBF NID policy"
3947
3948         local idis
3949         local rateis
3950         if [ "$OST1_VERSION" -ge $(version_code 2.8.54) ]; then
3951                 idis="nid="
3952                 rateis="rate="
3953         fi
3954
3955         # Only operate rules on ost1 since OSTs might run on the same OSS
3956         # Add some rules
3957         tbf_rule_operate ost1 "start\ localhost\ ${idis}{0@lo}\ ${rateis}1000"
3958         local address=$(comma_list "$(host_nids_address $CLIENTS $NETTYPE)")
3959         local client_nids=$(nids_list $address "\\")
3960         tbf_rule_operate ost1 "start\ clients\ ${idis}{$client_nids}\ ${rateis}100"
3961         tbf_rule_operate ost1 "start\ others\ ${idis}{*.*.*.*@$NETTYPE}\ ${rateis}50"
3962         nrs_write_read
3963
3964         # Change the rules
3965         tbf_rule_operate ost1 "change\ localhost\ ${rateis}1001"
3966         tbf_rule_operate ost1 "change\ clients\ ${rateis}101"
3967         tbf_rule_operate ost1 "change\ others\ ${rateis}51"
3968         nrs_write_read
3969
3970         # Stop the rules
3971         tbf_rule_operate ost1 "stop\ localhost"
3972         tbf_rule_operate ost1 "stop\ clients"
3973         tbf_rule_operate ost1 "stop\ others"
3974         nrs_write_read
3975
3976         # Cleanup the TBF policy
3977         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
3978         [ $? -ne 0 ] && error "failed to set policy back to fifo"
3979         nrs_write_read
3980         return 0
3981 }
3982 run_test 77e "check TBF NID nrs policy"
3983
3984 test_77f() {
3985         local rc
3986
3987         oss=$(comma_list $(osts_nodes))
3988
3989         do_nodes $oss $LCTL set_param \
3990                 ost.OSS.ost_io.nrs_policies="tbf\ jobid" || rc=$?
3991         [[ $rc -eq 3 ]] && skip "no NRS TBF exists" && return
3992         [[ $rc -ne 0 ]] && error "failed to set TBF JOBID policy"
3993
3994         # Configure jobid_var
3995         local saved_jobid_var=$($LCTL get_param -n jobid_var)
3996         rc=$?
3997         [[ $rc -eq 3 ]] && skip "jobid_var not found" && return
3998         [[ $rc -ne 0 ]] && error "failed to get param jobid_var"
3999         if [ $saved_jobid_var != procname_uid ]; then
4000                 set_persistent_param_and_check client \
4001                         "jobid_var" "$FSNAME.sys.jobid_var" procname_uid
4002         fi
4003
4004         local idis
4005         local rateis
4006         if [ "$OST1_VERSION" -ge $(version_code 2.8.54) ]; then
4007                 idis="jobid="
4008                 rateis="rate="
4009         fi
4010
4011         # Only operate rules on ost1 since OSTs might run on the same OSS
4012         # Add some rules
4013         tbf_rule_operate ost1 "start\ runas\ ${idis}{iozone.$RUNAS_ID\ dd.$RUNAS_ID\ tiotest.$RUNAS_ID}\ ${rateis}1000"
4014         tbf_rule_operate ost1 "start\ iozone_runas\ ${idis}{iozone.$RUNAS_ID}\ ${rateis}100"
4015         tbf_rule_operate ost1 "start\ dd_runas\ ${idis}{dd.$RUNAS_ID}\ ${rateis}50"
4016         nrs_write_read "$RUNAS"
4017
4018         # Change the rules
4019         tbf_rule_operate ost1 "change\ runas\ ${rateis}1001"
4020         tbf_rule_operate ost1 "change\ iozone_runas\ ${rateis}101"
4021         tbf_rule_operate ost1 "change\ dd_runas\ ${rateis}51"
4022         nrs_write_read "$RUNAS"
4023
4024         # Stop the rules
4025         tbf_rule_operate ost1 "stop\ runas"
4026         tbf_rule_operate ost1 "stop\ iozone_runas"
4027         tbf_rule_operate ost1 "stop\ dd_runas"
4028         nrs_write_read "$RUNAS"
4029
4030         # Cleanup the TBF policy
4031         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
4032         [ $? -ne 0 ] && error "failed to set policy back to fifo"
4033         nrs_write_read "$RUNAS"
4034
4035         local current_jobid_var=$($LCTL get_param -n jobid_var)
4036         [[ $? -ne 0 ]] && error "failed to get param jobid_var"
4037         if [ $saved_jobid_var != $current_jobid_var ]; then
4038                 set_persistent_param_and_check client \
4039                         "jobid_var" "$FSNAME.sys.jobid_var" $saved_jobid_var
4040         fi
4041         return 0
4042 }
4043 run_test 77f "check TBF JobID nrs policy"
4044
4045 test_77g() {
4046         local rc=0
4047
4048         oss=$(comma_list $(osts_nodes))
4049
4050         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ nid" ||
4051                 rc=$?
4052         [[ $rc -eq 3 ]] && skip "no NRS TBF exists" && return
4053         [[ $rc -ne 0 ]] && error "failed to set TBF NID policy"
4054
4055         do_nodes $oss lctl set_param \
4056                 ost.OSS.ost_io.nrs_policies="tbf\ jobid" || rc=$?
4057         [[ $rc -ne 0 ]] && error "failed to set TBF JOBID policy"
4058
4059         local idis
4060         local rateis
4061         if [ "$OST1_VERSION" -ge $(version_code 2.8.54) ]; then
4062                 idis="jobid="
4063                 rateis="rate="
4064         fi
4065
4066         # Add a rule that only valid for Jobid TBF. If direct change between
4067         # TBF types is not supported, this operation will fail.
4068         tbf_rule_operate ost1 "start\ dd_runas\ ${idis}{dd.$RUNAS_ID}\ ${rateis}50"
4069
4070         # Cleanup the TBF policy
4071         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
4072         [ $? -ne 0 ] && error "failed to set policy back to fifo"
4073         return 0
4074 }
4075 run_test 77g "Change TBF type directly"
4076
4077 test_77h() {
4078         [ "$OST1_VERSION" -ge $(version_code 2.8.55) ] ||
4079                 skip "Need OST version at least 2.8.55"
4080
4081         local old_policy=$(do_facet ost1 \
4082                 lctl get_param ost.OSS.ost_io.nrs_policies)
4083         local new_policy
4084
4085         do_facet ost1 lctl set_param \
4086                 ost.OSS.ost_io.nrs_policies="abc"
4087         [ $? -eq 0 ] && error "should return error"
4088
4089         do_facet ost1 lctl set_param \
4090                 ost.OSS.ost_io.nrs_policies="tbf\ abc"
4091         [ $? -eq 0 ] && error "should return error"
4092
4093         do_facet ost1 lctl set_param \
4094                 ost.OSS.ost_io.nrs_policies="tbf\ reg\ abc"
4095         [ $? -eq 0 ] && error "should return error"
4096
4097         do_facet ost1 lctl set_param \
4098                 ost.OSS.ost_io.nrs_policies="tbf\ abc\ efg"
4099         [ $? -eq 0 ] && error "should return error"
4100
4101         new_policy=$(do_facet ost1 lctl get_param ost.OSS.ost_io.nrs_policies)
4102         [ $? -eq 0 ] || error "shouldn't LBUG"
4103
4104         [ "$old_policy" = "$new_policy" ] || error "NRS policy should be same"
4105
4106         return 0
4107 }
4108 run_test 77h "Wrong policy name should report error, not LBUG"
4109
4110 tbf_rule_check()
4111 {
4112         local facet=$1
4113         local expected=$2
4114         local error_message=$3
4115         local rule_number=0
4116         for rule in $expected; do
4117                 rule_number=$((rule_number + 1))
4118         done
4119         local stop_line=$(($rule_number + 3))
4120         local awk_command="awk 'NR >= 4 && NR <= $stop_line {print \$1}'"
4121
4122         local output=$(do_facet $facet lctl get_param \
4123                 ost.OSS.ost_io.nrs_tbf_rule |
4124                 eval $awk_command |
4125                 tr "\n" " " |
4126                 sed 's/[ ]*$//')
4127         if [ "$output" != "$expected" ]; then
4128                 error "$error_message, expected '$expected', got '$output'"
4129         fi
4130 }
4131
4132 test_77i() {
4133         [ "$OST1_VERSION" -ge $(version_code 2.8.55) ] ||
4134                 skip "Need OST version at least 2.8.55"
4135
4136         for i in $(seq 1 $OSTCOUNT)
4137         do
4138                 do_facet ost"$i" lctl set_param \
4139                         ost.OSS.ost_io.nrs_policies="tbf\ jobid"
4140                 [ $? -ne 0 ] &&
4141                         error "failed to set TBF policy"
4142         done
4143
4144         tbf_rule_check ost1 "default" "error before inserting any rule"
4145
4146         tbf_rule_operate ost1 "start\ before\ jobid={jobid}\ rate=1000"
4147         tbf_rule_check ost1 "before default" \
4148                 "error when inserting rule 'before'"
4149
4150         tbf_rule_operate ost1 "start\ after\ jobid={jobid}\ rate=1000\ rank=default"
4151         tbf_rule_check ost1 "before after default" \
4152                 "error when inserting rule 'after'"
4153
4154         tbf_rule_operate ost1 "start\ target\ jobid={jobid}\ rate=1000\ rank=after"
4155         tbf_rule_check ost1 "before target after default" \
4156                 "error when inserting rule 'target'"
4157
4158         echo "Move before itself"
4159         tbf_rule_operate ost1 "change\ target\ rank=target"
4160         tbf_rule_check ost1 "before target after default" \
4161                 "error when moving before itself"
4162
4163         echo "Move to higher rank"
4164         tbf_rule_operate ost1 "change\ target\ rank=before"
4165         tbf_rule_check ost1 "target before after default" \
4166                 "error when moving to higher rank"
4167
4168         echo "Move to lower rank"
4169         tbf_rule_operate ost1 "change\ target\ rank=after"
4170         tbf_rule_check ost1 "before target after default" \
4171                 "error when moving to lower rank"
4172
4173         echo "Move before default"
4174         tbf_rule_operate ost1 "change\ target\ rank=default"
4175         tbf_rule_check ost1 "before after target default" \
4176                 error "error when moving before default"
4177
4178         # Cleanup the TBF policy
4179         do_nodes $(comma_list $(osts_nodes)) \
4180                 $LCTL set_param ost.OSS.ost_io.nrs_policies=fifo
4181         return 0
4182 }
4183 run_test 77i "Change rank of TBF rule"
4184
4185 test_77j() {
4186         local idis
4187         local rateis
4188
4189         [ "$OST1_VERSION" -ge $(version_code 2.9.53) ] ||
4190                 skip "Need OST version at least 2.9.53"
4191         if [ "$OST1_VERSION" -ge $(version_code 2.8.60) ]; then
4192                 idis="opcode="
4193                 rateis="rate="
4194         fi
4195
4196         do_nodes $(comma_list $(osts_nodes)) \
4197                 lctl set_param jobid_var=procname_uid \
4198                         ost.OSS.ost_io.nrs_policies="tbf\ opcode" \
4199                         ost.OSS.ost_io.nrs_tbf_rule="start\ ost_r\ ${idis}{ost_read}\ ${rateis}5" \
4200                         ost.OSS.ost_io.nrs_tbf_rule="start\ ost_w\ ${idis}{ost_write}\ ${rateis}20"
4201         [ $? -ne 0 ] && error "failed to set TBF OPCode policy"
4202
4203         nrs_write_read
4204         tbf_verify 20 5
4205
4206         do_nodes $(comma_list $(osts_nodes)) \
4207                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ost_r" \
4208                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ost_w" \
4209                         ost.OSS.ost_io.nrs_policies="fifo"
4210
4211         # sleep 3 seconds to wait the tbf policy stop completely,
4212         # or the next test case is possible get -EAGAIN when
4213         # setting the tbf policy
4214         sleep 3
4215 }
4216 run_test 77j "check TBF-OPCode NRS policy"
4217
4218 test_id() {
4219         local idstr="${1}id"
4220         local policy="${idstr}={$2}"
4221         local rate="rate=$3"
4222
4223         do_nodes $(comma_list $(osts_nodes)) \
4224                 lctl set_param jobid_var=procname_uid \
4225                         ost.OSS.ost_io.nrs_policies="tbf\ ${idstr}" \
4226                         ost.OSS.ost_io.nrs_tbf_rule="start\ ost_${idstr}\ ${policy}\ ${rate}"
4227         [ $? -ne 0 ] && error "failed to set tbf ${idstr} policy"
4228
4229         nrs_write_read "runas $4"
4230         tbf_verify $3 $3 "runas $4"
4231
4232         do_nodes $(comma_list $(osts_nodes)) \
4233                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ost_${idstr}" \
4234                         ost.OSS.ost_io.nrs_policies="fifo"
4235
4236         # sleep 3 seconds to wait the tbf policy stop completely,
4237         # or the next test case is possible get -eagain when
4238         # setting the tbf policy
4239         sleep 3
4240 }
4241
4242 test_77ja(){
4243         if [ "$OST1_VERSION" -lt $(version_code 2.11.50) ]; then
4244                 skip "Need OST version at least 2.11.50"
4245         fi
4246
4247         test_id "u" "500" "5" "-u 500"
4248         test_id "g" "500" "5" "-u 500 -g 500"
4249 }
4250 run_test 77ja "check TBF-UID/GID NRS policy"
4251
4252 cleanup_77k()
4253 {
4254         local rule_lists=$1
4255         local old_nrs=$2
4256
4257         trap 0
4258         for rule in $rule_lists; do
4259                 do_nodes $(comma_list $(osts_nodes)) \
4260                         lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ $rule"
4261         done
4262
4263         do_nodes $(comma_list $(osts_nodes)) \
4264                 lctl set_param ost.OSS.ost_io.nrs_policies="$old_nrs"
4265
4266         sleep 3
4267 }
4268
4269 test_77k() {
4270         [[ "$OST1_VERSION" -ge $(version_code 2.9.53) ]] ||
4271                 skip "Need OST version at least 2.9.53"
4272
4273         do_nodes $(comma_list $(osts_nodes)) \
4274                 lctl set_param ost.OSS.ost_io.nrs_policies="tbf" \
4275                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_w\ jobid={dd.$RUNAS_ID}\&opcode={ost_write}\ rate=20" \
4276                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_r\ jobid={dd.$RUNAS_ID}\&opcode={ost_read}\ rate=10"
4277
4278         nrs_write_read "$RUNAS"
4279         tbf_verify 20 10 "$RUNAS"
4280
4281         local address=$(comma_list "$(host_nids_address $CLIENTS $NETTYPE)")
4282         local client_nids=$(nids_list $address "\\")
4283         do_nodes $(comma_list $(osts_nodes)) \
4284                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_w" \
4285                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_r" \
4286                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_w\ nid={0@lo\ $client_nids}\&opcode={ost_write}\ rate=20" \
4287                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_r\ nid={0@lo\ $client_nids}\&opcode={ost_read}\ rate=10"
4288
4289         nrs_write_read
4290         tbf_verify 20 10
4291
4292         do_nodes $(comma_list $(osts_nodes)) \
4293                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_w" \
4294                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_r" \
4295                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext\ nid={0@lo\ $client_nids}\&jobid={dd.$RUNAS_ID}\ rate=20"
4296
4297         nrs_write_read "$RUNAS"
4298         tbf_verify 20 20 "$RUNAS"
4299
4300         do_nodes $(comma_list $(osts_nodes)) \
4301                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext" \
4302                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_a\ jobid={dd.$RUNAS_ID},opcode={ost_write}\ rate=20" \
4303                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_b\ jobid={dd.$RUNAS_ID},opcode={ost_read}\ rate=10"
4304
4305         nrs_write_read "$RUNAS"
4306         # with parameter "RUNAS", it will match the latest rule
4307         # "ext_b" first, so the limited write rate is 10.
4308         tbf_verify 10 10 "$RUNAS"
4309         tbf_verify 20 10
4310
4311         trap "cleanup_77k \"ext_a ext_b\" \"fifo\"" EXIT
4312
4313         [[ "$OST1_VERSION" -ge $(version_code 2.10.58) ]] ||
4314                 skip "Need OST version at least 2.10.58"
4315
4316         do_nodes $(comma_list $(osts_nodes)) \
4317                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_a" \
4318                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_b" \
4319                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_ug\ uid={500}\&gid={1000}\ rate=5"
4320         nrs_write_read "runas -u 500 -g 1000"
4321         tbf_verify 5 5 "runas -u 500 -g 1000"
4322
4323         do_nodes $(comma_list $(osts_nodes)) \
4324                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_ug" \
4325                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_uw\ uid={500}\&opcode={ost_write}\ rate=20" \
4326                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_ur\ uid={500}\&opcode={ost_read}\ rate=10"
4327
4328         nrs_write_read "runas -u 500"
4329         tbf_verify 20 10 "runas -u 500"
4330
4331         do_nodes $(comma_list $(osts_nodes)) \
4332                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_uw" \
4333                         ost.OSS.ost_io.nrs_tbf_rule="stop\ ext_ur" \
4334                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_a\ uid={500},opcode={ost_write}\ rate=20" \
4335                         ost.OSS.ost_io.nrs_tbf_rule="start\ ext_b\ uid={500},opcode={ost_read}\ rate=10"
4336         nrs_write_read "runas -u 500"
4337         tbf_verify 10 10 "runas -u 500"
4338         tbf_verify 20 10 "runas -u 500"
4339         cleanup_77k "ext_a ext_b" "fifo"
4340 }
4341 run_test 77k "check TBF policy with NID/JobID/OPCode expression"
4342
4343 test_77l() {
4344         [[ "$OST1_VERSION" -ge $(version_code 2.10.56) ]] ||
4345                 skip "Need OST version at least 2.10.56"
4346
4347         do_facet ost1 lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ nid"
4348         do_facet ost1 lctl set_param ost.OSS.ost_io.nrs_policies="tbf"
4349
4350         local output=$(do_facet ost1 lctl get_param \
4351                         ost.OSS.ost_io.nrs_policies | \
4352                         awk '/name: tbf/ {print;exit}' | \
4353                         awk -F ': ' '{print $2}')
4354
4355         if [ "$output" != "tbf" ]; then
4356                 error "The generic TBF output is '$output', not 'tbf'"
4357         fi
4358
4359         do_facet ost1 lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
4360 }
4361 run_test 77l "check the output of NRS policies for generic TBF"
4362
4363 test_77m() {
4364         if [ "$OST1_VERSION" -lt $(version_code 2.9.54) ]; then
4365                 skip "Need OST version at least 2.9.54"
4366         fi
4367
4368         local dir=$DIR/$tdir
4369
4370         mkdir $dir || error "mkdir $dir failed"
4371         $LFS setstripe -c $OSTCOUNT $dir || error "setstripe to $dir failed"
4372         chmod 777 $dir
4373
4374         local nodes=$(comma_list $(osts_nodes))
4375         do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies=delay \
4376                                        ost.OSS.ost_io.nrs_delay_min=4 \
4377                                        ost.OSS.ost_io.nrs_delay_max=4 \
4378                                        ost.OSS.ost_io.nrs_delay_pct=100
4379         [ $? -ne 0 ] && error "Failed to set delay policy"
4380
4381         local start=$SECONDS
4382         do_nodes "${SINGLECLIENT:-$HOSTNAME}" "$RUNAS" \
4383                  dd if=/dev/zero of="$dir/nrs_delay_$HOSTNAME" bs=1M count=1 \
4384                    oflag=direct conv=fdatasync ||
4385                 { do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo";
4386                   error "dd on client failed (1)"; }
4387         local elapsed=$((SECONDS - start))
4388
4389         # NRS delay doesn't do sub-second timing, so a request enqueued at
4390         # 0.9 seconds can be dequeued at 4.0
4391         [ $elapsed -lt 3 ] &&
4392                 { do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo";
4393                   error "Single 1M write should take at least 3 seconds"; }
4394
4395         start=$SECONDS
4396         do_nodes "${SINGLECLIENT:-$HOSTNAME}" "$RUNAS" \
4397                  dd if=/dev/zero of="$dir/nrs_delay_$HOSTNAME" bs=1M count=10 \
4398                    oflag=direct conv=fdatasync ||
4399                 { do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo";
4400                   error "dd on client failed (2)"; }
4401         elapsed=$((SECONDS - start))
4402
4403         [ $elapsed -lt 30 ] &&
4404                 { do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo";
4405                   error "Ten 1M writes should take at least 30 seconds"; }
4406
4407         do_nodes $nodes lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
4408         [ $? -ne 0 ] && error "failed to set policy back to fifo"
4409
4410         return 0
4411 }
4412 run_test 77m "check NRS Delay slows write RPC processing"
4413
4414 test_77n() { #LU-10802
4415         if [ "$OST1_VERSION" -lt $(version_code 2.10.58) ]; then
4416                 skip "Need OST version at least 2.10.58"
4417         fi
4418
4419         # Configure jobid_var
4420         local saved_jobid_var=$($LCTL get_param -n jobid_var)
4421         if [ $saved_jobid_var != procname_uid ]; then
4422                 set_persistent_param_and_check client \
4423                         "jobid_var" "$FSNAME.sys.jobid_var" procname_uid
4424         fi
4425
4426         do_nodes $(comma_list $(osts_nodes)) \
4427                 lctl set_param ost.OSS.ost_io.nrs_policies="tbf\ jobid" \
4428                         ost.OSS.ost_io.nrs_tbf_rule="stop\ dd_runas" \
4429                         ost.OSS.ost_io.nrs_tbf_rule="start\ dd_runas\ jobid={*.$RUNAS_ID}\ rate=20"
4430
4431         nrs_write_read
4432         tbf_verify 20 20 "$RUNAS"
4433
4434         do_nodes $(comma_list $(osts_nodes)) \
4435                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ dd_runas" \
4436                         ost.OSS.ost_io.nrs_tbf_rule="start\ dd_runas\ jobid={dd.*}\ rate=20"
4437
4438         nrs_write_read
4439         tbf_verify 20 20
4440
4441         do_nodes $(comma_list $(osts_nodes)) \
4442                 lctl set_param ost.OSS.ost_io.nrs_tbf_rule="stop\ dd_runas" \
4443                         ost.OSS.ost_io.nrs_policies="fifo"
4444
4445         sleep 3
4446
4447         local current_jobid_var=$($LCTL get_param -n jobid_var)
4448         if [ $saved_jobid_var != $current_jobid_var ]; then
4449                 set_persistent_param_and_check client \
4450                         "jobid_var" "$FSNAME.sys.jobid_var" $saved_jobid_var
4451         fi
4452 }
4453 run_test 77n "check wildcard support for TBF JobID NRS policy"
4454
4455 test_77o() {
4456         (( $OST1_VERSION > $(version_code 2.14.54) )) ||
4457                 skip "need OST > 2.14.54"
4458
4459         do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_policies="tbf\ nid"
4460         do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="start\ name\ nid={192.168.*.*@tcp}\ rate=10000"
4461         do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="start\ name1\ nid={192.168.*.*@tcp}\ rate=10000"
4462         do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="change\ name1\ rank=name"
4463         do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="stop\ name"
4464         do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_policies="fifo"
4465 }
4466 run_test 77o "Changing rank should not panic"
4467
4468 test_77q() {
4469         local i
4470
4471         (( $MDS1_VERSION > $(version_code 2.14.54) )) ||
4472                 skip "need MDS >= 2.14.54"
4473
4474         do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_policies="tbf"
4475         stack_trap "do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_policies=fifo"
4476
4477         for i in {1..50}; do
4478                 local pid1 pid2
4479
4480                 do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="'start rule77q_1 uid={500}&gid={500} rate=100'" &
4481                 pid1=$!
4482                 do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="'start rule77q_2 uid={1000}&gid={1000} rate=100'" &
4483                 pid2=$!
4484                 wait $pid1 || error "$i: Fail to start TBF rule 'rule77q_1'"
4485                 wait $pid2 || error "$i: Fail to start TBF rule 'rule77q_2'"
4486
4487                 do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="'stop rule77q_1'" &
4488                 pid1=$!
4489                 do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="'stop rule77q_2'" &
4490                 pid2=$!
4491                 wait $pid1 || error "$i: Fail to stop TBF rule 'rule77q_1'"
4492                 wait $pid2 || error "$i: Fail to stop TBF rule 'rule77q_2'"
4493         done
4494 }
4495 run_test 77q "Parallel TBF rule definitions should not panic"
4496
4497 test_77p() {
4498         local c
4499         local -a spec_chars=(
4500                 '@' '.' '~' '#' '/' '^' '%' '*' ';' ',' '?' '<' '>' ':'
4501                 '+' '=' ')' '(' '{' '}' '|' '[' ']' '!' '&' '\$' '\`' '\\')
4502
4503         (( $MDS1_VERSION > $(version_code 2.14.54) )) ||
4504                 skip "need MDS >= 2.14.54"
4505
4506         do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_policies="tbf"
4507         stack_trap "do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_policies=fifo"
4508
4509         # TBF rule name size is 16 bytes
4510         do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="start\ test_77p_overflo\ uid={500}\ rate=500" &&
4511                 error "The length of tbf rule name is not checked" || true
4512         do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="start\ \ uid={500}\ rate=500" &&
4513                 error "The server should not accept empty tbf rule name" || true
4514         do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="start\ test_77p_empty" &&
4515                 error "The server should not accept 'start <tbf_rule_name>' without an expression" || true
4516
4517         # Test with special chars
4518         for c in "${spec_chars[@]}"; do
4519                 do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="'start test77p${c}spec uid={500} rate=500'" &&
4520                 error "Special char '${c}' should not be accepted in a tbf rule name" || true
4521         done
4522
4523 }
4524 run_test 77p "Check validity of rule names for TBF policies"
4525
4526 test_78() { #LU-6673
4527         local rc
4528
4529         oss=$(comma_list $(osts_nodes))
4530         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="orr" &
4531         do_nodes $oss lctl set_param ost.OSS.*.nrs_orr_quantum=1
4532         rc=$?
4533         [[ $rc -eq 3 ]] && skip "no NRS exists" && return
4534         # Valid return codes are:
4535         # 0: Tuning succeeded
4536         # ENODEV: Policy is still stopped
4537         # EAGAIN: Policy is being initialized
4538         [ $rc -eq 0 -o $rc -eq 19 -o $rc -eq 11 ] ||
4539                 error "Expected set_param to return 0|ENODEV|EAGAIN"
4540
4541         # Cleanup the ORR policy
4542         do_nodes $oss lctl set_param ost.OSS.ost_io.nrs_policies="fifo"
4543         [ $? -ne 0 ] && error "failed to set policy back to fifo"
4544         return 0
4545 }
4546 run_test 78 "Enable policy and specify tunings right away"
4547
4548 test_79() {
4549         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4550         test_mkdir $DIR/$tdir
4551
4552         # Prevent interference from layout intent RPCs due to
4553         # asynchronous writeback. These will be tested in 130c below.
4554         do_nodes ${CLIENTS:-$HOSTNAME} sync
4555
4556         setfattr -n trusted.name1 -v value1 $DIR/$tdir ||
4557                 error "setfattr -n trusted.name1=value1 $DIR/$tdir failed"
4558
4559 #define OBD_FAIL_MDS_INTENT_DELAY               0x160
4560         local mdtidx=$($LFS getstripe -m $DIR/$tdir)
4561         local facet=mds$((mdtidx + 1))
4562         stat $DIR/$tdir
4563         set_nodes_failloc $(facet_active_host $facet) 0x80000160
4564         getfattr -n trusted.name1 $DIR/$tdir 2> /dev/null  &
4565         local pid=$!
4566         sleep 2
4567
4568 #define OBD_FAIL_MDS_GETXATTR_PACK       0x131
4569         set_nodes_failloc $(facet_active_host $facet) 0x80000131
4570
4571         wait $pid
4572         return 0
4573 }
4574 run_test 79 "xattr: intent error"
4575
4576 test_80a() {
4577         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4578         local MDTIDX=1
4579         local mdt_index
4580         local i
4581         local file
4582         local pid
4583
4584         mkdir_on_mdt0 $DIR1/$tdir
4585         mkdir -p $DIR1/$tdir/dir
4586         createmany -o $DIR1/$tdir/dir/f 10 ||
4587                 error "create files under remote dir failed $i"
4588
4589         cp /etc/passwd $DIR1/$tdir/$tfile
4590
4591         #migrate open file should fails
4592         multiop_bg_pause $DIR2/$tdir/$tfile O_c || error "open $file failed"
4593         pid=$!
4594         # give multiop a chance to open
4595         sleep 1
4596
4597         $LFS migrate -m $MDTIDX $DIR1/$tdir &&
4598                 error "migrate open files should failed with open files"
4599
4600         kill -USR1 $pid
4601
4602         $LFS migrate -m $MDTIDX $DIR1/$tdir ||
4603                         error "migrate remote dir error"
4604
4605         echo "Finish migration, then checking.."
4606         for file in $(find $DIR1/$tdir); do
4607                 mdt_index=$($LFS getstripe -m $file)
4608                 [ $mdt_index == $MDTIDX ] ||
4609                         error "$file is not on MDT${MDTIDX}"
4610         done
4611
4612         diff /etc/passwd $DIR1/$tdir/$tfile ||
4613                 error "file different after migration"
4614
4615         rm -rf $DIR1/$tdir || error "rm dir failed after migration"
4616 }
4617 run_test 80a "migrate directory when some children is being opened"
4618
4619 cleanup_80b() {
4620         trap 0
4621         kill -9 $migrate_pid
4622 }
4623
4624 test_80b() {
4625         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4626         local migrate_dir1=$DIR1/$tdir/migrate_dir
4627         local migrate_dir2=$DIR2/$tdir/migrate_dir
4628         local migrate_run=$LUSTRE/tests/migrate.sh
4629         local start_time
4630         local show_time=1
4631         local mdt_idx
4632         local rc=0
4633         local rc1=0
4634
4635         trap cleanup_80b EXIT
4636         #prepare migrate directory
4637         mkdir -p $migrate_dir1
4638         for F in {1,2,3,4,5}; do
4639                 echo "$F$F$F$F$F" > $migrate_dir1/file$F
4640                 echo "$F$F$F$F$F" > $DIR/$tdir/file$F
4641         done
4642
4643         #migrate the directories among MDTs
4644         (
4645                 while true; do
4646                         mdt_idx=$((RANDOM % MDSCOUNT))
4647                         $LFS migrate -m $mdt_idx $migrate_dir1 &>/dev/null ||
4648                                 rc=$?
4649                         (( $rc != 0 && $rc != 16 )) || break
4650                 done
4651         ) &
4652         migrate_pid=$!
4653
4654         echo "start migration thread $migrate_pid"
4655         #Access the files at the same time
4656         start_time=$SECONDS
4657         echo "accessing the migrating directory for 5 minutes..."
4658         while true; do
4659                 ls $migrate_dir2 > /dev/null || {
4660                         echo "read dir fails"
4661                         break
4662                 }
4663                 diff -u $DIR2/$tdir/file1 $migrate_dir2/file1 || {
4664                         echo "access file1 fails"
4665                         break
4666                 }
4667
4668                 cat $migrate_dir2/file2 > $migrate_dir2/file3 || {
4669                         echo "access file2/3 fails"
4670                         break
4671                 }
4672
4673                 echo "aaaaa" > $migrate_dir2/file4 > /dev/null || {
4674                         echo "access file4 fails"
4675                         break
4676                 }
4677
4678                 stat $migrate_dir2/file5 > /dev/null || {
4679                         echo "stat file5 fails"
4680                         break
4681                 }
4682
4683                 touch $migrate_dir2/source_file > /dev/null || rc1=$?
4684                 (( $rc != 0 && $rc != 1 )) || {
4685                         echo "touch file failed with $rc1"
4686                         break;
4687                 }
4688
4689                 if [ -e $migrate_dir2/source_file ]; then
4690                         ln $migrate_dir2/source_file $migrate_dir2/link_file \
4691                                         &>/dev/null || rc1=$?
4692                         if [ -e $migrate_dir2/link_file ]; then
4693                                 rm -rf $migrate_dir2/link_file
4694                         fi
4695
4696                         mrename $migrate_dir2/source_file \
4697                                 $migrate_dir2/target_file &>/dev/null || rc1=$?
4698                         (( $rc != 0 && $rc != 1 )) || {
4699                                 echo "rename failed with $rc1"
4700                                 break
4701                         }
4702
4703                         if [ -e $migrate_dir2/target_file ]; then
4704                                 rm -rf $migrate_dir2/target_file &>/dev/null ||
4705                                                                 rc1=$?
4706                         else
4707                                 rm -rf $migrate_dir2/source_file &>/dev/null ||
4708                                                                 rc1=$?
4709                         fi
4710                         (( $rc != 0 && $rc != 1 )) || {
4711                                 echo "unlink failed with $rc1"
4712                                 break
4713                         }
4714                 fi
4715
4716                 local duration=$((SECONDS - start_time))
4717                 if (( duration % 10 == 0 )); then
4718                         if (( $show_time == 1 )); then
4719                                 echo "...$duration seconds"
4720                                 show_time=0
4721                         fi
4722                 else
4723                         show_time=1
4724                 fi
4725
4726                 kill -0 $migrate_pid || {
4727                         echo "migration stopped 1"
4728                         break
4729                 }
4730
4731                 (( $duration < 300 )) || break
4732         done
4733
4734         #check migration are still there
4735         kill -0 $migrate_pid || error "migration stopped 2"
4736         cleanup_80b
4737 }
4738 run_test 80b "Accessing directory during migration"
4739
4740 test_81a() {
4741         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4742
4743         rm -rf $DIR1/$tdir
4744
4745         mkdir -p $DIR1/$tdir
4746
4747         $LFS setdirstripe -i0 -c$MDSCOUNT  $DIR1/$tdir/d0
4748         $LFS setdirstripe -i0 -c$MDSCOUNT  $DIR1/$tdir/d1
4749
4750         cd $DIR1/$tdir
4751         touch d0/0      || error "create 0 failed"
4752         mv d0/0 d1/0    || error "rename d0/0 d1/0 failed"
4753         stat d0/0       && error "stat mv filed succeed"
4754         mv $DIR2/$tdir/d1/0 $DIR2/$tdir/d0/0 || error "rename d1/0 d0/0 failed"
4755         stat d0/0       || error "stat failed"
4756
4757         local t=$(ls -ai $DIR1/$tdir/d0 | sort -u | wc -l)
4758
4759         if [ $t -ne 3 ]; then
4760                 ls -ai $DIR1/$tdir/d0
4761                 error "expect 3 get $t"
4762         fi
4763
4764         return 0
4765 }
4766 run_test 81a "rename and stat under striped directory"
4767
4768 test_81b() {
4769         [ $MDSCOUNT -lt 2 ] &&
4770                 skip "We need at least 2 MDTs for this test"
4771
4772         local total
4773         local setattr_pid
4774
4775         total=1000
4776
4777         $LFS mkdir -c $MDSCOUNT $DIR1/$tdir || error "$LFS mkdir"
4778         createmany -o $DIR1/$tdir/$tfile. $total || error "createmany"
4779
4780         (
4781                 while true; do
4782                         touch $DIR1/$tdir
4783                 done
4784         ) &
4785         setattr_pid=$!
4786
4787         for i in $(seq $total); do
4788                 mrename $DIR2/$tdir/$tfile.$i $DIR2/$tdir/$tfile-new.$i \
4789                         > /dev/null
4790         done
4791
4792         kill -9 $setattr_pid
4793 }
4794 run_test 81b "rename under striped directory doesn't deadlock"
4795
4796 test_81c() {
4797         [ $MDSCOUNT -lt 4 ] && skip_env "needs >= 4 MDTs"
4798         [ $MDS1_VERSION -lt $(version_code 2.13.52) ] &&
4799                 skip "Need MDS version at least 2.13.52"
4800
4801         # source is local, source parent is remote
4802         $LFS mkdir -i 0 $DIR1/${tdir}_src || error "mkdir ${tdir}_src"
4803         $LFS mkdir -i 1 $DIR1/${tdir}_tgt || error "mkdir ${tdir}_tgt"
4804         $LFS mkdir -i 3 $DIR1/${tdir}_src/sub || error "mkdir sub"
4805         $LFS mkdir -i 3 $DIR1/${tdir}_tgt/sub || error "mkdir sub"
4806         stat $DIR2/${tdir}_src/sub || error "stat sub failed"
4807         mv $DIR1/${tdir}_src/sub $DIR1/${tdir}_tgt/ || error "mv failed"
4808         [ -f $DIR2/${tdir}_src/sub ] && error "sub should be gone"
4809         rm -rf $DIR1/${tdir}_src $DIR1/${tdir}_tgt
4810
4811         # source is remote, source parent is local
4812         $LFS mkdir -i 3 $DIR1/${tdir}_src || error "mkdir ${tdir}_src"
4813         $LFS mkdir -i 1 $DIR1/${tdir}_tgt || error "mkdir ${tdir}_tgt"
4814         $LFS mkdir -i 0 $DIR1/${tdir}_src/sub || error "mkdir sub"
4815         $LFS mkdir -i 3 $DIR1/${tdir}_tgt/sub || error "mkdir sub"
4816         stat $DIR2/${tdir}_src/sub || error "stat sub failed"
4817         mv $DIR1/${tdir}_src/sub $DIR1/${tdir}_tgt/ || error "mv failed"
4818         [ -f $DIR2/${tdir}_src/sub ] && error "sub should be gone"
4819         rm -rf $DIR1/${tdir}_src $DIR1/${tdir}_tgt
4820
4821         # source and source parent are remote
4822         $LFS mkdir -i 0 $DIR1/${tdir}_src || error "mkdir ${tdir}_src"
4823         $LFS mkdir -i 1 $DIR1/${tdir}_tgt || error "mkdir ${tdir}_tgt"
4824         mkdir $DIR1/${tdir}_src/sub || error "mkdir sub"
4825         $LFS mkdir -i 3 $DIR1/${tdir}_tgt/sub || error "mkdir sub"
4826         stat $DIR2/${tdir}_src/sub || error "stat sub failed"
4827         mv $DIR1/${tdir}_src/sub $DIR1/${tdir}_tgt/ || error "mv failed"
4828         [ -f $DIR2/${tdir}_src/sub ] && error "sub should be gone"
4829         rm -rf $DIR1/${tdir}_src $DIR1/${tdir}_tgt
4830
4831         # source and source parent are remote, and source is remote object
4832         $LFS mkdir -i 0 $DIR1/${tdir}_src || error "mkdir ${tdir}_src"
4833         $LFS mkdir -i 1 $DIR1/${tdir}_tgt || error "mkdir ${tdir}_tgt"
4834         $LFS mkdir -i 2 $DIR1/${tdir}_src/sub || error "mkdir sub"
4835         $LFS mkdir -i 3 $DIR1/${tdir}_tgt/sub || error "mkdir sub"
4836         stat $DIR2/${tdir}_src/sub || error "stat sub failed"
4837         mv $DIR1/${tdir}_src/sub $DIR1/${tdir}_tgt/ || error "mv failed"
4838         [ -f $DIR2/${tdir}_src/sub ] && error "sub should be gone" || true
4839 }
4840 run_test 81c "rename revoke LOOKUP lock for remote object"
4841
4842 test_82() {
4843         [[ "$MDS1_VERSION" -gt $(version_code 2.6.91) ]] ||
4844                 skip "Need MDS version at least 2.6.92"
4845
4846         # Client 1 creates a file.
4847         multiop_bg_pause $DIR1/$tfile O_ac || error "multiop_bg_pause 1"
4848         pid1=$!
4849         # Client 2 opens the file.
4850         multiop_bg_pause $DIR2/$tfile o_Ac || error "multiop_bg_pause 2"
4851         pid2=$!
4852         # Client 1 makes the file an orphan.
4853         rm $DIR1/$tfile || error "rm"
4854         # Client 2 sets EA "user.multiop".
4855         kill -s USR1 $pid2
4856         wait $pid2 || error "multiop 2"
4857         # Client 1 gets EA "user.multiop".  This used to fail because the EA
4858         # cache refill would get "trusted.link" from mdd_xattr_list() but
4859         # -ENOENT when trying to get "trusted.link"'s value.  See also sanity
4860         # 102q.
4861         kill -s USR1 $pid1
4862         wait $pid1 || error "multiop 1"
4863 }
4864 run_test 82 "fsetxattr and fgetxattr on orphan files"
4865
4866 test_83() {
4867         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4868         local pid1
4869         local pid2
4870
4871         (
4872                 cd $DIR1
4873                 while true; do
4874                         $LFS mkdir -i1 -c2 $tdir
4875                         rmdir $tdir
4876                 done
4877         ) &
4878         pid1=$!
4879         echo "start pid $pid1 to create/unlink striped directory"
4880
4881         # Access the directory at the same time
4882         (
4883                 cd $DIR2
4884                 while true; do
4885                         stat $tdir > /dev/null 2>&1
4886                 done
4887         ) &
4888         pid2=$!
4889         echo "start pid $pid2 to stat striped directory"
4890
4891         sleep 120
4892         kill $pid1 $pid2
4893         wait $pid1 $pid2
4894
4895         return 0
4896 }
4897 run_test 83 "access striped directory while it is being created/unlinked"
4898
4899 test_84() {
4900         [ $MDS1_VERSION -lt $(version_code 2.12.55) ] &&
4901                 skip "lustre < 2.12.55 does not contain LU-12485 fix"
4902
4903         local mtime
4904
4905         $MULTIOP $DIR/$tfile oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:c ||
4906                 error "create $tfile failed"
4907         mtime=$(stat -c%Y $DIR/$tfile)
4908         mtime=$((mtime + 200))
4909
4910         #define OBD_FAIL_OBD_0NLINK_RACE  0x60b
4911         do_facet mds1 $LCTL set_param fail_loc=0x8000060b
4912
4913         touch -c -m $mtime $DIR/$tfile &
4914         setattr_pid=$!
4915         # sleep a while to let 'touch' run first
4916         sleep 5
4917         rm -f $DIR2/$tfile || error "unlink $tfile failed"
4918
4919         # touch may fail
4920         wait $setattr_pid || true
4921 }
4922 run_test 84 "0-nlink race in lu_object_find()"
4923
4924 test_90() {
4925         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4926         local pid1
4927         local pid2
4928         local duration=180
4929
4930         [ "$SLOW" = "yes" ] && duration=600
4931         # Open/Create under striped directory
4932         (
4933                 cd $DIR1
4934                 while true; do
4935                         $LFS mkdir -c$MDSCOUNT $tdir > /dev/null 2>&1
4936                         touch $tdir/f{0..3} > /dev/null 2>&1
4937                 done
4938         ) &
4939         pid1=$!
4940         echo "start pid $pid1 to open/create under striped directory"
4941
4942         # unlink the striped directory at the same time
4943         (
4944                 cd $DIR2
4945                 while true; do
4946                         rm -rf $tdir > /dev/null 2>&1
4947                 done
4948         ) &
4949         pid2=$!
4950         echo "start pid $pid2 to unlink striped directory"
4951
4952         sleep $duration
4953
4954         kill $pid1 $pid2
4955         wait $pid1 $pid2
4956
4957         return 0
4958 }
4959 run_test 90 "open/create and unlink striped directory"
4960
4961 test_91() {
4962         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4963         local pid1
4964         local pid2
4965         local duration=180
4966
4967         [ "$SLOW" = "yes" ] && duration=600
4968         # chmod striped directory
4969         (
4970                 cd $DIR1
4971                 while true; do
4972                         $LFS mkdir -c$MDSCOUNT $tdir > /dev/null 2>&1
4973                         chmod go+w $tdir > /dev/null 2>&1
4974                 done
4975         ) &
4976         pid1=$!
4977         echo "start pid $pid1 to chmod striped directory"
4978
4979         # unlink the striped directory at the same time
4980         (
4981                 cd $DIR2
4982                 while true; do
4983                         rm -rf $tdir > /dev/null 2>&1
4984                 done
4985         ) &
4986         pid2=$!
4987         echo "start pid $pid2 to unlink striped directory"
4988
4989         sleep $duration
4990
4991         kill $pid1 $pid2
4992         wait $pid1 $pid2
4993
4994         return 0
4995 }
4996 run_test 91 "chmod and unlink striped directory"
4997
4998 test_92() {
4999         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5000
5001         local fd=$(free_fd)
5002         local cmd="exec $fd<$DIR1/$tdir"
5003         $LFS setdirstripe -c$MDSCOUNT $DIR1/$tdir || error "mkdir $tdir fails"
5004         eval $cmd
5005         cmd="exec $fd<&-"
5006         trap "eval $cmd" EXIT
5007         cd $DIR1/$tdir || error "cd $DIR1/$tdir fails"
5008         rmdir ../$tdir || error "rmdir ../$tdir fails"
5009
5010         #define OBD_FAIL_LLITE_NO_CHECK_DEAD  0x1408
5011         $LCTL set_param fail_loc=0x1408
5012         mkdir $DIR2/$tdir/dir && error "create dir succeeds"
5013         $LFS setdirstripe -i1 $DIR2/$tdir/remote_dir &&
5014                 error "create remote dir succeeds"
5015         $LCTL set_param fail_loc=0
5016         eval $cmd
5017         return 0
5018 }
5019 run_test 92 "create remote directory under orphan directory"
5020
5021 test_93() {
5022         local rc1=0
5023         local rc2=0
5024         local old_rr
5025
5026         mkdir -p $DIR1/$tfile-1/
5027         mkdir -p $DIR2/$tfile-2/
5028         local old_rr=$(do_facet $SINGLEMDS "$LCTL get_param -n \
5029                 lod.$FSNAME-MDT0000-*/qos_threshold_rr" | sed -e 's/%//')
5030         do_facet $SINGLEMDS "$LCTL set_param -n \
5031                 lod.$FSNAME-MDT0000-*/qos_threshold_rr=100"
5032         #define OBD_FAIL_MDS_LOV_CREATE_RACE     0x163
5033         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x00000163"
5034
5035         $LFS setstripe -c -1 $DIR1/$tfile-1/file1 &
5036         local PID1=$!
5037         sleep 1
5038         $LFS setstripe -c -1 $DIR2/$tfile-2/file2 &
5039         local PID2=$!
5040         wait $PID2
5041         wait $PID1
5042         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x0"
5043         do_facet $SINGLEMDS "$LCTL set_param -n \
5044                 lod.$FSNAME-MDT0000-*/qos_threshold_rr=$old_rr"
5045
5046         $LFS getstripe $DIR1/$tfile-1/file1
5047         rc1=$($LFS getstripe -q $DIR1/$tfile-1/file1 |
5048                 awk '{if (/[0-9]/) print $1 }' | sort | uniq -d | wc -l)
5049         $LFS getstripe $DIR2/$tfile-2/file2
5050         rc2=$($LFS getstripe -q $DIR2/$tfile-2/file2 |
5051                 awk '{if (/[0-9]/) print $1 }' | sort | uniq -d | wc -l)
5052         echo "rc1=$rc1 and rc2=$rc2 "
5053         [ $rc1 -eq 0 ] && [ $rc2 -eq 0 ] ||
5054                 error "object allocate on same ost detected"
5055 }
5056 run_test 93 "alloc_rr should not allocate on same ost"
5057
5058 test_94() {
5059         $LCTL set_param osc.*.idle_timeout=0
5060         dd if=/dev/zero of=$DIR2/$tfile bs=4k count=2 conv=fsync
5061
5062         local before=$(date +%s)
5063         local evict
5064
5065         $LCTL mark write
5066 #define OBD_FAIL_LDLM_PAUSE_CANCEL       0x312
5067         $LCTL set_param fail_val=5 fail_loc=0x80000312
5068         dd if=/dev/zero of=$DIR/$tfile conv=notrunc oflag=append bs=4k count=1 &
5069         local pid=$!
5070         sleep 2
5071
5072 #define OBD_FAIL_LDLM_PAUSE_CANCEL_LOCAL 0x329
5073         $LCTL set_param fail_val=6 fail_loc=0x80000329
5074         $LCTL mark kill $pid
5075         kill -ALRM $pid
5076
5077         dd if=/dev/zero of=$DIR2/$tfile conv=notrunc oflag=append bs=4k count=1
5078
5079         wait $pid
5080         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 conv=fsync
5081
5082         evict=$(do_facet client $LCTL get_param \
5083                 osc.$FSNAME-OST*-osc-*/state |
5084             awk -F"[ [,]" '/EVICTED ]$/ { if (t<$5) {t=$5;} } END { print t }')
5085
5086         [ -z "$evict" ] || [[ $evict -le $before ]] ||
5087                 (do_facet client $LCTL get_param \
5088                         osc.$FSNAME-OST*-osc-*/state;
5089                     error "eviction happened: $evict before:$before")
5090         $LCTL set_param osc.*.idle_timeout=debug
5091 }
5092 run_test 94 "signal vs CP callback race"
5093
5094 # Data-on-MDT tests
5095 test_100a() {
5096         skip "Reserved for glimpse-ahead" && return
5097         [ "$MDS1_VERSION" -lt $(version_code 2.10.55) ] &&
5098                 skip "Need MDS version at least 2.10.55"
5099
5100         mkdir -p $DIR/$tdir
5101
5102         $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
5103
5104         lctl set_param -n mdc.*.stats=clear
5105         dd if=/dev/zero of=$DIR2/$tdir/dom bs=4096 count=1 || return 1
5106
5107         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #1"
5108         # first stat from server should return size data and save glimpse
5109         local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
5110         [ $gls -eq 0 ] || error "Unexpected $gls glimpse RPCs"
5111         # second stat to check size is NOT cached on client without IO lock
5112         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #2"
5113
5114         local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
5115         [ $gls -ge 1 ] || error "Expect glimpse RPCs but none"
5116         rm -f $dom
5117 }
5118 run_test 100a "DoM: glimpse RPCs for stat without IO lock (DoM only file)"
5119
5120 test_100b() {
5121         [ "$MDS1_VERSION" -lt $(version_code 2.10.55) ] &&
5122                 skip "Need MDS version at least 2.10.55"
5123
5124         mkdir -p $DIR/$tdir
5125
5126         $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
5127
5128         lctl set_param -n mdc.*.stats=clear
5129         dd if=/dev/zero of=$DIR2/$tdir/dom bs=4096 count=1 || return 1
5130         cancel_lru_locks mdc
5131         # first stat data from server should have size
5132         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #1"
5133         # second stat to check size is cached on client
5134         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #2"
5135
5136         local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
5137         # both stats should cause no glimpse requests
5138         [ $gls == 0 ] || error "Unexpected $gls glimpse RPCs"
5139         rm -f $dom
5140 }
5141 run_test 100b "DoM: no glimpse RPC for stat with IO lock (DoM only file)"
5142
5143 test_100c() {
5144         [ "$MDS1_VERSION" -lt $(version_code 2.10.55) ] &&
5145                 skip "Need MDS version at least 2.10.55"
5146
5147         mkdir -p $DIR/$tdir
5148
5149         $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
5150
5151         lctl set_param -n mdc.*.stats=clear
5152         lctl set_param -n osc.*.stats=clear
5153         dd if=/dev/zero of=$DIR2/$tdir/dom bs=2048K count=1 || return 1
5154
5155         # check that size is merged from MDT and OST correctly
5156         $CHECKSTAT -t file -s 2097152 $DIR/$tdir/dom ||
5157                 error "Wrong size from stat #1"
5158
5159         local gls=$(lctl get_param -n osc.*.stats | grep -c ldlm_glimpse)
5160         [ $gls -eq 0 ] && error "Expect OST glimpse RPCs but got none"
5161
5162         rm -f $dom
5163 }
5164 run_test 100c "DoM: write vs stat without IO lock (combined file)"
5165
5166 test_100d() {
5167         [ "$MDS1_VERSION" -lt $(version_code 2.10.55) ] &&
5168                 skip "Need MDS version at least 2.10.55"
5169
5170         mkdir -p $DIR/$tdir
5171
5172         $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
5173
5174
5175         dd if=/dev/zero of=$DIR2/$tdir/dom bs=2048K count=1 || return 1
5176         lctl set_param -n mdc.*.stats=clear
5177         $TRUNCATE $DIR2/$tdir/dom 4096
5178
5179         # check that reported size is valid after file grows to OST and
5180         # is truncated back to MDT stripe size
5181         $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom ||
5182                 error "Wrong size from stat #1"
5183
5184         local gls=$(lctl get_param -n osc.*.stats | grep -c ldlm_glimpse)
5185         [ $gls -eq 0 ] && error "Expect OST glimpse but got none"
5186
5187         rm -f $dom
5188 }
5189 run_test 100d "DoM: write+truncate vs stat without IO lock (combined file)"
5190
5191 test_100e() {
5192         [ "$MDS1_VERSION" -lt $(version_code 2.11.50) ] &&
5193                 skip "Need MDS version at least 2.11.50"
5194
5195         local dom=$DIR/$tdir/dom
5196         local dom2=$DIR2/$tdir/dom
5197         mkdir -p $DIR/$tdir
5198
5199         $LFS setstripe -E 1024K -L mdt $DIR/$tdir
5200
5201         cancel_lru_locks mdc
5202         dd if=/dev/urandom of=$dom bs=12000 count=1
5203         $TRUNCATE $dom2 6000
5204         cancel_lru_locks mdc
5205         lctl set_param -n mdc.*.stats=clear
5206         # expect read-on-open to return all data before write
5207         cat /etc/hosts >> $dom
5208         local read=$(lctl get_param -n mdc.*.stats | grep -c ost_read)
5209         [[ $read -eq 0 ]] || error "Unexpected $read READ RPCs"
5210 }
5211 run_test 100e "DoM: read on open and file size"
5212
5213 test_101a() {
5214         [ "$MDS1_VERSION" -lt $(version_code 2.10.55) ] &&
5215                 skip "Need MDS version at least 2.10.55"
5216
5217         $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
5218         # to get layout
5219         $CHECKSTAT -t file $DIR1/$tfile
5220
5221         local old_wb=$(sysctl -n vm.dirty_writeback_centisecs)
5222         sysctl -wq vm.dirty_writeback_centisecs=0
5223
5224         trap "sysctl -wq vm.dirty_writeback_centisecs=$old_wb" EXIT
5225
5226         # open + IO lock
5227         dd if=/dev/zero of=$DIR1/$tfile bs=4096 count=1 ||
5228                 error_noexit "Write fails"
5229         # must discard pages
5230         lctl set_param -n mdc.*.stats=clear
5231         rm $DIR2/$tfile || error "Unlink fails"
5232
5233         local writes=$(lctl get_param -n mdc.*.stats | grep -c ost_write)
5234         [ $writes -eq 0 ] || error "Found WRITE RPC but expect none"
5235 }
5236 run_test 101a "Discard DoM data on unlink"
5237
5238 test_101b() {
5239         [ "$MDS1_VERSION" -lt $(version_code 2.10.55) ] &&
5240                 skip "Need MDS version at least 2.10.55"
5241
5242         $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
5243         touch $DIR1/${tfile}_2
5244         # to get layout
5245         $CHECKSTAT -t file $DIR1/$tfile
5246
5247         local old_wb=$(sysctl -n vm.dirty_writeback_centisecs)
5248         sysctl -wq vm.dirty_writeback_centisecs=0
5249
5250         trap "sysctl -wq vm.dirty_writeback_centisecs=$old_wb" EXIT
5251
5252         # open + IO lock
5253         dd if=/dev/zero of=$DIR1/$tfile bs=4096 count=1 || error "Write fails"
5254         # must discard pages
5255         lctl set_param -n mdc.*.stats=clear
5256         mv $DIR2/${tfile}_2 $DIR2/$tfile || error "Rename fails"
5257
5258         local writes=$(lctl get_param -n mdc.*.stats | grep -c ost_write)
5259         [ $writes -eq 0 ] || error "Found WRITE RPC but expect none"
5260 }
5261 run_test 101b "Discard DoM data on rename"
5262
5263 test_101c() {
5264         [ "$MDS1_VERSION" -lt $(version_code 2.10.55) ] &&
5265                 skip "Need MDS version at least 2.10.55"
5266
5267         $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
5268         # to get layout
5269         $CHECKSTAT -t file $DIR1/$tfile
5270
5271         local old_wb=$(sysctl -n vm.dirty_writeback_centisecs)
5272         sysctl -wq vm.dirty_writeback_centisecs=0
5273
5274         trap "sysctl -wq vm.dirty_writeback_centisecs=$old_wb" EXIT
5275
5276         # open + IO lock
5277         dd if=/dev/zero of=$DIR1/$tfile bs=4096 count=1 || error "Write fails"
5278         $MULTIOP $DIR1/$tfile O_c &
5279         MULTIOP_PID=$!
5280         sleep 1
5281         lctl set_param -n mdc.*.stats=clear
5282         rm $DIR2/$tfile > /dev/null || error "Unlink fails for opened file"
5283         kill -USR1 $MULTIOP_PID && wait $MULTIOP_PID || error "multiop failure"
5284
5285         local writes=$(lctl get_param -n mdc.*.stats | grep -c ost_write)
5286         [ $writes -eq 0 ] || error "Found WRITE RPC but expect none"
5287 }
5288 run_test 101c "Discard DoM data on close-unlink"
5289
5290 # test to verify file handle related system calls
5291 # (name_to_handle_at/open_by_handle_at)
5292 # The new system calls are supported in glibc >= 2.14.
5293
5294 # test to verify we can open by handle an unlinked file from > 1 client
5295 # This test opens the file normally on $DIR1, which is on one mount, and then
5296 # opens it by handle on $DIR2, which is on a different mount.
5297 test_102() {
5298         (( "$MDS1_VERSION" >= $(version_code 2.11.57) )) ||
5299                 skip "Needs MDS version 2.11.57 or later"
5300
5301         echo "Test file_handle syscalls" > $DIR/$tfile ||
5302                 error "write failed"
5303         check_fhandle_syscalls $DIR/$tfile $DIR2 ||
5304                 error "check_fhandle_syscalls $tfile failed"
5305
5306         # test this is working on DNE directories also
5307         if (( MDSCOUNT > 1 && MDS1_VERSION >= $(version_code 2.14.52) )); then
5308                 $LFS mkdir -i 1 $DIR/$tdir.remote
5309                 cancel_lru_locks mdc
5310                 check_fhandle_syscalls $DIR/$tdir.remote $DIR2 ||
5311                         error "check_fhandle_syscalls $tdir.remote failed"
5312                 $LFS mkdir -c -1 $DIR/$tdir.remote/subdir
5313                 cancel_lru_locks mdc
5314                 check_fhandle_syscalls $DIR/$tdir.remote/subdir $DIR2 ||
5315                         error "check_fhandle_syscalls $tdir.remote/subdir fail"
5316
5317                 $LFS mkdir -c -1 $DIR/$tdir.stripe
5318                 cancel_lru_locks mdc
5319                 check_fhandle_syscalls $DIR/$tdir.stripe $DIR2 ||
5320                         error "check_fhandle_syscalls $tdir.stripe failed"
5321                 $LFS mkdir -c -1 $DIR/$tdir.stripe/subdir
5322                 cancel_lru_locks mdc
5323                 check_fhandle_syscalls $DIR/$tdir.stripe/subdir $DIR2 ||
5324                         error "check_fhandle_syscalls $tdir.stripe/subdir fail"
5325         fi
5326 }
5327 run_test 102 "Test open by handle of unlinked file"
5328
5329 # Compare file size between first & second mount, ensuring the client correctly
5330 # glimpses even with unused speculative locks - LU-11670
5331 test_103() {
5332         [ $OST1_VERSION -lt $(version_code 2.10.50) ] &&
5333                 skip "Lockahead needs OST version at least 2.10.50"
5334
5335         local locktest=23
5336
5337         test_mkdir -p $DIR/$tdir
5338
5339         # Force file on to OST0
5340         $LFS setstripe -i 0 $DIR/$tdir
5341
5342         # Do not check multiple locks on glimpse
5343         # OBD_FAIL_OSC_NO_SIZE_DATA 0x415
5344         $LCTL set_param fail_loc=0x415
5345
5346         # Delay write commit by 2 seconds to guarantee glimpse wins race
5347         # The same fail_loc is used on client & server so it can work in the
5348         # single node sanity setup
5349         do_facet ost1 $LCTL set_param fail_loc=0x415 fail_val=2
5350
5351         echo "Incorrect size expected (no glimpse fix):"
5352         lockahead_test -d $DIR/$tdir -D $DIR2/$tdir -t $locktest -f $tfile
5353         rc=$?
5354         if [ $rc -eq 0 ]; then
5355                 echo "This doesn't work 100%, but this is just reproducing the bug, not testing the fix, so OK to not fail test."
5356         fi
5357
5358         # guarantee write commit timeout has expired
5359         sleep 2
5360
5361         # Clear fail_loc on client
5362         $LCTL set_param fail_loc=0
5363
5364         # Delay write commit by 2 seconds to guarantee glimpse wins race
5365         # OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
5366         do_facet ost1 $LCTL set_param fail_loc=0x214 fail_val=2
5367
5368         # Write commit is still delayed by 2 seconds
5369         lockahead_test -d $DIR/$tdir -D $DIR2/$tdir -t $locktest -f $tfile
5370         rc=$?
5371         [ $rc -eq 0 ] || error "Lockahead test$locktest failed, $rc"
5372
5373         # guarantee write commit timeout has expired
5374         sleep 2
5375
5376         rm -f $DIR/$tfile || error "unable to delete $DIR/$tfile"
5377 }
5378 run_test 103 "Test size correctness with lockahead"
5379
5380 get_stat_xtimes()
5381 {
5382         local xtimes
5383
5384         xtimes=$(stat -c "%X %Y %Z" $DIR/$tfile)
5385
5386         echo ${xtimes[*]}
5387 }
5388
5389 get_mdt_xtimes()
5390 {
5391         local mdtdev=$1
5392         local output
5393         local xtimes
5394
5395         output=$(do_facet mds1 "$DEBUGFS -c -R 'stat ROOT/$tfile' $mdtdev")
5396         ((xtimes[0]=$(awk -F ':' /atime/'{ print $2 }' <<< "$output")))
5397         ((xtimes[1]=$(awk -F ':' /mtime/'{ print $2 }' <<< "$output")))
5398         ((xtimes[2]=$(awk -F ':' /ctime/'{ print $2 }' <<< "$output")))
5399
5400         echo ${xtimes[*]}
5401 }
5402
5403 check_mdt_xtimes()
5404 {
5405         local mdtdev=$1
5406         local xtimes=($(get_stat_xtimes))
5407         local mdt_xtimes=($(get_mdt_xtimes $mdtdev))
5408
5409         echo "STAT a|m|ctime ${xtimes[*]}"
5410         echo "MDT a|m|ctime ${mdt_xtimes[*]}"
5411         [[ ${xtimes[0]} == ${mdt_xtimes[0]} ]] ||
5412                 error "$DIR/$tfile atime (${xtimes[0]}:${mdt_xtimes[0]}) diff"
5413         [[ ${xtimes[1]} == ${mdt_xtimes[1]} ]] ||
5414                 error "$DIR/$tfile mtime (${xtimes[1]}:${mdt_xtimes[1]}) diff"
5415         [[ ${xtimes[2]} == ${mdt_xtimes[2]} ]] ||
5416                 error "$DIR/$tfile ctime (${xtimes[2]}:${mdt_xtimes[2]}) diff"
5417 }
5418
5419 test_104() {
5420         [ "$mds1_FSTYPE" == "ldiskfs" ] || skip_env "ldiskfs only test"
5421         [ $MDS1_VERSION -lt $(version_code 2.12.4) ] &&
5422                 skip "Need MDS version at least 2.12.4"
5423
5424         local pid
5425         local mdtdev=$(mdsdevname ${SINGLEMDS//mds/})
5426         local atime_diff=$(do_facet $SINGLEMDS \
5427                 lctl get_param -n mdd.*MDT0000*.atime_diff)
5428
5429         do_facet $SINGLEMDS \
5430                 lctl set_param -n mdd.*MDT0000*.atime_diff=0
5431
5432         stack_trap "do_facet $SINGLEMDS \
5433                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff" EXIT
5434
5435         dd if=/dev/zero of=$DIR/$tfile bs=1k count=1 conv=notrunc
5436         check_mdt_xtimes $mdtdev
5437         sleep 2
5438
5439         dd if=/dev/zero of=$DIR/$tfile bs=1k count=1 conv=notrunc
5440         check_mdt_xtimes $mdtdev
5441         sleep 2
5442         $MULTIOP $DIR2/$tfile Oz8192w8192_c &
5443         pid=$!
5444         sleep 2
5445         dd if=/dev/zero of=$DIR/$tfile bs=1k count=1 conv=notrunc
5446         sleep 2
5447         kill -USR1 $pid && wait $pid || error "multiop failure"
5448         check_mdt_xtimes $mdtdev
5449
5450         local xtimes
5451         local mdt_xtimes
5452
5453         # Verify mtime/ctime is NOT upated on MDS when there is no modification
5454         # on the client side
5455         xtimes=($(get_stat_xtimes))
5456         $MULTIOP $DIR/$tfile O_c &
5457         pid=$!
5458         sleep 2
5459         kill -USR1 $pid && wait $pid || error "multiop failure"
5460         mdt_xtimes=($(get_mdt_xtimes $mdtdev))
5461         [[ ${xtimes[1]} == ${mdt_xtimes[1]} ]] ||
5462                 error "$DIR/$tfile mtime (${xtimes[1]}:${mdt_xtimes[1]}) diff"
5463         [[ ${xtimes[2]} == ${mdt_xtimes[2]} ]] ||
5464                 error "$DIR/$tfile ctime (${xtimes[2]}:${mdt_xtimes[2]}) diff"
5465         check_mdt_xtimes $mdtdev
5466
5467         sleep 2
5468         # Change ctime via chmod
5469         $MULTIOP $DIR/$tfile o_tc &
5470         pid=$!
5471         sleep 2
5472         kill -USR1 $pid && wait $pid || error "multiop failure"
5473         check_mdt_xtimes $mdtdev
5474 }
5475 run_test 104 "Verify that MDS stores atime/mtime/ctime during close"
5476
5477 test_105() {
5478         test_mkdir -p $DIR/$tdir
5479         echo test > $DIR/$tdir/$tfile
5480         $LCTL set_param fail_loc=0x416
5481         cancel_lru_locks osc & sleep 1
5482         fsize1=$(stat -c %s $DIR2/$tdir/$tfile)
5483         wait
5484         [[ $fsize1 = 5 ]] ||  error "Glimpse returned wrong file size $fsize1"
5485 }
5486 run_test 105 "Glimpse and lock cancel race"
5487
5488 test_106a() {
5489         [ "$mds1_FSTYPE" == "ldiskfs" ] && statx_supported ||
5490                 skip_env "Test only for ldiskfs and statx() supported"
5491
5492         local btime
5493         local mdt_btime
5494         local output
5495         local mdtdev=$(mdsdevname ${SINGLEMDS//mds/})
5496
5497         dd if=/dev/zero of=$DIR/$tfile bs=1k count=1 conv=notrunc
5498         btime=$($STATX -c %W $DIR/$tfile)
5499         output=$(do_facet mds1 "$DEBUGFS -c -R 'stat ROOT/$tfile' $mdtdev")
5500         echo $output
5501         ((mdt_btime=$(awk -F ':' /crtime/'{ print $2 }' <<< "$output")))
5502         [[ $btime == $mdt_btime ]] ||
5503                 error "$DIR/$tfile btime ($btime:$mdt_btime) diff"
5504
5505 }
5506 run_test 106a "Verify the btime via statx()"
5507
5508 test_106b() {
5509         statx_supported || skip_env "statx() only test"
5510
5511         local rpcs_before
5512         local rpcs_after
5513
5514         $LFS setstripe -c 1 $DIR/$tfile || error "$DIR/$tfile setstripe failed"
5515         dd if=/dev/zero of=$DIR/$tfile bs=1k count=1 conv=notrunc
5516         cancel_lru_locks $OSC
5517         rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
5518         $STATX $DIR/$tfile
5519         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
5520         [ $rpcs_after -eq $((rpcs_before + 1)) ] ||
5521                 error "$STATX should send 1 glimpse RPC to $OSC"
5522
5523         cancel_lru_locks $OSC
5524         rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
5525         # %n: FILENAME; %i: STATX_INO; %A STATX_MODE; %h STATX_NLINK;
5526         # %u: STATX_UID; %g: STATX_GID; %W STATX_BTIME; %X STATX_ATIME;
5527         # %Z: STATX_CTIME
5528         $STATX -c "%n %i %A %h %u %g %W %X %Z" $DIR/$tfile
5529         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
5530         [ $rpcs_after -eq $rpcs_before ] ||
5531                 error "$STATX should not send glimpse RPCs to $OSC"
5532
5533         cancel_lru_locks $OSC
5534         rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
5535         $STATX --cached=always $DIR/$tfile
5536         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
5537         [ $rpcs_after -eq $rpcs_before ] ||
5538                 error "$STATX should not send glimpse RPCs to $OSC"
5539
5540         cancel_lru_locks $OSC
5541         rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
5542         $STATX -c %Y $DIR/$tfile
5543         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
5544         [ $rpcs_after -eq $((rpcs_before + 1)) ] ||
5545                 error "$STATX -c %Y should send 1 glimpse RPC to $OSC"
5546
5547         cancel_lru_locks $OSC
5548         rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
5549         $STATX -c %s $DIR/$tfile
5550         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
5551         [ $rpcs_after -eq $((rpcs_before + 1)) ] ||
5552                 error "$STATX -c %s should send 1 glimpse RPC to $OSC"
5553
5554         cancel_lru_locks $OSC
5555         rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
5556         $STATX -c %b $DIR/$tfile
5557         rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
5558         [ $rpcs_after -eq $((rpcs_before + 1)) ] ||
5559                 error "$STATX -c %b should send 1 glimpse RPC to $OSC"
5560 }
5561 run_test 106b "Glimpse RPCs test for statx"
5562
5563 test_106c() {
5564         statx_supported || skip_env "statx() only test"
5565
5566         local mask
5567
5568         touch $DIR/$tfile
5569         # Mask supported in stx_attributes by Lustre is
5570         # STATX_ATTR_IMMUTABLE(0x10) | STATX_ATTR_APPEND(0x20) : (0x30).
5571         mask=$($STATX -c %p $DIR/$tfile)
5572         [[ $mask == "30" ]] ||
5573                 error "supported stx_attributes: got '$mask', expected '30'"
5574         chattr +i $DIR/$tfile || error "chattr +i $DIR/$tfile failed"
5575         mask=$($STATX -c %r $DIR/$tfile)
5576         [[ $mask == "10" ]] ||
5577                 error "got immutable flags '$mask', expected '10'"
5578         chattr -i $DIR/$tfile || error "chattr -i $DIR/$tfile failed"
5579         mask=$($STATX -c %r $DIR/$tfile)
5580         [[ $mask == "0" ]] || error "got flags '$mask', expected '0'"
5581         chattr +a $DIR/$tfile || error "chattr +a $DIR/$tfile failed"
5582         mask=$($STATX -c %r $DIR/$tfile)
5583         [[ $mask == "20" ]] || error "got flags '$mask', expected '20'"
5584         chattr -a $DIR/$tfile || error "chattr -a $DIR/$tfile failed"
5585         mask=$($STATX -c %r $DIR/$tfile)
5586         [[ $mask == "0" ]] || error "got flags '$mask', expected '0'"
5587         chattr +ia $DIR/$tfile || error "chattr +ia $DIR/$tfile failed"
5588         mask=$($STATX -c %r $DIR/$tfile)
5589         [[ $mask == "30" ]] || error "got flags '$mask', expected '30'"
5590         chattr -ia $DIR/$tfile || error "chattr -ia $DIR/$tfile failed"
5591         mask=$($STATX -c %r $DIR/$tfile)
5592         [[ $mask == "0" ]] || error "got flags '$mask', expected '0'"
5593 }
5594 run_test 106c "Verify statx attributes mask"
5595
5596 test_107a() { # LU-1031
5597         dd if=/dev/zero of=$DIR1/$tfile bs=1M count=10
5598         local gid1=14091995
5599         local gid2=16022000
5600
5601         $LFS getstripe $DIR1/$tfile
5602
5603         multiop_bg_pause $DIR1/$tfile OG${gid1}_g${gid1}c || return 1
5604         local MULTIPID1=$!
5605         multiop_bg_pause $DIR2/$tfile O_G${gid2}r10g${gid2}c || return 2
5606         local MULTIPID2=$!
5607         kill -USR1 $MULTIPID2
5608         sleep 2
5609         if [[ $(ps h -o comm -p $MULTIPID2) == "" ]]; then
5610                 error "First grouplock does not block second one"
5611         else
5612                 echo "First grouplock blocks second one"
5613         fi
5614         kill -USR1 $MULTIPID1
5615         wait $MULTIPID1
5616         wait $MULTIPID2
5617 }
5618 run_test 107a "Basic grouplock conflict"
5619
5620 test_107b() {
5621         dd if=/dev/zero of=$DIR1/$tfile bs=1M count=10
5622         local gid1=14091995
5623         local gid2=16022000
5624
5625         $LFS getstripe $DIR1/$tfile
5626
5627         multiop_bg_pause $DIR1/$tfile OG${gid1}_g${gid1}c || return 1
5628         local MULTIPID1=$!
5629         multiop $DIR2/$tfile Or10c &
5630         local MULTIPID2=$!
5631         sleep 2
5632
5633         if [[ $(ps h -o comm -p $MULTIPID2) == "" ]]; then
5634                 error "Grouplock does not block IO"
5635         else
5636                 echo "Grouplock blocks IO"
5637         fi
5638
5639         multiop $DIR2/$tfile OG${gid2}_g${gid2}c &
5640         local MULTIPID3=$!
5641         sleep 2
5642         if [[ $(ps h -o comm -p $MULTIPID3) == "" ]]; then
5643                 error "First grouplock does not block second one"
5644         else
5645                 echo "First grouplock blocks second one"
5646         fi
5647
5648         kill -USR1 $MULTIPID1
5649         sleep 2
5650
5651         if [[ $(ps h -o comm -p $MULTIPID3) == "" ]]; then
5652                 error "Second grouplock thread disappeared"
5653         fi
5654
5655         if [[ $(ps h -o comm -p $MULTIPID2) == "" ]]; then
5656                 error "Second grouplock does not block IO"
5657         else
5658                 echo "Second grouplock blocks IO"
5659         fi
5660
5661         kill -USR1 $MULTIPID3
5662         wait $MULTIPID1
5663         wait $MULTIPID2
5664         wait $MULTIPID3
5665 }
5666 run_test 107b "Grouplock is added to the head of waiting list"
5667
5668 test_108a() {
5669         local offset
5670
5671         $LFS setstripe -E 1M -c 1 -E -1 $DIR1/$tfile ||
5672                 error "Create $DIR1/$tfile failed"
5673
5674         dd if=/dev/zero of=$DIR1/$tfile bs=10000 count=1 ||
5675                 error "dd $DIR1/$tfile failed"
5676         offset=$(lseek_test -d 5000 $DIR2/$tfile)
5677         [[ $offset == 5000 ]] || error "offset $offset != 5000"
5678
5679         $TRUNCATE $DIR1/$tfile 2000
5680         offset=$(lseek_test -l 1000 $DIR2/$tfile)
5681         [[ $offset == 2000 ]] || error "offset $offset != 2000"
5682
5683         #define OBD_FAIL_OSC_DELAY_IO 0x414
5684         $LCTL set_param fail_val=4 fail_loc=0x80000414
5685         dd if=/dev/zero of=$DIR1/$tfile count=1 bs=8M conv=notrunc oflag=dsync &
5686         local pid=$!
5687         sleep 2
5688
5689         offset=$(lseek_test -l 8000 $DIR2/$tfile)
5690         wait $pid
5691         [[ $offset == 8388608 ]] || error "offset $offset != 8388608"
5692 }
5693 run_test 108a "lseek: parallel updates"
5694
5695 # LU-14110
5696 test_109() {
5697         local i
5698         local pid1 pid2
5699
5700         ! local_mode ||
5701                 skip "Clients need to be on different nodes than the servers"
5702
5703         umount_client $MOUNT
5704         umount_client $MOUNT2
5705
5706         echo "Starting race between client mount instances (50 iterations):"
5707         for i in {1..50}; do
5708                 log "Iteration $i"
5709
5710 #define OBD_FAIL_ONCE|OBD_FAIL_LLITE_RACE_MOUNT        0x80001417
5711                 $LCTL set_param -n fail_loc=0x80001417
5712
5713                 mount_client $MOUNT  & pid1=$!
5714                 mount_client $MOUNT2 & pid2=$!
5715                 wait $pid1 || error "Mount $MOUNT fails with $?"
5716                 wait $pid2 || error "Mount $MOUNT2 fails with $?"
5717
5718                 umount_client $MOUNT  & pid1=$!
5719                 umount_client $MOUNT2 & pid2=$!
5720                 wait $pid1 || error "Umount $MOUNT fails with $?"
5721                 wait $pid2 || error "Umount $MOUNT2 fails with $?"
5722
5723                 $LUSTRE_RMMOD || error "Fail to remove lustre modules"
5724                 load_modules
5725                 echo
5726         done
5727
5728         mount_client $MOUNT
5729         mount_client $MOUNT2
5730 }
5731
5732 run_test 109 "Race with several mount instances on 1 node"
5733
5734 test_110() {
5735         local before=$(date +%s)
5736         local evict
5737
5738         mkdir -p $DIR/$tdir
5739         touch $DIR/$tdir/f1
5740         touch $DIR/$tfile
5741
5742         #define OBD_FAIL_PTLRPC_RESEND_RACE      0x525
5743         do_facet mds1 lctl set_param fail_loc=0x525 fail_val=3
5744
5745         # disable last_xid logic by dropping link reply
5746         ln $DIR/$tdir/f1 $DIR/$tdir/f2 &
5747         sleep 1
5748
5749         #define OBD_FAIL_PTLRPC_ENQ_RESEND      0x534
5750         do_facet mds1 lctl set_param fail_loc=0x534
5751
5752         # RPC will race with its Resend and the Resend will sleep to let
5753         # the original lock to get granted & cancelled.
5754         #
5755         # AST_SENT is set artificially, so an explicit conflict is not needed
5756         #
5757         # The woken up Resend gets a new lock, but client does not wait for it
5758         stat $DIR/$tfile
5759         sleep $TIMEOUT
5760         do_facet mds1 lctl set_param fail_loc=0 fail_val=0
5761
5762         # Take a conflict to wait long enough to see the eviction
5763         touch $DIR2/$tfile
5764
5765         # let the client reconnect
5766         client_reconnect
5767         evict=$(do_facet client $LCTL get_param mdc.$FSNAME-MDT*.state |
5768           awk -F"[ [,]" '/EVICTED ]$/ { if (mx<$5) {mx=$5;} } END { print mx }')
5769
5770         [ -z "$evict" ] || [[ $evict -le $before ]] ||
5771                 (do_facet client $LCTL get_param mdc.$FSNAME-MDT*.state;
5772                     error "eviction happened: $evict before:$before")
5773 }
5774 run_test 110 "do not grant another lock on resend"
5775
5776 test_111() {
5777         [ $MDSCOUNT -ge 2 ] || skip "needs >= 2 MDTs"
5778         [[ $(facet_active_host mds1) = $(facet_active_host mds2) ]] ||
5779                 skip "MDT0 and MDT1 should be on the same node"
5780
5781         mkdir $DIR1/$tdir
5782         $LFS mkdir -i 0 $DIR1/$tdir/mdt0dir
5783         $LFS mkdir -i 1 $DIR1/$tdir/mdt1dir
5784
5785         mkdir $DIR1/$tdir/mdt0dir/foodir
5786         touch $DIR1/$tdir/mdt0dir/foodir/{file1,file2}
5787
5788         $MULTIOP $DIR2/$tdir/mdt0dir/foodir/file2 Ow4096_c &
5789         MULTIOP_PID=$!
5790         ln $DIR1/$tdir/mdt0dir/foodir/file2 $DIR1/$tdir/mdt1dir/file2
5791
5792         #define OBD_FAIL_MDS_LINK_RENAME_RACE   0x18a
5793         do_facet mds1 $LCTL set_param fail_loc=0x8000018a
5794
5795         ln $DIR1/$tdir/mdt0dir/foodir/file2 $DIR1/$tdir/mdt1dir/file2x &
5796         sleep 1
5797
5798         rm $DIR2/$tdir/mdt1dir/file2
5799         sleep 1
5800
5801         mv $DIR2/$tdir/mdt0dir/foodir/file1 $DIR2/$tdir/mdt0dir/foodir/file2
5802         sleep 1
5803
5804         kill $MULTIOP_PID
5805         wait
5806         rm -r $DIR1/$tdir || error "Removing test dir failed"
5807 }
5808 run_test 111 "A racy rename/link an open file should not cause fs corruption"
5809
5810 test_112() {
5811         (( MDSCOUNT >= 2 )) ||
5812                 skip "We need at least 2 MDTs for this test"
5813
5814         (( MDS1_VERSION >= $(version_code 2.14.54) )) ||
5815                 skip "Need server version at least 2.14.54"
5816
5817         local rr
5818         local count
5819
5820         rr=$($LCTL get_param -n lmv.*.qos_threshold_rr | head -n1)
5821         rr=${rr%%%}
5822         stack_trap "$LCTL set_param lmv.*.qos_threshold_rr=$rr > /dev/null"
5823
5824         mkdir -p $DIR1/$tdir/s1/s2 || error "mkdir s2 failed"
5825         $LFS mkdir -i 0 $DIR1/$tdir/s1/s2/s3 || error "mkdir s3 failed"
5826         $LFS setdirstripe -D -i -1 --max-inherit-rr=0 $DIR1/$tdir/s1/s2/s3 ||
5827                 error "setdirstripe s3 failed"
5828         $LCTL set_param lmv.*.qos_threshold_rr=90
5829         mkdir $DIR2/$tdir/s1/s2/s3/d{1..64}
5830         count=$($LFS getstripe -m $DIR2/$tdir/s1/s2/s3/d* | grep ^0 | wc -l)
5831         (( count == 64 )) || error "only $count subdirs created on MDT0"
5832
5833         $LFS setdirstripe -D -i -1 --max-inherit-rr=3 $DIR1/$tdir/s1/s2/s3 ||
5834                 error "setdirstripe s3 failed"
5835         mkdir $DIR2/$tdir/s1/s2/s3/s{1..64}
5836         count=$($LFS getstripe -m $DIR2/$tdir/s1/s2/s3/s* | grep ^0 | wc -l)
5837         (( count == 64 / MDSCOUNT )) || error "$count subdirs created on MDT0"
5838 }
5839 run_test 112 "update max-inherit in default LMV"
5840
5841 log "cleanup: ======================================================"
5842
5843 # kill and wait in each test only guarentee script finish, but command in script
5844 # like 'rm' 'chmod' may still be running, wait for all commands to finish
5845 # otherwise umount below will fail
5846 [ "$(mount | grep $MOUNT2)" ] && wait_update $HOSTNAME "fuser -m $MOUNT2" "" ||
5847         true
5848
5849 complete $SECONDS
5850 rm -f $SAMPLE_FILE
5851 check_and_cleanup_lustre
5852 exit_status