diff --git a/block/src/raw_disk.rs b/block/src/raw_disk.rs index b12b0a6ac..78c1ad6fc 100644 --- a/block/src/raw_disk.rs +++ b/block/src/raw_disk.rs @@ -9,8 +9,12 @@ use std::os::unix::io::AsRawFd; use log::warn; -use crate::async_io::{BorrowedDiskFd, DiskFileError}; +use crate::async_io::{AsyncIo, BorrowedDiskFd, DiskFileError}; use crate::error::{BlockError, BlockErrorKind, BlockResult}; +#[cfg(feature = "io_uring")] +use crate::raw_async::RawFileAsync; +use crate::raw_async_aio::RawFileAsyncAio; +use crate::raw_sync::RawFileSync; use crate::{DiskTopology, disk_file, probe_sparse_support, query_device_size}; /// Selects which async I/O backend a `RawDisk` uses. @@ -108,3 +112,33 @@ impl disk_file::Resizable for RawDisk { } } } + +impl disk_file::DiskFile for RawDisk {} + +impl disk_file::AsyncDiskFile for RawDisk { + fn try_clone(&self) -> BlockResult> { + let file = self + .file + .try_clone() + .map_err(|e| BlockError::new(BlockErrorKind::Io, DiskFileError::Clone(e)))?; + Ok(Box::new(RawDisk { + file, + backend: self.backend, + })) + } + + fn create_async_io(&self, ring_depth: u32) -> BlockResult> { + match self.backend { + RawBackend::Sync => Ok(Box::new(RawFileSync::new(self.file.as_raw_fd()))), + #[cfg(feature = "io_uring")] + RawBackend::IoUring => Ok(Box::new(RawFileAsync::new( + self.file.as_raw_fd(), + ring_depth, + )?)), + RawBackend::Aio => Ok(Box::new(RawFileAsyncAio::new( + self.file.as_raw_fd(), + ring_depth, + )?)), + } + } +}