diff --git a/vmm/src/api/openapi/cloud-hypervisor.yaml b/vmm/src/api/openapi/cloud-hypervisor.yaml index d00873f56..b23bfff63 100644 --- a/vmm/src/api/openapi/cloud-hypervisor.yaml +++ b/vmm/src/api/openapi/cloud-hypervisor.yaml @@ -324,6 +324,9 @@ components: queue_size: type: integer default: 1024 + dax: + type: boolean + default: true cache_size: type: integer format: int64 diff --git a/vmm/src/config.rs b/vmm/src/config.rs index eeba43102..5eb58d20f 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -436,8 +436,10 @@ pub struct FsConfig { pub num_queues: usize, #[serde(default = "default_fsconfig_queue_size")] pub queue_size: u16, + #[serde(default = "default_fsconfig_dax")] + pub dax: bool, #[serde(default = "default_fsconfig_cache_size")] - pub cache_size: Option, + pub cache_size: u64, } fn default_fsconfig_num_queues() -> usize { @@ -448,8 +450,12 @@ fn default_fsconfig_queue_size() -> u16 { 1024 } -fn default_fsconfig_cache_size() -> Option { - Some(0x0002_0000_0000) +fn default_fsconfig_dax() -> bool { + true +} + +fn default_fsconfig_cache_size() -> u64 { + 0x0002_0000_0000 } impl FsConfig { @@ -482,9 +488,9 @@ impl FsConfig { let mut num_queues: usize = default_fsconfig_num_queues(); let mut queue_size: u16 = default_fsconfig_queue_size(); - let mut dax: bool = true; + let mut dax: bool = default_fsconfig_dax(); // Default cache size set to 8Gib. - let mut cache_size: Option = default_fsconfig_cache_size(); + let mut cache_size: u64 = default_fsconfig_cache_size(); if tag.is_empty() { return Err(Error::ParseFsTagParam); @@ -516,9 +522,9 @@ impl FsConfig { if !cache_size_str.is_empty() { return Err(Error::InvalidCacheSizeWithDaxOff); } - cache_size = None; + cache_size = 0; } else if !cache_size_str.is_empty() { - cache_size = Some(parse_size(cache_size_str)?); + cache_size = parse_size(cache_size_str)?; } Ok(FsConfig { @@ -526,6 +532,7 @@ impl FsConfig { sock: PathBuf::from(sock), num_queues, queue_size, + dax, cache_size, }) } diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 077509188..22309b6f5 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -977,8 +977,8 @@ impl DeviceManager { if let Some(fs_list_cfg) = &vm_info.vm_cfg.lock().unwrap().fs { for fs_cfg in fs_list_cfg.iter() { if let Some(fs_sock) = fs_cfg.sock.to_str() { - let mut cache: Option<(VirtioSharedMemoryList, u64)> = None; - if let Some(fs_cache) = fs_cfg.cache_size { + let cache: Option<(VirtioSharedMemoryList, u64)> = if fs_cfg.dax { + let fs_cache = fs_cfg.cache_size; // The memory needs to be 2MiB aligned in order to support // hugepages. let fs_guest_addr = allocator @@ -1023,15 +1023,18 @@ impl DeviceManager { offset: 0, len: fs_cache, }); - cache = Some(( + + Some(( VirtioSharedMemoryList { addr: fs_guest_addr, len: fs_cache as GuestUsize, region_list, }, addr as u64, - )); - } + )) + } else { + None + }; let virtio_fs_device = vm_virtio::vhost_user::Fs::new( fs_sock,