The normal fsck code doesn't call key_visible_in_snapshot() with an
empty list of snapshot IDs seen (the current snapshot ID will always be
on the list), but str_hash_repair_key() ->
bch2_get_snapshot_overwrites() can, and that's totally fine as long as
we check for it.

Signed-off-by: Kent Overstreet <[email protected]>
---
 fs/bcachefs/fsck.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/fs/bcachefs/fsck.c b/fs/bcachefs/fsck.c
index 57ddc20a5cce..9920f1affc5b 100644
--- a/fs/bcachefs/fsck.c
+++ b/fs/bcachefs/fsck.c
@@ -728,14 +728,8 @@ static int snapshots_seen_update(struct bch_fs *c, struct 
snapshots_seen *s,
 static bool key_visible_in_snapshot(struct bch_fs *c, struct snapshots_seen 
*seen,
                                    u32 id, u32 ancestor)
 {
-       ssize_t i;
-
        EBUG_ON(id > ancestor);
 
-       /* @ancestor should be the snapshot most recently added to @seen */
-       EBUG_ON(ancestor != seen->pos.snapshot);
-       EBUG_ON(ancestor != darray_last(seen->ids));
-
        if (id == ancestor)
                return true;
 
@@ -751,11 +745,8 @@ static bool key_visible_in_snapshot(struct bch_fs *c, 
struct snapshots_seen *see
         * 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] >= id;
-            --i)
-               if (bch2_snapshot_is_ancestor(c, id, seen->ids.data[i]))
+       darray_for_each_reverse(seen->ids, i)
+               if (*i != ancestor && bch2_snapshot_is_ancestor(c, id, *i))
                        return false;
 
        return true;
-- 
2.50.0


Reply via email to