Merge pull request #10850 from teawater/direct

Clean the config block_device_cache_direct of runtime-rs
This commit is contained in:
Fupan Li 2025-02-12 09:45:37 +08:00 committed by GitHub
commit ec7b2aa441
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 29 additions and 45 deletions

View File

@ -172,6 +172,11 @@ default_bridges = @DEFBRIDGES@
# rootfs is backed by a block device. # rootfs is backed by a block device.
block_device_driver = "virtio-blk-pci" block_device_driver = "virtio-blk-pci"
# Specifies cache-related options for block devices.
# Denotes whether use of O_DIRECT (bypass the host page cache) is enabled.
# Default false
#block_device_cache_direct = true
# Enable huge pages for VM RAM, default false # Enable huge pages for VM RAM, default false
# Enabling this will result in the VM memory # Enabling this will result in the VM memory
# being allocated using huge pages. # being allocated using huge pages.

View File

@ -204,6 +204,11 @@ virtio_fs_extra_args = @DEFVIRTIOFSEXTRAARGS@
# Metadata, data, and pathname lookup are cached in guest and never expire. # Metadata, data, and pathname lookup are cached in guest and never expire.
virtio_fs_cache = "@DEFVIRTIOFSCACHE@" virtio_fs_cache = "@DEFVIRTIOFSCACHE@"
# Specifies cache-related options for block devices.
# Denotes whether use of O_DIRECT (bypass the host page cache) is enabled.
# Default false
#block_device_cache_direct = true
# Enable huge pages for VM RAM, default false # Enable huge pages for VM RAM, default false
# Enabling this will result in the VM memory # Enabling this will result in the VM memory
# being allocated using huge pages. # being allocated using huge pages.

View File

@ -121,11 +121,6 @@ block_device_driver = "@DEFBLOCKSTORAGEDRIVER_FC@"
# Default false # Default false
#block_device_cache_set = true #block_device_cache_set = true
# Specifies cache-related options for block devices.
# Denotes whether use of O_DIRECT (bypass the host page cache) is enabled.
# Default false
#block_device_cache_direct = true
# Specifies cache-related options for block devices. # Specifies cache-related options for block devices.
# Denotes whether flush requests for the device are ignored. # Denotes whether flush requests for the device are ignored.
# Default false # Default false

View File

@ -27,7 +27,7 @@ pub struct CloudHypervisorInner {
pub(crate) api_socket: Option<UnixStream>, pub(crate) api_socket: Option<UnixStream>,
pub(crate) extra_args: Option<Vec<String>>, pub(crate) extra_args: Option<Vec<String>>,
pub(crate) config: Option<HypervisorConfig>, pub(crate) config: HypervisorConfig,
pub(crate) process: Option<Child>, pub(crate) process: Option<Child>,
pub(crate) pid: Option<u32>, pub(crate) pid: Option<u32>,
@ -101,7 +101,7 @@ impl CloudHypervisorInner {
process: None, process: None,
pid: None, pid: None,
config: None, config: Default::default(),
state: VmmState::NotReady, state: VmmState::NotReady,
timeout_secs: CH_DEFAULT_TIMEOUT_SECS as i32, timeout_secs: CH_DEFAULT_TIMEOUT_SECS as i32,
id: String::default(), id: String::default(),
@ -124,11 +124,11 @@ impl CloudHypervisorInner {
} }
pub fn set_hypervisor_config(&mut self, config: HypervisorConfig) { pub fn set_hypervisor_config(&mut self, config: HypervisorConfig) {
self.config = Some(config); self.config = config;
} }
pub fn hypervisor_config(&self) -> HypervisorConfig { pub fn hypervisor_config(&self) -> HypervisorConfig {
self.config.clone().unwrap_or_default() self.config.clone()
} }
} }
@ -168,7 +168,7 @@ impl Persist for CloudHypervisorInner {
let (tx, rx) = channel(true); let (tx, rx) = channel(true);
let mut ch = Self { let mut ch = Self {
config: Some(hypervisor_state.config), config: hypervisor_state.config,
state: VmmState::NotReady, state: VmmState::NotReady,
id: hypervisor_state.id, id: hypervisor_state.id,
vm_path: hypervisor_state.vm_path, vm_path: hypervisor_state.vm_path,

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

@ -117,11 +117,7 @@ impl CloudHypervisorInner {
} }
async fn get_kernel_params(&self) -> Result<String> { async fn get_kernel_params(&self) -> Result<String> {
let cfg = self let cfg = &self.config;
.config
.as_ref()
.ok_or("no hypervisor config for CH")
.map_err(|e| anyhow!(e))?;
let enable_debug = cfg.debug_info.enable_debug; let enable_debug = cfg.debug_info.enable_debug;
@ -200,15 +196,10 @@ impl CloudHypervisorInner {
let vsock_socket_path = get_vsock_path(&self.id)?; let vsock_socket_path = get_vsock_path(&self.id)?;
let hypervisor_config = self
.config
.as_ref()
.ok_or("no hypervisor config for CH")
.map_err(|e| anyhow!(e))?;
debug!( debug!(
sl!(), sl!(),
"generic Hypervisor configuration: {:?}", hypervisor_config "generic Hypervisor configuration: {:?}",
self.config.clone()
); );
let kernel_params = self.get_kernel_params().await?; let kernel_params = self.get_kernel_params().await?;
@ -217,7 +208,7 @@ impl CloudHypervisorInner {
kernel_params, kernel_params,
sandbox_path, sandbox_path,
vsock_socket_path, vsock_socket_path,
cfg: hypervisor_config.clone(), cfg: self.config.clone(),
guest_protection_to_use: self.guest_protection_to_use.clone(), guest_protection_to_use: self.guest_protection_to_use.clone(),
shared_fs_devices, shared_fs_devices,
network_devices, network_devices,
@ -324,11 +315,7 @@ impl CloudHypervisorInner {
async fn cloud_hypervisor_launch(&mut self, _timeout_secs: i32) -> Result<()> { async fn cloud_hypervisor_launch(&mut self, _timeout_secs: i32) -> Result<()> {
self.cloud_hypervisor_ensure_not_launched().await?; self.cloud_hypervisor_ensure_not_launched().await?;
let cfg = self let cfg = &self.config;
.config
.as_ref()
.ok_or("no hypervisor config for CH")
.map_err(|e| anyhow!(e))?;
let debug = cfg.debug_info.enable_debug; let debug = cfg.debug_info.enable_debug;
@ -338,13 +325,7 @@ impl CloudHypervisorInner {
let _ = std::fs::remove_file(api_socket_path.clone()); let _ = std::fs::remove_file(api_socket_path.clone());
let binary_path = self let binary_path = cfg.path.to_string();
.config
.as_ref()
.ok_or("no hypervisor config for CH")
.map_err(|e| anyhow!(e))?
.path
.to_string();
let path = Path::new(&binary_path).canonicalize()?; let path = Path::new(&binary_path).canonicalize()?;
@ -567,11 +548,7 @@ impl CloudHypervisorInner {
// call, if confidential_guest is set, a confidential // call, if confidential_guest is set, a confidential
// guest will be created. // guest will be created.
async fn handle_guest_protection(&mut self) -> Result<()> { async fn handle_guest_protection(&mut self) -> Result<()> {
let cfg = self let cfg = &self.config;
.config
.as_ref()
.ok_or("missing hypervisor config")
.map_err(|e| anyhow!(e))?;
let confidential_guest = cfg.security_info.confidential_guest; let confidential_guest = cfg.security_info.confidential_guest;

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)