Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow directly writing snapshots on top of existing files #4301

Merged
merged 8 commits into from
Dec 7, 2023

Conversation

roypat
Copy link
Contributor

@roypat roypat commented Dec 5, 2023

Rebase of #3002 onto newest main.

Allows Firecracker to write snapshot files directly on top of existing file. This unlocks the ability to write diff snapshots directly on top of their base layer, merging them without having to go through rebase-snap. It additionally fixes a bug where having a VM try to overwrite the snapshot it was loaded from, both the snapshot and the VM got corrupted (now it instead does a "write back" of all memory changed since the snapshot was loaded, leaving the running VM intact)

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license. For more information on following
Developer Certificate of Origin and signing off your commits, please check
CONTRIBUTING.md.

PR Checklist

  • If a specific issue led to this PR, this PR closes the issue.
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this PR.
  • API changes follow the Runbook for Firecracker API changes.
  • User-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.
  • New TODOs link to an issue.
  • Commits meet contribution quality standards.

  • This functionality cannot be added in rust-vmm.

@roypat roypat force-pushed the snapshot-overwrite branch from dec7b3c to b93cdcd Compare December 5, 2023 12:25
@roypat roypat force-pushed the snapshot-overwrite branch 2 times, most recently from 0cd7cb3 to 5343789 Compare December 5, 2023 13:42
Copy link

codecov bot commented Dec 5, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (dc552f5) 81.71% compared to head (12fb4b1) 81.71%.

Files Patch % Lines
src/vmm/src/persist.rs 92.59% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4301      +/-   ##
==========================================
- Coverage   81.71%   81.71%   -0.01%     
==========================================
  Files         240      240              
  Lines       29332    29355      +23     
==========================================
+ Hits        23970    23986      +16     
- Misses       5362     5369       +7     
Flag Coverage Δ
4.14-c7g.metal 77.13% <92.85%> (-0.01%) ⬇️
4.14-m5d.metal 79.01% <92.85%> (-0.02%) ⬇️
4.14-m6a.metal 78.14% <92.85%> (-0.01%) ⬇️
4.14-m6g.metal 77.13% <92.85%> (-0.01%) ⬇️
4.14-m6i.metal 79.01% <92.85%> (-0.01%) ⬇️
5.10-c7g.metal 80.03% <92.85%> (-0.01%) ⬇️
5.10-m5d.metal 81.69% <92.85%> (-0.02%) ⬇️
5.10-m6a.metal 80.90% <92.85%> (-0.02%) ⬇️
5.10-m6g.metal 80.03% <92.85%> (-0.01%) ⬇️
5.10-m6i.metal 81.67% <92.85%> (-0.02%) ⬇️
6.1-c7g.metal 80.03% <92.85%> (-0.01%) ⬇️
6.1-m5d.metal 81.69% <92.85%> (+<0.01%) ⬆️
6.1-m6a.metal 80.90% <92.85%> (-0.02%) ⬇️
6.1-m6g.metal 80.03% <92.85%> (-0.01%) ⬇️
6.1-m6i.metal 81.67% <92.85%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@roypat roypat force-pushed the snapshot-overwrite branch from 5343789 to 829a39e Compare December 5, 2023 14:31
@roypat roypat added the Status: Awaiting review Indicates that a pull request is ready to be reviewed label Dec 5, 2023
@roypat roypat force-pushed the snapshot-overwrite branch from 972cf1f to 9fd359b Compare December 5, 2023 15:12
@roypat roypat requested a review from pb8o December 6, 2023 10:37
Seems like these were missed in the big `this_error` refractoring.

Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
Passing this enough around by reference was making for awkward
dereferencing when comparing.

Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
Previously, it would always use the same file names, which makes taking
two snapshots from the same microvm slightly tedious (as the first
snapshot has to be copied out before making the second snapshot).

Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
The Microvm.snapshot_*() functions by default always write the snapshot
to the same file system location. This means that full_snapshot.mem and
diff_snapshot.mem point to the same path, making the final assert in the
test trivially true (as a file is the same as itself - the diff snapshot
will have overwritten the full snapshot). The fix is to use a different
path for the full snapshot.

Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
@roypat roypat force-pushed the snapshot-overwrite branch 2 times, most recently from 4bf7d3f to 3baf0b2 Compare December 7, 2023 10:35
roypat and others added 2 commits December 7, 2023 10:58
We need to add fstat/newfstatat to the seccomp filter list due to the
call to File::metadata() in snapshot_memory_to_file.

Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
Allows the automatic merging of diff snapshots with a base snapshot by
directly writing the diff snapshot on top of a base snapshot file of
matching size.

Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
Co-authored-by: Ives van Hoorne <ives@codesandbox.io>
@roypat roypat force-pushed the snapshot-overwrite branch from 3baf0b2 to 37fde44 Compare December 7, 2023 11:01
roypat and others added 2 commits December 7, 2023 11:02
The test first crates a full snapshot, and then takes a diff snapshot
with the same memory file, to merge it. We take both snapshots as "diff"
snapshots, as taking a full snapshot does not clear the dirty pages
tracked (and in this test, we want to exercise the path where the second
diff snapshot only writes a few pages).

Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
Co-authored-by: Ives van Hoorne <ives@codesandbox.io>
This commit adds a test that has a microvm overwrite the snapshot file
from which it was loaded with a new snapshot (e.g. a sort of "refresh"
operation on the snapshot to write any modifications done since loading
back to disk). Prior to this patch series, this caused both the snapshot
and the microvm to become corrupted, as the zeroing done by the
truncate/set_len pair would be reflected in the mmap'd memory region.

Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
@roypat roypat force-pushed the snapshot-overwrite branch from 37fde44 to 12fb4b1 Compare December 7, 2023 11:03
@roypat roypat merged commit 4d66562 into firecracker-microvm:main Dec 7, 2023
@roypat roypat deleted the snapshot-overwrite branch December 7, 2023 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Awaiting review Indicates that a pull request is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants