All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: Nikolay Borisov <nborisov@suse.com>
Subject: [PATCH 09/10] btrfs-progs: tests: Test for FST corruption detection/repair
Date: Mon,  1 Oct 2018 17:46:20 +0300	[thread overview]
Message-ID: <1538405181-25231-10-git-send-email-nborisov@suse.com> (raw)
In-Reply-To: <1538405181-25231-1-git-send-email-nborisov@suse.com>

Simple test case which preps a filesystem, then corrupts the FST and
finally repairs it. Tests both extent based and bitmap based FSTs.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 tests/fsck-tests/036-freespacetree-repair/test.sh | 76 +++++++++++++++++++++++
 1 file changed, 76 insertions(+)
 create mode 100755 tests/fsck-tests/036-freespacetree-repair/test.sh

diff --git a/tests/fsck-tests/036-freespacetree-repair/test.sh b/tests/fsck-tests/036-freespacetree-repair/test.sh
new file mode 100755
index 000000000000..8c91ce9dedbc
--- /dev/null
+++ b/tests/fsck-tests/036-freespacetree-repair/test.sh
@@ -0,0 +1,76 @@
+#!/bin/bash
+# Corrupt a filesystem that is using freespace tree and then ensure that
+# btrfs check is able to repair it. This tests correct detection/repair of
+# both a FREE_SPACE_EXTENT based FST and a FREE_SPACE_BITMAP based FST.
+
+source "$TEST_TOP/common"
+
+# wrapper for btrfs-corrupt-item
+# $1: Type of item we want to corrupt - extent or bitmap
+corrupt_fst_item()
+{
+	local type
+	local objectid
+	local offset
+	type="$1"
+
+	if [[ $type == "bitmap" ]]; then
+		type=200
+		objectid=$("$TOP/btrfs" inspect-internal dump-tree -t 10 "$TEST_DEV" | \
+			grep -o "[[:digit:]]* FREE_SPACE_BITMAP [[:digit:]]*" | \
+			cut -d' ' -f1 | tail -2 | head -1)
+		offset=$("$TOP/btrfs" inspect-internal dump-tree -t 10 "$TEST_DEV" | \
+			grep -o "[[:digit:]]* FREE_SPACE_BITMAP [[:digit:]]*" | \
+			cut -d' ' -f3 |tail -2 | head -1)
+		echo "Corrupting $objectid,FREE_SPACE_BITMAP,$offset" >> "$RESULTS"
+	elif [[ $type == "extent" ]]; then
+		type=199
+		objectid=$("$TOP/btrfs" inspect-internal dump-tree -t 10 "$TEST_DEV" | \
+			grep -o "[[:digit:]]* FREE_SPACE_EXTENT [[:digit:]]*" | \
+			cut -d' ' -f1 | tail -2 | head -1)
+		offset=$("$TOP/btrfs" inspect-internal dump-tree -t 10 "$TEST_DEV" | \
+			grep -o "[[:digit:]]* FREE_SPACE_EXTENT [[:digit:]]*" | \
+			cut -d' ' -f3 | tail -2 | head -1)
+		echo "Corrupting $objectid,FREE_SPACE_EXTENT,$offset" >> "$RESULTS"
+	else
+		_fail "Unknown item type for corruption"
+	fi
+
+	run_check "$TOP/btrfs-corrupt-block" -r 10 -K "$objectid,$type,$offset" \
+		-f offset "$TEST_DEV"
+}
+
+check_prereq btrfs
+check_prereq mkfs.btrfs
+check_global_prereq grep
+check_global_prereq tail
+check_global_prereq head
+check_global_prereq cut
+
+setup_root_helper
+prepare_test_dev 256M
+
+run_check "$TOP/mkfs.btrfs" -n 4k -f "$TEST_DEV"
+run_check_mount_test_dev -oclear_cache,space_cache=v2
+
+#create files which will populate the FST
+for i in {1..3000}; do
+	fallocate -l 4k "$TEST_MNT/file.$i"
+done
+
+run_check_umount_test_dev
+
+#now corrupt one of the bitmap items
+corrupt_fst_item "bitmap"
+check_image "$TEST_DEV"
+
+# change the freespace such that we now have at least one free_space_extent
+# object
+run_check_mount_test_dev
+rm -rf "$TEST_MNT/file.*"
+fallocate -l 50m "$TEST_MNT/file"
+run_check_umount_test_dev
+
+#now corrupt an extent
+corrupt_fst_item "extent"
+check_image "$TEST_DEV"
-- 
2.7.4


  parent reply	other threads:[~2018-10-01 14:46 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-01 14:46 [PATCH 00/10] Freespace tree repair support v2 Nikolay Borisov
2018-10-01 14:46 ` [PATCH 01/10] btrfs-progs: Add support for freespace tree in btrfs_read_fs_root Nikolay Borisov
2018-10-02 19:20   ` Omar Sandoval
2018-10-04  1:05   ` Su Yue
2018-10-01 14:46 ` [PATCH 02/10] btrfs-progs: Add extent buffer bitmap manipulation infrastructure Nikolay Borisov
2018-10-02 19:24   ` Omar Sandoval
2018-10-04  1:31   ` Su Yue
2018-10-01 14:46 ` [PATCH 03/10] btrfs-progs: Replace homegrown bitops related functions with kernel counterparts Nikolay Borisov
2018-10-02 23:32   ` Omar Sandoval
2018-10-01 14:46 ` [PATCH 04/10] btrfs-progs: Implement find_*_bit_le operations Nikolay Borisov
2018-10-04 18:08   ` Omar Sandoval
2018-10-04 18:09     ` Nikolay Borisov
2018-10-01 14:46 ` [PATCH 05/10] btrfs-progs: Pull free space tree related code from kernel Nikolay Borisov
2018-10-04 18:26   ` Omar Sandoval
2018-10-04 18:34     ` Nikolay Borisov
2018-10-04 19:01       ` Omar Sandoval
2018-10-23 14:05     ` David Sterba
2018-10-01 14:46 ` [PATCH 06/10] btrfs-progs: Hook FST code in extent (de)alloc Nikolay Borisov
2018-10-01 14:46 ` [PATCH 07/10] btrfs-progs: Add freespace tree as compat_ro supported feature Nikolay Borisov
2018-10-04 18:30   ` Omar Sandoval
2018-10-04 18:36     ` Nikolay Borisov
2018-10-01 14:46 ` [PATCH 08/10] btrfs-progs: check: Add support for freespace tree fixing Nikolay Borisov
2018-10-04 19:16   ` Omar Sandoval
2018-10-01 14:46 ` Nikolay Borisov [this message]
2018-10-01 14:46 ` [PATCH 10/10] btrfs-progs: check: Fix wrong error message in case of corrupted bitmap Nikolay Borisov
2018-10-04 19:18   ` Omar Sandoval
2018-10-23 15:00 ` [PATCH 00/10] Freespace tree repair support v2 David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1538405181-25231-10-git-send-email-nborisov@suse.com \
    --to=nborisov@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.