+cleanup_805() {
+ do_facet $SINGLEMDS zfs set quota=$old $fsset
+ unlinkmany $DIR/$tdir/f- 1000000
+ trap 0
+}
+
+test_805() {
+ local zfs_version=$(do_node $SINGLEMDS cat /sys/module/zfs/version)
+ [ "$(facet_fstype mds1)" != "zfs" ] &&
+ skip "ZFS specific test"
+ [ $(version_code $zfs_version) -lt $(version_code 0.7.2) ] &&
+ skip "netfree not implemented before 0.7"
+ [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.57) ]] ||
+ skip "Need MDS version at least 2.10.57"
+
+ local fsset
+ local freekb
+ local usedkb
+ local old
+ local quota
+ local pref="osd-zfs.lustre-MDT0000."
+
+ # limit available space on MDS dataset to meet nospace issue
+ # quickly. then ZFS 0.7.2 can use reserved space if asked
+ # properly (using netfree flag in osd_declare_destroy()
+ fsset=$(do_facet $SINGLEMDS lctl get_param -n $pref.mntdev)
+ old=$(do_facet $SINGLEMDS zfs get -H quota $fsset | \
+ gawk '{print $3}')
+ freekb=$(do_facet $SINGLEMDS lctl get_param -n $pref.kbytesfree)
+ usedkb=$(do_facet $SINGLEMDS lctl get_param -n $pref.kbytestotal)
+ let "usedkb=usedkb-freekb"
+ let "freekb=freekb/2"
+ if let "freekb > 5000"; then
+ let "freekb=5000"
+ fi
+ do_facet $SINGLEMDS zfs set quota=$(((usedkb+freekb)*1024)) $fsset
+ trap cleanup_805 EXIT
+ mkdir $DIR/$tdir
+ $LFS setstripe -E 1M -L mdt $DIR/$tdir || error "DoM not working"
+ createmany -m $DIR/$tdir/f- 1000000 && error "ENOSPC wasn't met"
+ rm -rf $DIR/$tdir || error "not able to remove"
+ do_facet $SINGLEMDS zfs set quota=$old $fsset
+ trap 0
+}
+run_test 805 "ZFS can remove from full fs"
+
+# Size-on-MDS test
+check_lsom_data()
+{
+ local file=$1
+ local size=$($LFS getsom -s $file)
+ local expect=$(stat -c %s $file)
+
+ [[ $size == $expect ]] ||
+ error "$file expected size: $expect, got: $size"
+
+ local blocks=$($LFS getsom -b $file)
+ expect=$(stat -c %b $file)
+ [[ $blocks == $expect ]] ||
+ error "$file expected blocks: $expect, got: $blocks"
+}
+
+check_lsom_size()
+{
+ local size=$($LFS getsom -s $1)
+ local expect=$2
+
+ [[ $size == $expect ]] ||
+ error "$file expected size: $expect, got: $size"
+}
+
+test_806() {
+ [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.52) ] &&
+ skip "Need MDS version at least 2.11.52" && return
+
+ local bs=1048576
+
+ touch $DIR/$tfile || error "touch $tfile failed"
+
+ local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
+ save_lustre_params client "llite.*.xattr_cache" > $save
+ lctl set_param llite.*.xattr_cache=0
+ stack_trap "restore_lustre_params < $save" EXIT
+
+ # single-threaded write
+ echo "Test SOM for single-threaded write"
+ dd if=/dev/zero of=$DIR/$tfile bs=$bs count=1 ||
+ error "write $tfile failed"
+ check_lsom_size $DIR/$tfile $bs
+
+ local num=32
+ local size=$(($num * $bs))
+ local offset=0
+ local i
+
+ echo "Test SOM for single client muti-threaded($num) write"
+ $TRUNCATE $DIR/$tfile 0
+ for ((i = 0; i < $num; i++)); do
+ $MULTIOP $DIR/$tfile Oz${offset}w${bs}c &
+ local pids[$i]=$!
+ offset=$((offset + $bs))
+ done
+ for (( i=0; i < $num; i++ )); do
+ wait ${pids[$i]}
+ done
+ check_lsom_size $DIR/$tfile $size
+
+ $TRUNCATE $DIR/$tfile 0
+ for ((i = 0; i < $num; i++)); do
+ offset=$((offset - $bs))
+ $MULTIOP $DIR/$tfile Oz${offset}w${bs}c &
+ local pids[$i]=$!
+ done
+ for (( i=0; i < $num; i++ )); do
+ wait ${pids[$i]}
+ done
+ check_lsom_size $DIR/$tfile $size
+
+ # multi-client wirtes
+ num=$(get_node_count ${CLIENTS//,/ })
+ size=$(($num * $bs))
+ offset=0
+ i=0
+
+ echo "Test SOM for muti-client ($num) writes"
+ $TRUNCATE $DIR/$tfile 0
+ for client in ${CLIENTS//,/ }; do
+ do_node $client $MULTIOP $DIR/$tfile Oz${offset}w${bs}c &
+ local pids[$i]=$!
+ i=$((i + 1))
+ offset=$((offset + $bs))
+ done
+ for (( i=0; i < $num; i++ )); do
+ wait ${pids[$i]}
+ done
+ check_lsom_size $DIR/$tfile $offset
+
+ i=0
+ $TRUNCATE $DIR/$tfile 0
+ for client in ${CLIENTS//,/ }; do
+ offset=$((offset - $bs))
+ do_node $client $MULTIOP $DIR/$tfile Oz${offset}w${bs}c &
+ local pids[$i]=$!
+ i=$((i + 1))
+ done
+ for (( i=0; i < $num; i++ )); do
+ wait ${pids[$i]}
+ done
+ check_lsom_size $DIR/$tfile $size
+
+ # verify truncate
+ echo "Test SOM for truncate"
+ $TRUNCATE $DIR/$tfile 1048576
+ check_lsom_size $DIR/$tfile 1048576
+ $TRUNCATE $DIR/$tfile 1234
+ check_lsom_size $DIR/$tfile 1234
+
+ # verify SOM blocks count
+ echo "Verify SOM block count"
+ $TRUNCATE $DIR/$tfile 0
+ $MULTIOP $DIR/$tfile oO_TRUNC:O_RDWR:w1048576YSc ||
+ error "failed to write file $tfile"
+ check_lsom_data $DIR/$tfile
+}
+run_test 806 "Verify Lazy Size on MDS"
+
+test_807() {
+ [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.52) ] &&
+ skip "Need MDS version at least 2.11.52" && return
+
+ # Registration step
+ changelog_register || error "changelog_register failed"
+ local cl_user="${CL_USERS[$SINGLEMDS]%% *}"
+ changelog_users $SINGLEMDS | grep -q $cl_user ||
+ error "User $cl_user not found in changelog_users"
+
+ local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
+ save_lustre_params client "llite.*.xattr_cache" > $save
+ lctl set_param llite.*.xattr_cache=0
+ stack_trap "restore_lustre_params < $save" EXIT
+
+ rm -rf $DIR/$tdir || error "rm $tdir failed"
+ mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
+ touch $DIR/$tdir/trunc || error "touch $tdir/trunc failed"
+ $TRUNCATE $DIR/$tdir/trunc 1024 || error "truncate $tdir/trunc failed"
+ $TRUNCATE $DIR/$tdir/trunc 1048576 ||
+ error "truncate $tdir/trunc failed"
+
+ local bs=1048576
+ dd if=/dev/zero of=$DIR/$tdir/single_dd bs=$bs count=1 ||
+ error "write $tfile failed"
+
+ # multi-client wirtes
+ local num=$(get_node_count ${CLIENTS//,/ })
+ local offset=0
+ local i=0
+
+ echo "Test SOM for muti-client ($num) writes"
+ touch $DIR/$tfile || error "touch $tfile failed"
+ $TRUNCATE $DIR/$tfile 0
+ for client in ${CLIENTS//,/ }; do
+ do_node $client $MULTIOP $DIR/$tfile Oz${offset}w${bs}c &
+ local pids[$i]=$!
+ i=$((i + 1))
+ offset=$((offset + $bs))
+ done
+ for (( i=0; i < $num; i++ )); do
+ wait ${pids[$i]}
+ done
+
+ sleep 5
+ $LSOM_SYNC -u $cl_user -m $FSNAME-MDT0000 $MOUNT
+ check_lsom_data $DIR/$tdir/trunc
+ check_lsom_data $DIR/$tdir/single_dd
+ check_lsom_data $DIR/$tfile
+
+ rm -rf $DIR/$tdir
+ # Deregistration step
+ changelog_deregister || error "changelog_deregister failed"
+}
+run_test 807 "verify LSOM syncing tool"
+