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