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

Simplify read_config #4458

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

kornelski
Copy link

Changes

read_config doesn't have to use io::Write to just copy bytes in memory.

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][3].

Copy link

codecov bot commented Feb 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.12%. Comparing base (3853362) to head (d339342).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4458      +/-   ##
==========================================
- Coverage   82.14%   82.12%   -0.02%     
==========================================
  Files         255      255              
  Lines       31285    31262      -23     
==========================================
- Hits        25700    25675      -25     
- Misses       5585     5587       +2     
Flag Coverage Δ
4.14-c5n.metal 79.62% <100.00%> (-0.03%) ⬇️
4.14-c7g.metal ?
4.14-m5n.metal 79.60% <100.00%> (-0.04%) ⬇️
4.14-m6a.metal 78.83% <100.00%> (-0.03%) ⬇️
4.14-m6g.metal 76.67% <100.00%> (-0.03%) ⬇️
4.14-m6i.metal 79.60% <100.00%> (-0.04%) ⬇️
4.14-m7g.metal 76.67% <100.00%> (-0.03%) ⬇️
5.10-c5n.metal 82.14% <100.00%> (-0.03%) ⬇️
5.10-c7g.metal ?
5.10-m5n.metal 82.12% <100.00%> (-0.03%) ⬇️
5.10-m6a.metal 81.43% <100.00%> (-0.03%) ⬇️
5.10-m6g.metal 79.45% <100.00%> (-0.03%) ⬇️
5.10-m6i.metal 82.12% <100.00%> (-0.03%) ⬇️
5.10-m7g.metal 79.45% <100.00%> (-0.03%) ⬇️
6.1-c5n.metal 82.13% <100.00%> (-0.03%) ⬇️
6.1-c7g.metal ?
6.1-m5n.metal 82.12% <100.00%> (-0.03%) ⬇️
6.1-m6a.metal 81.43% <100.00%> (-0.03%) ⬇️
6.1-m6g.metal 79.45% <100.00%> (-0.03%) ⬇️
6.1-m6i.metal 82.12% <100.00%> (-0.03%) ⬇️
6.1-m7g.metal 79.45% <100.00%> (-0.03%) ⬇️

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.

Copy link
Contributor

@ShadowCurse ShadowCurse left a comment

Choose a reason for hiding this comment

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

Overall everything looks good, but please update commit messages (otherwise CI will be angry). Also can you update the write_config as well while you are at it?

@ShadowCurse ShadowCurse added Status: Awaiting review Indicates that a pull request is ready to be reviewed Type: Enhancement Indicates new feature requests labels Feb 19, 2024
@kornelski kornelski force-pushed the read-conf branch 2 times, most recently from 7a47fff to 971bdab Compare February 19, 2024 14:40
@kornelski
Copy link
Author

write_config already uses copy_from_slice, so changes to it would be just a code-golf.

However, I'm wondering if these functions should be reporting errors instead of just not reading/writing. Isn't there a risk from leaving data unchanged?

@ShadowCurse
Copy link
Contributor

Don't think returning errors makes a lot of sense here. There are 2 paths: panic and abort the process, or log the error and continue execution. In case of read_config I assume driver will simply not initialize the device. WDYT @bchalios

@kornelski kornelski force-pushed the read-conf branch 2 times, most recently from e0cc36f to e54fba3 Compare February 28, 2024 03:07
Copy link
Contributor

@bchalios bchalios left a comment

Choose a reason for hiding this comment

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

Sorry for the delay @kornelski @ShadowCurse,

I don't think there's any danger from failed reads/writes. At least, not on the host side. If the guest kernel driver is not working properly it might fail, but that's the guest's problem. We do the right thing.

LGTM, apart from the commit messages. Would you mind adding a bit of more info on what each commit does and why? Also, really a nit, but we typically have commit titles like:

virtio: simplify read_config for VirtIO devices

@ShadowCurse
Copy link
Contributor

@kornelski Also please fix compilations/stylistics errors from here: https://buildkite.com/firecracker/firecracker-pr/builds/9248#_

@roypat roypat added Status: Awaiting author Indicates that a pull request requires author action and removed Status: Awaiting review Indicates that a pull request is ready to be reviewed labels Mar 4, 2024
@kornelski kornelski force-pushed the read-conf branch 2 times, most recently from e55297a to 76a7c00 Compare March 20, 2024 15:49
@bchalios
Copy link
Contributor

bchalios commented Apr 8, 2024

Hi @kornelski, could you fix the style issues in the PR so we can merge this?

kornelski and others added 2 commits May 20, 2024 11:16
Rust doesn't guarantee struct layout by default, so `repr(C)` or
`repr(transparent)` are necessary for safety.

Signed-off-by: Kornel <kornel@cloudflare.com>
From: Kornel <kornel@cloudflare.com>

`io::Write` has higher overhead and unnecessary error handling. Slices
can be copied without it.

Signed-off-by: Kornel <kornel@cloudflare.com>
Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
Co-authored-by: Patrick Roy <roypat@amazon.co.uk>
@roypat roypat added Status: Awaiting review Indicates that a pull request is ready to be reviewed and removed Status: Awaiting author Indicates that a pull request requires author action labels May 20, 2024
@roypat
Copy link
Contributor

roypat commented May 20, 2024

Hi @kornelski,
I've gone ahead and fixed up the style issues so that we can go ahead with merging this improvement. Thanks again for your contribution!

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 Type: Enhancement Indicates new feature requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants