From df91ade143d3d0f7b60ab9dd046e88387ccc666a Mon Sep 17 00:00:00 2001 From: Alex Lyn Date: Tue, 31 Mar 2026 17:16:56 +0800 Subject: [PATCH] runtime-rs: Add BlockDeviceFormat enum to support more block formats In practice, we need more kinds of block formats, not limited to `Raw`. This commit aims to add BlockDeviceFormat enum for kinds of block device formats support, like RAW, VMDK, etc. And it will do some following actions to make this changes work well, including format field in BlockConfig. Signed-off-by: Alex Lyn --- .../hypervisor/src/device/driver/mod.rs | 6 +++--- .../src/device/driver/virtio_blk.rs | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/runtime-rs/crates/hypervisor/src/device/driver/mod.rs b/src/runtime-rs/crates/hypervisor/src/device/driver/mod.rs index a108a9a90f..ec2c569a9f 100644 --- a/src/runtime-rs/crates/hypervisor/src/device/driver/mod.rs +++ b/src/runtime-rs/crates/hypervisor/src/device/driver/mod.rs @@ -24,9 +24,9 @@ pub use vfio::{ pub use vhost_user::{VhostUserConfig, VhostUserDevice, VhostUserType}; pub use vhost_user_net::VhostUserNetDevice; pub use virtio_blk::{ - BlockConfig, BlockDevice, BlockDeviceAio, KATA_BLK_DEV_TYPE, KATA_CCW_DEV_TYPE, - KATA_MMIO_BLK_DEV_TYPE, KATA_NVDIMM_DEV_TYPE, KATA_SCSI_DEV_TYPE, VIRTIO_BLOCK_CCW, - VIRTIO_BLOCK_MMIO, VIRTIO_BLOCK_PCI, VIRTIO_PMEM, + BlockConfig, BlockDevice, BlockDeviceAio, BlockDeviceFormat, KATA_BLK_DEV_TYPE, + KATA_CCW_DEV_TYPE, KATA_MMIO_BLK_DEV_TYPE, KATA_NVDIMM_DEV_TYPE, KATA_SCSI_DEV_TYPE, + VIRTIO_BLOCK_CCW, VIRTIO_BLOCK_MMIO, VIRTIO_BLOCK_PCI, VIRTIO_PMEM, }; pub use virtio_fs::{ ShareFsConfig, ShareFsDevice, ShareFsMountConfig, ShareFsMountOperation, ShareFsMountType, diff --git a/src/runtime-rs/crates/hypervisor/src/device/driver/virtio_blk.rs b/src/runtime-rs/crates/hypervisor/src/device/driver/virtio_blk.rs index fcfdfeaf74..0913ed53f7 100644 --- a/src/runtime-rs/crates/hypervisor/src/device/driver/virtio_blk.rs +++ b/src/runtime-rs/crates/hypervisor/src/device/driver/virtio_blk.rs @@ -59,6 +59,23 @@ impl std::fmt::Display for BlockDeviceAio { } } +#[derive(Debug, Clone, Default, PartialEq, Eq)] +pub enum BlockDeviceFormat { + #[default] + Raw, + Vmdk, +} + +impl std::fmt::Display for BlockDeviceFormat { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let to_string = match *self { + BlockDeviceFormat::Raw => "raw".to_string(), + BlockDeviceFormat::Vmdk => "vmdk".to_string(), + }; + write!(f, "{to_string}") + } +} + #[derive(Debug, Clone, Default)] pub struct BlockConfig { /// Path of the drive. @@ -71,6 +88,9 @@ pub struct BlockConfig { /// Don't close `path_on_host` file when dropping the device. pub no_drop: bool, + /// raw, vmdk, etc. And default to raw if not set. + pub format: BlockDeviceFormat, + /// Specifies cache-related options for block devices. /// Denotes whether use of O_DIRECT (bypass the host page cache) is enabled. /// If not set, use configurarion block_device_cache_direct.