gentoo-overlay/sys-kernel/hardened-kernel/files/linux-6.12/0055-bcachefs-Add-assert-fo...

81 lines
2.5 KiB
Diff

From 0877e537bcecaaa8b2a7926a130fab809a83e6da Mon Sep 17 00:00:00 2001
From: Kent Overstreet <kent.overstreet@linux.dev>
Date: Thu, 31 Oct 2024 03:35:41 -0400
Subject: [PATCH 055/233] bcachefs: Add assert for use of journal replay keys
for updates
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
The journal replay keys mechanism can only be used for updates in early
recovery, when still single threaded.
Add some asserts to make sure we never accidentally use it elsewhere.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Signed-off-by: Alexander Miroshnichenko <alex@millerson.name>
---
fs/bcachefs/bcachefs.h | 6 ++++++
fs/bcachefs/btree_trans_commit.c | 2 ++
fs/bcachefs/super.c | 5 +++++
3 files changed, 13 insertions(+)
diff --git a/fs/bcachefs/bcachefs.h b/fs/bcachefs/bcachefs.h
index e1ab67c533f0..c59a58b93a92 100644
--- a/fs/bcachefs/bcachefs.h
+++ b/fs/bcachefs/bcachefs.h
@@ -743,6 +743,12 @@ struct bch_fs {
#else
struct percpu_ref writes;
#endif
+ /*
+ * Certain operations are only allowed in single threaded mode, during
+ * recovery, and we want to assert that this is the case:
+ */
+ struct task_struct *recovery_task;
+
/*
* Analagous to c->writes, for asynchronous ops that don't necessarily
* need fs to be read-write
diff --git a/fs/bcachefs/btree_trans_commit.c b/fs/bcachefs/btree_trans_commit.c
index b47f11881fe4..529a5a19ab8a 100644
--- a/fs/bcachefs/btree_trans_commit.c
+++ b/fs/bcachefs/btree_trans_commit.c
@@ -999,6 +999,8 @@ do_bch2_trans_commit_to_journal_replay(struct btree_trans *trans)
{
struct bch_fs *c = trans->c;
+ BUG_ON(current != c->recovery_task);
+
trans_for_each_update(trans, i) {
int ret = bch2_journal_key_insert(c, i->btree_id, i->level, i->k);
if (ret)
diff --git a/fs/bcachefs/super.c b/fs/bcachefs/super.c
index 7e2431de3a94..7e0ff17a6dbb 100644
--- a/fs/bcachefs/super.c
+++ b/fs/bcachefs/super.c
@@ -441,6 +441,8 @@ static int __bch2_fs_read_write(struct bch_fs *c, bool early)
{
int ret;
+ BUG_ON(!test_bit(BCH_FS_may_go_rw, &c->flags));
+
if (test_bit(BCH_FS_initial_gc_unfixed, &c->flags)) {
bch_err(c, "cannot go rw, unfixed btree errors");
return -BCH_ERR_erofs_unfixed_errors;
@@ -1031,9 +1033,12 @@ int bch2_fs_start(struct bch_fs *c)
bch2_dev_allocator_add(c, ca);
bch2_recalc_capacity(c);
+ c->recovery_task = current;
ret = BCH_SB_INITIALIZED(c->disk_sb.sb)
? bch2_fs_recovery(c)
: bch2_fs_initialize(c);
+ c->recovery_task = NULL;
+
if (ret)
goto err;
--
2.45.2