# Attempt to make files of "every" format for data, dirs, attrs etc.
# (with apologies to Eric Sandeen for mutating xfser.sh)
+# Create a file of a given size.
+__populate_create_file() {
+ local sz="$1"
+ local fname="$2"
+
+ $XFS_IO_PROG -f -c "pwrite -S 0x62 -W -b 1m 0 $sz" "${fname}"
+}
+
+# Punch out every other hole in this file, if it exists.
+#
+# The goal here is to force the creation of a large number of metadata records
+# by creating a lot of tiny extent mappings in a file. Callers should ensure
+# that fragmenting the file actually causes record creation. Call this
+# function /after/ creating all other metadata structures.
+__populate_fragment_file() {
+ local fname="$1"
+
+ test -f "${fname}" && $here/src/punch-alternating "${fname}"
+}
+
# Create a large directory
__populate_create_dir() {
name="$1"
_populate_xfs_qmount_option
_scratch_mount
+
+ # We cannot directly force the filesystem to create the metadata
+ # structures we want; we can only achieve this indirectly by carefully
+ # crafting files and a directory tree. Therefore, we must have exact
+ # control over the layout and device selection of all files created.
+ # Clear the rtinherit flag on the root directory so that files are
+ # always created on the data volume regardless of MKFS_OPTIONS. We can
+ # set the realtime flag when needed.
+ $XFS_IO_PROG -c 'chattr -t' $SCRATCH_MNT
+
blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
dblksz="$($XFS_INFO_PROG "${SCRATCH_MNT}" | grep naming.*bsize | sed -e 's/^.*bsize=//g' -e 's/\([0-9]*\).*$/\1/g')"
crc="$($XFS_INFO_PROG "${SCRATCH_MNT}" | grep crc= | sed -e 's/^.*crc=//g' -e 's/\([0-9]*\).*$/\1/g')"
# Regular files
# - FMT_EXTENTS
echo "+ extents file"
- $XFS_IO_PROG -f -c "pwrite -S 0x61 0 ${blksz}" "${SCRATCH_MNT}/S_IFREG.FMT_EXTENTS"
+ __populate_create_file $blksz "${SCRATCH_MNT}/S_IFREG.FMT_EXTENTS"
# - FMT_BTREE
echo "+ btree extents file"
nr="$((blksz * 2 / 16))"
- $XFS_IO_PROG -f -c "pwrite -S 0x62 0 $((blksz * nr))" "${SCRATCH_MNT}/S_IFREG.FMT_BTREE"
- ./src/punch-alternating "${SCRATCH_MNT}/S_IFREG.FMT_BTREE"
+ __populate_create_file $((blksz * nr)) "${SCRATCH_MNT}/S_IFREG.FMT_BTREE"
# Directories
# - INLINE
# Char & block
echo "+ special"
mknod "${SCRATCH_MNT}/S_IFCHR" c 1 1
- mknod "${SCRATCH_MNT}/S_IFBLK" c 1 1
+ mknod "${SCRATCH_MNT}/S_IFBLK" b 1 1
# special file with an xattr
setfacl -P -m u:nobody:r ${SCRATCH_MNT}/S_IFCHR
# Free space btree
echo "+ freesp btree"
nr="$((blksz * 2 / 8))"
- $XFS_IO_PROG -f -c "pwrite -S 0x62 0 $((blksz * nr))" "${SCRATCH_MNT}/BNOBT"
- ./src/punch-alternating "${SCRATCH_MNT}/BNOBT"
+ __populate_create_file $((blksz * nr)) "${SCRATCH_MNT}/BNOBT"
# Inode btree
echo "+ inobt btree"
if [ $is_rmapbt -gt 0 ]; then
echo "+ rmapbt btree"
nr="$((blksz * 2 / 24))"
- $XFS_IO_PROG -f -c "pwrite -S 0x62 0 $((blksz * nr))" "${SCRATCH_MNT}/RMAPBT"
- ./src/punch-alternating "${SCRATCH_MNT}/RMAPBT"
+ __populate_create_file $((blksz * nr)) "${SCRATCH_MNT}/RMAPBT"
fi
# Realtime Reverse-mapping btree
if [ $is_rmapbt -gt 0 ] && [ $is_rt -gt 0 ]; then
echo "+ rtrmapbt btree"
nr="$((blksz * 2 / 32))"
- $XFS_IO_PROG -f -R -c "pwrite -S 0x62 0 $((blksz * nr))" "${SCRATCH_MNT}/RTRMAPBT"
- ./src/punch-alternating "${SCRATCH_MNT}/RTRMAPBT"
+ $XFS_IO_PROG -R -f -c 'truncate 0' "${SCRATCH_MNT}/RTRMAPBT"
+ __populate_create_file $((blksz * nr)) "${SCRATCH_MNT}/RTRMAPBT"
fi
# Reference-count btree
if [ $is_reflink -gt 0 ]; then
echo "+ reflink btree"
nr="$((blksz * 2 / 12))"
- $XFS_IO_PROG -f -c "pwrite -S 0x62 0 $((blksz * nr))" "${SCRATCH_MNT}/REFCOUNTBT"
+ __populate_create_file $((blksz * nr)) "${SCRATCH_MNT}/REFCOUNTBT"
cp --reflink=always "${SCRATCH_MNT}/REFCOUNTBT" "${SCRATCH_MNT}/REFCOUNTBT2"
- ./src/punch-alternating "${SCRATCH_MNT}/REFCOUNTBT"
fi
# Copy some real files (xfs tests, I guess...)
echo "+ real files"
test $fill -ne 0 && __populate_fill_fs "${SCRATCH_MNT}" 5
+ # Make sure we get all the fragmentation we asked for
+ __populate_fragment_file "${SCRATCH_MNT}/S_IFREG.FMT_BTREE"
+ __populate_fragment_file "${SCRATCH_MNT}/BNOBT"
+ __populate_fragment_file "${SCRATCH_MNT}/RMAPBT"
+ __populate_fragment_file "${SCRATCH_MNT}/RTRMAPBT"
+ __populate_fragment_file "${SCRATCH_MNT}/REFCOUNTBT"
+
umount "${SCRATCH_MNT}"
}
# Regular files
# - FMT_INLINE
echo "+ inline file"
- $XFS_IO_PROG -f -c "pwrite -S 0x61 0 1" "${SCRATCH_MNT}/S_IFREG.FMT_INLINE"
+ __populate_create_file 1 "${SCRATCH_MNT}/S_IFREG.FMT_INLINE"
# - FMT_EXTENTS
echo "+ extents file"
- $XFS_IO_PROG -f -c "pwrite -S 0x61 0 ${blksz}" "${SCRATCH_MNT}/S_IFREG.FMT_EXTENTS"
+ __populate_create_file $blksz "${SCRATCH_MNT}/S_IFREG.FMT_EXTENTS"
# - FMT_ETREE
echo "+ extent tree file"
nr="$((blksz * 2 / 12))"
- $XFS_IO_PROG -f -c "pwrite -S 0x62 0 $((blksz * nr))" "${SCRATCH_MNT}/S_IFREG.FMT_ETREE"
- ./src/punch-alternating "${SCRATCH_MNT}/S_IFREG.FMT_ETREE"
+ __populate_create_file $((blksz * nr)) "${SCRATCH_MNT}/S_IFREG.FMT_ETREE"
# Directories
# - INLINE
# Char & block
echo "+ special"
mknod "${SCRATCH_MNT}/S_IFCHR" c 1 1
- mknod "${SCRATCH_MNT}/S_IFBLK" c 1 1
+ mknod "${SCRATCH_MNT}/S_IFBLK" b 1 1
# special file with an xattr
setfacl -P -m u:nobody:r ${SCRATCH_MNT}/S_IFCHR
echo "+ real files"
test $fill -ne 0 && __populate_fill_fs "${SCRATCH_MNT}" 5
+ # Make sure we get all the fragmentation we asked for
+ __populate_fragment_file "${SCRATCH_MNT}/S_IFREG.FMT_ETREE"
+
umount "${SCRATCH_MNT}"
}
fi
if [ -f $dir/$file_count ]; then
- bytes_written=$(stat -c '%s' $dir/$file_count)
+ bytes_written=$(_get_filesize $dir/$file_count)
fi
# If there was no room to make the file, then divide it in
_scratch_populate_restore_cached() {
local metadump="$1"
+ # If we're configured for compressed dumps and there isn't already an
+ # uncompressed dump, see if we can use DUMP_COMPRESSOR to decompress
+ # something.
+ if [ -n "$DUMP_COMPRESSOR" ]; then
+ for compr in "$metadump".*; do
+ [ -e "$compr" ] && $DUMP_COMPRESSOR -d -f -k "$compr" && break
+ done
+ fi
+
+ test -r "$metadump" || return 1
+
case "${FSTYP}" in
"xfs")
xfs_mdrestore "${metadump}" "${SCRATCH_DEV}" && return 0
rm -rf "${POPULATE_METADUMP}"
# Try to restore from the metadump
- test -r "${POPULATE_METADUMP}" && \
- _scratch_populate_restore_cached "${POPULATE_METADUMP}" && \
+ _scratch_populate_restore_cached "${POPULATE_METADUMP}" && \
return
# Oh well, just create one from scratch
"xfs")
_scratch_xfs_populate $@
_scratch_xfs_populate_check
- _scratch_metadump "${POPULATE_METADUMP}" -a -o
+ _scratch_xfs_metadump "${POPULATE_METADUMP}"
+
+ local logdev=
+ [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
+ logdev=$SCRATCH_LOGDEV
+
+ _xfs_metadump "$POPULATE_METADUMP" "$SCRATCH_DEV" "$logdev" \
+ compress
;;
"ext2"|"ext3"|"ext4")
_scratch_ext4_populate $@
_scratch_ext4_populate_check
- e2image -Q "${SCRATCH_DEV}" "${POPULATE_METADUMP}"
+ _ext4_metadump "${SCRATCH_DEV}" "${POPULATE_METADUMP}" compress
;;
*)
_fail "Don't know how to populate a ${FSTYP} filesystem."