From c38883d8b46d683da3be0b4e249cc1d416f45f8a Mon Sep 17 00:00:00 2001 From: Debin Date: Tue, 24 Jun 2025 11:17:17 +0800 Subject: [PATCH] feat(config): add VirtIO block device configuration - Add VirtioBlkMmioDeviceConfig struct to represent VirtIO block device configuration - Include VirtIO block device information in VMDevicesConfig - Update VM configuration template to support VirtIO block devices --- src/lib.rs | 29 +++++++++++++++++++++++++++++ src/templates.rs | 1 + 2 files changed, 30 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 9ab8602..85e8136 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -106,6 +106,33 @@ pub struct PassThroughDeviceConfig { pub irq_id: usize, } +/// A part of `AxVMConfig`, which represents the configuration of a VirtIO block device for a virtual machine. +#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)] +pub struct VirtioBlkMmioDeviceConfig { + /// The device ID. + pub device_id: String, + /// The MMIO base address. + pub mmio_base: String, + /// The MMIO size. + pub mmio_size: String, + /// The interrupt type. + pub interrupt_type: String, + /// The interrupt number. + pub interrupt_number: usize, + /// The guest device path. + pub guest_device_path: String, + /// The backend type. + pub backend_type: String, + /// The backend path. + pub backend_path: String, + /// The image size. + pub size: String, + /// Whether the device is readonly. + pub readonly: bool, + /// The serial number. + pub serial: String, +} + /// The configuration structure for the guest VM base info. #[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)] pub struct VMBaseConfig { @@ -175,6 +202,8 @@ pub struct VMDevicesConfig { pub emu_devices: Vec, /// Passthrough device Information pub passthrough_devices: Vec, + /// VirtIO block device Information + pub virtio_blk_mmio: Option>, } /// The configuration structure for the guest VM serialized from a toml file provided by user, diff --git a/src/templates.rs b/src/templates.rs index a0898a0..3579168 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -38,6 +38,7 @@ pub fn get_vm_config_template( devices: VMDevicesConfig { emu_devices: vec![], passthrough_devices: vec![], + virtio_blk_mmio: None, }, } }