mirror of
https://github.com/linux-apfs/apfstests.git
synced 2026-05-01 15:01:44 -07:00
populate: cache scratch metadata images
Create a helper function to create a populated FS image and dump the metadata into a file on the test device, with the purpose of allowing future (fuzzer) invocations of _populate_fs use the cached metadata to save time. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Eryu Guan <eguan@redhat.com> Signed-off-by: Eryu Guan <eguan@redhat.com>
This commit is contained in:
committed by
Eryu Guan
parent
dac5feaea7
commit
d6445ed41a
@@ -673,3 +673,47 @@ _fill_fs()
|
|||||||
file_count=$((file_count + 1))
|
file_count=$((file_count + 1))
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Populate a scratch FS from scratch or from a cached image.
|
||||||
|
_scratch_populate_cached() {
|
||||||
|
POPULATE_METADUMP="${TEST_DIR}/__populate.${FSTYP}"
|
||||||
|
POPULATE_METADUMP_DESCR="${TEST_DIR}/__populate.${FSTYP}.txt"
|
||||||
|
|
||||||
|
# Don't keep metadata images cached for more 48 hours...
|
||||||
|
rm -rf "$(find "${POPULATE_METADUMP}" -mtime +2 2>/dev/null)"
|
||||||
|
|
||||||
|
# Throw away cached image if it doesn't match our spec.
|
||||||
|
meta_descr="FSTYP ${FSTYP} MKFS_OPTIONS ${MKFS_OPTIONS} SIZE $(blockdev --getsz "${SCRATCH_DEV}") ARGS $@"
|
||||||
|
cmp -s "${POPULATE_METADUMP_DESCR}" <(echo "${meta_descr}") || rm -rf "${POPULATE_METADUMP}"
|
||||||
|
|
||||||
|
# Do we have a cached image?
|
||||||
|
if [ -r "${POPULATE_METADUMP}" ]; then
|
||||||
|
case "${FSTYP}" in
|
||||||
|
"xfs")
|
||||||
|
xfs_mdrestore "${POPULATE_METADUMP}" "${SCRATCH_DEV}" && return
|
||||||
|
;;
|
||||||
|
"ext2"|"ext3"|"ext4")
|
||||||
|
e2image -r "${POPULATE_METADUMP}" "${SCRATCH_DEV}" && return
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Oh well, just create one from scratch
|
||||||
|
_scratch_mkfs
|
||||||
|
echo "${meta_descr}" > "${POPULATE_METADUMP_DESCR}"
|
||||||
|
case "${FSTYP}" in
|
||||||
|
"xfs")
|
||||||
|
_scratch_xfs_populate $@
|
||||||
|
_scratch_xfs_populate_check
|
||||||
|
_scratch_metadump "${POPULATE_METADUMP}" -a -o
|
||||||
|
;;
|
||||||
|
"ext2"|"ext3"|"ext4")
|
||||||
|
_scratch_ext4_populate $@
|
||||||
|
_scratch_ext4_populate_check
|
||||||
|
e2image -Q "${SCRATCH_DEV}" "${POPULATE_METADUMP}"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
_fail "Don't know how to populate a ${FSTYP} filesystem."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|||||||
@@ -471,12 +471,13 @@ _scratch_do_mkfs()
|
|||||||
_scratch_metadump()
|
_scratch_metadump()
|
||||||
{
|
{
|
||||||
dumpfile=$1
|
dumpfile=$1
|
||||||
|
shift
|
||||||
options=
|
options=
|
||||||
|
|
||||||
[ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
|
[ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
|
||||||
options="-l $SCRATCH_LOGDEV"
|
options="-l $SCRATCH_LOGDEV"
|
||||||
|
|
||||||
xfs_metadump $options $SCRATCH_DEV $dumpfile
|
xfs_metadump $options "$@" $SCRATCH_DEV $dumpfile
|
||||||
}
|
}
|
||||||
|
|
||||||
_setup_large_ext4_fs()
|
_setup_large_ext4_fs()
|
||||||
|
|||||||
Reference in New Issue
Block a user