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

Rustify snapshot module #4691

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

beamandala
Copy link

Changes

...

Reason

...

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.

@beamandala beamandala mentioned this pull request Jul 20, 2024
3 tasks
@roypat roypat self-requested a review July 22, 2024 16:07
src/vmm/src/snapshot/mod.rs Outdated Show resolved Hide resolved
// The snapshot version we can handle
version: Version,
}
pub fn load<R: Read>(reader: &mut R) -> Result<Self, SnapshotError> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should also do the check the the header's magic value is correct

pub data: Data,
}

impl<Data: for<'a> Deserialize<'a>> Snapshot<Data> {
/// Helper function to deserialize an object from a reader
pub fn deserialize<T, O>(reader: &mut T) -> Result<O, SnapshotError>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should probably be free-standing, and not pub. Then you can reuse it inside SnapshotHdr::load as well

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By free standing I'm assuming you mean not have the deserialize and serialize functions as implementations of Snapshot so I moved them outside.

}

/// Load a snapshot from a reader and validate its CRC
pub fn load<T, O>(reader: &mut T, snapshot_len: usize) -> Result<(O, Version), SnapshotError>
pub fn load<R: Read>(reader: &mut R, snapshot_len: usize) -> Result<Self, SnapshotError>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function's implementation we can change to only do a single pass over the snapshot bytes, as well as not taking a snapshot_len: usize parameter, I think:

  1. Construct crc_reader from the given reader, as is done now
  2. Deserialize the Snapshot<Data> object from this reader. Since the struct Snapshot does not contain the crc, and allow_trailing_bytes is set for bincode, this will simply leave the crc bytes unread.
  3. at the end, store the crc from the CrcReader in some local variable.
  4. Read the remaining 4 bytes in the input stream, and check that they match the computed CRC.

) -> Result<O, SnapshotError>
impl<Data: Serialize + Debug> Snapshot<Data> {
/// Helper function to serialize an object to a writer
pub fn serialize<T, O>(writer: &mut T, data: &O) -> Result<usize, SnapshotError>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just like deserialize, this can be a free standing function, non-pub, and be reused in SnapshotHdr

.map_err(|err| SnapshotError::Serde(err.to_string()))?;

Ok(buffer.len())
// bincode::serialize_into(writer, data).map_err(|err| SnapshotError::Serde(err.to_string()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use a temporary buffer instead of just this commented out line? :o

@beamandala
Copy link
Author

Messaging to let you know I'm still working on this

@roypat roypat linked an issue Oct 9, 2024 that may be closed by this pull request
3 tasks
@roypat
Copy link
Contributor

roypat commented Oct 9, 2024

Messaging to let you know I'm still working on this

Hey, just wanted to check in if you're still looking into this or need help with anything :)

@beamandala
Copy link
Author

Hi, yeah I still am. I'll push commits addressing your comments and a few other changes in the next couple days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rustify Snapshot Module
2 participants