From a15bfcfee6ce7dc1e42b131ea9d1a7ec1722ad8a Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 12 Mar 2026 20:13:01 +0100 Subject: [PATCH] block: Add disk_file module skeleton Composable disk capability traits with DiskFile as a supertrait bundling DiskSize and Geometry. Optional capabilities are separate traits: PhysicalSize, DiskFd, SparseCapable, Resizable. AsyncDiskFile extends DiskFile with async I/O construction. Empty module with doc comment, trait definitions follow. Signed-off-by: Anatol Belski --- block/src/disk_file.rs | 34 ++++++++++++++++++++++++++++++++++ block/src/lib.rs | 1 + 2 files changed, 35 insertions(+) create mode 100644 block/src/disk_file.rs diff --git a/block/src/disk_file.rs b/block/src/disk_file.rs new file mode 100644 index 000000000..30efaff55 --- /dev/null +++ b/block/src/disk_file.rs @@ -0,0 +1,34 @@ +// Copyright 2026 The Cloud Hypervisor Authors. All rights reserved. +// +// SPDX-License-Identifier: Apache-2.0 + +//! Composable disk capability traits for the block crate. +//! +//! Small traits define individual capabilities: +//! +//! - [`DiskSize`] - reported capacity (logical size) +//! - [`PhysicalSize`] - host allocation size +//! - [`DiskFd`] - backing file descriptor access +//! - [`Geometry`] - sector/cluster geometry (default 512B) +//! - [`SparseCapable`] - sparse and zero flag support +//! - [`Resizable`] - online resize +//! +//! [`DiskFile`] is a supertrait that bundles the universal capabilities +//! (`DiskSize` + `Geometry`). [`FullDiskFile`] adds all optional +//! capabilities. [`AsyncDiskFile`] extends `DiskFile` with async I/O +//! construction for virtio queue workers. [`AsyncFullDiskFile`] +//! combines both axes. +//! +//! ```text +//! DiskFile: DiskSize + Geometry + Sync +//! / \ +//! FullDiskFile: AsyncDiskFile: +//! DiskFile + PhysicalSize + DiskFile + Unpin +//! DiskFd + SparseCapable + try_clone, new_async_io +//! Resizable +//! \ / +//! AsyncFullDiskFile: FullDiskFile + AsyncDiskFile +//! ``` +//! +//! Readonly accessors take `&self`. Only [`Resizable::resize`] requires +//! `&mut self`. Errors are returned as [`BlockResult`]. diff --git a/block/src/lib.rs b/block/src/lib.rs index 4a6ea4979..288db3fbf 100644 --- a/block/src/lib.rs +++ b/block/src/lib.rs @@ -9,6 +9,7 @@ // SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause pub mod async_io; +pub mod disk_file; pub mod error; pub mod fcntl; pub mod fixed_vhd;