Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement and use try_from for DiskConfig #8582

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 20 additions & 12 deletions src/runtime-rs/crates/hypervisor/src/ch/inner_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

use super::inner::CloudHypervisorInner;
use crate::device::DeviceType;
use crate::BlockDevice;
use crate::HybridVsockDevice;
use crate::NetworkConfig;
use crate::PciPath;
use crate::ShareFsConfig;
use crate::ShareFsDevice;
use crate::VfioDevice;
use crate::VmmState;
use crate::{BlockConfig, BlockDevice};
use anyhow::{anyhow, Context, Result};
use ch_config::ch_api::cloud_hypervisor_vm_device_add;
use ch_config::ch_api::{
Expand Down Expand Up @@ -312,20 +312,11 @@ impl CloudHypervisorInner {
.ok_or("missing socket")
.map_err(|e| anyhow!(e))?;

let num_queues: usize = DEFAULT_DISK_QUEUES;
let queue_size: u16 = DEFAULT_DISK_QUEUE_SIZE;

let block_config = DiskConfig {
path: Some(device.config.path_on_host.as_str().into()),
readonly: device.config.is_readonly,
num_queues,
queue_size,
..Default::default()
};
let disk_config = DiskConfig::try_from(device.config)?;

let response = cloud_hypervisor_vm_blockdev_add(
socket.try_clone().context("failed to clone socket")?,
block_config,
disk_config,
)
.await?;

Expand Down Expand Up @@ -388,6 +379,23 @@ impl TryFrom<NetworkConfig> for NetConfig {
Err(anyhow!("Missing mac address for network device"))
}
}

impl TryFrom<BlockConfig> for DiskConfig {
type Error = anyhow::Error;

fn try_from(blkcfg: BlockConfig) -> Result<Self, Self::Error> {
let disk_config: DiskConfig = DiskConfig {
path: Some(blkcfg.path_on_host.as_str().into()),
readonly: blkcfg.is_readonly,
num_queues: DEFAULT_DISK_QUEUES,
queue_size: DEFAULT_DISK_QUEUE_SIZE,
..Default::default()
};

Ok(disk_config)
}
}

#[derive(Debug)]
pub struct ShareFsSettings {
cfg: ShareFsConfig,
Expand Down