runtime-rs: Add block_device_cache_direct config to ch and qemu

Add block_device_cache_direct config to ch and qemu in runtime-rs.

Fixes: #10849

Signed-off-by: Hui Zhu <teawater@antgroup.com>
This commit is contained in:
Hui Zhu 2025-02-07 13:54:45 +08:00
parent e4cbc6abce
commit db04c7ec93
3 changed files with 7 additions and 5 deletions

View File

@ -315,7 +315,8 @@ impl CloudHypervisorInner {
.ok_or("missing socket") .ok_or("missing socket")
.map_err(|e| anyhow!(e))?; .map_err(|e| anyhow!(e))?;
let disk_config = DiskConfig::try_from(device.config)?; let mut disk_config = DiskConfig::try_from(device.config.clone())?;
disk_config.direct = self.config.blockdev_info.block_device_cache_direct;
let response = cloud_hypervisor_vm_blockdev_add( let response = cloud_hypervisor_vm_blockdev_add(
socket.try_clone().context("failed to clone socket")?, socket.try_clone().context("failed to clone socket")?,

View File

@ -852,13 +852,13 @@ struct BlockBackend {
} }
impl BlockBackend { impl BlockBackend {
fn new(id: &str, path: &str) -> BlockBackend { fn new(id: &str, path: &str, cache_direct: bool) -> BlockBackend {
BlockBackend { BlockBackend {
driver: "file".to_owned(), driver: "file".to_owned(),
id: id.to_owned(), id: id.to_owned(),
path: path.to_owned(), path: path.to_owned(),
aio: "threads".to_owned(), aio: "threads".to_owned(),
cache_direct: true, cache_direct,
cache_no_flush: false, cache_no_flush: false,
read_only: true, read_only: true,
} }
@ -1959,9 +1959,9 @@ impl<'a> QemuCmdLine<'a> {
Ok(()) Ok(())
} }
pub fn add_block_device(&mut self, device_id: &str, path: &str) -> Result<()> { pub fn add_block_device(&mut self, device_id: &str, path: &str, is_direct: bool) -> Result<()> {
self.devices self.devices
.push(Box::new(BlockBackend::new(device_id, path))); .push(Box::new(BlockBackend::new(device_id, path, is_direct)));
let devno = get_devno_ccw(&mut self.ccw_subchannel, device_id); let devno = get_devno_ccw(&mut self.ccw_subchannel, device_id);
self.devices.push(Box::new(DeviceVirtioBlk::new( self.devices.push(Box::new(DeviceVirtioBlk::new(
device_id, device_id,

View File

@ -109,6 +109,7 @@ impl QemuInner {
"ccw" => cmdline.add_block_device( "ccw" => cmdline.add_block_device(
block_dev.device_id.as_str(), block_dev.device_id.as_str(),
&block_dev.config.path_on_host, &block_dev.config.path_on_host,
self.config.blockdev_info.block_device_cache_direct,
)?, )?,
unsupported => { unsupported => {
info!(sl!(), "unsupported block device driver: {}", unsupported) info!(sl!(), "unsupported block device driver: {}", unsupported)