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
Subject: [PATCH v3 5/9] btrfs-progs: do not double add unaligned extent records
Date: Mon, 23 Aug 2021 15:23:09 -0400	[thread overview]
Message-ID: <9369a488d508519a4bea2742dfd0bdadccf4dc99.1629746415.git.josef@toxicpanda.com> (raw)
In-Reply-To: <cover.1629746415.git.josef@toxicpanda.com>

The repair cycle in the main check will drop all of our cache and loop
through again to make sure everything is still good to go.
Unfortunately we record our unaligned extent records on a per-root list
so they can be retrieved when we're checking the fs roots.  This isn't
straightforward to clean up, so instead simply check our current list of
unaligned extent records when we are adding a new one to make sure we're
not duplicating our efforts.  This makes us able to pass 001 with my
super bytes_used fix applied.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 check/main.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/check/main.c b/check/main.c
index 81b6650f..6f77b5ff 100644
--- a/check/main.c
+++ b/check/main.c
@@ -7928,6 +7928,8 @@ static int record_unaligned_extent_rec(struct extent_record *rec)
 
 	rbtree_postorder_for_each_entry_safe(back, tmp,
 					     &rec->backref_tree, node) {
+		bool skip = false;
+
 		if (back->full_backref || !back->is_data)
 			continue;
 
@@ -7943,6 +7945,24 @@ static int record_unaligned_extent_rec(struct extent_record *rec)
 		if (IS_ERR_OR_NULL(dest_root))
 			continue;
 
+		/*
+		 * If we repaired something and restarted we could potentially
+		 * try to add this unaligned record multiple times, so check
+		 * before we add a new one.
+		 */
+		list_for_each_entry(urec, &dest_root->unaligned_extent_recs,
+				    list) {
+			if (urec->objectid == dest_root->objectid &&
+			    urec->owner == dback->owner &&
+			    urec->bytenr == rec->start) {
+				skip = true;
+				break;
+			}
+		}
+
+		if (skip)
+			continue;
+
 		urec = malloc(sizeof(struct unaligned_extent_rec_t));
 		if (!urec)
 			return -ENOMEM;
-- 
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 ` Josef Bacik [this message]
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 ` [PATCH v3 7/9] btrfs-progs: check: detect issues with btrfs_super_used in lowmem check Josef Bacik
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=9369a488d508519a4bea2742dfd0bdadccf4dc99.1629746415.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).