From: Josef Bacik <josef@toxicpanda.com>
To: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH v2 09/12] btrfs-progs: make check detect and fix problems with super_bytes_used
Date: Wed, 18 Aug 2021 17:33:21 -0400 [thread overview]
Message-ID: <fd18dba016fbacb15e30c25acc8b0f9e66d10fe0.1629322156.git.josef@toxicpanda.com> (raw)
In-Reply-To: <cover.1629322156.git.josef@toxicpanda.com>
We do not detect problems with our bytes_used counter in the super
block. Thankfully the same method to fix block groups is used to re-set
the value in the super block, so simply add some extra code to validate
the bytes_used field and then piggy back on the repair code for block
groups.
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
check/main.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/check/main.c b/check/main.c
index af9e0ff3..b1b1b866 100644
--- a/check/main.c
+++ b/check/main.c
@@ -8663,12 +8663,14 @@ static int check_block_groups(struct block_group_tree *bg_cache)
struct btrfs_trans_handle *trans;
struct cache_extent *item;
struct block_group_record *bg_rec;
+ u64 used = 0;
int ret = 0;
for (item = first_cache_extent(&bg_cache->tree); item;
item = next_cache_extent(item)) {
bg_rec = container_of(item, struct block_group_record,
cache);
+ used += bg_rec->actual_used;
if (bg_rec->disk_used == bg_rec->actual_used)
continue;
fprintf(stderr,
@@ -8678,6 +8680,19 @@ static int check_block_groups(struct block_group_tree *bg_cache)
ret = -1;
}
+ /*
+ * We check the super bytes_used here because it's the sum of all block
+ * groups used, and the repair actually happens in
+ * btrfs_fix_block_accounting, so we can kill both birds with the same
+ * stone here.
+ */
+ if (used != btrfs_super_bytes_used(gfs_info->super_copy)) {
+ fprintf(stderr,
+ "super bytes used %llu mismatches actual used %llu\n",
+ btrfs_super_bytes_used(gfs_info->super_copy), used);
+ ret = -1;
+ }
+
if (!repair || !ret)
return ret;
--
2.26.3
next prev parent reply other threads:[~2021-08-18 21:33 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-18 21:33 [PATCH v2 00/12] btrfs-progs: make check handle invalid bg items Josef Bacik
2021-08-18 21:33 ` [PATCH v2 01/12] btrfs-progs: fix running lowmem check tests Josef Bacik
2021-08-19 5:40 ` Qu Wenruo
2021-08-23 14:54 ` David Sterba
2021-08-18 21:33 ` [PATCH v2 02/12] btrfs-progs: do not infinite loop on corrupt keys with lowmem mode Josef Bacik
2021-08-19 5:42 ` Qu Wenruo
2021-08-23 15:04 ` David Sterba
2021-08-23 18:44 ` Josef Bacik
2021-08-23 23:34 ` Qu Wenruo
2021-08-18 21:33 ` [PATCH v2 03/12] btrfs-progs: propagate fs root errors in " Josef Bacik
2021-08-19 5:43 ` Qu Wenruo
2021-08-18 21:33 ` [PATCH v2 04/12] btrfs-progs: propagate extent item " Josef Bacik
2021-08-19 5:45 ` Qu Wenruo
2021-08-18 21:33 ` [PATCH v2 05/12] btrfs-progs: do not double add unaligned extent records Josef Bacik
2021-08-18 21:33 ` [PATCH v2 06/12] btrfs-progs: add the ability to corrupt block group items Josef Bacik
2021-08-18 21:33 ` [PATCH v2 07/12] btrfs-progs: add the ability to corrupt fields of the super block Josef Bacik
2021-08-23 14:59 ` David Sterba
2021-08-18 21:33 ` [PATCH v2 08/12] btrfs-progs: make check detect and fix invalid used for block groups Josef Bacik
2021-08-19 5:54 ` Qu Wenruo
2021-08-18 21:33 ` Josef Bacik [this message]
2021-08-19 5:56 ` [PATCH v2 09/12] btrfs-progs: make check detect and fix problems with super_bytes_used Qu Wenruo
2021-08-18 21:33 ` [PATCH v2 10/12] btrfs-progs: check btrfs_super_used in lowmem check Josef Bacik
2021-08-19 5:57 ` Qu Wenruo
2021-08-18 21:33 ` [PATCH v2 11/12] btrfs-progs: add a test image with a corrupt block group item Josef Bacik
2021-08-18 21:33 ` [PATCH v2 12/12] btrfs-progs: add a test image with an invalid super bytes_used Josef Bacik
2021-08-23 18:31 ` [PATCH v2 00/12] btrfs-progs: make check handle invalid bg items 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=fd18dba016fbacb15e30c25acc8b0f9e66d10fe0.1629322156.git.josef@toxicpanda.com \
--to=josef@toxicpanda.com \
--cc=kernel-team@fb.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).