Skip to content

Conversation

roypat
Copy link
Contributor

@roypat roypat commented Sep 2, 2024

Changes

Correctly handle various error conditions that can only occur if a malformed snapshot file is attempted to be loaded.

Reason

Graceful exits are nicer than panics

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.

If a snapshot file is malformed in a way that a field that is expected
to never be zero ends up being zero, Firecracker would panic. Fix this
by consistency typing this field as `NonZeroUsize` through the code
base. For the `NonZero*` types, serde already has support. Now if a
snapshot file is malformed and has zeroes here, serde will return an
error, which causes Firecracker to exit gracefully instead of panicking.

Signed-off-by: Patrick Roy <[email protected]>
If a snapshot file is corrupted in a way that makes it _look_ like it
contains a vhost-user-blk device, restoring will hit an `unimplemented!`
inside `block::vhost_user/persist.rs`. So instead of using
`unimplemented!`, just unconditionally return an error here. These
errors are handled properly and cause Firecracker to exit gracefully
instead.

Signed-off-by: Patrick Roy <[email protected]>
@roypat roypat added the Status: Awaiting review Indicates that a pull request is ready to be reviewed label Sep 2, 2024
Copy link

codecov bot commented Sep 2, 2024

Codecov Report

Attention: Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 84.34%. Comparing base (5f5bb4a) to head (4ac642b).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...vmm/src/devices/virtio/block/vhost_user/persist.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4764      +/-   ##
==========================================
- Coverage   84.34%   84.34%   -0.01%     
==========================================
  Files         249      249              
  Lines       27461    27460       -1     
==========================================
- Hits        23162    23160       -2     
- Misses       4299     4300       +1     
Flag Coverage Δ
5.10-c5n.metal 84.56% <90.00%> (-0.01%) ⬇️
5.10-m5n.metal 84.54% <90.00%> (-0.02%) ⬇️
5.10-m6a.metal 83.83% <90.00%> (-0.02%) ⬇️
5.10-m6g.metal 80.91% <90.00%> (-0.01%) ⬇️
5.10-m6i.metal 84.54% <90.00%> (-0.02%) ⬇️
5.10-m7g.metal 80.91% <90.00%> (-0.01%) ⬇️
6.1-c5n.metal 84.55% <90.00%> (-0.02%) ⬇️
6.1-m5n.metal 84.54% <90.00%> (-0.01%) ⬇️
6.1-m6a.metal 83.83% <90.00%> (-0.02%) ⬇️
6.1-m6g.metal 80.91% <90.00%> (-0.01%) ⬇️
6.1-m6i.metal 84.54% <90.00%> (-0.01%) ⬇️
6.1-m7g.metal 80.91% <90.00%> (-0.01%) ⬇️

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.

@zulinx86 zulinx86 merged commit 9e627a7 into firecracker-microvm:main Sep 2, 2024
@roypat roypat deleted the snapshot-restore-error-improvements branch September 2, 2024 08:31
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