forked from firecracker-microvm/firecracker
-
Notifications
You must be signed in to change notification settings - Fork 4
Make async IO request submission more robust and fail early in case of in-kernel errors #17
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
Open
bchalios
wants to merge
2
commits into
firecracker-v1.14-direct-mem
Choose a base branch
from
fix-async-io-eintr
base: firecracker-v1.14-direct-mem
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+38
−24
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -197,7 +197,7 @@ pub struct ConfigSpace { | |
| pub max_write_zeroes_seg: u32, // offset 52 | ||
| pub write_zeroes_may_unmap: u8, // offset 56 | ||
| pub(crate) _unused1: [u8; 3], // offset 57 (spec field — virtio_blk_config.unused1) | ||
| pub(crate) _pad: [u8; 4], // offset 60 (Rust alignment padding to 64; spec ends at 60) | ||
| pub(crate) _pad: [u8; 4], // offset 60 (Rust alignment padding to 64; spec ends at 60) | ||
| } | ||
| const _: () = assert!(std::mem::size_of::<ConfigSpace>() == 64); | ||
| // Compile-time guards against accidental layout drift. The byte offsets here | ||
|
|
@@ -722,9 +722,10 @@ impl VirtioBlock { | |
| } | ||
|
|
||
| fn drain_and_flush(&mut self, discard: bool) { | ||
| if let Err(err) = self.disk.file_engine.drain_and_flush(discard) { | ||
| error!("Failed to drain ops and flush block data: {:?}", err); | ||
| } | ||
| self.disk | ||
| .file_engine | ||
| .drain_and_flush(discard) | ||
| .expect("virtio-block: failed to drain ops and flush block data"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: can add a comment on why we crash here |
||
| } | ||
|
|
||
| /// Prepare device for being snapshotted. | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| use std::fmt::Debug; | ||
| use std::io::Error as IOError; | ||
| use std::io::{Error as IOError, ErrorKind}; | ||
| use std::mem; | ||
| use std::num::Wrapping; | ||
| use std::os::unix::io::RawFd; | ||
|
|
@@ -130,26 +130,39 @@ impl SubmissionQueue { | |
| if min_complete > 0 { | ||
| flags |= generated::IORING_ENTER_GETEVENTS; | ||
| } | ||
| // SAFETY: Safe because values are valid and we check the return value. | ||
| let submitted = SyscallReturnCode(unsafe { | ||
| libc::syscall( | ||
| libc::SYS_io_uring_enter, | ||
| self.io_uring_fd, | ||
| self.to_submit, | ||
| min_complete, | ||
| flags, | ||
| std::ptr::null::<libc::sigset_t>(), | ||
| ) | ||
| }) | ||
| .into_result()?; | ||
| // It's safe to convert to u32 since the syscall didn't return an error. | ||
| let submitted = u32::try_from(submitted).unwrap(); | ||
|
|
||
| // This is safe since submitted <= self.to_submit. However we use a saturating_sub | ||
| // for extra safety. | ||
| self.to_submit = self.to_submit.saturating_sub(submitted); | ||
|
|
||
| Ok(submitted) | ||
| // The number of retries is completely arbitrary here. I assume that this | ||
| // will happen rarely and that if it happens subsequent retry will immediately | ||
| // succeed. If we fall in a storm of interrupts something else is probably wrong | ||
| // so let the consumer know. | ||
| let mut eintr_retries = 3; | ||
| loop { | ||
| // SAFETY: Safe because values are valid and we check the return value. | ||
| let ret = SyscallReturnCode(unsafe { | ||
| libc::syscall( | ||
| libc::SYS_io_uring_enter, | ||
| self.io_uring_fd, | ||
| self.to_submit, | ||
| min_complete, | ||
| flags, | ||
| std::ptr::null::<libc::sigset_t>(), | ||
| ) | ||
| }) | ||
| .into_result(); | ||
| match ret { | ||
| Ok(num) => { | ||
| // It's safe to convert to u32 since the syscall didn't return an error. | ||
| let submitted = u32::try_from(num).unwrap(); | ||
| self.to_submit = self.to_submit.saturating_sub(submitted); | ||
| return Ok(submitted); | ||
| } | ||
| Err(err) if err.kind() == ErrorKind::Interrupted && eintr_retries > 0 => { | ||
| eintr_retries -= 1; | ||
| continue; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Claude suggests we clear to_submit on retrials: // All SQEs were submitted before the wait; only retry the wait.
self.to_submit = 0;I'm not sure how to verify that. |
||
| } | ||
| Err(err) => return Err(SQueueError::from(err)), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn mmap( | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like an accidental change