From 6e0c39964a842d694e0e5d21d4bf1b57134eb083 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Tue, 7 Jul 2026 21:23:37 +0200 Subject: [PATCH] block: vhd: Flatten internal and worker modules Remove the internal and worker submodule layers from the VHD format directory. The footer and fixed parsers move up as footer.rs and fixed.rs, and the backends move up as engine_sync.rs and engine_uring.rs. Both internal/mod.rs and worker/mod.rs held only module declarations and are dropped. Assisted-by: Claude:Opus-4.8 Signed-off-by: Anatol Belski --- .../vhd/{worker/sync.rs => engine_sync.rs} | 4 ++-- .../{worker/async_uring.rs => engine_uring.rs} | 4 ++-- block/src/formats/vhd/{internal => }/fixed.rs | 4 ++-- block/src/formats/vhd/{internal => }/footer.rs | 14 +++++++------- block/src/formats/vhd/internal/mod.rs | 11 ----------- block/src/formats/vhd/mod.rs | 15 +++++++++------ block/src/formats/vhd/worker/mod.rs | 12 ------------ 7 files changed, 22 insertions(+), 42 deletions(-) rename block/src/formats/vhd/{worker/sync.rs => engine_sync.rs} (93%) rename block/src/formats/vhd/{worker/async_uring.rs => engine_uring.rs} (93%) rename block/src/formats/vhd/{internal => }/fixed.rs (92%) rename block/src/formats/vhd/{internal => }/footer.rs (96%) delete mode 100644 block/src/formats/vhd/internal/mod.rs delete mode 100644 block/src/formats/vhd/worker/mod.rs diff --git a/block/src/formats/vhd/worker/sync.rs b/block/src/formats/vhd/engine_sync.rs similarity index 93% rename from block/src/formats/vhd/worker/sync.rs rename to block/src/formats/vhd/engine_sync.rs index 9cc55fd91..9ed74791c 100644 --- a/block/src/formats/vhd/worker/sync.rs +++ b/block/src/formats/vhd/engine_sync.rs @@ -12,13 +12,13 @@ use crate::AlignedFile; use crate::async_io::{AsyncIo, AsyncIoCompletion, AsyncIoError, AsyncIoOperation, AsyncIoResult}; use crate::formats::raw::engine_sync::RawSync; -pub struct FixedVhdSync { +pub(super) struct FixedVhdSync { raw_file_sync: RawSync, size: u64, } impl FixedVhdSync { - pub fn new(raw_file: AlignedFile, size: u64) -> Self { + pub(super) fn new(raw_file: AlignedFile, size: u64) -> Self { FixedVhdSync { raw_file_sync: RawSync::new(raw_file), size, diff --git a/block/src/formats/vhd/worker/async_uring.rs b/block/src/formats/vhd/engine_uring.rs similarity index 93% rename from block/src/formats/vhd/worker/async_uring.rs rename to block/src/formats/vhd/engine_uring.rs index c622dedd0..c40797ce5 100644 --- a/block/src/formats/vhd/worker/async_uring.rs +++ b/block/src/formats/vhd/engine_uring.rs @@ -13,13 +13,13 @@ use crate::async_io::{AsyncIo, AsyncIoCompletion, AsyncIoError, AsyncIoOperation use crate::error::BlockResult; use crate::formats::raw::engine_uring::RawAsync; -pub struct FixedVhdAsync { +pub(super) struct FixedVhdAsync { raw_file_async: RawAsync, size: u64, } impl FixedVhdAsync { - pub fn new(raw_file: AlignedFile, ring_depth: u32, size: u64) -> BlockResult { + pub(super) fn new(raw_file: AlignedFile, ring_depth: u32, size: u64) -> BlockResult { let raw_file_async = RawAsync::new(raw_file, ring_depth)?; Ok(FixedVhdAsync { diff --git a/block/src/formats/vhd/internal/fixed.rs b/block/src/formats/vhd/fixed.rs similarity index 92% rename from block/src/formats/vhd/internal/fixed.rs rename to block/src/formats/vhd/fixed.rs index a4265181a..62864cb49 100644 --- a/block/src/formats/vhd/internal/fixed.rs +++ b/block/src/formats/vhd/fixed.rs @@ -9,13 +9,13 @@ use std::os::unix::io::{AsRawFd, RawFd}; use super::footer::VhdFooter; #[derive(Debug)] -pub struct FixedVhd { +pub(super) struct FixedVhd { file: File, size: u64, } impl FixedVhd { - pub fn new(mut file: File) -> io::Result { + pub(super) fn new(mut file: File) -> io::Result { let footer = VhdFooter::new(&mut file)?; Ok(Self { diff --git a/block/src/formats/vhd/internal/footer.rs b/block/src/formats/vhd/footer.rs similarity index 96% rename from block/src/formats/vhd/internal/footer.rs rename to block/src/formats/vhd/footer.rs index 0bb07952e..cd033a1fc 100644 --- a/block/src/formats/vhd/internal/footer.rs +++ b/block/src/formats/vhd/footer.rs @@ -13,7 +13,7 @@ use crate::{AlignedFile, query_device_size}; // spec completeness and exercised only by unit tests. #[derive(Clone, Copy)] #[cfg_attr(not(test), expect(dead_code))] -pub struct VhdFooter { +pub(super) struct VhdFooter { cookie: u64, features: u32, file_format_version: u32, @@ -32,7 +32,7 @@ pub struct VhdFooter { } impl VhdFooter { - pub fn new(file: &mut File) -> io::Result { + pub(super) fn new(file: &mut File) -> io::Result { let aligned = AlignedFile::new(file.try_clone()?, true); let size = query_device_size(file)?.0; let footer_offset = size.checked_sub(512).ok_or_else(|| { @@ -60,17 +60,17 @@ impl VhdFooter { }) } - pub fn cookie(&self) -> u64 { + pub(super) fn cookie(&self) -> u64 { self.cookie } #[cfg(test)] pub fn features(&self) -> u32 { self.features } - pub fn file_format_version(&self) -> u32 { + pub(super) fn file_format_version(&self) -> u32 { self.file_format_version } - pub fn data_offset(&self) -> u64 { + pub(super) fn data_offset(&self) -> u64 { self.data_offset } #[cfg(test)] @@ -93,14 +93,14 @@ impl VhdFooter { pub fn original_size(&self) -> u64 { self.original_size } - pub fn current_size(&self) -> u64 { + pub(super) fn current_size(&self) -> u64 { self.current_size } #[cfg(test)] pub fn disk_geometry(&self) -> u32 { self.disk_geometry } - pub fn disk_type(&self) -> u32 { + pub(super) fn disk_type(&self) -> u32 { self.disk_type } #[cfg(test)] diff --git a/block/src/formats/vhd/internal/mod.rs b/block/src/formats/vhd/internal/mod.rs deleted file mode 100644 index e02ca46f8..000000000 --- a/block/src/formats/vhd/internal/mod.rs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2026 The Cloud Hypervisor Authors. All rights reserved. -// -// SPDX-License-Identifier: Apache-2.0 - -//! VHD format parsing and data structures. -//! -//! Contains the footer parser and the low level fixed VHD -//! block backend. - -pub(crate) mod fixed; -pub(crate) mod footer; diff --git a/block/src/formats/vhd/mod.rs b/block/src/formats/vhd/mod.rs index d65f182d4..eb46574d9 100644 --- a/block/src/formats/vhd/mod.rs +++ b/block/src/formats/vhd/mod.rs @@ -9,20 +9,23 @@ //! Provides [`VhdDisk`], the `DiskFile` wrapper for fixed size VHD //! images. -pub(crate) mod internal; -pub(crate) mod worker; +mod engine_sync; +#[cfg(feature = "io_uring")] +mod engine_uring; +mod fixed; +mod footer; use std::fs::File; use std::io; use std::os::unix::io::AsRawFd; -pub use internal::footer::is_fixed_vhd; +pub use footer::is_fixed_vhd; use log::warn; -use self::internal::fixed::FixedVhd; +use self::engine_sync::FixedVhdSync; #[cfg(feature = "io_uring")] -use self::worker::async_uring::FixedVhdAsync; -use self::worker::sync::FixedVhdSync; +use self::engine_uring::FixedVhdAsync; +use self::fixed::FixedVhd; use crate::async_io::{AsyncIo, BorrowedDiskFd, DiskFileError}; use crate::disk_file::DiskSize; use crate::error::{BlockError, BlockErrorKind, BlockResult, ErrorOp}; diff --git a/block/src/formats/vhd/worker/mod.rs b/block/src/formats/vhd/worker/mod.rs deleted file mode 100644 index 39769731c..000000000 --- a/block/src/formats/vhd/worker/mod.rs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2026 The Cloud Hypervisor Authors. All rights reserved. -// -// SPDX-License-Identifier: Apache-2.0 - -//! Sync/async I/O workers for fixed VHD images. -//! -//! Thin wrappers around the raw workers that clamp I/O to the -//! virtual disk size. - -#[cfg(feature = "io_uring")] -pub(crate) mod async_uring; -pub(crate) mod sync;