From a850bde6498b46d6e3143d8847f9aa9598491f9f Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Thu, 8 Feb 2024 21:10:32 -0500 Subject: bcachefs: fsck_err() may now take a btree_trans fsck_err() now optionally takes a btree_trans; if the current thread has one, it is required that it be passed. The next patch will use this to unlock when waiting for user input. Signed-off-by: Kent Overstreet --- fs/bcachefs/disk_accounting.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'fs/bcachefs/disk_accounting.c') diff --git a/fs/bcachefs/disk_accounting.c b/fs/bcachefs/disk_accounting.c index ed3b368ea1af..bc45f53efc27 100644 --- a/fs/bcachefs/disk_accounting.c +++ b/fs/bcachefs/disk_accounting.c @@ -433,7 +433,7 @@ int bch2_accounting_gc_done(struct bch_fs *c) for (unsigned j = 0; j < nr; j++) src_v[j] -= dst_v[j]; - if (fsck_err(c, accounting_mismatch, "%s", buf.buf)) { + if (fsck_err(trans, accounting_mismatch, "%s", buf.buf)) { ret = commit_do(trans, NULL, NULL, 0, bch2_disk_accounting_mod(trans, &acc_k, src_v, nr, false)); if (ret) @@ -464,8 +464,9 @@ fsck_err: return ret; } -static int accounting_read_key(struct bch_fs *c, struct bkey_s_c k) +static int accounting_read_key(struct btree_trans *trans, struct bkey_s_c k) { + struct bch_fs *c = trans->c; struct printbuf buf = PRINTBUF; if (k.k->type != KEY_TYPE_accounting) @@ -483,7 +484,7 @@ static int accounting_read_key(struct bch_fs *c, struct bkey_s_c k) bpos_to_disk_accounting_pos(&acc, k.k->p); if (fsck_err_on(ret == -BCH_ERR_btree_insert_need_mark_replicas, - c, accounting_replicas_not_marked, + trans, accounting_replicas_not_marked, "accounting not marked in superblock replicas\n %s", (bch2_accounting_key_to_text(&buf, &acc), buf.buf))) @@ -500,15 +501,15 @@ fsck_err: int bch2_accounting_read(struct bch_fs *c) { struct bch_accounting_mem *acc = &c->accounting[0]; + struct btree_trans *trans = bch2_trans_get(c); - int ret = bch2_trans_run(c, - for_each_btree_key(trans, iter, + int ret = for_each_btree_key(trans, iter, BTREE_ID_accounting, POS_MIN, BTREE_ITER_prefetch|BTREE_ITER_all_snapshots, k, ({ struct bkey u; struct bkey_s_c k = bch2_btree_path_peek_slot_exact(btree_iter_path(trans, &iter), &u); - accounting_read_key(c, k); - }))); + accounting_read_key(trans, k); + })); if (ret) goto err; @@ -541,7 +542,7 @@ int bch2_accounting_read(struct bch_fs *c) continue; } - ret = accounting_read_key(c, k); + ret = accounting_read_key(trans, k); if (ret) goto err; } @@ -588,6 +589,7 @@ int bch2_accounting_read(struct bch_fs *c) preempt_enable(); percpu_up_read(&c->mark_lock); err: + bch2_trans_put(trans); bch_err_fn(c, ret); return ret; } -- cgit