From: Kent Overstreet Date: Sun, 16 Jul 2023 22:15:01 +0000 (-0400) Subject: bcachefs: Improve key_visible_in_snapshot() X-Git-Tag: io_uring-6.7-2023-11-10~119^2~182 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=464ee1929b7761d2939ad76573e6679b4246dc82;p=linux-block.git 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 --- 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;