summaryrefslogtreecommitdiff
path: root/fs/bcachefs
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2022-04-12 03:57:01 +0300
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-23 00:09:31 +0300
commit0b090326535c8fe5a1da6ca3d7bd4a3fa9dfd6c9 (patch)
treebcf0e8a0e509212cba289d17c20bd7757656aeb8 /fs/bcachefs
parent5650bb46be89a1254609d47e4c87d1e9cf9121fb (diff)
downloadlinux-0b090326535c8fe5a1da6ca3d7bd4a3fa9dfd6c9.tar.xz
bcachefs: Improve bch2_lru_delete() error messages
When we detect a filesystem inconsistency, we should include the relevent keys in the error message. This patch adds a parameter to pass the key with the lru entry to bch2_lru_delete(), so that it can be printed. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Diffstat (limited to 'fs/bcachefs')
-rw-r--r--fs/bcachefs/alloc_background.c2
-rw-r--r--fs/bcachefs/lru.c20
-rw-r--r--fs/bcachefs/lru.h4
3 files changed, 16 insertions, 10 deletions
diff --git a/fs/bcachefs/alloc_background.c b/fs/bcachefs/alloc_background.c
index 1e6283b55e3b..ce8803658369 100644
--- a/fs/bcachefs/alloc_background.c
+++ b/fs/bcachefs/alloc_background.c
@@ -593,7 +593,7 @@ int bch2_trans_mark_alloc(struct btree_trans *trans,
if (old_lru != new_lru) {
ret = bch2_lru_change(trans, new->k.p.inode, new->k.p.offset,
- old_lru, &new_lru);
+ old_lru, &new_lru, old);
if (ret)
return ret;
diff --git a/fs/bcachefs/lru.c b/fs/bcachefs/lru.c
index 49a0f0d69664..fe9d15742947 100644
--- a/fs/bcachefs/lru.c
+++ b/fs/bcachefs/lru.c
@@ -30,11 +30,13 @@ void bch2_lru_to_text(struct printbuf *out, struct bch_fs *c,
pr_buf(out, "idx %llu", le64_to_cpu(lru->idx));
}
-int bch2_lru_delete(struct btree_trans *trans, u64 id, u64 idx, u64 time)
+int bch2_lru_delete(struct btree_trans *trans, u64 id, u64 idx, u64 time,
+ struct bkey_s_c orig_k)
{
struct btree_iter iter;
struct bkey_s_c k;
u64 existing_idx;
+ struct printbuf buf = PRINTBUF;
int ret = 0;
if (!time)
@@ -50,18 +52,20 @@ int bch2_lru_delete(struct btree_trans *trans, u64 id, u64 idx, u64 time)
goto err;
if (k.k->type != KEY_TYPE_lru) {
+ bch2_bkey_val_to_text(&buf, trans->c, orig_k);
bch2_trans_inconsistent(trans,
- "pointer to nonexistent lru %llu:%llu",
- id, time);
+ "pointer to nonexistent lru %llu:%llu\n%s",
+ id, time, buf.buf);
ret = -EIO;
goto err;
}
existing_idx = le64_to_cpu(bkey_s_c_to_lru(k).v->idx);
if (existing_idx != idx) {
+ bch2_bkey_val_to_text(&buf, trans->c, orig_k);
bch2_trans_inconsistent(trans,
- "lru %llu:%llu with wrong backpointer: got %llu, should be %llu",
- id, time, existing_idx, idx);
+ "lru %llu:%llu with wrong backpointer: got %llu, should be %llu\n%s",
+ id, time, existing_idx, idx, buf.buf);
ret = -EIO;
goto err;
}
@@ -69,6 +73,7 @@ int bch2_lru_delete(struct btree_trans *trans, u64 id, u64 idx, u64 time)
ret = bch2_btree_delete_at(trans, &iter, 0);
err:
bch2_trans_iter_exit(trans, &iter);
+ printbuf_exit(&buf);
return ret;
}
@@ -114,12 +119,13 @@ err:
}
int bch2_lru_change(struct btree_trans *trans, u64 id, u64 idx,
- u64 old_time, u64 *new_time)
+ u64 old_time, u64 *new_time,
+ struct bkey_s_c k)
{
if (old_time == *new_time)
return 0;
- return bch2_lru_delete(trans, id, idx, old_time) ?:
+ return bch2_lru_delete(trans, id, idx, old_time, k) ?:
bch2_lru_set(trans, id, idx, new_time);
}
diff --git a/fs/bcachefs/lru.h b/fs/bcachefs/lru.h
index 0a01836c07c1..bfe38a67e585 100644
--- a/fs/bcachefs/lru.h
+++ b/fs/bcachefs/lru.h
@@ -10,9 +10,9 @@ void bch2_lru_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
.val_to_text = bch2_lru_to_text, \
}
-int bch2_lru_delete(struct btree_trans *, u64, u64, u64);
+int bch2_lru_delete(struct btree_trans *, u64, u64, u64, struct bkey_s_c);
int bch2_lru_set(struct btree_trans *, u64, u64, u64 *);
-int bch2_lru_change(struct btree_trans *, u64, u64, u64, u64 *);
+int bch2_lru_change(struct btree_trans *, u64, u64, u64, u64 *, struct bkey_s_c);
int bch2_check_lrus(struct bch_fs *, bool);