Skip to content

Commit 1df3108

Browse files
author
Kent Overstreet
committed
bcachefs: fsck: Fix oops in key_visible_in_snapshot()
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]>
1 parent 3f89076 commit 1df3108

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

fs/bcachefs/fsck.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -728,14 +728,8 @@ static int snapshots_seen_update(struct bch_fs *c, struct snapshots_seen *s,
728728
static bool key_visible_in_snapshot(struct bch_fs *c, struct snapshots_seen *seen,
729729
u32 id, u32 ancestor)
730730
{
731-
ssize_t i;
732-
733731
EBUG_ON(id > ancestor);
734732

735-
/* @ancestor should be the snapshot most recently added to @seen */
736-
EBUG_ON(ancestor != seen->pos.snapshot);
737-
EBUG_ON(ancestor != darray_last(seen->ids));
738-
739733
if (id == ancestor)
740734
return true;
741735

@@ -751,11 +745,8 @@ static bool key_visible_in_snapshot(struct bch_fs *c, struct snapshots_seen *see
751745
* numerically, since snapshot ID lists are kept sorted, so if we find
752746
* an id that's an ancestor of @id we're done:
753747
*/
754-
755-
for (i = seen->ids.nr - 2;
756-
i >= 0 && seen->ids.data[i] >= id;
757-
--i)
758-
if (bch2_snapshot_is_ancestor(c, id, seen->ids.data[i]))
748+
darray_for_each_reverse(seen->ids, i)
749+
if (*i != ancestor && bch2_snapshot_is_ancestor(c, id, *i))
759750
return false;
760751

761752
return true;

0 commit comments

Comments
 (0)