From patchwork Tue Mar 9 04:39:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12123945 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED375C4332D for ; Tue, 9 Mar 2021 04:40:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D35E865295 for ; Tue, 9 Mar 2021 04:40:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229701AbhCIEjf (ORCPT ); Mon, 8 Mar 2021 23:39:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:60734 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229714AbhCIEjM (ORCPT ); Mon, 8 Mar 2021 23:39:12 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id AA85065275; Tue, 9 Mar 2021 04:39:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615264751; bh=Tq45zGehPxRMEUw5QknLtgg5WA3vn1LE+HtkhsKU6wc=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=BF2e8v1Pe435iSuecHrZxPn0tQ5tEllv6LCz2L6gtYnVtSnLZqE1odK/6Wocg9sxW 4ZWj94C2EEM11xXGDoml6UX79aXxS3g9qsTsQQjdVUHRlp3AoUePacr7aIRBZYsD9k 5xyuNP4EERc4wM8DJsOgNB7SoTNg+DiB8cmUg4EMNIyKyCrSxKM7VWJ1LCo5H+syhc Pm6LHy76Js8eM4ZreNQ7CrtmVAugn4Pq0Iy2F9Snn9KnWGmJp6NfiAOblQsSUqPrtn F8BxeIcVHtzrhrjOUWZXMbixzbqCDtnziO6QibfXzZY1o3EV8vNIDYmjQ/JDoqB7no jM4NCrE6I7MdQ== Subject: [PATCH 1/4] common: capture metadump output if xfs filesystem check fails From: "Darrick J. Wong" To: djwong@kernel.org, guaneryu@gmail.com Cc: linux-xfs@vger.kernel.org, fstests@vger.kernel.org, guan@eryu.me Date: Mon, 08 Mar 2021 20:39:11 -0800 Message-ID: <161526475154.1212855.395880843881325184.stgit@magnolia> In-Reply-To: <161526474588.1212855.9208390435676413014.stgit@magnolia> References: <161526474588.1212855.9208390435676413014.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org From: Darrick J. Wong Capture metadump output when various userspace repair and checker tools fail or indicate corruption, to aid in debugging. We don't bother to annotate xfs_check because it's bitrotting. Signed-off-by: Darrick J. Wong --- README | 2 ++ common/xfs | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/README b/README index 43bb0cee..b00328ac 100644 --- a/README +++ b/README @@ -109,6 +109,8 @@ 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 + filesystems if a filesystem check fails. - or add a case to the switch in common/config assigning these variables based on the hostname of your test diff --git a/common/xfs b/common/xfs index 2156749d..b30d289f 100644 --- a/common/xfs +++ b/common/xfs @@ -432,6 +432,27 @@ _supports_xfs_scrub() return 0 } +# Save a snapshot of a corrupt xfs filesystem for later debugging. +_xfs_metadump() { + local metadump="$1" + local device="$2" + local logdev="$3" + local compressopt="$4" + shift; shift; shift; shift + local options="$@" + test -z "$options" && options="-a -o" + + if [ "$logdev" != "none" ]; then + options="$options -l $logdev" + fi + + $XFS_METADUMP_PROG $options "$device" "$metadump" + res=$? + [ "$compressopt" = "compress" ] && [ -n "$DUMP_COMPRESSOR" ] && + $DUMP_COMPRESSOR "$metadump" &> /dev/null + return $res +} + # run xfs_check and friends on a FS. _check_xfs_filesystem() { @@ -448,14 +469,16 @@ _check_xfs_filesystem() extra_options="-f" fi - if [ "$2" != "none" ]; then - extra_log_options="-l$2" - extra_mount_options="-ologdev=$2" + local logdev="$2" + if [ "$logdev" != "none" ]; then + extra_log_options="-l$logdev" + extra_mount_options="-ologdev=$logdev" fi - if [ "$3" != "none" ]; then - extra_rt_options="-r$3" - extra_mount_options=$extra_mount_options" -ortdev=$3" + local rtdev="$3" + if [ "$rtdev" != "none" ]; then + extra_rt_options="-r$rtdev" + extra_mount_options=$extra_mount_options" -ortdev=$rtdev" fi extra_mount_options=$extra_mount_options" $MOUNT_OPTIONS" @@ -520,8 +543,15 @@ _check_xfs_filesystem() fi rm -f $tmp.fs_check $tmp.logprint $tmp.repair + if [ "$ok" -ne 1 ] && [ "$DUMP_CORRUPT_FS" = "1" ]; then + local flatdev="$(basename "$device")" + _xfs_metadump "$seqres.$flatdev.check.md" "$device" "$logdev" \ + compress >> $seqres.full + fi + # Optionally test the index rebuilding behavior. if [ -n "$TEST_XFS_REPAIR_REBUILD" ]; then + rebuild_ok=1 $XFS_REPAIR_PROG $extra_options $extra_log_options $extra_rt_options $device >$tmp.repair 2>&1 if [ $? -ne 0 ]; then _log_err "_check_xfs_filesystem: filesystem on $device is inconsistent (rebuild)" @@ -530,6 +560,7 @@ _check_xfs_filesystem() echo "*** end xfs_repair output" >>$seqres.full ok=0 + rebuild_ok=0 fi rm -f $tmp.repair @@ -541,8 +572,15 @@ _check_xfs_filesystem() echo "*** end xfs_repair output" >>$seqres.full ok=0 + rebuild_ok=0 fi rm -f $tmp.repair + + if [ "$rebuild_ok" -ne 1 ] && [ "$DUMP_CORRUPT_FS" = "1" ]; then + local flatdev="$(basename "$device")" + _xfs_metadump "$seqres.$flatdev.rebuild.md" "$device" \ + "$logdev" compress >> $seqres.full + fi fi if [ $ok -eq 0 ]; then From patchwork Tue Mar 9 04:39:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12123943 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0DE5C4332E for ; Tue, 9 Mar 2021 04:40:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF0066529C for ; Tue, 9 Mar 2021 04:40:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229980AbhCIEjg (ORCPT ); Mon, 8 Mar 2021 23:39:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:60760 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229772AbhCIEjR (ORCPT ); Mon, 8 Mar 2021 23:39:17 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 333846523B; Tue, 9 Mar 2021 04:39:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615264757; bh=/myM8H1fNfDvMNUu+T8UflMSvkyGle1dV9UqqSe/g5Q=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=pD93ivVzXHfaXaL8AtG5FGud9RpCcTzW5/YDjTqlFKe8gy0ZhLruzOYL91IAPNjld 27+szvWtMDNGpLJaolqezpd09yDEnz+tLgVp9EA3YrMY02yiyONcHUTNq/IbAA8zEp 1plsKkm9tZoFnQuwU27cuXJXMgdXbzsRbihxR1ZN3qFywoVnElIyYSYXxspjBEcqzA u4KasDTkOAsHBNA0gsmqtN+HFyD2upihAf3E+Bn2DI0mnGmmGI+j8M7P+Y72wLavOX Tj71a7iLIAYuuIwOBPOYVHngQ89Si6a2jpn8634o2wX3uakG4g5C8eXInettGoiQ5i ZYAgewixY2a1Q== Subject: [PATCH 2/4] common: move _scratch_metadump to common/xfs From: "Darrick J. Wong" To: djwong@kernel.org, guaneryu@gmail.com Cc: linux-xfs@vger.kernel.org, fstests@vger.kernel.org, guan@eryu.me Date: Mon, 08 Mar 2021 20:39:17 -0800 Message-ID: <161526475700.1212855.1193550819027912831.stgit@magnolia> In-Reply-To: <161526474588.1212855.9208390435676413014.stgit@magnolia> References: <161526474588.1212855.9208390435676413014.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org From: Darrick J. Wong _scratch_metadump is really an xfs-specific dump helper, so move it to common/xfs, add 'xfs' to the name, and convert all users. Signed-off-by: Darrick J. Wong --- common/populate | 2 +- common/rc | 12 ------------ common/xfs | 13 +++++++++++++ tests/xfs/129 | 2 +- tests/xfs/234 | 2 +- tests/xfs/253 | 2 +- tests/xfs/284 | 4 ++-- tests/xfs/291 | 2 +- tests/xfs/336 | 2 +- tests/xfs/432 | 2 +- tests/xfs/503 | 8 ++++---- 11 files changed, 26 insertions(+), 25 deletions(-) diff --git a/common/populate b/common/populate index f4ad8669..4e5b645f 100644 --- a/common/populate +++ b/common/populate @@ -866,7 +866,7 @@ _scratch_populate_cached() { "xfs") _scratch_xfs_populate $@ _scratch_xfs_populate_check - _scratch_metadump "${POPULATE_METADUMP}" -a -o + _scratch_xfs_metadump "${POPULATE_METADUMP}" ;; "ext2"|"ext3"|"ext4") _scratch_ext4_populate $@ diff --git a/common/rc b/common/rc index 0ce3cb0d..835c3c24 100644 --- a/common/rc +++ b/common/rc @@ -490,18 +490,6 @@ _scratch_do_mkfs() return $mkfs_status } -_scratch_metadump() -{ - local dumpfile=$1 - shift - local options= - - [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \ - options="-l $SCRATCH_LOGDEV" - - $XFS_METADUMP_PROG $options "$@" $SCRATCH_DEV $dumpfile -} - _setup_large_ext4_fs() { local fs_size=$1 diff --git a/common/xfs b/common/xfs index b30d289f..fe4dea99 100644 --- a/common/xfs +++ b/common/xfs @@ -453,6 +453,19 @@ _xfs_metadump() { return $res } +# Snapshot the metadata on the scratch device +_scratch_xfs_metadump() +{ + local metadump=$1 + shift + local logdev=none + + [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \ + logdev=$SCRATCH_LOGDEV + + _xfs_metadump "$metadump" "$SCRATCH_DEV" "$logdev" nocompress "$@" +} + # run xfs_check and friends on a FS. _check_xfs_filesystem() { diff --git a/tests/xfs/129 b/tests/xfs/129 index 78baf5c4..513d2fdd 100755 --- a/tests/xfs/129 +++ b/tests/xfs/129 @@ -56,7 +56,7 @@ done echo "Create metadump file" _scratch_unmount -_scratch_metadump $metadump_file +_scratch_xfs_metadump $metadump_file # Now restore the obfuscated one back and take a look around echo "Restore metadump" diff --git a/tests/xfs/234 b/tests/xfs/234 index 14172c3d..a3a57f2d 100755 --- a/tests/xfs/234 +++ b/tests/xfs/234 @@ -56,7 +56,7 @@ done echo "Create metadump file" _scratch_unmount -_scratch_metadump $metadump_file +_scratch_xfs_metadump $metadump_file # Now restore the obfuscated one back and take a look around echo "Restore metadump" diff --git a/tests/xfs/253 b/tests/xfs/253 index 9d967a50..fb7fc80b 100755 --- a/tests/xfs/253 +++ b/tests/xfs/253 @@ -156,7 +156,7 @@ ls -R | od -c >> $seqres.full cd $here _scratch_unmount -_scratch_metadump $METADUMP_FILE +_scratch_xfs_metadump $METADUMP_FILE # Now restore the obfuscated one back and take a look around xfs_mdrestore "${METADUMP_FILE}" "${SCRATCH_DEV}" diff --git a/tests/xfs/284 b/tests/xfs/284 index dbfd752b..cc9d723a 100755 --- a/tests/xfs/284 +++ b/tests/xfs/284 @@ -50,12 +50,12 @@ COPY_FILE="${TEST_DIR}/${seq}_copyfile" # xfs_metadump should refuse to dump a mounted device _scratch_mkfs >> $seqres.full 2>&1 _scratch_mount -_scratch_metadump $METADUMP_FILE 2>&1 | filter_mounted +_scratch_xfs_metadump $METADUMP_FILE 2>&1 | filter_mounted _scratch_unmount # Test restore to a mounted device # xfs_mdrestore should refuse to restore to a mounted device -_scratch_metadump $METADUMP_FILE +_scratch_xfs_metadump $METADUMP_FILE _scratch_mount xfs_mdrestore $METADUMP_FILE $SCRATCH_DEV 2>&1 | filter_mounted _scratch_unmount diff --git a/tests/xfs/291 b/tests/xfs/291 index 6a507d58..c906f248 100755 --- a/tests/xfs/291 +++ b/tests/xfs/291 @@ -105,7 +105,7 @@ _scratch_xfs_check >> $seqres.full 2>&1 || _fail "xfs_check failed" # Yes they can! Now... # Can xfs_metadump cope with this monster? -_scratch_metadump $tmp.metadump || _fail "xfs_metadump failed" +_scratch_xfs_metadump $tmp.metadump || _fail "xfs_metadump failed" xfs_mdrestore $tmp.metadump $tmp.img || _fail "xfs_mdrestore failed" [ "$USE_EXTERNAL" = yes ] && [ -n "$SCRATCH_RTDEV" ] && \ rt_repair_opts="-r $SCRATCH_RTDEV" diff --git a/tests/xfs/336 b/tests/xfs/336 index a006938d..b35be8a0 100755 --- a/tests/xfs/336 +++ b/tests/xfs/336 @@ -66,7 +66,7 @@ _scratch_cycle_mount echo "Create metadump file" _scratch_unmount -_scratch_metadump $metadump_file +_scratch_xfs_metadump $metadump_file # Now restore the obfuscated one back and take a look around echo "Restore metadump" diff --git a/tests/xfs/432 b/tests/xfs/432 index f41ecfdb..7df74234 100755 --- a/tests/xfs/432 +++ b/tests/xfs/432 @@ -91,7 +91,7 @@ echo "qualifying extent: $extlen blocks" >> $seqres.full test -n "$extlen" || _notrun "could not create dir extent > 1000 blocks" echo "Try to metadump" -_scratch_metadump $metadump_file -w +_scratch_xfs_metadump $metadump_file -w xfs_mdrestore $metadump_file $metadump_img echo "Check restored metadump image" diff --git a/tests/xfs/503 b/tests/xfs/503 index edf546a2..20d9c83d 100755 --- a/tests/xfs/503 +++ b/tests/xfs/503 @@ -47,16 +47,16 @@ metadump_file_ag=${metadump_file}.ag copy_file=$testdir/copy.img echo metadump -_scratch_metadump $metadump_file >> $seqres.full +_scratch_xfs_metadump $metadump_file >> $seqres.full echo metadump a -_scratch_metadump $metadump_file_a -a >> $seqres.full +_scratch_xfs_metadump $metadump_file_a -a >> $seqres.full echo metadump g -_scratch_metadump $metadump_file_g -g >> $seqres.full +_scratch_xfs_metadump $metadump_file_g -g >> $seqres.full echo metadump ag -_scratch_metadump $metadump_file_ag -a -g >> $seqres.full +_scratch_xfs_metadump $metadump_file_ag -a -g >> $seqres.full echo copy $XFS_COPY_PROG $SCRATCH_DEV $copy_file >> $seqres.full From patchwork Tue Mar 9 04:39:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12123939 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AABE1C433E9 for ; Tue, 9 Mar 2021 04:40:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7EE0A65299 for ; Tue, 9 Mar 2021 04:40:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229772AbhCIEjg (ORCPT ); Mon, 8 Mar 2021 23:39:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:60788 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229775AbhCIEjX (ORCPT ); Mon, 8 Mar 2021 23:39:23 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id A36876523B; Tue, 9 Mar 2021 04:39:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615264762; bh=ImKUwqcf+R5uzs/wFuEe9XzHY+rIk8zrOXG/BoP6/x0=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Y4oWJJZl480FkaRZjy5Vxk0Saff/ACPWhFOHshDPwoMYSlKGplLf9u4dXV77tFuxP OjzgiZrS3m+iF+p04qo3KHPJwOK9KfuEeCEPXCAqtJXQlojda1telGzfOaHcJExQPz CcK3rwgzFIFe2TazCKkEsCdpvGebcubhJBN759lJ8YcVLuK9k8yGLyuk3YUJG1ZkQn +ZfSTwWyoW5+tqGKQLQIfXQJy7Nb0GHFKjVCoWmyjMHRHhW7ZJa6P46CvSkGNe0AQM ZL7hjyF7q9LF0F3m1Mh0Mmd0zZ/xbb2i/jBabqvkW7gevK7p58r8EfBUIzFKGlO5/J Mb2Wi/c48fy+w== Subject: [PATCH 3/4] populate: support compressing metadumps From: "Darrick J. Wong" To: djwong@kernel.org, guaneryu@gmail.com Cc: linux-xfs@vger.kernel.org, fstests@vger.kernel.org, guan@eryu.me Date: Mon, 08 Mar 2021 20:39:22 -0800 Message-ID: <161526476250.1212855.18197470277954527515.stgit@magnolia> In-Reply-To: <161526474588.1212855.9208390435676413014.stgit@magnolia> References: <161526474588.1212855.9208390435676413014.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org From: Darrick J. Wong 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 --- README | 5 +++++ common/populate | 21 +++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/README b/README index b00328ac..3d369438 100644 --- 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 diff --git a/common/populate b/common/populate index 4e5b645f..b897922c 100644 --- a/common/populate +++ b/common/populate @@ -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 $@ From patchwork Tue Mar 9 04:39:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12123937 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84A78C433DB for ; Tue, 9 Mar 2021 04:40:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5F3BF6528A for ; Tue, 9 Mar 2021 04:40:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230050AbhCIEjg (ORCPT ); Mon, 8 Mar 2021 23:39:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:60804 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229813AbhCIEj2 (ORCPT ); Mon, 8 Mar 2021 23:39:28 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 19F7765275; Tue, 9 Mar 2021 04:39:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615264768; bh=9XRsAZ8FAxeuTStWvCNwZLRLqwqJnTLPKMn+T2un58c=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=CqWGaSnSdpBNOUwNaL0zT5MvgPSnl6oB/CN2BfAVqBWdqeuY2eWsxawaiptVoG32q BvacSqR/BB4uL3obZY98CTgucR4R5g6NBNqNTxlTrH3/VIY64A7l1WUoOSq28xwUCG goOpXO3kaZp1WMo50Syp5a+MJVcXrsCT6yqYc7FQi7ZFGPn60XPJM6Tidj8EWe4j80 URiz2yabpDPqmUvEXSGW4gD9gagSyguuePRQO2ebNT2knMXrVZYzzN+AoYsYJPKhgv vaeeuLk0mYKL6go4cvYNZWzvgUXJJMDiIPv4rCgSYjaFcMCbN76Mh1i6fthmHRpukS FAA4Ndizz2YAQ== Subject: [PATCH 4/4] common: capture qcow2 dumps of corrupt ext* filesystems From: "Darrick J. Wong" To: djwong@kernel.org, guaneryu@gmail.com Cc: linux-xfs@vger.kernel.org, fstests@vger.kernel.org, guan@eryu.me Date: Mon, 08 Mar 2021 20:39:27 -0800 Message-ID: <161526476796.1212855.15194258148539741251.stgit@magnolia> In-Reply-To: <161526474588.1212855.9208390435676413014.stgit@magnolia> References: <161526474588.1212855.9208390435676413014.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org From: Darrick J. Wong 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 --- 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