mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-11 04:26:38 +00:00
cros_async: Skip zero length reads and writes
Sometimes the guest asks to read or write zero bytes. Skip sending that to the kernel as it is a no-op. Change-Id: I67ac3cd75551b994517eedb02830b3ea9451fb15 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2275722 Commit-Queue: Dylan Reid <dgreid@chromium.org> Tested-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
parent
9affaf1ae0
commit
68ef7cfc9a
2 changed files with 14 additions and 0 deletions
|
@ -38,6 +38,13 @@ impl<R: IoSource + ?Sized + Unpin> Future for ReadMem<'_, '_, R> {
|
|||
type Output = Result<u32>;
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
// Special case reading zero bytes, no need to bother the kernel with an empty operation.
|
||||
if let UringFutState::Init((_, _, regions)) = &self.state {
|
||||
if regions.iter().all(|region| region.len == 0) {
|
||||
return Poll::Ready(Ok(0));
|
||||
}
|
||||
}
|
||||
|
||||
let state = std::mem::replace(&mut self.state, UringFutState::Processing);
|
||||
let (new_state, ret) = match state.advance(
|
||||
|(file_offset, mem, mem_offsets)| {
|
||||
|
|
|
@ -38,6 +38,13 @@ impl<R: IoSource + ?Sized + Unpin> Future for WriteMem<'_, '_, R> {
|
|||
type Output = Result<u32>;
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
// Special case writing zero bytes, no need to bother the kernel with an empty operation.
|
||||
if let UringFutState::Init((_, _, regions)) = &self.state {
|
||||
if regions.iter().all(|region| region.len == 0) {
|
||||
return Poll::Ready(Ok(0));
|
||||
}
|
||||
}
|
||||
|
||||
let state = std::mem::replace(&mut self.state, UringFutState::Processing);
|
||||
let (new_state, ret) = match state.advance(
|
||||
|(file_offset, mem, mem_offsets)| {
|
||||
|
|
Loading…
Reference in a new issue