Linux-bcachefs Archive mirror
 help / color / mirror / Atom feed
From: Daniel Hill <daniel@gluo.nz>
To: linux-bcachefs@vger.kernel.org
Cc: Daniel Hill <daniel@gluo.nz>
Subject: [PATCH 3/3] bcachefs: add check for missing fragmentation in check_alloc_to_lru_ref()
Date: Tue, 20 Feb 2024 03:49:17 +1300	[thread overview]
Message-ID: <20240219145008.915291-4-daniel@gluo.nz> (raw)
In-Reply-To: <20240219145008.915291-1-daniel@gluo.nz>

We need to make sure we're not missing any fragmenation entries in the
LRU BTREE after repairing ALLOC BTREE

Signed-off-by: Daniel Hill <daniel@gluo.nz>
---
 fs/bcachefs/alloc_background.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/fs/bcachefs/alloc_background.c b/fs/bcachefs/alloc_background.c
index 3bf2a2daad93..c0894680ac4c 100644
--- a/fs/bcachefs/alloc_background.c
+++ b/fs/bcachefs/alloc_background.c
@@ -1566,6 +1566,32 @@ static int bch2_check_alloc_to_lru_ref(struct btree_trans *trans,
 
 	a = bch2_alloc_to_v4(alloc_k, &a_convert);
 
+	if (a->fragmentation_lru) {
+		lru_k = bch2_bkey_get_iter(trans, &lru_iter, BTREE_ID_lru,
+					   lru_pos(BCH_LRU_FRAGMENTATION_START,
+						   bucket_to_u64(alloc_k.k->p),
+						   a->fragmentation_lru), 0);
+		ret = bkey_err(lru_k);
+
+		if (ret)
+			return ret;
+
+		if (fsck_err_on(lru_k.k->type != KEY_TYPE_set, c,
+				alloc_key_to_missing_lru_entry,
+				"missing fragmentation_lru entry\n"
+				"  %s",
+				(printbuf_reset(&buf),
+				bch2_bkey_val_to_text(&buf, c, alloc_k), buf.buf))) {
+			ret = bch2_lru_set(trans,
+					BCH_LRU_FRAGMENTATION_START,
+					bucket_to_u64(alloc_k.k->p),
+					a->fragmentation_lru);
+			if (ret)
+				goto err;
+		}
+		bch2_trans_iter_exit(trans, &lru_iter);
+	}
+
 	if (a->data_type != BCH_DATA_cached)
 		return 0;
 
-- 
2.43.0


      parent reply	other threads:[~2024-02-19 14:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-19 14:49 [PATCH 0/3] fragmention_lru validation and repair code Daniel Hill
2024-02-19 14:49 ` [PATCH 1/3] bcachefs: alloc_v4_invalid() now checks fragmenation for consistency Daniel Hill
2024-02-19 14:49 ` [PATCH 2/3] bcachefs: update fragmenation_lru in alloc_write_key() Daniel Hill
2024-02-19 14:49 ` Daniel Hill [this message]

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=20240219145008.915291-4-daniel@gluo.nz \
    --to=daniel@gluo.nz \
    --cc=linux-bcachefs@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 read-only IMAP folder(s) and NNTP newsgroup(s).