summaryrefslogtreecommitdiff
path: root/fs/bcachefs/snapshot.h
AgeCommit message (Collapse)Author
2024-04-03bcachefs: Reconstruct missing snapshot nodesKent Overstreet
When the snapshots btree is going, we'll have to delete huge amounts of data - unless we can reconstruct it by looking at the keys that refer to it. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-03-31bcachefs: Add checks for invalid snapshot IDsKent Overstreet
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>
2024-03-31bcachefs: Move snapshot table size to struct snapshot_tableKent Overstreet
We need to add bounds checking for snapshot table accesses - it turns out there are cases where we do need to use the snapshots table before fsck checks have completed (and indeed, fsck may not have been run). Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-05bcachefs: Combine .trans_trigger, .atomic_triggerKent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-05bcachefs: mark now takes bkey_sKent Overstreet
Prep work for disk space accounting rewrite: we're going to want to use a single callback for both of our current triggers, so we need to change them to have the same type signature first. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-01bcachefs: darray_for_each() now declares loop iterKent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-11-01bcachefs: Enumerate fsck errorsKent Overstreet
This patch adds a superblock error counter for every distinct fsck error; this means that when analyzing filesystems out in the wild we'll be able to see what sorts of inconsistencies are being found and repair, and hence what bugs to look for. Errors validating bkeys are not yet considered distinct fsck errors, but this patch adds a new helper, bkey_fsck_err(), in order to add distinct error types for them as well. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-10-31bcachefs: Don't run bch2_delete_dead_snapshots() unnecessarilyKent Overstreet
Be a bit more careful about when bch2_delete_dead_snapshots needs to run: it only needs to run synchronously if we're running fsck, and it only needs to run at all if we have snapshot nodes to delete or if fsck has noticed that it needs to run. Also: Rename BCH_FS_HAVE_DELETED_SNAPSHOTS -> BCH_FS_NEED_DELETE_DEAD_SNAPSHOTS Kill bch2_delete_dead_snapshots_hook(), move functionality to bch2_mark_snapshot() Factor out bch2_check_snapshot_needs_deletion(), to explicitly check if we need to be running snapshot deletion. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-10-22bcachefs: Make sure to initialize equiv when creating new snapshotsKent Overstreet
Previously, equiv was set in the snapshot deletion path, which is where it's needed - equiv, for snapshot ID equivalence classes, would ideally be a private data structure to the snapshot deletion path. But if a new snapshot is created while snapshot deletion is running, move_key_to_correct_snapshot() moves a key to snapshot id 0 - oops. Fixes: https://github.com/koverstreet/bcachefs/issues/593 Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-10-22bcachefs: bch2_propagate_key_to_snapshot_leaves()Kent Overstreet
If fsck finds a key that needs work done, the primary example being an unlinked inode that needs to be deleted, and the key is in an internal snapshot node, we have a bit of a conundrum. The conundrum is that internal snapshot nodes are shared, and we in general do updates in internal snapshot nodes because there may be overwrites in some snapshots and not others, and this may affect other keys referenced by this key (i.e. extents). For example, we might be seeing an unlinked inode in an internal snapshot node, but then in one child snapshot the inode might have been reattached and might not be unlinked. Deleting the inode in the internal snapshot node would be wrong, because then we'll delete all the extents that the child snapshot references. But if an unlinked inode does not have any overwrites in child snapshots, we're fine: the inode is overwrritten in all child snapshots, so we can do the deletion at the point of comonality in the snapshot tree, i.e. the node where we found it. This patch adds a new helper, bch2_propagate_key_to_snapshot_leaves(), to handle the case where we need a to update a key that does have overwrites in child snapshots: we copy the key to leaf snapshot nodes, and then rewind fsck and process the needed updates there. With this, fsck can now always correctly handle unlinked inodes found in internal snapshot nodes. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-10-22bcachefs: move check_pos_snapshot_overwritten() to snapshot.cKent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-10-22bcachefs: Split out snapshot.cKent Overstreet
subvolume.c has gotten a bit large, this splits out a separate file just for managing snapshot trees - BTREE_ID_snapshots. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>