Commit e7808eef authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Kill bch2_fs_bug()

These have all been converted to fsck/inconsistent errors
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 31ba2cd3
...@@ -156,7 +156,7 @@ void bch2_bkey_debugcheck(struct bch_fs *c, struct btree *b, struct bkey_s_c k) ...@@ -156,7 +156,7 @@ void bch2_bkey_debugcheck(struct bch_fs *c, struct btree *b, struct bkey_s_c k)
char buf[160]; char buf[160];
bch2_bkey_val_to_text(&PBUF(buf), c, k); bch2_bkey_val_to_text(&PBUF(buf), c, k);
bch2_fs_bug(c, "invalid bkey %s: %s", buf, invalid); bch2_fs_inconsistent(c, "invalid bkey %s: %s", buf, invalid);
return; return;
} }
......
...@@ -16,26 +16,6 @@ struct work_struct; ...@@ -16,26 +16,6 @@ struct work_struct;
/* Error messages: */ /* Error messages: */
/*
* Very fatal logic/inconsistency errors: these indicate that we've majorly
* screwed up at runtime, i.e. it's not likely that it was just caused by the
* data on disk being inconsistent. These BUG():
*
* XXX: audit and convert to inconsistent() checks
*/
#define bch2_fs_bug(c, ...) \
do { \
bch_err(c, __VA_ARGS__); \
BUG(); \
} while (0)
#define bch2_fs_bug_on(cond, c, ...) \
do { \
if (cond) \
bch2_fs_bug(c, __VA_ARGS__); \
} while (0)
/* /*
* Inconsistency errors: The on disk data is inconsistent. If these occur during * Inconsistency errors: The on disk data is inconsistent. If these occur during
* initial recovery, they don't indicate a bug in the running code - we walk all * initial recovery, they don't indicate a bug in the running code - we walk all
......
...@@ -171,14 +171,17 @@ void bch2_btree_ptr_debugcheck(struct bch_fs *c, struct bkey_s_c k) ...@@ -171,14 +171,17 @@ void bch2_btree_ptr_debugcheck(struct bch_fs *c, struct bkey_s_c k)
struct bucket_mark mark; struct bucket_mark mark;
struct bch_dev *ca; struct bch_dev *ca;
bch2_fs_bug_on(!test_bit(BCH_FS_REBUILD_REPLICAS, &c->flags) &&
!bch2_bkey_replicas_marked(c, k, false), c,
"btree key bad (replicas not marked in superblock):\n%s",
(bch2_bkey_val_to_text(&PBUF(buf), c, k), buf));
if (!test_bit(BCH_FS_INITIAL_GC_DONE, &c->flags)) if (!test_bit(BCH_FS_INITIAL_GC_DONE, &c->flags))
return; return;
if (!percpu_down_read_trylock(&c->mark_lock))
return;
bch2_fs_inconsistent_on(!test_bit(BCH_FS_REBUILD_REPLICAS, &c->flags) &&
!bch2_bkey_replicas_marked(c, k, false), c,
"btree key bad (replicas not marked in superblock):\n%s",
(bch2_bkey_val_to_text(&PBUF(buf), c, k), buf));
bkey_for_each_ptr(ptrs, ptr) { bkey_for_each_ptr(ptrs, ptr) {
ca = bch_dev_bkey_exists(c, ptr->dev); ca = bch_dev_bkey_exists(c, ptr->dev);
...@@ -193,13 +196,15 @@ void bch2_btree_ptr_debugcheck(struct bch_fs *c, struct bkey_s_c k) ...@@ -193,13 +196,15 @@ void bch2_btree_ptr_debugcheck(struct bch_fs *c, struct bkey_s_c k)
mark.dirty_sectors < c->opts.btree_node_size) mark.dirty_sectors < c->opts.btree_node_size)
goto err; goto err;
} }
out:
percpu_up_read(&c->mark_lock);
return; return;
err: err:
bch2_bkey_val_to_text(&PBUF(buf), c, k); bch2_fs_inconsistent(c, "%s btree pointer %s: bucket %zi gen %i mark %08x",
bch2_fs_bug(c, "%s btree pointer %s: bucket %zi gen %i mark %08x", err, (bch2_bkey_val_to_text(&PBUF(buf), c, k), buf),
err, buf, PTR_BUCKET_NR(ca, ptr), PTR_BUCKET_NR(ca, ptr),
mark.gen, (unsigned) mark.v.counter); mark.gen, (unsigned) mark.v.counter);
goto out;
} }
void bch2_btree_ptr_to_text(struct printbuf *out, struct bch_fs *c, void bch2_btree_ptr_to_text(struct printbuf *out, struct bch_fs *c,
...@@ -222,29 +227,18 @@ void bch2_extent_debugcheck(struct bch_fs *c, struct bkey_s_c k) ...@@ -222,29 +227,18 @@ void bch2_extent_debugcheck(struct bch_fs *c, struct bkey_s_c k)
struct extent_ptr_decoded p; struct extent_ptr_decoded p;
char buf[160]; char buf[160];
/* if (!test_bit(JOURNAL_REPLAY_DONE, &c->journal.flags) ||
* XXX: we should be doing most/all of these checks at startup time, !test_bit(BCH_FS_INITIAL_GC_DONE, &c->flags))
* where we check bch2_bkey_invalid() in btree_node_read_done()
*
* But note that we can't check for stale pointers or incorrect gc marks
* until after journal replay is done (it might be an extent that's
* going to get overwritten during replay)
*/
if (percpu_down_read_trylock(&c->mark_lock)) {
bch2_fs_bug_on(!test_bit(BCH_FS_REBUILD_REPLICAS, &c->flags) &&
!bch2_bkey_replicas_marked_locked(c, e.s_c, false), c,
"extent key bad (replicas not marked in superblock):\n%s",
(bch2_bkey_val_to_text(&PBUF(buf), c, e.s_c), buf));
percpu_up_read(&c->mark_lock);
}
/*
* If journal replay hasn't finished, we might be seeing keys
* that will be overwritten by the time journal replay is done:
*/
if (!test_bit(JOURNAL_REPLAY_DONE, &c->journal.flags))
return; return;
if (!percpu_down_read_trylock(&c->mark_lock))
return;
bch2_fs_inconsistent_on(!test_bit(BCH_FS_REBUILD_REPLICAS, &c->flags) &&
!bch2_bkey_replicas_marked_locked(c, e.s_c, false), c,
"extent key bad (replicas not marked in superblock):\n%s",
(bch2_bkey_val_to_text(&PBUF(buf), c, e.s_c), buf));
extent_for_each_ptr_decode(e, p, entry) { extent_for_each_ptr_decode(e, p, entry) {
struct bch_dev *ca = bch_dev_bkey_exists(c, p.ptr.dev); struct bch_dev *ca = bch_dev_bkey_exists(c, p.ptr.dev);
struct bucket_mark mark = ptr_bucket_mark(ca, &p.ptr); struct bucket_mark mark = ptr_bucket_mark(ca, &p.ptr);
...@@ -254,21 +248,24 @@ void bch2_extent_debugcheck(struct bch_fs *c, struct bkey_s_c k) ...@@ -254,21 +248,24 @@ void bch2_extent_debugcheck(struct bch_fs *c, struct bkey_s_c k)
? mark.cached_sectors ? mark.cached_sectors
: mark.dirty_sectors; : mark.dirty_sectors;
bch2_fs_bug_on(stale && !p.ptr.cached, c, bch2_fs_inconsistent_on(stale && !p.ptr.cached, c,
"stale dirty pointer (ptr gen %u bucket %u", "stale dirty pointer (ptr gen %u bucket %u",
p.ptr.gen, mark.gen); p.ptr.gen, mark.gen);
bch2_fs_bug_on(stale > 96, c, "key too stale: %i", stale); bch2_fs_inconsistent_on(stale > 96, c,
"key too stale: %i", stale);
bch2_fs_bug_on(!stale &&
(mark.data_type != BCH_DATA_USER || bch2_fs_inconsistent_on(!stale &&
mark_sectors < disk_sectors), c, (mark.data_type != BCH_DATA_USER ||
"extent pointer not marked: %s:\n" mark_sectors < disk_sectors), c,
"type %u sectors %u < %u", "extent pointer not marked: %s:\n"
(bch2_bkey_val_to_text(&PBUF(buf), c, e.s_c), buf), "type %u sectors %u < %u",
mark.data_type, (bch2_bkey_val_to_text(&PBUF(buf), c, e.s_c), buf),
mark_sectors, disk_sectors); mark.data_type,
mark_sectors, disk_sectors);
} }
percpu_up_read(&c->mark_lock);
} }
void bch2_extent_to_text(struct printbuf *out, struct bch_fs *c, void bch2_extent_to_text(struct printbuf *out, struct bch_fs *c,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment