diff --git a/block/src/lib.rs b/block/src/lib.rs index d988a1399..560010e26 100644 --- a/block/src/lib.rs +++ b/block/src/lib.rs @@ -232,6 +232,11 @@ pub struct AlignedOperation { layout: Layout, } +pub struct ExecuteAsync { + // `true` if the execution will complete asynchronously + pub async_complete: bool, +} + #[derive(Debug)] pub struct Request { pub request_type: RequestType, @@ -397,7 +402,7 @@ impl Request { disk_image: &mut dyn AsyncIo, serial: &[u8], user_data: u64, - ) -> result::Result { + ) -> result::Result { let sector = self.sector; let request_type = self.request_type; let offset = (sector << SECTOR_SHIFT) as libc::off_t; @@ -473,6 +478,9 @@ impl Request { iovecs.push(iovec); } + let mut ret = ExecuteAsync { + async_complete: true, + }; // Queue operations expected to be submitted. match request_type { RequestType::In => { @@ -507,12 +515,13 @@ impl Request { } mem.write_slice(serial, data_addr) .map_err(ExecuteError::Write)?; - return Ok(false); + ret.async_complete = false; + return Ok(ret); } RequestType::Unsupported(t) => return Err(ExecuteError::Unsupported(t)), } - Ok(true) + Ok(ret) } pub fn complete_async(&mut self) -> result::Result<(), Error> { diff --git a/virtio-devices/src/block.rs b/virtio-devices/src/block.rs index 7e337ad5b..f301294b4 100644 --- a/virtio-devices/src/block.rs +++ b/virtio-devices/src/block.rs @@ -20,7 +20,9 @@ use std::{io, result}; use anyhow::anyhow; use block::async_io::{AsyncIo, AsyncIoError, DiskFile}; use block::fcntl::{get_lock_state, LockError, LockType}; -use block::{build_serial, fcntl, ExecuteError, Request, RequestType, VirtioBlockConfig}; +use block::{ + build_serial, fcntl, ExecuteAsync, ExecuteError, Request, RequestType, VirtioBlockConfig, +}; use rate_limiter::group::{RateLimiterGroup, RateLimiterGroupHandle}; use rate_limiter::TokenType; use seccompiler::SeccompAction; @@ -232,7 +234,11 @@ impl BlockEpollHandler { desc_chain.head_index() as u64, ); - if let Ok(true) = result { + if let Ok(ExecuteAsync { + async_complete: true, + .. + }) = result + { self.inflight_requests .push_back((desc_chain.head_index(), request)); } else {