linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Cc: Qu Wenruo <wqu@suse.com>
Subject: [PATCH v3 7/9] btrfs-progs: check: detect issues with btrfs_super_used in lowmem check
Date: Mon, 23 Aug 2021 15:23:11 -0400	[thread overview]
Message-ID: <48b9b7334f233d9e3d1ad650085262c892420cae.1629746415.git.josef@toxicpanda.com> (raw)
In-Reply-To: <cover.1629746415.git.josef@toxicpanda.com>

We can already fix this problem with the block accounting code, we just
need to keep track of how much we should have used on the file system,
and then check it against the bytes_super.  The repair just piggy backs
on the block group used repair.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 check/mode-lowmem.c | 13 ++++++++++++-
 check/mode-lowmem.h |  1 +
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index cb8e3ab8..a1ad9606 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -28,6 +28,7 @@
 #include "check/mode-lowmem.h"
 
 static u64 last_allocated_chunk;
+static u64 total_used = 0;
 
 static int calc_extent_flag(struct btrfs_root *root, struct extent_buffer *eb,
 			    u64 *flags_ret)
@@ -3645,6 +3646,8 @@ next:
 out:
 	btrfs_release_path(&path);
 
+	total_used += used;
+
 	if (total != used) {
 		error(
 		"block group[%llu %llu] used %llu but extent items used %llu",
@@ -5547,6 +5550,14 @@ next:
 	}
 out:
 
+	if (total_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),
+			total_used);
+		err |= SUPER_BYTES_USED_ERROR;
+	}
+
 	if (repair) {
 		ret = end_avoid_extents_overwrite();
 		if (ret < 0)
@@ -5559,7 +5570,7 @@ out:
 		if (ret)
 			err |= ret;
 		else
-			err &= ~BG_ACCOUNTING_ERROR;
+			err &= ~(BG_ACCOUNTING_ERROR|SUPER_BYTES_USED_ERROR);
 	}
 
 	btrfs_release_path(&path);
diff --git a/check/mode-lowmem.h b/check/mode-lowmem.h
index da9f8600..0bcc338b 100644
--- a/check/mode-lowmem.h
+++ b/check/mode-lowmem.h
@@ -48,6 +48,7 @@
 #define DIR_ITEM_HASH_MISMATCH	(1<<24) /* Dir item hash mismatch */
 #define INODE_MODE_ERROR	(1<<25) /* Bad inode mode */
 #define INVALID_GENERATION	(1<<26)	/* Generation is too new */
+#define SUPER_BYTES_USED_ERROR	(1<<27)	/* Super bytes_used is invalid */
 
 /*
  * Error bit for low memory mode check.
-- 
2.26.3


  parent reply	other threads:[~2021-08-23 19:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-23 19:23 [PATCH v3 0/9] btrfs-progs: make check handle invalid bg items Josef Bacik
2021-08-23 19:23 ` [PATCH v3 1/9] btrfs-progs: tests: fix running lowmem checks Josef Bacik
2021-08-23 19:23 ` [PATCH v3 2/9] btrfs-progs: check blocks in btrfs_next_sibling_block Josef Bacik
2021-08-24 16:48   ` David Sterba
2021-08-23 19:23 ` [PATCH v3 3/9] btrfs-progs: check: propagate fs root errors in lowmem mode Josef Bacik
2021-08-23 19:23 ` [PATCH v3 4/9] btrfs-progs: check: propagate extent item " Josef Bacik
2021-08-23 19:23 ` [PATCH v3 5/9] btrfs-progs: do not double add unaligned extent records Josef Bacik
2021-08-23 19:23 ` [PATCH v3 6/9] btrfs-progs: check: detect and fix problems with super_bytes_used Josef Bacik
2021-08-23 19:23 ` Josef Bacik [this message]
2021-08-23 19:23 ` [PATCH v3 8/9] btrfs-progs: test: add a test image with a corrupt block group item Josef Bacik
2021-08-24 17:00   ` David Sterba
2021-08-25 13:27     ` David Sterba
2021-08-23 19:23 ` [PATCH v3 9/9] btrfs-progs: tests: add a test image with an invalid super bytes_used Josef Bacik

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=48b9b7334f233d9e3d1ad650085262c892420cae.1629746415.git.josef@toxicpanda.com \
    --to=josef@toxicpanda.com \
    --cc=kernel-team@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=wqu@suse.com \
    /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).