mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
block: Return BlockResult from RawFileAsyncAio::new()
Change the return type of RawFileAsyncAio::new() from std::io::Result<Self> to BlockResult<Self>, wrapping internal errors from EventFd::new() and IoContext::new() in BlockError with DiskFileError::NewAsyncIo. This simplifies the caller in AsyncDiskFile::new_async_io() which no longer needs its own error mapping. Signed-off-by: Muminul Islam <muislam@microsoft.com>
This commit is contained in:
@@ -86,8 +86,7 @@ impl disk_file::AsyncDiskFile for RawFileDiskAio {
|
||||
}
|
||||
|
||||
fn new_async_io(&self, ring_depth: u32) -> BlockResult<Box<dyn AsyncIo>> {
|
||||
let mut raw = RawFileAsyncAio::new(self.file.as_raw_fd(), ring_depth)
|
||||
.map_err(|e| BlockError::new(BlockErrorKind::Io, DiskFileError::NewAsyncIo(e)))?;
|
||||
let mut raw = RawFileAsyncAio::new(self.file.as_raw_fd(), ring_depth)?;
|
||||
raw.alignment =
|
||||
DiskTopology::probe(&self.file).map_or(SECTOR_SIZE, |t| t.logical_block_size);
|
||||
Ok(Box::new(raw) as Box<dyn AsyncIo>)
|
||||
@@ -103,9 +102,11 @@ pub struct RawFileAsyncAio {
|
||||
}
|
||||
|
||||
impl RawFileAsyncAio {
|
||||
pub fn new(fd: RawFd, queue_depth: u32) -> std::io::Result<Self> {
|
||||
let eventfd = EventFd::new(libc::EFD_NONBLOCK)?;
|
||||
let ctx = aio::IoContext::new(queue_depth)?;
|
||||
pub fn new(fd: RawFd, queue_depth: u32) -> BlockResult<Self> {
|
||||
let eventfd =
|
||||
EventFd::new(libc::EFD_NONBLOCK).map_err(|e| BlockError::new(BlockErrorKind::Io, e))?;
|
||||
let ctx =
|
||||
aio::IoContext::new(queue_depth).map_err(|e| BlockError::new(BlockErrorKind::Io, e))?;
|
||||
|
||||
Ok(RawFileAsyncAio {
|
||||
fd,
|
||||
|
||||
Reference in New Issue
Block a user