diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2023-07-17 00:15:01 +0200 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 23:10:08 +0200 |
commit | 464ee1929b7761d2939ad76573e6679b4246dc82 (patch) | |
tree | 557206205765f333e1beee86193d8039e212a3aa /fs/bcachefs/fsck.c | |
parent | bcachefs: Refactor overlapping extent checks (diff) | |
download | linux-464ee1929b7761d2939ad76573e6679b4246dc82.tar.xz linux-464ee1929b7761d2939ad76573e6679b4246dc82.zip |
bcachefs: Improve key_visible_in_snapshot()
Delete a redundant bch2_snapshot_is_ancestor() check, and convert some
assertions to debug assertions.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/fsck.c')
-rw-r--r-- | fs/bcachefs/fsck.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/fs/bcachefs/fsck.c b/fs/bcachefs/fsck.c index e40040001ac1..93281b701473 100644 --- a/fs/bcachefs/fsck.c +++ b/fs/bcachefs/fsck.c @@ -517,15 +517,14 @@ static bool key_visible_in_snapshot(struct bch_fs *c, struct snapshots_seen *see u32 id, u32 ancestor) { ssize_t i; - u32 top = seen->ids.nr ? seen->ids.data[seen->ids.nr - 1].equiv : 0; - BUG_ON(id > ancestor); - BUG_ON(!bch2_snapshot_is_equiv(c, id)); - BUG_ON(!bch2_snapshot_is_equiv(c, ancestor)); + EBUG_ON(id > ancestor); + EBUG_ON(!bch2_snapshot_is_equiv(c, id)); + EBUG_ON(!bch2_snapshot_is_equiv(c, ancestor)); /* @ancestor should be the snapshot most recently added to @seen */ - BUG_ON(ancestor != seen->pos.snapshot); - BUG_ON(ancestor != top); + EBUG_ON(ancestor != seen->pos.snapshot); + EBUG_ON(ancestor != seen->ids.data[seen->ids.nr - 1].equiv); if (id == ancestor) return true; @@ -533,11 +532,20 @@ static bool key_visible_in_snapshot(struct bch_fs *c, struct snapshots_seen *see if (!bch2_snapshot_is_ancestor(c, id, ancestor)) return false; + /* + * We know that @id is a descendant of @ancestor, we're checking if + * we've seen a key that overwrote @ancestor - i.e. also a descendent of + * @ascestor and with @id as a descendent. + * + * But we already know that we're scanning IDs between @id and @ancestor + * numerically, since snapshot ID lists are kept sorted, so if we find + * an id that's an ancestor of @id we're done: + */ + for (i = seen->ids.nr - 2; i >= 0 && seen->ids.data[i].equiv >= id; --i) - if (bch2_snapshot_is_ancestor(c, id, seen->ids.data[i].equiv) && - bch2_snapshot_is_ancestor(c, seen->ids.data[i].equiv, ancestor)) + if (bch2_snapshot_is_ancestor(c, id, seen->ids.data[i].equiv)) return false; return true; |