populate: support compressing metadumps
authorDarrick J. Wong <djwong@kernel.org>
Tue, 9 Mar 2021 04:39:22 +0000 (20:39 -0800)
committerEryu Guan <guaneryu@gmail.com>
Sun, 21 Mar 2021 13:31:35 +0000 (21:31 +0800)
If the test runner passed in a DUMP_COMPRESSOR program, make it so that
the metadumps we generate are also compressed.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
README
common/populate

diff --git a/README b/README
index a369019..569b574 100644 (file)
--- a/README
+++ b/README
@@ -111,6 +111,11 @@ Preparing system for tests:
                the module is the same as FSTYP.
              - Set DUMP_CORRUPT_FS=1 to record metadata dumps of XFS
                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
+               name of a file to compress; and it must accept '-d -f -k' and
+               the name of a file to decompress.  In other words, it must
+               emulate gzip.
 
         - or add a case to the switch in common/config assigning
           these variables based on the hostname of your test
index 4e5b645..b897922 100644 (file)
@@ -824,6 +824,17 @@ _scratch_populate_cache_tag() {
 _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
@@ -855,8 +866,7 @@ _scratch_populate_cached() {
                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
@@ -867,6 +877,13 @@ _scratch_populate_cached() {
                _scratch_xfs_populate $@
                _scratch_xfs_populate_check
                _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 $@