diff options
| author | Kent Overstreet <kent.overstreet@linux.dev> | 2024-03-22 16:29:23 -0400 |
|---|---|---|
| committer | Kent Overstreet <kent.overstreet@linux.dev> | 2024-03-31 20:36:11 -0400 |
| commit | ec9cc18fc2e65b08c588e01f24aaeb71551a7132 (patch) | |
| tree | af145579dc99b4b2f90f9ddf72f7f20f6df45106 /fs/bcachefs/snapshot.c | |
| parent | 63332394c7e1f4f26e8e5b1387212016aaa7eae2 (diff) | |
| download | linux-ec9cc18fc2e65b08c588e01f24aaeb71551a7132.tar.gz linux-ec9cc18fc2e65b08c588e01f24aaeb71551a7132.tar.bz2 linux-ec9cc18fc2e65b08c588e01f24aaeb71551a7132.zip | |
bcachefs: Add checks for invalid snapshot IDs
Previously, we assumed that keys were consistent with the snapshots
btree - but that's not correct as fsck may not have been run or may not
be complete.
This adds checks and error handling when using the in-memory snapshots
table (that mirrors the snapshots btree).
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/snapshot.c')
| -rw-r--r-- | fs/bcachefs/snapshot.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/fs/bcachefs/snapshot.c b/fs/bcachefs/snapshot.c index 9cd71e613dc9..4e074136c490 100644 --- a/fs/bcachefs/snapshot.c +++ b/fs/bcachefs/snapshot.c @@ -93,8 +93,10 @@ static int bch2_snapshot_tree_create(struct btree_trans *trans, static bool __bch2_snapshot_is_ancestor_early(struct snapshot_table *t, u32 id, u32 ancestor) { - while (id && id < ancestor) - id = __snapshot_t(t, id)->parent; + while (id && id < ancestor) { + const struct snapshot_t *s = __snapshot_t(t, id); + id = s ? s->parent : 0; + } return id == ancestor; } @@ -110,6 +112,8 @@ static bool bch2_snapshot_is_ancestor_early(struct bch_fs *c, u32 id, u32 ancest static inline u32 get_ancestor_below(struct snapshot_table *t, u32 id, u32 ancestor) { const struct snapshot_t *s = __snapshot_t(t, id); + if (!s) + return 0; if (s->skip[2] <= ancestor) return s->skip[2]; |
