All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: add support for capturing metadumps of corrupted fses
@ 2022-02-16 19:03 Anthony Iliopoulos
  0 siblings, 0 replies; only message in thread
From: Anthony Iliopoulos @ 2022-02-16 19:03 UTC (permalink / raw)
  To: fstests

Add the capability to capture btrfs metadumps when filesystem checks
fail, so that they can be used for further debugging. This is useful for
tests that _require_test and/or _require_scratch for which filesystem
checkers will run after a test completes and may occasionally pick up
inconsistencies.

Signed-off-by: Anthony Iliopoulos <ailiop@suse.com>
---
 README        |  4 ++--
 common/btrfs  | 15 +++++++++++++++
 common/config |  1 +
 common/rc     |  3 +++
 4 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/README b/README
index e9284b229eca..9f01aa10d61a 100644
--- a/README
+++ b/README
@@ -110,8 +110,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 or ext*
-               filesystems if a filesystem check fails.
+             - Set DUMP_CORRUPT_FS=1 to record metadata dumps of XFS, ext* or
+               btrfs 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
diff --git a/common/btrfs b/common/btrfs
index 5de926dd9bfa..32d02bf2b3ce 100644
--- a/common/btrfs
+++ b/common/btrfs
@@ -155,6 +155,11 @@ _check_btrfs_filesystem()
 	fi
 	rm -f $tmp.fsck
 
+	if [ $ok -eq 0 ] && [ "$DUMP_CORRUPT_FS" = "1" ]; then
+		local flatdev="$(basename "$device")"
+		_btrfs_metadump "$device" "$seqres.$flatdev.check.md" >>$seqres.full
+	fi
+
 	if [ $ok -eq 0 ]; then
 		echo "*** mount output ***"		>>$seqres.full
 		_mount					>>$seqres.full
@@ -496,3 +501,13 @@ _require_btrfs_support_sectorsize()
 	grep -wq $sectorsize /sys/fs/btrfs/features/supported_sectorsizes || \
 		_notrun "sectorsize $sectorsize is not supported"
 }
+
+_btrfs_metadump()
+{
+	local device="$1"
+	local dumpfile="$2"
+
+	test -n "$BTRFS_IMAGE_PROG" || _fail "btrfs-image not installed"
+	$BTRFS_IMAGE_PROG "$device" "$dumpfile"
+	[ -n "$DUMP_COMPRESSOR" ] && $DUMP_COMPRESSOR -f "$dumpfile" &> /dev/null
+}
diff --git a/common/config b/common/config
index 0566ab4a963e..121ba000279f 100644
--- a/common/config
+++ b/common/config
@@ -227,6 +227,7 @@ export ACCTON_PROG="$(type -P accton)"
 export E2IMAGE_PROG="$(type -P e2image)"
 export BLKZONE_PROG="$(type -P blkzone)"
 export GZIP_PROG="$(type -P gzip)"
+export BTRFS_IMAGE_PROG="$(type -P btrfs-image)"
 
 # 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/rc b/common/rc
index de60fb7b0677..e2d3d72a00f6 100644
--- a/common/rc
+++ b/common/rc
@@ -642,6 +642,9 @@ _metadump_dev() {
 	test "$DUMP_CORRUPT_FS" = 1 || return 0
 
 	case "$FSTYP" in
+	btrfs)
+		_btrfs_metadump $device $dumpfile
+		;;
 	ext*)
 		_ext4_metadump $device $dumpfile $compressopt
 		;;
-- 
2.35.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-02-16 19:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-16 19:03 [PATCH] btrfs: add support for capturing metadumps of corrupted fses Anthony Iliopoulos

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.