From b68349f8b394ced263be1312685a1421cddb4790 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Fri, 24 Apr 2026 21:36:13 +0200 Subject: [PATCH] block: Create io/ module for shared I/O infrastructure Move async_io.rs, fcntl.rs, and request.rs into block/src/io/. These files are generic I/O infrastructure shared by all formats rather than format specific code. The io/ directory name clashes with std::io in lib.rs, so the module is declared as io_impl via #[path] and the submodules are re-exported at the crate root to keep existing import paths working. Signed-off-by: Anatol Belski --- block/src/{ => io}/async_io.rs | 2 +- block/src/{ => io}/async_io/aio_data_io.rs | 0 block/src/{ => io}/async_io/common.rs | 0 block/src/{ => io}/async_io/completion.rs | 0 block/src/{ => io}/async_io/guest_memory_target.rs | 0 block/src/{ => io}/async_io/operation.rs | 0 block/src/{ => io}/async_io/owned_io_buffer.rs | 0 block/src/{ => io}/async_io/uring_data_io.rs | 0 block/src/{ => io}/fcntl.rs | 0 block/src/io/mod.rs | 12 ++++++++++++ block/src/{ => io}/request.rs | 0 block/src/lib.rs | 6 +++--- 12 files changed, 16 insertions(+), 4 deletions(-) rename block/src/{ => io}/async_io.rs (99%) rename block/src/{ => io}/async_io/aio_data_io.rs (100%) rename block/src/{ => io}/async_io/common.rs (100%) rename block/src/{ => io}/async_io/completion.rs (100%) rename block/src/{ => io}/async_io/guest_memory_target.rs (100%) rename block/src/{ => io}/async_io/operation.rs (100%) rename block/src/{ => io}/async_io/owned_io_buffer.rs (100%) rename block/src/{ => io}/async_io/uring_data_io.rs (100%) rename block/src/{ => io}/fcntl.rs (100%) create mode 100644 block/src/io/mod.rs rename block/src/{ => io}/request.rs (100%) diff --git a/block/src/async_io.rs b/block/src/io/async_io.rs similarity index 99% rename from block/src/async_io.rs rename to block/src/io/async_io.rs index 64e7a742d..ffd0621f5 100644 --- a/block/src/async_io.rs +++ b/block/src/io/async_io.rs @@ -61,7 +61,7 @@ pub struct BorrowedDiskFd<'fd> { } impl BorrowedDiskFd<'_> { - pub(super) fn new(raw_fd: RawFd) -> Self { + pub(crate) fn new(raw_fd: RawFd) -> Self { Self { raw_fd, _lifetime: PhantomData, diff --git a/block/src/async_io/aio_data_io.rs b/block/src/io/async_io/aio_data_io.rs similarity index 100% rename from block/src/async_io/aio_data_io.rs rename to block/src/io/async_io/aio_data_io.rs diff --git a/block/src/async_io/common.rs b/block/src/io/async_io/common.rs similarity index 100% rename from block/src/async_io/common.rs rename to block/src/io/async_io/common.rs diff --git a/block/src/async_io/completion.rs b/block/src/io/async_io/completion.rs similarity index 100% rename from block/src/async_io/completion.rs rename to block/src/io/async_io/completion.rs diff --git a/block/src/async_io/guest_memory_target.rs b/block/src/io/async_io/guest_memory_target.rs similarity index 100% rename from block/src/async_io/guest_memory_target.rs rename to block/src/io/async_io/guest_memory_target.rs diff --git a/block/src/async_io/operation.rs b/block/src/io/async_io/operation.rs similarity index 100% rename from block/src/async_io/operation.rs rename to block/src/io/async_io/operation.rs diff --git a/block/src/async_io/owned_io_buffer.rs b/block/src/io/async_io/owned_io_buffer.rs similarity index 100% rename from block/src/async_io/owned_io_buffer.rs rename to block/src/io/async_io/owned_io_buffer.rs diff --git a/block/src/async_io/uring_data_io.rs b/block/src/io/async_io/uring_data_io.rs similarity index 100% rename from block/src/async_io/uring_data_io.rs rename to block/src/io/async_io/uring_data_io.rs diff --git a/block/src/fcntl.rs b/block/src/io/fcntl.rs similarity index 100% rename from block/src/fcntl.rs rename to block/src/io/fcntl.rs diff --git a/block/src/io/mod.rs b/block/src/io/mod.rs new file mode 100644 index 000000000..4406ecc4d --- /dev/null +++ b/block/src/io/mod.rs @@ -0,0 +1,12 @@ +// Copyright 2026 The Cloud Hypervisor Authors. All rights reserved. +// +// SPDX-License-Identifier: Apache-2.0 + +//! Shared I/O infrastructure for all disk format backends. +//! +//! Contains the async I/O trait, request handling, and file locking +//! helpers. + +pub mod async_io; +pub mod fcntl; +pub mod request; diff --git a/block/src/request.rs b/block/src/io/request.rs similarity index 100% rename from block/src/request.rs rename to block/src/io/request.rs diff --git a/block/src/lib.rs b/block/src/lib.rs index 972e3e559..0c2170511 100644 --- a/block/src/lib.rs +++ b/block/src/lib.rs @@ -8,11 +8,12 @@ // // SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause -pub mod async_io; pub mod disk_file; pub mod error; pub mod factory; -pub mod fcntl; +#[path = "io/mod.rs"] +mod io_impl; +pub use io_impl::{async_io, fcntl, request}; pub mod fixed_vhd; #[cfg(feature = "io_uring")] /// Enabled with the `"io_uring"` feature @@ -32,7 +33,6 @@ pub(crate) mod raw_async_aio; mod raw_async_io_tests; pub mod raw_disk; pub(crate) mod raw_sync; -mod request; mod sparse; pub use sparse::{BLKDISCARD, BLKZEROOUT}; pub mod vhd;