runtime-rs: Add is_direct to struct BlockConfig

Add is_direct to struct BlockConfig.
This option 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.

Fixes: #10988

Signed-off-by: Hui Zhu <teawater@antgroup.com>
This commit is contained in:
Hui Zhu
2025-03-07 10:11:18 +08:00
parent 730e007abd
commit 4cd9d70c4d
4 changed files with 17 additions and 3 deletions

View File

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

View File

@@ -36,6 +36,11 @@ pub struct BlockConfig {
/// Don't close `path_on_host` file when dropping the device.
pub no_drop: bool,
/// 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.
pub is_direct: Option<bool>,
/// device index
pub index: u64,

View File

@@ -68,6 +68,7 @@ impl DragonballInner {
block.device_id.as_str(),
block.config.is_readonly,
block.config.no_drop,
block.config.is_direct,
)
.context("add block device")?;
Ok(DeviceType::Block(block))
@@ -78,6 +79,7 @@ impl DragonballInner {
block.device_id.as_str(),
block.is_readonly,
block.no_drop,
None,
)
.context("add vhost user based block device")?;
Ok(DeviceType::VhostUserBlk(block))
@@ -205,6 +207,7 @@ impl DragonballInner {
id: &str,
read_only: bool,
no_drop: bool,
is_direct: Option<bool>,
) -> Result<()> {
let jailed_drive = self.get_resource(path, id).context("get resource")?;
self.cached_block_devices.insert(id.to_string());
@@ -213,7 +216,7 @@ impl DragonballInner {
drive_id: id.to_string(),
device_type: BlockDeviceType::get_type(path),
path_on_host: PathBuf::from(jailed_drive),
is_direct: self.config.blockdev_info.block_device_cache_direct,
is_direct: is_direct.unwrap_or(self.config.blockdev_info.block_device_cache_direct),
no_drop,
is_read_only: read_only,
..Default::default()

View File

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