runtime-rs: Map and propagate block discard to CH sparse disks

Add the Cloud Hypervisor disk sparse option to the local DiskConfig
model and keep its default aligned with upstream. Map
BlockConfigModern.discard_unmap to DiskConfig.sparse so block devices
that request discard/unmap explicitly expose sparse discard support
through the CH API.

Signed-off-by: Alex Lyn <alex.lyn@antgroup.com>
This commit is contained in:
Alex Lyn
2026-07-13 11:36:45 +08:00
committed by Fabiano Fidêncio
parent f1b772eef0
commit a886f99a00
2 changed files with 29 additions and 1 deletions

View File

@@ -123,7 +123,7 @@ pub enum ImageType {
Unknown,
}
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, Default)]
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct DiskConfig {
pub path: Option<PathBuf>,
#[serde(default)]
@@ -148,10 +148,37 @@ pub struct DiskConfig {
pub disable_io_uring: bool,
#[serde(default)]
pub pci_segment: u16,
#[serde(default = "default_diskconfig_sparse")]
pub sparse: bool,
#[serde(default)]
pub image_type: ImageType,
}
pub fn default_diskconfig_sparse() -> bool {
true
}
impl Default for DiskConfig {
fn default() -> Self {
Self {
path: None,
readonly: false,
direct: false,
iommu: false,
num_queues: 0,
queue_size: 0,
vhost_user: false,
vhost_socket: None,
rate_limiter_config: None,
id: None,
disable_io_uring: false,
pci_segment: 0,
sparse: default_diskconfig_sparse(),
image_type: ImageType::default(),
}
}
}
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, Default)]
pub struct FsConfig {
pub tag: String,

View File

@@ -522,6 +522,7 @@ impl TryFrom<BlockConfigModern> for DiskConfig {
readonly: blkcfg.is_readonly,
num_queues: blkcfg.num_queues,
queue_size: blkcfg.queue_size as u16,
sparse: blkcfg.discard_unmap,
image_type: ImageType::Raw,
..Default::default()
};