From 10d44476974c03e9907af5158a4c14a1ce51e2d1 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 23 Apr 2026 10:31:37 +0200 Subject: [PATCH] block: raw: Impl DiskFile and AsyncDiskFile for RawDisk Add the DiskFile marker and AsyncDiskFile with try_clone and create_async_io. The dispatch creates RawFileSync, RawFileAsync, or RawFileAsyncAio depending on the backend selected at construction. Alignment handling is left to the workers as is, to be centralized separately per #8050. Signed-off-by: Anatol Belski --- block/src/raw_disk.rs | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) 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, + )?)), + } + } +}