+# 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" >= $(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 $tfile failed"
+
+ # test this is working on DNE directories also
+ if (( MDSCOUNT > 1 && MDS1_VERSION >= $(version_code 2.14.52) )); then
+ $LFS mkdir -i 1 $DIR/$tdir.remote
+ cancel_lru_locks mdc
+ check_fhandle_syscalls $DIR/$tdir.remote $DIR2 ||
+ error "check_fhandle_syscalls $tdir.remote failed"
+ $LFS mkdir -c -1 $DIR/$tdir.remote/subdir
+ cancel_lru_locks mdc
+ check_fhandle_syscalls $DIR/$tdir.remote/subdir $DIR2 ||
+ error "check_fhandle_syscalls $tdir.remote/subdir fail"
+
+ $LFS mkdir -c -1 $DIR/$tdir.stripe
+ cancel_lru_locks mdc
+ check_fhandle_syscalls $DIR/$tdir.stripe $DIR2 ||
+ error "check_fhandle_syscalls $tdir.stripe failed"
+ $LFS mkdir -c -1 $DIR/$tdir.stripe/subdir
+ cancel_lru_locks mdc
+ check_fhandle_syscalls $DIR/$tdir.stripe/subdir $DIR2 ||
+ error "check_fhandle_syscalls $tdir.stripe/subdir fail"
+ fi
+}
+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() {
+ [ $OST1_VERSION -lt $(version_code 2.10.50) ] &&
+ skip "Lockahead needs OST version at least 2.10.50"
+
+ local locktest=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 $locktest -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 $locktest -f $tfile
+ rc=$?
+ [ $rc -eq 0 ] || error "Lockahead test$locktest 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 ${mdt_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"
+
+test_106a() {
+ [ "$mds1_FSTYPE" == "ldiskfs" ] && statx_supported ||
+ skip_env "Test only for ldiskfs and statx() supported"
+
+ local btime
+ local mdt_btime
+ local output
+ local mdtdev=$(mdsdevname ${SINGLEMDS//mds/})
+
+ dd if=/dev/zero of=$DIR/$tfile bs=1k count=1 conv=notrunc
+ btime=$($STATX -c %W $DIR/$tfile)
+ output=$(do_facet mds1 "$DEBUGFS -c -R 'stat ROOT/$tfile' $mdtdev")
+ echo $output
+ ((mdt_btime=$(awk -F ':' /crtime/'{ print $2 }' <<< "$output")))
+ [[ $btime == $mdt_btime ]] ||
+ error "$DIR/$tfile btime ($btime:$mdt_btime) diff"
+
+}
+run_test 106a "Verify the btime via statx()"
+
+test_106b() {
+ statx_supported || skip_env "statx() only test"
+
+ local rpcs_before
+ local rpcs_after
+
+ $LFS setstripe -c 1 $DIR/$tfile || error "$DIR/$tfile setstripe failed"
+ dd if=/dev/zero of=$DIR/$tfile bs=1k count=1 conv=notrunc
+ cancel_lru_locks $OSC
+ rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
+ $STATX $DIR/$tfile
+ rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
+ [ $rpcs_after -eq $((rpcs_before + 1)) ] ||
+ error "$STATX should send 1 glimpse RPC to $OSC"
+
+ cancel_lru_locks $OSC
+ rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
+ # %n: FILENAME; %i: STATX_INO; %A STATX_MODE; %h STATX_NLINK;
+ # %u: STATX_UID; %g: STATX_GID; %W STATX_BTIME; %X STATX_ATIME;
+ # %Z: STATX_CTIME
+ $STATX -c "%n %i %A %h %u %g %W %X %Z" $DIR/$tfile
+ rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
+ [ $rpcs_after -eq $rpcs_before ] ||
+ error "$STATX should not send glimpse RPCs to $OSC"
+
+ cancel_lru_locks $OSC
+ rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
+ $STATX --cached=always $DIR/$tfile
+ rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
+ [ $rpcs_after -eq $rpcs_before ] ||
+ error "$STATX should not send glimpse RPCs to $OSC"
+
+ cancel_lru_locks $OSC
+ rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
+ $STATX -c %Y $DIR/$tfile
+ rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
+ [ $rpcs_after -eq $((rpcs_before + 1)) ] ||
+ error "$STATX -c %Y should send 1 glimpse RPC to $OSC"
+
+ cancel_lru_locks $OSC
+ rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
+ $STATX -c %s $DIR/$tfile
+ rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
+ [ $rpcs_after -eq $((rpcs_before + 1)) ] ||
+ error "$STATX -c %s should send 1 glimpse RPC to $OSC"
+
+ cancel_lru_locks $OSC
+ rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
+ $STATX -c %b $DIR/$tfile
+ rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue)
+ [ $rpcs_after -eq $((rpcs_before + 1)) ] ||
+ error "$STATX -c %b should send 1 glimpse RPC to $OSC"
+}
+run_test 106b "Glimpse RPCs test for statx"
+
+test_106c() {
+ statx_supported || skip_env "statx() only test"
+
+ local mask
+
+ touch $DIR/$tfile
+ # Mask supported in stx_attributes by Lustre is
+ # STATX_ATTR_IMMUTABLE(0x10) | STATX_ATTR_APPEND(0x20) : (0x30).
+ mask=$($STATX -c %p $DIR/$tfile)
+ (( (0x$mask & 0x30) == 0x30 )) ||
+ error "supported stx_attributes: got '0x$mask', expected '0x30' at least"
+ chattr +i $DIR/$tfile || error "chattr +i $DIR/$tfile failed"
+ mask=$($STATX -c %r $DIR/$tfile)
+ [[ $mask == "10" ]] ||
+ error "got immutable flags '$mask', expected '10'"
+ chattr -i $DIR/$tfile || error "chattr -i $DIR/$tfile failed"
+ mask=$($STATX -c %r $DIR/$tfile)
+ [[ $mask == "0" ]] || error "got flags '$mask', expected '0'"
+ chattr +a $DIR/$tfile || error "chattr +a $DIR/$tfile failed"
+ mask=$($STATX -c %r $DIR/$tfile)
+ [[ $mask == "20" ]] || error "got flags '$mask', expected '20'"
+ chattr -a $DIR/$tfile || error "chattr -a $DIR/$tfile failed"
+ mask=$($STATX -c %r $DIR/$tfile)
+ [[ $mask == "0" ]] || error "got flags '$mask', expected '0'"
+ chattr +ia $DIR/$tfile || error "chattr +ia $DIR/$tfile failed"
+ mask=$($STATX -c %r $DIR/$tfile)
+ [[ $mask == "30" ]] || error "got flags '$mask', expected '30'"
+ chattr -ia $DIR/$tfile || error "chattr -ia $DIR/$tfile failed"
+ mask=$($STATX -c %r $DIR/$tfile)
+ [[ $mask == "0" ]] || error "got flags '$mask', expected '0'"
+}
+run_test 106c "Verify statx attributes mask"
+
+test_107a() { # LU-1031
+ dd if=/dev/zero of=$DIR1/$tfile bs=1M count=10
+ local gid1=14091995
+ local gid2=16022000
+
+ $LFS getstripe $DIR1/$tfile
+
+ multiop_bg_pause $DIR1/$tfile OG${gid1}_g${gid1}c || return 1
+ local MULTIPID1=$!
+ multiop_bg_pause $DIR2/$tfile O_G${gid2}r10g${gid2}c || return 2
+ local MULTIPID2=$!
+ kill -USR1 $MULTIPID2
+ sleep 2
+ if [[ $(ps h -o comm -p $MULTIPID2) == "" ]]; then
+ error "First grouplock does not block second one"
+ else
+ echo "First grouplock blocks second one"
+ fi
+ kill -USR1 $MULTIPID1
+ wait $MULTIPID1
+ wait $MULTIPID2
+}
+run_test 107a "Basic grouplock conflict"
+
+test_107b() {
+ dd if=/dev/zero of=$DIR1/$tfile bs=1M count=10
+ local gid1=14091995
+ local gid2=16022000
+
+ $LFS getstripe $DIR1/$tfile
+
+ multiop_bg_pause $DIR1/$tfile OG${gid1}_g${gid1}c || return 1
+ local MULTIPID1=$!
+ multiop $DIR2/$tfile Or10c &
+ local MULTIPID2=$!
+ sleep 2
+
+ if [[ $(ps h -o comm -p $MULTIPID2) == "" ]]; then
+ error "Grouplock does not block IO"
+ else
+ echo "Grouplock blocks IO"
+ fi
+
+ multiop $DIR2/$tfile OG${gid2}_g${gid2}c &
+ local MULTIPID3=$!
+ sleep 2
+ if [[ $(ps h -o comm -p $MULTIPID3) == "" ]]; then
+ error "First grouplock does not block second one"
+ else
+ echo "First grouplock blocks second one"
+ fi
+
+ kill -USR1 $MULTIPID1
+ sleep 2
+
+ if [[ $(ps h -o comm -p $MULTIPID3) == "" ]]; then
+ error "Second grouplock thread disappeared"
+ fi
+
+ if [[ $(ps h -o comm -p $MULTIPID2) == "" ]]; then
+ error "Second grouplock does not block IO"
+ else
+ echo "Second grouplock blocks IO"
+ fi
+
+ kill -USR1 $MULTIPID3
+ wait $MULTIPID1
+ wait $MULTIPID2
+ wait $MULTIPID3
+}
+run_test 107b "Grouplock is added to the head of waiting list"
+
+test_108a() {
+ local offset
+
+ $LFS setstripe -E 1M -c 1 -E -1 $DIR1/$tfile ||
+ error "Create $DIR1/$tfile failed"
+
+ dd if=/dev/zero of=$DIR1/$tfile bs=10000 count=1 ||
+ error "dd $DIR1/$tfile failed"
+ offset=$(lseek_test -d 5000 $DIR2/$tfile)
+ [[ $offset == 5000 ]] || error "offset $offset != 5000"
+
+ $TRUNCATE $DIR1/$tfile 2000
+ offset=$(lseek_test -l 1000 $DIR2/$tfile)
+ [[ $offset == 2000 ]] || error "offset $offset != 2000"
+
+ #define OBD_FAIL_OSC_DELAY_IO 0x414
+ $LCTL set_param fail_val=4 fail_loc=0x80000414
+ dd if=/dev/zero of=$DIR1/$tfile count=1 bs=8M conv=notrunc oflag=dsync &
+ local pid=$!
+ sleep 2
+
+ offset=$(lseek_test -l 8000 $DIR2/$tfile)
+ wait $pid
+ [[ $offset == 8388608 ]] || error "offset $offset != 8388608"
+}
+run_test 108a "lseek: parallel updates"
+
+# LU-14110
+test_109() {
+ local i
+ local pid1 pid2
+
+ ! local_mode ||
+ skip "Clients need to be on different nodes than the servers"
+
+ umount_client $MOUNT
+ umount_client $MOUNT2
+
+ echo "Starting race between client mount instances (50 iterations):"
+ for i in {1..50}; do
+ log "Iteration $i"
+
+#define CFS_FAIL_ONCE|OBD_FAIL_LLITE_RACE_MOUNT 0x80001417
+ $LCTL set_param -n fail_loc=0x80001417
+
+ mount_client $MOUNT & pid1=$!
+ mount_client $MOUNT2 & pid2=$!
+ wait $pid1 || error "Mount $MOUNT fails with $?"
+ wait $pid2 || error "Mount $MOUNT2 fails with $?"
+
+ umount_client $MOUNT & pid1=$!
+ umount_client $MOUNT2 & pid2=$!
+ wait $pid1 || error "Umount $MOUNT fails with $?"
+ wait $pid2 || error "Umount $MOUNT2 fails with $?"
+
+ $LUSTRE_RMMOD || error "Fail to remove lustre modules"
+ load_modules
+ echo
+ done
+
+ mount_client $MOUNT
+ mount_client $MOUNT2
+}
+
+run_test 109 "Race with several mount instances on 1 node"
+
+test_110() {
+ local before=$(date +%s)
+ local evict
+
+ mkdir -p $DIR/$tdir
+ touch $DIR/$tdir/f1
+ touch $DIR/$tfile
+
+ #define OBD_FAIL_PTLRPC_RESEND_RACE 0x525
+ do_facet mds1 lctl set_param fail_loc=0x525 fail_val=3
+
+ # disable last_xid logic by dropping link reply
+ ln $DIR/$tdir/f1 $DIR/$tdir/f2 &
+ sleep 1
+
+ #define OBD_FAIL_PTLRPC_ENQ_RESEND 0x534
+ do_facet mds1 lctl set_param fail_loc=0x534
+
+ # RPC will race with its Resend and the Resend will sleep to let
+ # the original lock to get granted & cancelled.
+ #
+ # AST_SENT is set artificially, so an explicit conflict is not needed
+ #
+ # The woken up Resend gets a new lock, but client does not wait for it
+ stat $DIR/$tfile
+ sleep $TIMEOUT
+ do_facet mds1 lctl set_param fail_loc=0 fail_val=0
+
+ # Take a conflict to wait long enough to see the eviction
+ touch $DIR2/$tfile
+
+ # let the client reconnect
+ client_reconnect
+ evict=$(do_facet client $LCTL get_param mdc.$FSNAME-MDT*.state |
+ awk -F"[ [,]" '/EVICTED ]$/ { if (mx<$5) {mx=$5;} } END { print mx }')
+
+ [ -z "$evict" ] || [[ $evict -le $before ]] ||
+ (do_facet client $LCTL get_param mdc.$FSNAME-MDT*.state;
+ error "eviction happened: $evict before:$before")
+}
+run_test 110 "do not grant another lock on resend"
+
+test_111() {
+ [ $MDSCOUNT -ge 2 ] || skip "needs >= 2 MDTs"
+ [[ $(facet_active_host mds1) = $(facet_active_host mds2) ]] ||
+ skip "MDT0 and MDT1 should be on the same node"
+
+ mkdir $DIR1/$tdir
+ $LFS mkdir -i 0 $DIR1/$tdir/mdt0dir
+ $LFS mkdir -i 1 $DIR1/$tdir/mdt1dir
+
+ mkdir $DIR1/$tdir/mdt0dir/foodir
+ touch $DIR1/$tdir/mdt0dir/foodir/{file1,file2}
+
+ $MULTIOP $DIR2/$tdir/mdt0dir/foodir/file2 Ow4096_c &
+ MULTIOP_PID=$!
+ ln $DIR1/$tdir/mdt0dir/foodir/file2 $DIR1/$tdir/mdt1dir/file2
+
+ #define OBD_FAIL_MDS_LINK_RENAME_RACE 0x18a
+ do_facet mds1 $LCTL set_param fail_loc=0x8000018a
+
+ ln $DIR1/$tdir/mdt0dir/foodir/file2 $DIR1/$tdir/mdt1dir/file2x &
+ sleep 1
+
+ rm $DIR2/$tdir/mdt1dir/file2
+ sleep 1
+
+ mv $DIR2/$tdir/mdt0dir/foodir/file1 $DIR2/$tdir/mdt0dir/foodir/file2
+ sleep 1
+
+ kill $MULTIOP_PID
+ wait
+ rm -r $DIR1/$tdir || error "Removing test dir failed"
+}
+run_test 111 "A racy rename/link an open file should not cause fs corruption"
+
+test_112() {
+ (( MDSCOUNT >= 2 )) ||
+ skip "We need at least 2 MDTs for this test"
+
+ (( MDS1_VERSION >= $(version_code 2.14.54) )) ||
+ skip "Need server version at least 2.14.54"
+
+ local rr
+ local count
+
+ rr=$($LCTL get_param -n lmv.*.qos_threshold_rr | head -n1)
+ rr=${rr%%%}
+ stack_trap "$LCTL set_param lmv.*.qos_threshold_rr=$rr > /dev/null"
+
+ mkdir -p $DIR1/$tdir/s1/s2 || error "mkdir s2 failed"
+ $LFS mkdir -i 0 $DIR1/$tdir/s1/s2/s3 || error "mkdir s3 failed"
+ $LFS setdirstripe -D -i -1 --max-inherit-rr=0 $DIR1/$tdir/s1/s2/s3 ||
+ error "setdirstripe s3 failed"
+ $LCTL set_param lmv.*.qos_threshold_rr=90
+ mkdir $DIR2/$tdir/s1/s2/s3/d{1..64}
+ count=$($LFS getstripe -m $DIR2/$tdir/s1/s2/s3/d* | grep ^0 | wc -l)
+ (( count == 64 )) || error "only $count subdirs created on MDT0"
+
+ $LFS setdirstripe -D -i -1 --max-inherit-rr=3 $DIR1/$tdir/s1/s2/s3 ||
+ error "setdirstripe s3 failed"
+ mkdir $DIR2/$tdir/s1/s2/s3/s{1..64}
+ count=$($LFS getstripe -m $DIR2/$tdir/s1/s2/s3/s* | grep ^0 | wc -l)
+ (( count == 64 / MDSCOUNT )) || error "$count subdirs created on MDT0"
+}
+run_test 112 "update max-inherit in default LMV"
+
+test_113 () {
+ (( MDS1_VERSION >= $(version_code 2.15.50) )) ||
+ skip "Need server version at least 2.15.50"
+
+ local instance
+ local nid
+
+ instance=$($LFS getname -i $DIR1) ||
+ error "cannot get instance of $DIR1"
+
+ $LFS check osts $DIR1 | grep $instance ||
+ error "cannot find OSTs of instance $instance"
+
+ $LFS check osts $DIR1 | grep -v $instance
+ if (( $? == 0 )); then
+ error "find OSTs other than instance $instance"
+ fi
+
+ $LFS check osts | grep $instance ||
+ error "cannot find other OSTs"
+
+ nid=$(df $DIR2 | tail -1 | sed 's%:/.*%%') ||
+ error "cannot parse nid for $DIR2"
+
+ $LFS check mgts $DIR2 | grep MGC$nid ||
+ error "cannot find mgc of $nid"
+
+ $LFS check mgts $DIR2 | grep -v MGC$nid
+ if (( $? == 0 )); then
+ error "find MGTs other than nid $nid"
+ fi
+}
+run_test 113 "check servers of specified fs"
+
+check_default_lmv() {
+ local dir=$1
+
+ local enabled
+ local dmv
+ local index
+ local count
+ local inherit
+ local inherit_rr
+ local raw
+
+ enabled=$(do_facet mds1 \
+ $LCTL get_param -n mdt.*-MDT0000*.enable_dmv_implicit_inherit)
+
+ dmv=$($LFS getdirstripe -D $dir)
+ echo $dir $dmv
+ index=$(echo $dmv | awk '{ print $4 }')
+ (( index == $2 )) || error "$dir default stripe index $index != $2"
+
+ count=$(echo $dmv | awk '{ print $2 }')
+ (( count == $3 )) || error "$dir default stripe count $count != $3"
+
+ inherit=$(echo $dmv | awk '{ print $8 }')
+ (( inherit == $4 )) || error "$dir default max-inherit $inherit != $4"
+
+ if [ $index -eq -1 ]; then
+ inherit_rr=$(echo $dmv | awk '{ print $10 }')
+ (( inherit_rr == $5 )) ||
+ error "$dir default max-inherit-rr $inherit_rr != $5"
+ fi
+
+ # with --raw, print default LMV stored in inode, otherwise print nothing
+ raw=$($LFS getdirstripe -D --raw $dir)
+ if (( enabled == 1 )); then
+ [ -z $raw ] ||
+ error "implicit inherited DMV is printed with --raw"
+ else
+ # if disabled, dmv is stored in inode, which will always
+ # print max-inherit-rr
+ echo $dir $raw
+ [[ $raw =~ $dmv.* ]] || error "$dir raw $raw != dmv $dmv"
+ fi
+}
+
+test_dmv_imp_inherit() {
+ local dmv
+ local raw
+ local index
+ local count
+ local inherit
+ local inherit_rr
+
+ rm -rf $DIR/$tdir || error "rm $tdir failed"
+ mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
+
+ # set dir default LMV
+ $LFS setdirstripe -D -c1 -X4 --max-inherit-rr 2 $DIR/$tdir ||
+ error "setdirstripe -D $tdir failed"
+ dmv=$($LFS getdirstripe -D $DIR/$tdir)
+ raw=$($LFS getdirstripe -D --raw $DIR/$tdir)
+ [ "$dmv" == "$raw" ] || error "$dmv != $raw"
+
+ mkdir -p $DIR/$tdir/l1/l2/l3 || error "mkdir $DIR/$tdir/l1/l2/l3 failed"
+ check_default_lmv $DIR/$tdir/l1/l2/l3 -1 1 1 0
+ check_default_lmv $DIR2/$tdir/l1/l2/l3 -1 1 1 0
+
+ # below tests are valid only when this feature is enabled
+ local enabled=$(do_facet mds1 \
+ $LCTL get_param -n mdt.*-MDT0000*.enable_dmv_implicit_inherit)
+
+ (( enabled == 1 )) || return 0
+
+ # set l2 default LMV, dmv of l3 should change immediately
+ $LFS setdirstripe -D -i1 -c2 -X4 $DIR/$tdir/l1/l2 ||
+ error "setdirstripe -D $tdir/l1/l2 failed"
+
+ check_default_lmv $DIR/$tdir/l1/l2/l3 1 2 3
+ check_default_lmv $DIR2/$tdir/l1/l2/l3 1 2 3
+
+ # change tdir default LMV, dmv of l3 should be unchanged because dmv
+ # of l2 is explicitly set
+ $LFS setdirstripe -D -i2 -c2 -X3 $DIR/$tdir ||
+ error "setdirstripe -D $tdir failed"
+
+ check_default_lmv $DIR/$tdir/l1 2 2 2
+ check_default_lmv $DIR2/$tdir/l1 2 2 2
+ check_default_lmv $DIR/$tdir/l1/l2/l3 1 2 3
+ check_default_lmv $DIR2/$tdir/l1/l2/l3 1 2 3
+}
+
+test_114() {
+ (( MDSCOUNT >= 2 )) ||
+ skip "We need at least 2 MDTs for this test"
+
+ (( MDS1_VERSION >= $(version_code 2.15.55.45) )) ||
+ skip "Need server version at least 2.15.54.45"
+
+ test_dmv_imp_inherit
+
+ # disable dmv_imp_inherit to simulate old client
+ local mdts=$(comma_list $(mdts_nodes))
+
+ do_nodes $mdts $LCTL set_param -n \
+ mdt.*MDT*.enable_dmv_implicit_inherit=0
+ test_dmv_imp_inherit
+ do_nodes $mdts $LCTL set_param -n \
+ mdt.*MDT*.enable_dmv_implicit_inherit=1
+}
+run_test 114 "implicit default LMV inherit"
+
+test_115() {
+ local td=$DIR/$tdir
+
+ [ "$mds1_FSTYPE" == "ldiskfs" ] || skip_env "ldiskfs only test"
+
+ mkdir_on_mdt0 $td || error "can't mkdir"
+ # turn it htree (don't really needed)
+ createmany -m $td/f 3000 || error "can't createmany"
+
+ # here is an example of debugfs output for htree command:
+ # Entry #0: Hash 0x00000000, block 27
+ # Reading directory block 27, phys 16760
+ # 938 0x0016fb58-7f3d21f5 (32) f775 834 0x001db8c8-d31a4e0e (32) f671
+ # 1085 0x0040cb70-4498abd4 (32) f922 1850 0x0066a1e6-f6f0dc69 (32) f1687
+ # 2005 0x006c1a46-ef466058 (32) f1842 2025 0x007e64d4-8b28b734 (32) f1862
+ # 642 0x008b53a0-77adc601 (32) f479 447 0x009ec152-af54eea3 (32) f284
+ # 1740 0x00c38f56-ed310e61 (32) f1577 2165 0x00cdfd66-f429a93f (32) f2002
+ # 930 0x00d7ada4-b80421c9 (32) f767 1946 0x00da6a7a-e8080600 (32) f1783
+ # 273 0x00f8ea00-760bf97c (32) f110 1589 0x0103c4ee-94fad5dd (32) f1426
+ # 1383 0x01193516-83120b48 (32) f1220 2379 0x01431e3c-e85b5bd9 (32) f2216
+ #
+ # find couple names in a same htree block of the same size
+ mdt_dev=$(facet_device $SINGLEMDS)
+ de=( $(do_facet $SINGLEMDS "debugfs -c -R 'htree /ROOT/$tdir' $mdt_dev" |
+ awk '/Reading directory block/ { getline; print $4,$8; exit; }' ))
+ local de1=${de[0]}
+ local de2=${de[1]}
+ [[ $de1 == "" || $de2 == "" ]] && error "de1=$de1 de2=$de2"
+ echo "USE: $de1 $de2"
+ # release one mkdir will lookup
+ rm $DIR/$tdir/$de2
+#define OBD_FAIL_MDS_PAUSE_CREATE_AFTER_LOOKUP 0x2401
+ do_facet $SINGLEMDS $LCTL set_param fail_loc=0x80002401 fail_val=5
+ mkdir $DIR/$tdir/$de2 &
+ sleep 0.3
+ local PID1=$!
+ # recreate $de2
+ mkdir $DIR2/$tdir/$de2
+ # release space $de1 (should be enough to save $de2)
+ rm $DIR2/$tdir/$de1
+ # ready to create a dup of $de2
+ wait $PID1
+ local found=$(ls $DIR/$tdir/|grep "^$de2\$"|wc -l)
+ (( $found == 1 )) || error "found $found"
+}
+run_test 115 "ldiskfs doesn't check direntry for uniqueness"
+
+test_116() {
+ (( $MDSCOUNT >= 2 )) || skip "needs >= 2 MDTs"
+ (( $MDS1_VERSION >= $(version_code 2.15.61) )) ||
+ skip "Need MDS version at least 2.15.61 for intent mkdir"
+
+ local mdt_idx
+ local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
+
+ save_lustre_params client "llite.*.intent_mkdir" > $save
+ stack_trap "restore_lustre_params < $save; rm -f $save" EXIT
+ $LCTL set_param llite.*.intent_mkdir=1
+
+ $LFS mkdir -c$MDSCOUNT -i0 $DIR/$tdir ||
+ error "$LFS mkdir $DIR/$tdir failed"
+ echo "MD layout $DIR/$tdir:"
+ $LFS getdirstripe $DIR/$tdir
+ echo "mkdir $DIR/$tdir/tdir0"
+ mkdir $DIR/$tdir/tdir0 || error "mkdir tdir0 failed"
+ echo "setdirstripe -D -i1 $DIR2/$tdir/tdir0"
+ $LFS setdirstripe -D -i1 $DIR2/$tdir/tdir0 ||
+ error "$LFS setdirstripe $DIR2/$tdir/tdir0 failed"
+ echo "mkdir $DIR/$tdir/tdir0/tdir11"
+ mkdir $DIR/$tdir/tdir0/tdir11 || error "mkdir tdir0/tdir11 failed"
+ $LFS getdirstripe $DIR/$tdir/tdir0
+ $LFS getdirstripe $DIR/$tdir/tdir0/tdir11
+
+ mdt_idx=$($LFS getstripe -m $DIR/$tdir/tdir0/tdir11)
+ [ $mdt_idx == 1 ] ||
+ error "$DIR/$tdir/tdir0/tdir11 on wrong MDT $mdt_idx"
+}
+run_test 116 "DNE: Set default LMV layout from a remote client"
+