+ local last_wm_h=$(do_facet $SINGLEMDS $LCTL get_param -n \
+ osp.$mdtosc_proc1.reserved_mb_high)
+ local last_wm_l=$(do_facet $SINGLEMDS $LCTL get_param -n \
+ osp.$mdtosc_proc1.reserved_mb_low)
+ echo "prev high watermark $last_wm_h, prev low watermark $last_wm_l"
+
+ do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME ||
+ error "Pool creation failed"
+ do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $ost_name ||
+ error "Adding $ost_name to pool failed"
+
+ # Wait for client to see a OST at pool
+ wait_update $HOSTNAME "$LCTL get_param -n
+ lov.$FSNAME-*.pools.$TESTNAME | sort -u |
+ grep $ost_name" "$ost_name""_UUID" $((TIMEOUT/2)) ||
+ error "Client can not see the pool"
+ $SETSTRIPE $DIR/$tdir -i $ostidx -c 1 -p $FSNAME.$TESTNAME ||
+ error "Setstripe failed"
+
+ dd if=/dev/zero of=$DIR/$tdir/0 bs=1M count=10
+ local blocks=$($LFS df $MOUNT | grep $ost_name | awk '{ print $4 }')
+ echo "OST still has $((blocks/1024)) mbytes free"
+
+ local new_lwm=$((blocks/1024-10))
+ do_facet $SINGLEMDS $LCTL set_param \
+ osp.$mdtosc_proc1.reserved_mb_high=$((new_lwm+5))
+ do_facet $SINGLEMDS $LCTL set_param \
+ osp.$mdtosc_proc1.reserved_mb_low=$new_lwm
+
+ test_253_fill_ost $ost_name $mdtosc_proc1 $new_lwm
+
+ #First enospc could execute orphan deletion so repeat.
+ test_253_fill_ost $ost_name $mdtosc_proc1 $new_lwm
+
+ local oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
+ osp.$mdtosc_proc1.prealloc_status)
+ echo "prealloc_status $oa_status"
+
+ dd if=/dev/zero of=$DIR/$tdir/2 bs=1M count=1 &&
+ error "File creation should fail"
+ #object allocation was stopped, but we still able to append files
+ dd if=/dev/zero of=$DIR/$tdir/1 bs=1M seek=6 count=5 oflag=append ||
+ error "Append failed"
+ rm -f $DIR/$tdir/1 $DIR/$tdir/0 $DIR/$tdir/r*
+
+ wait_delete_completed
+
+ sleep_maxage
+
+ for i in $(seq 10 12); do
+ dd if=/dev/zero of=$DIR/$tdir/$i bs=1M count=1 2>/dev/null ||
+ error "File creation failed after rm";
+ done
+
+ oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
+ osp.$mdtosc_proc1.prealloc_status)
+ echo "prealloc_status $oa_status"
+
+ if (( oa_status != 0 )); then
+ error "Object allocation still disable after rm"
+ fi
+ do_facet $SINGLEMDS $LCTL set_param \
+ osp.$mdtosc_proc1.reserved_mb_high=$last_wm_h
+ do_facet $SINGLEMDS $LCTL set_param \
+ osp.$mdtosc_proc1.reserved_mb_low=$last_wm_l
+
+
+ do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $ost_name ||
+ error "Remove $ost_name from pool failed"
+ do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME ||
+ error "Pool destroy fialed"
+}
+run_test 253 "Check object allocation limit"
+
+test_254() {
+ local cl_user
+
+ [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
+ remote_mds_nodsh && skip "remote MDS with nodsh" && return
+ do_facet mds1 $LCTL get_param -n mdd.$MDT0.changelog_size ||
+ { skip "MDS does not support changelog_size" && return; }
+
+ cl_user=$(do_facet mds1 $LCTL --device $MDT0 changelog_register -n)
+ echo "Registered as changelog user $cl_user"
+
+ $LFS changelog_clear $MDT0 $cl_user 0
+
+ local size1=$(do_facet mds1 \
+ $LCTL get_param -n mdd.$MDT0.changelog_size)
+ echo "Changelog size $size1"
+
+ rm -rf $DIR/$tdir
+ $LFS mkdir -i 0 $DIR/$tdir
+ # change something
+ mkdir -p $DIR/$tdir/pics/2008/zachy
+ touch $DIR/$tdir/pics/2008/zachy/timestamp
+ cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
+ mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
+ ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
+ ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
+ rm $DIR/$tdir/pics/desktop.jpg
+
+ local size2=$(do_facet mds1 \
+ $LCTL get_param -n mdd.$MDT0.changelog_size)
+ echo "Changelog size after work $size2"
+
+ do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
+
+ if (( size2 <= size1 )); then
+ error "Changelog size after work should be greater than original"
+ fi
+ return 0
+}
+run_test 254 "Check changelog size"
+
+ladvise_no_type()
+{
+ local type=$1
+ local file=$2
+
+ lfs ladvise -a invalid $file 2>&1 | grep "Valid types" |
+ awk -F: '{print $2}' | grep $type > /dev/null
+ if [ $? -ne 0 ]; then
+ return 0
+ fi
+ return 1
+}
+
+ladvise_no_ioctl()
+{
+ local file=$1
+
+ lfs ladvise -a willread $file > /dev/null 2>&1
+ if [ $? -eq 0 ]; then
+ return 1
+ fi
+
+ lfs ladvise -a willread $file 2>&1 |
+ grep "Inappropriate ioctl for device" > /dev/null
+ if [ $? -eq 0 ]; then
+ return 0
+ fi
+ return 1
+}
+
+ladvise_willread_performance()
+{
+ local repeat=10
+ local average_cache=0
+ local average_ladvise=0
+
+ for ((i = 1; i <= $repeat; i++)); do
+ echo "Iter $i/$repeat: reading without willread hint"
+ cancel_lru_locks osc
+ do_nodes $(comma_list $(osts_nodes)) \
+ "echo 3 > /proc/sys/vm/drop_caches"
+ local speed_origin=$($READS -f $DIR/$tfile -s $size \
+ -b 4096 -n $((size / 4096)) -t 60 |
+ sed -e '/^$/d' -e 's#.*s, ##' -e 's#MB/s##')
+
+ echo "Iter $i/$repeat: Reading again without willread hint"
+ cancel_lru_locks osc
+ local speed_cache=$($READS -f $DIR/$tfile -s $size \
+ -b 4096 -n $((size / 4096)) -t 60 |
+ sed -e '/^$/d' -e 's#.*s, ##' -e 's#MB/s##')
+
+ echo "Iter $i/$repeat: reading with willread hint"
+ cancel_lru_locks osc
+ do_nodes $(comma_list $(osts_nodes)) \
+ "echo 3 > /proc/sys/vm/drop_caches"
+ lfs ladvise -a willread $DIR/$tfile ||
+ error "Ladvise failed"
+ local speed_ladvise=$($READS -f $DIR/$tfile -s $size \
+ -b 4096 -n $((size / 4096)) -t 60 |
+ sed -e '/^$/d' -e 's#.*s, ##' -e 's#MB/s##')
+
+ local cache_speedup=$(echo "scale=2; \
+ ($speed_cache-$speed_origin)/$speed_origin*100" | bc)
+ cache_speedup=$(echo ${cache_speedup%.*})
+ echo "Iter $i/$repeat: cache speedup: $cache_speedup%"
+ average_cache=$((average_cache + cache_speedup))
+
+ local ladvise_speedup=$(echo "scale=2; \
+ ($speed_ladvise-$speed_origin)/$speed_origin*100" | bc)
+ ladvise_speedup=$(echo ${ladvise_speedup%.*})
+ echo "Iter $i/$repeat: ladvise speedup: $ladvise_speedup%"
+ average_ladvise=$((average_ladvise + ladvise_speedup))
+ done
+ average_cache=$((average_cache / repeat))
+ average_ladvise=$((average_ladvise / repeat))
+
+ if [ $average_cache -lt 20 ]; then
+ echo "Speedup with cache is less than 20% ($average_cache%),"\
+ "skipping check of speedup with willread:"\
+ "$average_ladvise%"
+ return 0
+ fi
+
+ local lowest_speedup=$((average_cache / 2))
+ [ $average_ladvise -gt $lowest_speedup ] ||
+ error_not_in_vm "Speedup with willread is less than " \
+ "$lowest_speedup%, got $average_ladvise%"
+ echo "Speedup with willread ladvise: $average_ladvise%"
+ echo "Speedup with cache: $average_cache%"
+}
+
+test_255a() {
+ lfs setstripe -c -1 -i 0 $DIR/$tfile || error "$tfile failed"
+
+ ladvise_no_type willread $DIR/$tfile &&
+ skip "willread ladvise is not supported" && return
+
+ ladvise_no_ioctl $DIR/$tfile &&
+ skip "ladvise ioctl is not supported" && return
+
+ [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
+ skip "lustre < 2.8.54 does not support ladvise " && return
+
+ local size_mb=100
+ local size=$((size_mb * 1048576))
+ dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
+ error "dd to $DIR/$tfile failed"
+
+ lfs ladvise -a willread $DIR/$tfile ||
+ error "Ladvise failed with no range argument"
+
+ lfs ladvise -a willread -s 0 $DIR/$tfile ||
+ error "Ladvise failed with no -l or -e argument"
+
+ lfs ladvise -a willread -e 1 $DIR/$tfile ||
+ error "Ladvise failed with only -e argument"
+
+ lfs ladvise -a willread -l 1 $DIR/$tfile ||
+ error "Ladvise failed with only -l argument"
+
+ lfs ladvise -a willread -s 2 -e 1 $DIR/$tfile &&
+ error "End offset should not be smaller than start offset"
+
+ lfs ladvise -a willread -s 2 -e 2 $DIR/$tfile &&
+ error "End offset should not be equal to start offset"
+
+ lfs ladvise -a willread -s $size -l 1 $DIR/$tfile ||
+ error "Ladvise failed with overflowing -s argument"
+
+ lfs ladvise -a willread -s 1 -e $((size + 1)) $DIR/$tfile ||
+ error "Ladvise failed with overflowing -e argument"
+
+ lfs ladvise -a willread -s 1 -l $size $DIR/$tfile ||
+ error "Ladvise failed with overflowing -l argument"
+
+ lfs ladvise -a willread -l 1 -e 2 $DIR/$tfile &&
+ error "Ladvise succeeded with conflicting -l and -e arguments"
+
+ echo "Synchronous ladvise should wait"
+ local delay=4
+#define OBD_FAIL_OST_LADVISE_PAUSE 0x237
+ do_nodes $(comma_list $(osts_nodes)) \
+ $LCTL set_param fail_val=$delay fail_loc=0x237
+
+ local start_ts=$SECONDS
+ lfs ladvise -a willread $DIR/$tfile ||
+ error "Ladvise failed with no range argument"
+ local end_ts=$SECONDS
+ local inteval_ts=$((end_ts - start_ts))
+
+ if [ $inteval_ts -lt $(($delay - 1)) ]; then
+ error "Synchronous advice didn't wait reply"
+ fi
+
+ echo "Asynchronous ladvise shouldn't wait"
+ local start_ts=$SECONDS
+ lfs ladvise -a willread -b $DIR/$tfile ||
+ error "Ladvise failed with no range argument"
+ local end_ts=$SECONDS
+ local inteval_ts=$((end_ts - start_ts))
+
+ if [ $inteval_ts -gt $(($delay / 2)) ]; then
+ error "Asynchronous advice blocked"
+ fi
+
+ do_nodes $(comma_list $(osts_nodes)) $LCTL set_param fail_loc=0
+ ladvise_willread_performance
+}
+run_test 255a "check 'lfs ladvise -a willread'"
+
+facet_meminfo() {
+ local facet=$1
+ local info=$2
+
+ do_facet $facet "cat /proc/meminfo | grep ^${info}:" | awk '{print $2}'
+}
+
+test_255b() {
+ ladvise_no_type dontneed $DIR/$tfile &&
+ skip "dontneed ladvise is not supported" && return
+
+ ladvise_no_ioctl $DIR/$tfile &&
+ skip "ladvise ioctl is not supported" && return
+
+ [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
+ skip "lustre < 2.8.54 does not support ladvise" && return
+
+ [ "$(facet_fstype ost1)" = "zfs" ] &&
+ skip "zfs-osd does not support dontneed advice" && return
+
+ lfs setstripe -c 1 -i 0 $DIR/$tfile
+
+ local size_mb=100
+ local size=$((size_mb * 1048576))
+ # In order to prevent disturbance of other processes, only check 3/4
+ # of the memory usage
+ local kibibytes=$((size_mb * 1024 * 3 / 4))
+
+ dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
+ error "dd to $DIR/$tfile failed"
+
+ local total=$(facet_meminfo ost1 MemTotal)
+ echo "Total memory: $total KiB"
+
+ do_facet ost1 "sync && echo 3 > /proc/sys/vm/drop_caches"
+ local before_read=$(facet_meminfo ost1 Cached)
+ echo "Cache used before read: $before_read KiB"
+
+ lfs ladvise -a willread $DIR/$tfile ||
+ error "Ladvise willread failed"
+ local after_read=$(facet_meminfo ost1 Cached)
+ echo "Cache used after read: $after_read KiB"
+
+ lfs ladvise -a dontneed $DIR/$tfile ||
+ error "Ladvise dontneed again failed"
+ local no_read=$(facet_meminfo ost1 Cached)
+ echo "Cache used after dontneed ladvise: $no_read KiB"
+
+ if [ $total -lt $((before_read + kibibytes)) ]; then
+ echo "Memory is too small, abort checking"
+ return 0
+ fi
+
+ if [ $((before_read + kibibytes)) -gt $after_read ]; then
+ error "Ladvise willread should use more memory" \
+ "than $kibibytes KiB"
+ fi
+
+ if [ $((no_read + kibibytes)) -gt $after_read ]; then
+ error "Ladvise dontneed should release more memory" \
+ "than $kibibytes KiB"
+ fi
+}
+run_test 255b "check 'lfs ladvise -a dontneed'"
+
+test_256() {
+ local cl_user
+ local cat_sl
+ local mdt_dev
+
+ [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
+ remote_mds_nodsh && skip "remote MDS with nodsh" && return
+ [ "$(facet_fstype mds1)" != "ldiskfs" ] &&
+ skip "non-ldiskfs backend" && return
+
+ mdt_dev=$(mdsdevname 1)
+ echo $mdt_dev
+ cl_user=$(do_facet mds1 \
+ "$LCTL get_param -n mdd.$MDT0.changelog_users | grep cl")
+ if [[ -n $cl_user ]]; then
+ skip "active changelog user"
+ return
+ fi
+
+ cl_user=$(do_facet mds1 $LCTL --device $MDT0 changelog_register -n)
+ echo "Registered as changelog user $cl_user"
+
+ rm -rf $DIR/$tdir
+ mkdir -p $DIR/$tdir
+
+ $LFS changelog_clear $MDT0 $cl_user 0
+
+ # change something
+ touch $DIR/$tdir/{1..10}
+
+ # stop the MDT
+ stop mds1 || error "Fail to stop MDT."
+
+ # remount the MDT
+ start mds1 $mdt_dev $MDS_MOUNT_OPTS || error "Fail to start MDT."
+
+ #after mount new plainllog is used
+ touch $DIR/$tdir/{11..19}
+ cat_sl=$(do_facet mds1 \
+ "$DEBUGFS -R \\\"dump changelog_catalog cat.dmp\\\" $mdt_dev; \
+ llog_reader cat.dmp | grep \\\"type=1064553b\\\" | wc -l")
+
+ if (( cat_sl != 2 )); then
+ do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
+ error "Changelog catalog has wrong number of slots $cat_sl"
+ fi
+
+ $LFS changelog_clear $MDT0 $cl_user 0
+
+ cat_sl=$(do_facet mds1 \
+ "$DEBUGFS -R \\\"dump changelog_catalog cat.dmp\\\" $mdt_dev; \
+ llog_reader cat.dmp | grep \\\"type=1064553b\\\" | wc -l")
+
+ do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
+
+ if (( cat_sl == 2 )); then
+ error "Empty plain llog was not deleted from changelog catalog"
+ fi
+ if (( cat_sl != 1 )); then
+ error "Active plain llog shouldn\`t be deleted from catalog"
+ fi
+}
+run_test 256 "Check llog delete for empty and not full state"
+
+test_257() {
+ remote_mds_nodsh && skip "remote MDS with nodsh" && return
+ [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ]] &&
+ skip "Need MDS version at least 2.8.55" && return
+
+ test_mkdir -p $DIR/$tdir
+
+ setfattr -n trusted.name1 -v value1 $DIR/$tdir ||
+ error "setfattr -n trusted.name1=value1 $DIR/$tdir failed"
+ stat $DIR/$tdir
+
+#define OBD_FAIL_MDS_XATTR_REP 0x161
+ local mdtidx=$($LFS getstripe -M $DIR/$tdir)
+ local facet=mds$((mdtidx + 1))
+ set_nodes_failloc $(facet_active_host $facet) 0x80000161
+ getfattr -n trusted.name1 $DIR/$tdir 2> /dev/null
+
+ stop $facet || error "stop MDS failed"
+ start $facet $(mdsdevname $((mdtidx + 1))) $MDS_MOUNT_OPTS ||
+ error "start MDS fail"
+}
+run_test 257 "xattr locks are not lost"
+
+test_260() {
+#define OBD_FAIL_MDC_CLOSE 0x806
+ $LCTL set_param fail_loc=0x80000806
+ touch $DIR/$tfile
+
+}
+run_test 260 "Check mdc_close fail"
+
+cleanup_test_300() {
+ trap 0
+ umask $SAVE_UMASK
+}
+test_striped_dir() {
+ local mdt_index=$1
+ local stripe_count
+ local stripe_index
+
+ mkdir -p $DIR/$tdir
+
+ SAVE_UMASK=$(umask)
+ trap cleanup_test_300 RETURN EXIT
+
+ $LFS setdirstripe -i $mdt_index -c 2 -t all_char -m 755 \
+ $DIR/$tdir/striped_dir ||
+ error "set striped dir error"
+
+ local mode=$(stat -c%a $DIR/$tdir/striped_dir)
+ [ "$mode" = "755" ] || error "expect 755 got $mode"
+
+ $LFS getdirstripe $DIR/$tdir/striped_dir > /dev/null 2>&1 ||
+ error "getdirstripe failed"
+ stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
+ if [ "$stripe_count" != "2" ]; then