common: capture qcow2 dumps of corrupt ext* filesystems
authorDarrick J. Wong <djwong@kernel.org>
Tue, 9 Mar 2021 04:39:27 +0000 (20:39 -0800)
committerEryu Guan <guaneryu@gmail.com>
Sun, 21 Mar 2021 13:31:38 +0000 (21:31 +0800)
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@kernel.org>
README
common/config
common/populate
common/rc

diff --git a/README b/README
index 569b574..f15363f 100644 (file)
--- 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
index d4cf808..a47e462 100644 (file)
@@ -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.
index b897922..4135d89 100644 (file)
@@ -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."
index b0241b0..6d1757d 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -584,6 +584,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
@@ -2729,6 +2741,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