From a11f55157275c2e965b7cfc0555e6ab0d128d1fd Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Fri, 24 Apr 2026 21:50:56 +0200 Subject: [PATCH] block: Move raw format files into formats/raw/ Move raw format implementation into a structured directory layout: raw_disk.rs -> formats/raw/mod.rs (RawDisk) raw_sync.rs -> formats/raw/worker/sync.rs (RawSync) raw_async.rs -> formats/raw/worker/async_uring.rs (RawAsync) raw_async_aio.rs -> formats/raw/worker/async_aio.rs (RawAio) raw_async_io_tests.rs -> formats/raw/worker/tests.rs Update imports in fixed_vhd_sync.rs and fixed_vhd_async.rs to use the new paths. Re-export formats::raw as raw_disk in lib.rs to preserve the external API. Signed-off-by: Anatol Belski --- block/src/factory.rs | 2 +- block/src/fixed_vhd_async.rs | 2 +- block/src/fixed_vhd_sync.rs | 2 +- block/src/formats/mod.rs | 10 ++++++++++ block/src/{raw_disk.rs => formats/raw/mod.rs} | 15 +++++++++++---- .../raw/worker/async_aio.rs} | 8 ++++---- .../raw/worker/async_uring.rs} | 0 block/src/formats/raw/worker/mod.rs | 15 +++++++++++++++ .../{raw_sync.rs => formats/raw/worker/sync.rs} | 8 ++++---- .../raw/worker/tests.rs} | 0 block/src/lib.rs | 11 +++-------- 11 files changed, 50 insertions(+), 23 deletions(-) create mode 100644 block/src/formats/mod.rs rename block/src/{raw_disk.rs => formats/raw/mod.rs} (96%) rename block/src/{raw_async_aio.rs => formats/raw/worker/async_aio.rs} (93%) rename block/src/{raw_async.rs => formats/raw/worker/async_uring.rs} (100%) create mode 100644 block/src/formats/raw/worker/mod.rs rename block/src/{raw_sync.rs => formats/raw/worker/sync.rs} (94%) rename block/src/{raw_async_io_tests.rs => formats/raw/worker/tests.rs} (100%) diff --git a/block/src/factory.rs b/block/src/factory.rs index 9b15346c2..a2eee3ae8 100644 --- a/block/src/factory.rs +++ b/block/src/factory.rs @@ -21,8 +21,8 @@ use crate::block_io_uring_is_supported; use crate::disk_file::AsyncFullDiskFile; use crate::error::{BlockError, BlockErrorKind, BlockResult}; use crate::fixed_vhd_disk::VhdDisk; +use crate::formats::raw::{RawBackend, RawDisk}; use crate::qcow_disk::QcowDisk; -use crate::raw_disk::{RawBackend, RawDisk}; use crate::vhdx_sync::VhdxDisk; use crate::{ ImageType, block_aio_is_supported, detect_image_type, open_disk_image, preallocate_disk, diff --git a/block/src/fixed_vhd_async.rs b/block/src/fixed_vhd_async.rs index f5dc465e6..20402916f 100644 --- a/block/src/fixed_vhd_async.rs +++ b/block/src/fixed_vhd_async.rs @@ -10,7 +10,7 @@ use vmm_sys_util::eventfd::EventFd; use crate::async_io::{AsyncIo, AsyncIoCompletion, AsyncIoError, AsyncIoOperation, AsyncIoResult}; use crate::error::BlockResult; -use crate::raw_async::RawAsync; +use crate::formats::raw::worker::async_uring::RawAsync; pub struct FixedVhdAsync { raw_file_async: RawAsync, diff --git a/block/src/fixed_vhd_sync.rs b/block/src/fixed_vhd_sync.rs index 4cf880076..0aa3f9377 100644 --- a/block/src/fixed_vhd_sync.rs +++ b/block/src/fixed_vhd_sync.rs @@ -9,7 +9,7 @@ use std::os::unix::io::RawFd; use vmm_sys_util::eventfd::EventFd; use crate::async_io::{AsyncIo, AsyncIoCompletion, AsyncIoError, AsyncIoOperation, AsyncIoResult}; -use crate::raw_sync::RawSync; +use crate::formats::raw::worker::sync::RawSync; pub struct FixedVhdSync { raw_file_sync: RawSync, diff --git a/block/src/formats/mod.rs b/block/src/formats/mod.rs new file mode 100644 index 000000000..cf66cd49a --- /dev/null +++ b/block/src/formats/mod.rs @@ -0,0 +1,10 @@ +// Copyright 2026 The Cloud Hypervisor Authors. All rights reserved. +// +// SPDX-License-Identifier: Apache-2.0 + +//! Disk format implementations. +//! +//! Each format lives in its own submodule with a `DiskFile` wrapper, +//! format specific internals, and sync/async I/O workers. + +pub mod raw; diff --git a/block/src/raw_disk.rs b/block/src/formats/raw/mod.rs similarity index 96% rename from block/src/raw_disk.rs rename to block/src/formats/raw/mod.rs index 703b68a5c..adefcee34 100644 --- a/block/src/raw_disk.rs +++ b/block/src/formats/raw/mod.rs @@ -2,6 +2,11 @@ // // SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause +//! Raw disk image format. +//! +//! Provides [`RawDisk`], the `DiskFile` wrapper for flat disk images +//! with no metadata or copy on write layer. + use std::fs::File; use std::io; use std::os::unix::fs::FileTypeExt; @@ -9,14 +14,16 @@ use std::os::unix::io::AsRawFd; use log::warn; +use self::worker::async_aio::RawAio; +#[cfg(feature = "io_uring")] +use self::worker::async_uring::RawAsync; +use self::worker::sync::RawSync; use crate::async_io::{AsyncIo, BorrowedDiskFd, DiskFileError}; use crate::error::{BlockError, BlockErrorKind, BlockResult}; -#[cfg(feature = "io_uring")] -use crate::raw_async::RawAsync; -use crate::raw_async_aio::RawAio; -use crate::raw_sync::RawSync; use crate::{DiskTopology, disk_file, probe_sparse_support, query_device_size}; +pub(crate) mod worker; + /// Selects which async I/O backend a `RawDisk` uses. #[derive(Clone, Copy, Debug, PartialEq)] pub enum RawBackend { diff --git a/block/src/raw_async_aio.rs b/block/src/formats/raw/worker/async_aio.rs similarity index 93% rename from block/src/raw_async_aio.rs rename to block/src/formats/raw/worker/async_aio.rs index ce1877fb6..1e1f5d105 100644 --- a/block/src/raw_async_aio.rs +++ b/block/src/formats/raw/worker/async_aio.rs @@ -107,14 +107,14 @@ mod unit_tests { use vmm_sys_util::tempfile::TempFile; use super::*; - use crate::raw_async_io_tests; + use crate::raw_disk::worker::tests; #[test] fn test_punch_hole() { let temp_file = TempFile::new().unwrap(); let mut file = temp_file.into_file(); let mut async_io = RawAio::new(file.as_raw_fd(), 128).unwrap(); - raw_async_io_tests::test_punch_hole(&mut async_io, &mut file); + tests::test_punch_hole(&mut async_io, &mut file); } #[test] @@ -122,7 +122,7 @@ mod unit_tests { let temp_file = TempFile::new().unwrap(); let mut file = temp_file.into_file(); let mut async_io = RawAio::new(file.as_raw_fd(), 128).unwrap(); - raw_async_io_tests::test_write_zeroes(&mut async_io, &mut file); + tests::test_write_zeroes(&mut async_io, &mut file); } #[test] @@ -130,6 +130,6 @@ mod unit_tests { let temp_file = TempFile::new().unwrap(); let mut file = temp_file.into_file(); let mut async_io = RawAio::new(file.as_raw_fd(), 128).unwrap(); - raw_async_io_tests::test_punch_hole_multiple_operations(&mut async_io, &mut file); + tests::test_punch_hole_multiple_operations(&mut async_io, &mut file); } } diff --git a/block/src/raw_async.rs b/block/src/formats/raw/worker/async_uring.rs similarity index 100% rename from block/src/raw_async.rs rename to block/src/formats/raw/worker/async_uring.rs diff --git a/block/src/formats/raw/worker/mod.rs b/block/src/formats/raw/worker/mod.rs new file mode 100644 index 000000000..9ceb431de --- /dev/null +++ b/block/src/formats/raw/worker/mod.rs @@ -0,0 +1,15 @@ +// Copyright 2026 The Cloud Hypervisor Authors. All rights reserved. +// +// SPDX-License-Identifier: Apache-2.0 + +//! Sync/async I/O workers for raw images. +//! +//! Each backend implements the [`AsyncIo`](crate::async_io::AsyncIo) +//! trait. + +pub(crate) mod async_aio; +#[cfg(feature = "io_uring")] +pub(crate) mod async_uring; +pub(crate) mod sync; +#[cfg(test)] +pub(crate) mod tests; diff --git a/block/src/raw_sync.rs b/block/src/formats/raw/worker/sync.rs similarity index 94% rename from block/src/raw_sync.rs rename to block/src/formats/raw/worker/sync.rs index 02b2deea1..89276744c 100644 --- a/block/src/raw_sync.rs +++ b/block/src/formats/raw/worker/sync.rs @@ -135,14 +135,14 @@ mod unit_tests { use vmm_sys_util::tempfile::TempFile; use super::*; - use crate::raw_async_io_tests; + use crate::raw_disk::worker::tests; #[test] fn test_punch_hole() { let temp_file = TempFile::new().unwrap(); let mut file = temp_file.into_file(); let mut async_io = RawSync::new(file.as_raw_fd()); - raw_async_io_tests::test_punch_hole(&mut async_io, &mut file); + tests::test_punch_hole(&mut async_io, &mut file); } #[test] @@ -150,7 +150,7 @@ mod unit_tests { let temp_file = TempFile::new().unwrap(); let mut file = temp_file.into_file(); let mut async_io = RawSync::new(file.as_raw_fd()); - raw_async_io_tests::test_write_zeroes(&mut async_io, &mut file); + tests::test_write_zeroes(&mut async_io, &mut file); } #[test] @@ -158,6 +158,6 @@ mod unit_tests { let temp_file = TempFile::new().unwrap(); let mut file = temp_file.into_file(); let mut async_io = RawSync::new(file.as_raw_fd()); - raw_async_io_tests::test_punch_hole_multiple_operations(&mut async_io, &mut file); + tests::test_punch_hole_multiple_operations(&mut async_io, &mut file); } } diff --git a/block/src/raw_async_io_tests.rs b/block/src/formats/raw/worker/tests.rs similarity index 100% rename from block/src/raw_async_io_tests.rs rename to block/src/formats/raw/worker/tests.rs diff --git a/block/src/lib.rs b/block/src/lib.rs index 0c2170511..ff974a164 100644 --- a/block/src/lib.rs +++ b/block/src/lib.rs @@ -20,21 +20,15 @@ pub mod fixed_vhd; pub mod fixed_vhd_async; pub mod fixed_vhd_disk; pub mod fixed_vhd_sync; +pub mod formats; pub mod qcow; #[cfg(feature = "io_uring")] pub(crate) mod qcow_async; pub(crate) mod qcow_common; pub mod qcow_disk; pub(crate) mod qcow_sync; -#[cfg(feature = "io_uring")] -pub(crate) mod raw_async; -pub(crate) mod raw_async_aio; -#[cfg(test)] -mod raw_async_io_tests; -pub mod raw_disk; -pub(crate) mod raw_sync; mod sparse; -pub use sparse::{BLKDISCARD, BLKZEROOUT}; +pub use formats::raw as raw_disk; pub mod vhd; pub mod vhdx; pub mod vhdx_sync; @@ -58,6 +52,7 @@ use libc::{ use log::{debug, info, warn}; pub use request::{ExecuteAsync, MAX_DISCARD_WRITE_ZEROES_SEG, Request, RequestType}; use serde::{Deserialize, Serialize}; +pub use sparse::{BLKDISCARD, BLKZEROOUT}; use thiserror::Error; use virtio_bindings::virtio_blk::*; use vm_memory::bitmap::Bitmap;