DEFRAG_PROG="$XFS_FSR_PROG"
;;
ext4|ext4dev)
- DEFRAG_PROG="$E4DEFRAG_PROG"
+ testfile="$TEST_DIR/$$-test.defrag"
+ donorfile="$TEST_DIR/$$-donor.defrag"
+ bsize=`_get_block_size $TEST_DIR`
+ $XFS_IO_PROG -f -c "pwrite -b $bsize 0 $bsize" $testfile > /dev/null
+ cp $testfile $donorfile
+ echo $testfile | $here/src/e4compact -v -f $donorfile | \
+ grep -q "err:95"
+ if [ $? -eq 0 ]; then
+ rm -f $testfile $donorfile 2>&1 > /dev/null
+ _notrun "$FSTYP test filesystem doesn't support online defrag"
+ fi
+ rm -f $testfile $donorfile 2>&1 > /dev/null
+ DEFRAG_PROG="$E4DEFRAG_PROG"
;;
btrfs)
DEFRAG_PROG="$BTRFS_UTIL_PROG filesystem defragment"
;;
esac
- _require_command $DEFRAG_PROG
+ _require_command "$DEFRAG_PROG" defragment
_require_xfs_io_command "fiemap"
}
max=$2
ext_cnt=$3
- [ "$min" -gt "$ext_cnt" ] && _fail "Found $ext_cnt extents min:$max"
- [ "$max" -ne -1 ] && [ "$ext_cnt" -gt "$max" ] && _fail "Found $ext_cnt max: $max"
+ # Return failure if $3 isn't between $1 and $2; let caller decide
+ # action if it's not, we just return status here.
+ if [ "$min" -gt "$ext_cnt" ]; then
+ echo "Found $ext_cnt extents min:$max"
+ return 1;
+ fi
+ if [ "$max" -ne -1 ] && [ "$ext_cnt" -gt "$max" ]; then
+ echo "Found $ext_cnt max: $max"
+ return 1;
+ fi
if [ $max -ne $min ]; then
echo "in_range($min, $max)"
else
echo "$ext_cnt"
fi
- return $ext_cnt
+ # success
+ return 0
}
# Defrag file, check it, and remove it.
echo -n "Before: "
ext_before=$(_extent_count $1)
_check_extent_count $min_before $max_before $ext_before
+ [ $? -eq 0 ] || _notrun "Could not adequately fragment file"
[ ! -z $csum ] && CSUM_BEFORE=`md5sum $1`
STAT_BEFORE=`stat -c "a: %x m: %y c: %z" $1`
$DEFRAG_PROG -v $1 >> $seqres.full 2>&1
- _scratch_remount
+ _scratch_cycle_mount
STAT_AFTER=`stat -c "a: %x m: %y c: %z" $1`
[ ! -z $csum ] && CSUM_AFTER=`md5sum $1`
echo -n "After: "
ext_after=$(_extent_count $1)
_check_extent_count $min_after $max_after $ext_after
+ [ $? -eq 0 ] || _fail "Failed to adequately defragment file"
[ "$ext_before" -lt "$ext_after" ] && \
_fail "Number of extents increased after defragmentation," \