+test_127() { # bug 15521
+ $LSTRIPE -i 0 -c 1 $DIR/$tfile
+ $LCTL set_param osc.*.stats=0
+ FSIZE=$((2048 * 1024))
+ dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
+ cancel_lru_locks osc
+ dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
+
+ $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
+ while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
+ echo "got $COUNT $NAME"
+ [ ! $MIN ] && error "Missing min value for $NAME proc entry"
+ eval $NAME=$COUNT || error "Wrong proc format"
+
+ case $NAME in
+ read_bytes|write_bytes)
+ [ $MIN -lt 4096 ] && error "min is too small: $MIN"
+ [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
+ [ $MAX -lt 4096 ] && error "max is too small: $MAX"
+ [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
+ [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
+ [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
+ error "sumsquare is too small: $SUMSQ"
+ [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
+ error "sumsquare is too big: $SUMSQ"
+ ;;
+ *) ;;
+ esac
+ done < $DIR/${tfile}.tmp
+
+ #check that we actually got some stats
+ [ "$read_bytes" ] || error "Missing read_bytes stats"
+ [ "$write_bytes" ] || error "Missing write_bytes stats"
+ [ "$read_bytes" != 0 ] || error "no read done"
+ [ "$write_bytes" != 0 ] || error "no write done"
+}
+run_test 127 "verify the client stats are sane"
+
+test_128() { # bug 15212
+ touch $DIR/$tfile
+ $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
+ find $DIR/$tfile
+ find $DIR/$tfile
+ EOF
+
+ result=$(grep error $TMP/$tfile.log)
+ rm -f $DIR/$tfile
+ [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
+}
+run_test 128 "interactive lfs for 2 consecutive find's"
+
+set_dir_limits () {
+ local mntdev
+ local node
+
+ local LDPROC=/proc/fs/ldiskfs
+
+ for node in $(mdts_nodes); do
+ devs=$(do_node $node "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }')
+ for dev in $devs; do
+ mntdev=$(do_node $node "lctl get_param -n osd.$dev.mntdev")
+ do_node $node "echo $1 >$LDPROC/\\\$(basename $mntdev)/max_dir_size"
+ done
+ done
+}
+test_129() {
+ [ "$FSTYPE" != "ldiskfs" ] && skip "not needed for FSTYPE=$FSTYPE" && return 0
+ remote_mds_nodsh && skip "remote MDS with nodsh" && return
+
+ EFBIG=27
+ MAX=16384
+
+ set_dir_limits $MAX
+
+ mkdir -p $DIR/$tdir
+
+ I=0
+ J=0
+ while [ ! $I -gt $((MAX * MDSCOUNT)) ]; do
+ multiop $DIR/$tdir/$J Oc
+ rc=$?
+ if [ $rc -eq $EFBIG ]; then
+ set_dir_limits 0
+ echo "return code $rc received as expected"
+ return 0
+ elif [ $rc -ne 0 ]; then
+ set_dir_limits 0
+ error_exit "return code $rc received instead of expected $EFBIG"
+ fi
+ J=$((J+1))
+ I=$(stat -c%s "$DIR/$tdir")
+ done
+
+ error "exceeded dir size limit $MAX x $MDSCOUNT $((MAX * MDSCOUNT)) : $I bytes"
+ do_facet $SINGLEMDS "echo 0 >$LDPROC"
+}
+run_test 129 "test directory size limit ========================"
+
+test_130a() {
+ filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
+ [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
+
+ local fm_file=$DIR/$tfile
+ lfs setstripe -s 65536 -c 1 $fm_file || error "setstripe failed on $fm_file"
+ dd if=/dev/zero of=$fm_file bs=65536 count=1 || error "dd failed for $fm_file"
+
+ filefrag -ves $fm_file || error "filefrag $fm_file failed"
+ filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
+
+ lun=`$GETSTRIPE $fm_file | grep -A 10 obdidx | awk '{print $1}' | grep -v "obdidx"`
+
+ start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
+ IFS=$'\n'
+ tot_len=0
+ for line in $filefrag_op
+ do
+ frag_lun=`echo $line | cut -d: -f5`
+ ext_len=`echo $line | cut -d: -f4`
+ if (( $frag_lun != $lun )); then
+ error "FIEMAP on 1-stripe file($fm_file) failed"
+ return
+ fi
+ (( tot_len += ext_len ))
+ done
+
+ if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
+ error "FIEMAP on 1-stripe file($fm_file) failed;"
+ return
+ fi
+ echo "FIEMAP on single striped file succeeded"
+}
+run_test 130a "FIEMAP (1-stripe file)"
+
+test_130b() {
+ [ "$OSTCOUNT" -lt "2" ] && skip "skipping FIEMAP on 2-stripe file test" && return
+
+ filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
+ [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
+
+ local fm_file=$DIR/$tfile
+ lfs setstripe -s 65536 -c 2 $fm_file || error "setstripe failed on $fm_file"
+ dd if=/dev/zero of=$fm_file bs=1M count=2 || error "dd failed on $fm_file"
+
+ filefrag -ves $fm_file || error "filefrag $fm_file failed"
+ filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
+
+ last_lun=`echo $filefrag_op | cut -d: -f5`
+
+ IFS=$'\n'
+ tot_len=0
+ num_luns=1
+ for line in $filefrag_op
+ do
+ frag_lun=`echo $line | cut -d: -f5`
+ ext_len=`echo $line | cut -d: -f4`
+ if (( $frag_lun != $last_lun )); then
+ if (( tot_len != 1024 )); then
+ error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 256"
+ return
+ else
+ (( num_luns += 1 ))
+ tot_len=0
+ fi
+ fi
+ (( tot_len += ext_len ))
+ last_lun=$frag_lun
+ done
+ if (( num_luns != 2 || tot_len != 1024 )); then
+ error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
+ return
+ fi
+
+ echo "FIEMAP on 2-stripe file succeeded"
+}
+run_test 130b "FIEMAP (2-stripe file)"
+
+test_130c() {
+ [ "$OSTCOUNT" -lt "2" ] && skip "skipping FIEMAP on 2-stripe file with hole test" && return
+
+ filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
+ [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
+
+ local fm_file=$DIR/$tfile
+ lfs setstripe -s 65536 -c 2 $fm_file || error "setstripe failed on $fm_file"
+ dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 || error "dd failed on $fm_file"
+
+ filefrag -ves $fm_file || error "filefrag $fm_file failed"
+ filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
+
+ last_lun=`echo $filefrag_op | cut -d: -f5`
+
+ IFS=$'\n'
+ tot_len=0
+ num_luns=1
+ for line in $filefrag_op
+ do
+ frag_lun=`echo $line | cut -d: -f5`
+ ext_len=`echo $line | cut -d: -f4`
+ if (( $frag_lun != $last_lun )); then
+ logical=`echo $line | cut -d: -f2 | cut -d. -f1`
+ if (( logical != 512 )); then
+ error "FIEMAP on $fm_file failed; returned logical start for lun $logical instead of 512"
+ return
+ fi
+ if (( tot_len != 512 )); then
+ error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
+ return
+ else
+ (( num_luns += 1 ))
+ tot_len=0
+ fi
+ fi
+ (( tot_len += ext_len ))
+ last_lun=$frag_lun
+ done
+ if (( num_luns != 2 || tot_len != 512 )); then
+ error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
+ return
+ fi
+
+ echo "FIEMAP on 2-stripe file with hole succeeded"
+}
+run_test 130c "FIEMAP (2-stripe file with hole)"
+
+test_130d() {
+ [ "$OSTCOUNT" -lt "3" ] && skip "skipping FIEMAP on N-stripe file test" && return
+
+ filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
+ [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
+
+ local fm_file=$DIR/$tfile
+ lfs setstripe -s 65536 -c $OSTCOUNT $fm_file || error "setstripe failed on $fm_file"
+ dd if=/dev/zero of=$fm_file bs=1M count=$OSTCOUNT || error "dd failed on $fm_file"
+
+ filefrag -ves $fm_file || error "filefrag $fm_file failed"
+ filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
+
+ last_lun=`echo $filefrag_op | cut -d: -f5`
+
+ IFS=$'\n'
+ tot_len=0
+ num_luns=1
+ for line in $filefrag_op
+ do
+ frag_lun=`echo $line | cut -d: -f5`
+ ext_len=`echo $line | cut -d: -f4`
+ if (( $frag_lun != $last_lun )); then
+ if (( tot_len != 1024 )); then
+ error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
+ return
+ else
+ (( num_luns += 1 ))
+ tot_len=0
+ fi
+ fi
+ (( tot_len += ext_len ))
+ last_lun=$frag_lun
+ done
+ if (( num_luns != OSTCOUNT || tot_len != 1024 )); then
+ error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
+ return
+ fi
+
+ echo "FIEMAP on N-stripe file succeeded"
+}
+run_test 130d "FIEMAP (N-stripe file)"
+
+test_130e() {
+ [ "$OSTCOUNT" -lt "2" ] && skip "skipping continuation FIEMAP test" && return
+
+ filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
+ [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
+
+ local fm_file=$DIR/$tfile
+ lfs setstripe -s 65536 -c 2 $fm_file || error "setstripe failed on $fm_file"
+ NUM_BLKS=512
+ EXPECTED_LEN=$(( (NUM_BLKS / 2) * 4 ))
+ for ((i = 0; i < $NUM_BLKS; i++))
+ do
+ dd if=/dev/zero of=$fm_file count=1 bs=4096 seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
+ done
+
+ filefrag -ves $fm_file || error "filefrag $fm_file failed"
+ filefrag_op=`filefrag -ve $fm_file | grep -A 750 "ext:" | grep -v "ext:" | grep -v "found"`
+
+ last_lun=`echo $filefrag_op | cut -d: -f5`
+
+ IFS=$'\n'
+ tot_len=0
+ num_luns=1
+ for line in $filefrag_op
+ do
+ frag_lun=`echo $line | cut -d: -f5`
+ ext_len=`echo $line | cut -d: -f4`
+ if (( $frag_lun != $last_lun )); then
+ if (( tot_len != $EXPECTED_LEN )); then
+ error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
+ return
+ else
+ (( num_luns += 1 ))
+ tot_len=0
+ fi
+ fi
+ (( tot_len += ext_len ))
+ last_lun=$frag_lun
+ done
+ if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
+ echo "$num_luns $tot_len"
+ error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
+ return
+ fi
+
+ echo "FIEMAP with continuation calls succeeded"
+}
+run_test 130e "FIEMAP (test continuation FIEMAP calls)"
+
+# Test for writev/readv
+test_131a() {
+ rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
+ error "writev test failed"
+ rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
+ error "readv failed"
+ rm -f $DIR/$tfile
+}
+run_test 131a "test iov's crossing stripe boundary for writev/readv"
+
+test_131b() {
+ rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
+ error "append writev test failed"
+ rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
+ error "append writev test failed"
+ rm -f $DIR/$tfile
+}
+run_test 131b "test append writev"
+
+test_131c() {
+ rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
+ error "NOT PASS"
+}
+run_test 131c "test read/write on file w/o objects"
+
+test_131d() {
+ rwv -f $DIR/$tfile -w -n 1 1572864
+ NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
+ if [ "$NOB" != 1572864 ]; then
+ error "Short read filed: read $NOB bytes instead of 1572864"
+ fi
+ rm -f $DIR/$tfile
+}
+run_test 131d "test short read"
+
+test_131e() {
+ rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
+ rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
+ error "read hitting hole failed"
+ rm -f $DIR/$tfile
+}
+run_test 131e "test read hitting hole"
+
+test_140() { #bug-17379
+ mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
+ cd $DIR/$tdir || error "Changing to $DIR/$tdir"
+ cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
+
+ # VFS limits max symlink depth to 5(4KSTACK) or 8
+ local i=0
+ while i=`expr $i + 1`; do
+ mkdir -p $i || error "Creating dir $i"
+ cd $i || error "Changing to $i"
+ ln -s ../stat stat || error "Creating stat symlink"
+ # Read the symlink until ELOOP present,
+ # not LBUGing the system is considered success,
+ # we didn't overrun the stack.
+ $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
+ [ $ret -ne 0 ] && {
+ if [ $ret -eq 40 ]; then
+ break # -ELOOP
+ else
+ error "Open stat symlink"
+ return
+ fi
+ }
+ done
+ i=`expr $i - 1`
+ echo "The symlink depth = $i"
+ [ $i -eq 5 -o $i -eq 8 ] || error "Invalid symlink depth"
+}
+run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
+
+test_150() {
+ local TF="$TMP/$tfile"
+
+ dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
+ cp $TF $DIR/$tfile
+ cancel_lru_locks osc
+ cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
+ remount_client $MOUNT
+ cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
+
+ $TRUNCATE $TF 6000
+ $TRUNCATE $DIR/$tfile 6000
+ cancel_lru_locks osc
+ cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
+
+ echo "12345" >>$TF
+ echo "12345" >>$DIR/$tfile
+ cancel_lru_locks osc
+ cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
+
+ echo "12345" >>$TF
+ echo "12345" >>$DIR/$tfile
+ cancel_lru_locks osc
+ cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
+
+ rm -f $TF
+ true
+}
+run_test 150 "truncate/append tests"
+
+function roc_access() {
+ ACCNUM=`$LCTL get_param -n obdfilter.*.stats | \
+ grep 'cache_access'| awk '{print $2}' | \
+ awk '{sum=sum+$3} END{print sum}'`
+ echo $ACCNUM
+}
+
+function roc_hit() {
+ ACCNUM=`$LCTL get_param -n obdfilter.*.stats | \
+ grep 'cache_hit'|awk '{print $2}' | \
+ awk '{sum=sum+$1} END{print sum}'`
+ echo $ACCNUM
+}
+
+test_151() {
+ local CPAGES=3
+
+ # check whether obdfilter is cache capable at all
+ if ! $LCTL get_param -n obdfilter.*.read_cache_enable; then
+ echo "not cache-capable obdfilter"
+ return 0
+ fi
+
+ # check cache is enabled on all obdfilters
+ if $LCTL get_param -n obdfilter.*.read_cache_enable | grep 0 >&/dev/null; then
+ echo "oss cache is disabled"
+ return 0
+ fi
+
+ $LCTL set_param -n obdfilter.*.writethrough_cache_enable 1
+
+ # pages should be in the case right after write
+ dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES || error "dd failed"
+ BEFORE=`roc_hit`
+ cancel_lru_locks osc
+ cat $DIR/$tfile >/dev/null
+ AFTER=`roc_hit`
+ if ! let "AFTER - BEFORE == CPAGES"; then
+ error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
+ fi
+
+ # the following read invalidates the cache
+ cancel_lru_locks osc
+ $LCTL set_param -n obdfilter.*.read_cache_enable 0
+ cat $DIR/$tfile >/dev/null
+
+ # now data shouldn't be found in the cache
+ BEFORE=`roc_hit`
+ cancel_lru_locks osc
+ cat $DIR/$tfile >/dev/null
+ AFTER=`roc_hit`
+ if let "AFTER - BEFORE != 0"; then
+ error "IN CACHE: before: $BEFORE, after: $AFTER"
+ fi
+
+ $LCTL set_param -n obdfilter.*.read_cache_enable 1
+ rm -f $DIR/$tfile
+}
+run_test 151 "test cache on oss and controls ==============================="
+
+test_152() {
+ local TF="$TMP/$tfile"
+
+ # simulate ENOMEM during write
+#define OBD_FAIL_OST_NOMEM 0x226
+ lctl set_param fail_loc=0x80000226
+ dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
+ cp $TF $DIR/$tfile
+ sync || error "sync failed"
+ lctl set_param fail_loc=0
+
+ # discard client's cache
+ cancel_lru_locks osc
+
+ # simulate ENOMEM during read
+ lctl set_param fail_loc=0x80000226
+ cmp $TF $DIR/$tfile || error "cmp failed"
+ lctl set_param fail_loc=0
+
+ rm -f $TF
+}
+run_test 152 "test read/write with enomem ============================"
+
+test_153() {
+ multiop $DIR/$tfile Ow4096Ycu || error "multiop failed"
+}
+run_test 153 "test if fdatasync does not crash ======================="
+
+#Changelogs
+test_160() {
+ remote_mds && skip "remote MDS" && return
+ lctl set_param -n mdd.*.changelog on
+ $LFS changelog_clear $FSNAME 0
+
+ # 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
+
+ # verify contents
+ $LFS changelog $FSNAME
+ # check target fid
+ fidc=$($LFS changelog $FSNAME | grep timestamp | grep "CREAT" | tail -1 | \
+ awk '{print $5}')
+ fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
+ [ "$fidc" == "t=$fidf" ] || \
+ error "fid in changelog $fidc != file fid $fidf"
+ # check parent fid
+ fidc=$($LFS changelog $FSNAME | grep timestamp | grep "CREAT" | tail -1 | \
+ awk '{print $6}')
+ fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
+ [ "$fidc" == "p=$fidf" ] || \
+ error "pfid in changelog $fidc != dir fid $fidf"
+
+ # verify purge
+ FIRST_REC=$($LFS changelog $FSNAME | head -1 | awk '{print $1}')
+ $LFS changelog_clear $FSNAME $(($FIRST_REC + 5))
+ PURGE_REC=$($LFS changelog $FSNAME | head -1 | awk '{print $1}')
+ [ $PURGE_REC == $(($FIRST_REC + 6)) ] || \
+ error "first rec after purge should be $(($FIRST_REC + 6)); is $PURGE_REC"
+ # purge all
+ $LFS changelog_clear $FSNAME 0
+ lctl set_param -n mdd.*.changelog off
+}
+run_test 160 "changelog sanity"
+
+test_161() {
+ # need local MDT for fid2path
+ remote_mds && skip "remote MDS" && return
+
+ mkdir -p $DIR/$tdir
+ cp /etc/hosts $DIR/$tdir/$tfile
+ mkdir $DIR/$tdir/foo1
+ mkdir $DIR/$tdir/foo2
+ ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
+ ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
+ ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
+ ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
+ local FID=$($LFS path2fid $DIR/$tdir/$tfile)
+ if [ "$($LFS fid2path ${mds1_svc} $FID | wc -l)" != "5" ]; then
+ $LFS fid2path ${mds1_svc} $FID
+ error "bad link ea"
+ fi
+ # middle
+ rm $DIR/$tdir/foo2/zachary
+ # last
+ rm $DIR/$tdir/foo2/thor
+ # first
+ rm $DIR/$tdir/$tfile
+ # rename
+ mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
+ if [ "$($LFS fid2path ${mds1_svc} --link 1 $FID)" != "/$tdir/foo2/maggie" ]
+ then
+ $LFS fid2path ${mds1_svc} $FID
+ error "bad link rename"
+ fi
+ rm $DIR/$tdir/foo2/maggie
+
+ # overflow the EA
+ local longname=filename_avg_len_is_thirty_two_
+ createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 || \
+ error "failed to hardlink many files"
+ links=$($LFS fid2path ${mds1_svc} $FID | wc -l)
+ echo -n "${links}/1000 links in link EA"
+ [ ${links} -gt 60 ] || error "expected at least 60 links in link EA"
+ unlinkmany $DIR/$tdir/foo2/$longname 1000 || \
+ error "failed to unlink many hardlinks"
+}
+run_test 161 "link ea sanity"
+
+check_path() {
+ local expected=$1
+ shift
+ local fid=$2
+
+ local path=$(${LFS} fid2path $*)
+ RC=$?
+
+ if [ $RC -ne 0 ]; then
+ error "path looked up of $expected failed. Error $RC"
+ return $RC
+ elif [ "${path}" != "${expected}" ]; then
+ error "path looked up \"${path}\" instead of \"${expected}\""
+ return 2
+ fi
+ echo "fid $fid resolves to path $path"
+}
+
+test_162() {
+ # need local MDT for fid2path
+ remote_mds && skip "remote MDS" && return
+
+ # Make changes to filesystem
+ mkdir -p $DIR/$tdir/d2
+ touch $DIR/$tdir/d2/$tfile
+ touch $DIR/$tdir/d2/x1
+ touch $DIR/$tdir/d2/x2
+ mkdir -p $DIR/$tdir/d2/a/b/c
+ mkdir -p $DIR/$tdir/d2/p/q/r
+ fid=$($LFS path2fid $DIR/$tdir/d2/$tfile)
+ check_path "/$tdir/d2/$tfile" ${mds1_svc} $fid --link 0
+ ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
+ mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
+ fid=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file)
+ check_path "/$tdir/d2/a/b/c/new_file" ${mds1_svc} $fid --link 1
+ check_path "/$tdir/d2/p/q/r/hlink" ${mds1_svc} $fid --link 0
+ # check that there are 2 links, and that --rec doesnt break anything
+ ${LFS} fid2path ${mds1_svc} $fid --rec 20 | wc -l | grep -q 2 || \
+ error "expected 2 links"
+
+ rm $DIR/$tdir/d2/p/q/r/hlink
+ check_path "/$tdir/d2/a/b/c/new_file" ${mds1_svc} $fid --link 0
+}
+run_test 162 "path lookup sanity"
+
+# OST pools tests
+POOL=${POOL:-cea1}
+TGT_COUNT=$OSTCOUNT
+TGTPOOL_FIRST=1
+TGTPOOL_MAX=$(($TGT_COUNT - 1))
+TGTPOOL_STEP=2
+TGTPOOL_LIST=`seq $TGTPOOL_FIRST $TGTPOOL_STEP $TGTPOOL_MAX`
+POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
+POOL_DIR=$POOL_ROOT/dir_tst
+POOL_FILE=$POOL_ROOT/file_tst
+
+check_file_in_pool()
+{
+ file=$1
+ res=$($GETSTRIPE $file | grep 0x | cut -f2)
+ for i in $res
+ do
+ found=$(echo :$TGTPOOL_LIST: | tr " " ":" | grep :$i:)
+ if [[ "$found" == "" ]]
+ then
+ echo "pool list: $TGTPOOL_LIST"
+ echo "striping: $res"
+ error "$file not allocated in $POOL"
+ return 1
+ fi
+ done
+ return 0
+}
+
+test_200a() {
+ remote_mds_nodsh && skip "remote MDS with nodsh" && return
+ do_facet mgs $LCTL pool_new $FSNAME.$POOL
+ do_facet mgs $LCTL get_param -n lov.$FSNAME-MDT0000-mdtlov.pools.$POOL
+ [ $? == 0 ] || error "Pool creation of $POOL failed"
+}
+run_test 200a "Create new pool =========================================="
+
+test_200b() {
+ remote_mds_nodsh && skip "remote MDS with nodsh" && return
+ TGT=$(seq -f $FSNAME-OST%04g_UUID $TGTPOOL_FIRST $TGTPOOL_STEP \
+ $TGTPOOL_MAX | tr '\n' ' ')
+ do_facet mgs $LCTL pool_add $FSNAME.$POOL \
+ $FSNAME-OST[$TGTPOOL_FIRST-$TGTPOOL_MAX/$TGTPOOL_STEP]_UUID
+ res=$(do_facet mgs $LCTL get_param -n lov.$FSNAME-MDT0000-mdtlov.pools.$POOL | sort \
+ | tr '\n' ' ')
+ [ "$res" = "$TGT" ] || error "Pool content ($res) do not match requested ($TGT)"
+}
+run_test 200b "Add targets to a pool ===================================="
+
+test_200c() {
+ remote_mds_nodsh && skip "remote MDS with nodsh" && return
+ mkdir -p $POOL_DIR
+ $SETSTRIPE -c 2 -p $POOL $POOL_DIR
+ [ $? = 0 ] || error "Cannot set pool $POOL to $POOL_DIR"
+}
+run_test 200c "Set pool on a directory ================================="
+
+test_200d() {
+ remote_mds_nodsh && skip "remote MDS with nodsh" && return
+ res=$($GETSTRIPE $POOL_DIR | grep pool: | cut -f8 -d " ")
+ [ "$res" = $POOL ] || error "Pool on $POOL_DIR is not $POOL"
+}
+run_test 200d "Check pool on a directory ==============================="
+
+test_200e() {
+ remote_mds_nodsh && skip "remote MDS with nodsh" && return
+ failed=0
+ for i in $(seq -w 1 $(($TGT_COUNT * 3)))
+ do
+ file=$POOL_DIR/file-$i
+ touch $file
+ check_file_in_pool $file
+ if [[ $? != 0 ]]
+ then
+ failed=$(($failed + 1))
+ fi
+ done
+ [ "$failed" = 0 ] || error "$failed files not allocated in $POOL"
+}
+run_test 200e "Check files allocation from directory pool =============="
+
+test_200f() {
+ remote_mds_nodsh && skip "remote MDS with nodsh" && return
+ mkdir -p $POOL_FILE
+ failed=0
+ for i in $(seq -w 1 $(($TGT_COUNT * 3)))
+ do
+ file=$POOL_FILE/spoo-$i
+ $SETSTRIPE -p $POOL $file
+ check_file_in_pool $file
+ if [[ $? != 0 ]]
+ then
+ failed=$(($failed + 1))
+ fi
+ done
+ [ "$failed" = 0 ] || error "$failed files not allocated in $POOL"
+}
+run_test 200f "Create files in a pool ==================================="
+
+test_200g() {
+ remote_mds_nodsh && skip "remote MDS with nodsh" && return
+ TGT=$(do_facet mgs $LCTL get_param -n lov.$FSNAME-MDT0000-mdtlov.pools.$POOL | head -1)
+ do_facet mgs $LCTL pool_remove $FSNAME.$POOL $TGT
+ res=$(do_facet mgs $LCTL get_param -n lov.$FSNAME-MDT0000-mdtlov.pools.$POOL | grep $TGT)
+ [ "$res" = "" ] || error "$TGT not removed from $FSNAME.$POOL"
+}
+run_test 200g "Remove a target from a pool ============================="
+
+test_200h() {
+ remote_mds_nodsh && skip "remote MDS with nodsh" && return
+ for TGT in $(do_facet mgs $LCTL get_param -n lov.$FSNAME-MDT0000-mdtlov.pools.$POOL)
+ do
+ do_facet mgs $LCTL pool_remove $FSNAME.$POOL $TGT
+ done
+ res=$(do_facet mgs $LCTL get_param -n lov.$FSNAME-MDT0000-mdtlov.pools.$POOL)
+ [ "$res" = "" ] || error "Pool $FSNAME.$POOL cannot be drained"
+}
+run_test 200h "Remove all targets from a pool =========================="
+
+test_200i() {
+ remote_mds_nodsh && skip "remote MDS with nodsh" && return
+ do_facet mgs $LCTL pool_destroy $FSNAME.$POOL
+ res=$(do_facet mgs "$LCTL get_param -n lov.$FSNAME-MDT0000-mdtlov.pools.$POOL 2>/dev/null")
+ [ "$res" = "" ] || error "Pool $FSNAME.$POOL is not destroyed"
+}
+run_test 200i "Remove a pool ============================================"
+
+test_212() {
+ size=`date +%s`
+ size=$((size % 8192 + 1))
+ dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
+ sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
+ rm -f $DIR/f212 $DIR/f212.xyz
+}
+run_test 212 "Sendfile test ============================================"
+
+#
+# tests that do cleanup/setup should be run at the end
+#
+
+test_900() {
+ local ls
+ #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG 0x903
+ $LCTL set_param fail_loc=0x903
+ # cancel_lru_locks mgc - does not work due to lctl set_param syntax
+ for ls in /proc/fs/lustre/ldlm/namespaces/MGC*/lru_size; do
+ echo "clear" > $ls
+ done
+ FAIL_ON_ERROR=true cleanup
+ FAIL_ON_ERROR=true setup
+}
+run_test 900 "umount should not race with any mgc requeue thread"