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