+test_93() {
+ local rc1=0
+ local rc2=0
+ local old_rr
+
+ mkdir -p $DIR1/$tfile-1/
+ mkdir -p $DIR2/$tfile-2/
+ local old_rr=$(do_facet $SINGLEMDS "$LCTL get_param -n \
+ lod.$FSNAME-MDT0000-*/qos_threshold_rr" | sed -e 's/%//')
+ do_facet $SINGLEMDS "$LCTL set_param -n \
+ lod.$FSNAME-MDT0000-*/qos_threshold_rr=100"
+ #define OBD_FAIL_MDS_LOV_CREATE_RACE 0x163
+ do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x00000163"
+
+ $LFS setstripe -c -1 $DIR1/$tfile-1/file1 &
+ local PID1=$!
+ sleep 1
+ $LFS setstripe -c -1 $DIR2/$tfile-2/file2 &
+ local PID2=$!
+ wait $PID2
+ wait $PID1
+ do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x0"
+ do_facet $SINGLEMDS "$LCTL set_param -n \
+ lod.$FSNAME-MDT0000-*/qos_threshold_rr=$old_rr"
+
+ $LFS getstripe $DIR1/$tfile-1/file1
+ rc1=$($LFS getstripe -q $DIR1/$tfile-1/file1 |
+ awk '{if (/[0-9]/) print $1 }' | sort | uniq -d | wc -l)
+ $LFS getstripe $DIR2/$tfile-2/file2
+ rc2=$($LFS getstripe -q $DIR2/$tfile-2/file2 |
+ awk '{if (/[0-9]/) print $1 }' | sort | uniq -d | wc -l)
+ echo "rc1=$rc1 and rc2=$rc2 "
+ [ $rc1 -eq 0 ] && [ $rc2 -eq 0 ] ||
+ error "object allocate on same ost detected"
+}
+run_test 93 "alloc_rr should not allocate on same ost"
+
+test_94() {
+ $LCTL set_param osc.*.idle_timeout=0
+ dd if=/dev/zero of=$DIR2/$tfile bs=4k count=2 conv=fsync
+
+ local before=$(date +%s)
+ local evict
+
+ $LCTL mark write
+#define OBD_FAIL_LDLM_PAUSE_CANCEL 0x312
+ $LCTL set_param fail_val=5 fail_loc=0x80000312
+ dd if=/dev/zero of=$DIR/$tfile conv=notrunc oflag=append bs=4k count=1 &
+ local pid=$!
+ sleep 2
+
+#define OBD_FAIL_LDLM_PAUSE_CANCEL_LOCAL 0x329
+ $LCTL set_param fail_val=6 fail_loc=0x80000329
+ $LCTL mark kill $pid
+ kill -ALRM $pid
+
+ dd if=/dev/zero of=$DIR2/$tfile conv=notrunc oflag=append bs=4k count=1
+
+ wait $pid
+ dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 conv=fsync
+
+ evict=$(do_facet client $LCTL get_param \
+ osc.$FSNAME-OST*-osc-*/state |
+ awk -F"[ [,]" '/EVICTED ]$/ { if (t<$5) {t=$5;} } END { print t }')
+
+ [ -z "$evict" ] || [[ $evict -le $before ]] ||
+ (do_facet client $LCTL get_param \
+ osc.$FSNAME-OST*-osc-*/state;
+ error "eviction happened: $evict before:$before")
+ $LCTL set_param osc.*.idle_timeout=debug
+}
+run_test 94 "signal vs CP callback race"
+
+# Data-on-MDT tests
+test_100a() {
+ skip "Reserved for glimpse-ahead" && return
+ [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
+ skip "Need MDS version at least 2.10.55"
+
+ mkdir -p $DIR/$tdir
+
+ $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
+
+ lctl set_param -n mdc.*.stats=clear
+ dd if=/dev/zero of=$DIR2/$tdir/dom bs=4096 count=1 || return 1
+
+ $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #1"
+ # first stat from server should return size data and save glimpse
+ local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
+ [ $gls -eq 0 ] || error "Unexpected $gls glimpse RPCs"
+ # second stat to check size is NOT cached on client without IO lock
+ $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #2"
+
+ local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
+ [ $gls -ge 1 ] || error "Expect glimpse RPCs but none"
+ rm -f $dom
+}
+run_test 100a "DoM: glimpse RPCs for stat without IO lock (DoM only file)"
+
+test_100b() {
+ [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
+ skip "Need MDS version at least 2.10.55"
+
+ mkdir -p $DIR/$tdir
+
+ $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
+
+ lctl set_param -n mdc.*.stats=clear
+ dd if=/dev/zero of=$DIR2/$tdir/dom bs=4096 count=1 || return 1
+ cancel_lru_locks mdc
+ # first stat data from server should have size
+ $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #1"
+ # second stat to check size is cached on client
+ $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom || error "stat #2"
+
+ local gls=$(lctl get_param -n mdc.*.stats | grep -c ldlm_glimpse)
+ # both stats should cause no glimpse requests
+ [ $gls == 0 ] || error "Unexpected $gls glimpse RPCs"
+ rm -f $dom
+}
+run_test 100b "DoM: no glimpse RPC for stat with IO lock (DoM only file)"
+
+test_100c() {
+ [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
+ skip "Need MDS version at least 2.10.55"
+
+ mkdir -p $DIR/$tdir
+
+ $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
+
+ lctl set_param -n mdc.*.stats=clear
+ lctl set_param -n osc.*.stats=clear
+ dd if=/dev/zero of=$DIR2/$tdir/dom bs=2048K count=1 || return 1
+
+ # check that size is merged from MDT and OST correctly
+ $CHECKSTAT -t file -s 2097152 $DIR/$tdir/dom ||
+ error "Wrong size from stat #1"
+
+ local gls=$(lctl get_param -n osc.*.stats | grep -c ldlm_glimpse)
+ [ $gls -eq 0 ] && error "Expect OST glimpse RPCs but got none"
+
+ rm -f $dom
+}
+run_test 100c "DoM: write vs stat without IO lock (combined file)"
+
+test_100d() {
+ [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
+ skip "Need MDS version at least 2.10.55"
+
+ mkdir -p $DIR/$tdir
+
+ $LFS setstripe -E 1024K -L mdt -E EOF $DIR/$tdir/dom
+
+
+ dd if=/dev/zero of=$DIR2/$tdir/dom bs=2048K count=1 || return 1
+ lctl set_param -n mdc.*.stats=clear
+ $TRUNCATE $DIR2/$tdir/dom 4096
+
+ # check that reported size is valid after file grows to OST and
+ # is truncated back to MDT stripe size
+ $CHECKSTAT -t file -s 4096 $DIR/$tdir/dom ||
+ error "Wrong size from stat #1"
+
+ local gls=$(lctl get_param -n osc.*.stats | grep -c ldlm_glimpse)
+ [ $gls -eq 0 ] && error "Expect OST glimpse but got none"
+
+ rm -f $dom
+}
+run_test 100d "DoM: write+truncate vs stat without IO lock (combined file)"
+
+test_100e() {
+ [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.50) ] &&
+ skip "Need MDS version at least 2.11.50"
+
+ local dom=$DIR/$tdir/dom
+ local dom2=$DIR2/$tdir/dom
+ mkdir -p $DIR/$tdir
+
+ $LFS setstripe -E 1024K -L mdt $DIR/$tdir
+
+ cancel_lru_locks mdc
+ dd if=/dev/urandom of=$dom bs=12000 count=1
+ $TRUNCATE $dom2 6000
+ cancel_lru_locks mdc
+ lctl set_param -n mdc.*.stats=clear
+ # expect read-on-open to return all data before write
+ cat /etc/hosts >> $dom
+ local read=$(lctl get_param -n mdc.*.stats | grep -c ost_read)
+ [[ $read -eq 0 ]] || error "Unexpected $read READ RPCs"
+}
+run_test 100e "DoM: read on open and file size"
+
+test_101a() {
+ [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
+ skip "Need MDS version at least 2.10.55" && return
+
+ $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
+ # to get layout
+ $CHECKSTAT -t file $DIR1/$tfile
+
+ local old_wb=$(sysctl -n vm.dirty_writeback_centisecs)
+ sysctl -wq vm.dirty_writeback_centisecs=0
+
+ trap "sysctl -wq vm.dirty_writeback_centisecs=$old_wb" EXIT
+
+ # open + IO lock
+ dd if=/dev/zero of=$DIR1/$tfile bs=4096 count=1 ||
+ error_noexit "Write fails"
+ # must discard pages
+ lctl set_param -n mdc.*.stats=clear
+ rm $DIR2/$tfile || error "Unlink fails"
+
+ local writes=$(lctl get_param -n mdc.*.stats | grep -c ost_write)
+ [ $writes -eq 0 ] || error "Found WRITE RPC but expect none"
+}
+run_test 101a "Discard DoM data on unlink"
+
+test_101b() {
+ [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
+ skip "Need MDS version at least 2.10.55" && return
+
+ $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
+ touch $DIR1/${tfile}_2
+ # to get layout
+ $CHECKSTAT -t file $DIR1/$tfile
+
+ local old_wb=$(sysctl -n vm.dirty_writeback_centisecs)
+ sysctl -wq vm.dirty_writeback_centisecs=0
+
+ trap "sysctl -wq vm.dirty_writeback_centisecs=$old_wb" EXIT
+
+ # open + IO lock
+ dd if=/dev/zero of=$DIR1/$tfile bs=4096 count=1 || error "Write fails"
+ # must discard pages
+ lctl set_param -n mdc.*.stats=clear
+ mv $DIR2/${tfile}_2 $DIR2/$tfile || error "Rename fails"
+
+ local writes=$(lctl get_param -n mdc.*.stats | grep -c ost_write)
+ [ $writes -eq 0 ] || error "Found WRITE RPC but expect none"
+}
+run_test 101b "Discard DoM data on rename"
+
+test_101c() {
+ [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.55) ] &&
+ skip "Need MDS version at least 2.10.55" && return
+
+ $LFS setstripe -E 1024K -L mdt -E EOF $DIR1/$tfile
+ # to get layout
+ $CHECKSTAT -t file $DIR1/$tfile
+
+ local old_wb=$(sysctl -n vm.dirty_writeback_centisecs)
+ sysctl -wq vm.dirty_writeback_centisecs=0
+
+ trap "sysctl -wq vm.dirty_writeback_centisecs=$old_wb" EXIT
+
+ # open + IO lock
+ dd if=/dev/zero of=$DIR1/$tfile bs=4096 count=1 || error "Write fails"
+ $MULTIOP $DIR1/$tfile O_c &
+ MULTIOP_PID=$!
+ sleep 1
+ lctl set_param -n mdc.*.stats=clear
+ rm $DIR2/$tfile > /dev/null || error "Unlink fails for opened file"
+ kill -USR1 $MULTIOP_PID && wait $MULTIOP_PID || error "multiop failure"
+
+ local writes=$(lctl get_param -n mdc.*.stats | grep -c ost_write)
+ [ $writes -eq 0 ] || error "Found WRITE RPC but expect none"
+}
+run_test 101c "Discard DoM data on close-unlink"
+
+# test to verify file handle related system calls
+# (name_to_handle_at/open_by_handle_at)
+# The new system calls are supported in glibc >= 2.14.
+
+# test to verify we can open by handle an unlinked file from > 1 client
+# This test opens the file normally on $DIR1, which is on one mount, and then
+# opens it by handle on $DIR2, which is on a different mount.
+test_102() {
+ [ $MDS1_VERSION -lt $(version_code 2.11.57) ] &&
+ skip "Needs MDS version 2.11.57 or later"
+
+ echo "Test file_handle syscalls" > $DIR/$tfile ||
+ error "write failed"
+ check_fhandle_syscalls $DIR/$tfile $DIR2 ||
+ error "check_fhandle_syscalls failed"
+ rm -f $DIR2/$tfile
+}
+run_test 102 "Test open by handle of unlinked file"
+
+# Compare file size between first & second mount, ensuring the client correctly
+# glimpses even with unused speculative locks - LU-11670
+test_103() {
+ [ $(lustre_version_code $ost1) -lt $(version_code 2.10.50) ] &&
+ skip "Lockahead needs OST version at least 2.10.50"
+
+ local testnum=23
+
+ test_mkdir -p $DIR/$tdir
+
+ # Force file on to OST0
+ $LFS setstripe -i 0 $DIR/$tdir
+
+ # Do not check multiple locks on glimpse
+ # OBD_FAIL_OSC_NO_SIZE_DATA 0x415
+ $LCTL set_param fail_loc=0x415
+
+ # Delay write commit by 2 seconds to guarantee glimpse wins race
+ # The same fail_loc is used on client & server so it can work in the
+ # single node sanity setup
+ do_facet ost1 $LCTL set_param fail_loc=0x415 fail_val=2
+
+ echo "Incorrect size expected (no glimpse fix):"
+ lockahead_test -d $DIR/$tdir -D $DIR2/$tdir -t $testnum -f $tfile
+ rc=$?
+ if [ $rc -eq 0 ]; then
+ echo "This doesn't work 100%, but this is just reproducing the bug, not testing the fix, so OK to not fail test."
+ fi
+
+ # guarantee write commit timeout has expired
+ sleep 2
+
+ # Clear fail_loc on client
+ $LCTL set_param fail_loc=0
+
+ # Delay write commit by 2 seconds to guarantee glimpse wins race
+ # OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
+ do_facet ost1 $LCTL set_param fail_loc=0x214 fail_val=2
+
+ # Write commit is still delayed by 2 seconds
+ lockahead_test -d $DIR/$tdir -D $DIR2/$tdir -t $testnum -f $tfile
+ rc=$?
+ [ $rc -eq 0 ] || error "Lockahead test${testnum} failed, ${rc}"
+
+ # guarantee write commit timeout has expired
+ sleep 2
+
+ rm -f $DIR/$tfile || error "unable to delete $DIR/$tfile"
+}
+run_test 103 "Test size correctness with lockahead"
+
+get_stat_xtimes()
+{
+ local xtimes
+
+ xtimes=$(stat -c "%X %Y %Z" $DIR/$tfile)
+
+ echo ${xtimes[*]}
+}
+
+get_mdt_xtimes()
+{
+ local mdtdev=$1
+ local output
+ local xtimes
+
+ output=$(do_facet mds1 "$DEBUGFS -c -R 'stat ROOT/$tfile' $mdtdev")
+ ((xtimes[0]=$(awk -F ':' /atime/'{ print $2 }' <<< "$output")))
+ ((xtimes[1]=$(awk -F ':' /mtime/'{ print $2 }' <<< "$output")))
+ ((xtimes[2]=$(awk -F ':' /ctime/'{ print $2 }' <<< "$output")))
+
+ echo ${xtimes[*]}
+}
+
+check_mdt_xtimes()
+{
+ local mdtdev=$1
+ local xtimes=($(get_stat_xtimes))
+ local mdt_xtimes=($(get_mdt_xtimes $mdtdev))
+
+ echo "STAT a|m|ctime ${xtimes[*]}"
+ echo "MDT a|m|ctime ${xtimes[*]}"
+ [[ ${xtimes[0]} == ${mdt_xtimes[0]} ]] ||
+ error "$DIR/$tfile atime (${xtimes[0]}:${mdt_xtimes[0]}) diff"
+ [[ ${xtimes[1]} == ${mdt_xtimes[1]} ]] ||
+ error "$DIR/$tfile mtime (${xtimes[1]}:${mdt_xtimes[1]}) diff"
+ [[ ${xtimes[2]} == ${mdt_xtimes[2]} ]] ||
+ error "$DIR/$tfile ctime (${xtimes[2]}:${mdt_xtimes[2]}) diff"
+}
+
+test_104() {
+ [ "$mds1_FSTYPE" == "ldiskfs" ] || skip_env "ldiskfs only test"
+ [ $MDS1_VERSION -lt $(version_code 2.12.4) ] &&
+ skip "Need MDS version at least 2.12.4"
+
+ local pid
+ local mdtdev=$(mdsdevname ${SINGLEMDS//mds/})
+ local atime_diff=$(do_facet $SINGLEMDS \
+ lctl get_param -n mdd.*MDT0000*.atime_diff)
+
+ do_facet $SINGLEMDS \
+ lctl set_param -n mdd.*MDT0000*.atime_diff=0
+
+ stack_trap "do_facet $SINGLEMDS \
+ lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff" EXIT
+
+ dd if=/dev/zero of=$DIR/$tfile bs=1k count=1 conv=notrunc
+ check_mdt_xtimes $mdtdev
+ sleep 2
+
+ dd if=/dev/zero of=$DIR/$tfile bs=1k count=1 conv=notrunc
+ check_mdt_xtimes $mdtdev
+ sleep 2
+ $MULTIOP $DIR2/$tfile Oz8192w8192_c &
+ pid=$!
+ sleep 2
+ dd if=/dev/zero of=$DIR/$tfile bs=1k count=1 conv=notrunc
+ sleep 2
+ kill -USR1 $pid && wait $pid || error "multiop failure"
+ check_mdt_xtimes $mdtdev
+
+ local xtimes
+ local mdt_xtimes
+
+ # Verify mtime/ctime is NOT upated on MDS when there is no modification
+ # on the client side
+ xtimes=($(get_stat_xtimes))
+ $MULTIOP $DIR/$tfile O_c &
+ pid=$!
+ sleep 2
+ kill -USR1 $pid && wait $pid || error "multiop failure"
+ mdt_xtimes=($(get_mdt_xtimes $mdtdev))
+ [[ ${xtimes[1]} == ${mdt_xtimes[1]} ]] ||
+ error "$DIR/$tfile mtime (${xtimes[1]}:${mdt_xtimes[1]}) diff"
+ [[ ${xtimes[2]} == ${mdt_xtimes[2]} ]] ||
+ error "$DIR/$tfile ctime (${xtimes[2]}:${mdt_xtimes[2]}) diff"
+ check_mdt_xtimes $mdtdev
+
+ sleep 2
+ # Change ctime via chmod
+ $MULTIOP $DIR/$tfile o_tc &
+ pid=$!
+ sleep 2
+ kill -USR1 $pid && wait $pid || error "multiop failure"
+ check_mdt_xtimes $mdtdev
+}
+run_test 104 "Verify that MDS stores atime/mtime/ctime during close"
+
+test_105() {
+ test_mkdir -p $DIR/$tdir
+ echo test > $DIR/$tdir/$tfile
+ $LCTL set_param fail_loc=0x416
+ cancel_lru_locks osc & sleep 1
+ fsize1=$(stat -c %s $DIR2/$tdir/$tfile)
+ wait
+ [[ $fsize1 = 5 ]] || error "Glimpse returned wrong file size $fsize1"
+}
+run_test 105 "Glimpse and lock cancel race"
+