fix(snapshot): harden snapshot subsystem with chain-walk safety and crash recovery#390
Merged
Merged
Conversation
…rash recovery Fix three issues found during systems-level review of the snapshot/clone subsystem: 1. **Reverse deletion order in snapshot remove** (critical): Delete DB record before filesystem. Previous order (FS first, DB second) left orphaned DB records on crash — phantom snapshots visible to users. New order leaves orphaned files (harmless, cleaned by GC) on crash instead. 2. **Validate backing path in crash recovery** (medium): When both container disk and snapshot disk exist during recovery (Case 2), validate that the COW child's backing path actually points to the expected snapshot before declaring success. Preserves both files on mismatch for manual inspection. 3. **Log warning on chain walk errors** (low): `read_backing_chain()` now emits `tracing::warn` instead of silently swallowing errors, aiding diagnosis of partial chain results. Also adds `is_backing_dependency()` helper that walks full qcow2 backing chains to detect transitive dependencies, used by `remove()` to check container disks, other snapshots, and clone bases before deletion. Includes 67 integration tests covering snapshot create/restore/remove, clone operations, and deep backing chain scenarios.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
remove(): Delete DB record before filesystem to prevent phantom snapshots on crash (orphaned files are harmless and GC-able)read_backing_chain()now emitstracing::warninstead of silently swallowing errorsis_backing_dependency()helper: Walks full qcow2 backing chains to detect transitive dependencies, used byremove()to check container disks, other snapshots, and clone basesTest plan
cargo test -p boxlite --lib— 31 unit tests passcargo clippy -p boxlite --lib -- -D warnings— cleancargo clippy -p boxlite --tests -- -D warnings— clean