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 <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-04-24 21:50:56 +02:00
committed by Rob Bradford
parent b68349f8b3
commit a11f551572
11 changed files with 50 additions and 23 deletions

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

10
block/src/formats/mod.rs Normal file
View File

@@ -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;

View File

@@ -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 {

View File

@@ -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);
}
}

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -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;