From: Darrick J. Wong <djwong@xxxxxxxxxx> Create a new helper to use e2image to capture a qcow2 image of an ext* filesystem and make _check_generic_filesystem use it to dump corrupt ext images. Refactor the single user of e2image to use the helper. Signed-off-by: Darrick J. Wong <djwong@xxxxxxxxxx> --- README | 2 +- common/config | 1 + common/populate | 2 +- common/rc | 21 +++++++++++++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/README b/README index 3d369438..7a2638af 100644 --- a/README +++ b/README @@ -109,7 +109,7 @@ Preparing system for tests: - Set TEST_FS_MODULE_RELOAD=1 to unload the module and reload it between test invocations. This assumes that the name of the module is the same as FSTYP. - - Set DUMP_CORRUPT_FS=1 to record metadata dumps of XFS + - Set DUMP_CORRUPT_FS=1 to record metadata dumps of XFS or ext* filesystems if a filesystem check fails. - Set DUMP_COMPRESSOR to a compression program to compress metadumps of filesystems. This program must accept '-f' and the diff --git a/common/config b/common/config index d4cf8089..a47e462c 100644 --- a/common/config +++ b/common/config @@ -225,6 +225,7 @@ export CC_PROG="$(type -P cc)" export FSVERITY_PROG="$(type -P fsverity)" export OPENSSL_PROG="$(type -P openssl)" export ACCTON_PROG="$(type -P accton)" +export E2IMAGE_PROG="$(type -P e2image)" # use 'udevadm settle' or 'udevsettle' to wait for lv to be settled. # newer systems have udevadm command but older systems like RHEL5 don't. diff --git a/common/populate b/common/populate index b897922c..4135d89d 100644 --- a/common/populate +++ b/common/populate @@ -888,7 +888,7 @@ _scratch_populate_cached() { "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." diff --git a/common/rc b/common/rc index 835c3c24..a460ec9c 100644 --- a/common/rc +++ b/common/rc @@ -585,6 +585,18 @@ _scratch_mkfs_ext4() return $mkfs_status } +_ext4_metadump() +{ + local device="$1" + local dumpfile="$2" + local compressopt="$3" + + test -n "$E2IMAGE_PROG" || _fail "e2image not installed" + $E2IMAGE_PROG -Q "$device" "$dumpfile" + [ "$compressopt" = "compress" ] && [ -n "$DUMP_COMPRESSOR" ] && + $DUMP_COMPRESSOR "$dumpfile" &>> "$seqres.full" +} + _test_mkfs() { case $FSTYP in @@ -2730,6 +2742,15 @@ _check_generic_filesystem() fi rm -f $tmp.fsck + if [ $ok -eq 0 ] && [ -n "$DUMP_CORRUPT_FS" ]; then + case "$FSTYP" in + ext*) + local flatdev="$(basename "$device")" + _ext4_metadump "$seqres.$flatdev.check.qcow2" "$device" compress + ;; + esac + fi + if [ $ok -eq 0 ] then echo "*** mount output ***" >>$seqres.full