vmm: api: Adjust FsConfig for OpenAPI

The FsConfig structure has been recently adjusted so that the default
value matches between OpenAPI and CLI. Unfortunately, with the current
description, there is no way from the OpenAPI to describe a cache_size
value "None", so that DAX does not get enabled. Usually, using a Rust
"Option" works because the default value is None. But in this case, the
default value is Some(8G), which means we cannot describe a None.

This commit tackles the problem, introducing an explicit parameter
"dax", and leaving "cache_size" as a simple u64 integer.

This way, the default value is dax=true and cache_size=8G, but it lets
the opportunity to disable DAX entirely with dax=false, which will
simply ignore the cache_size value.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2019-12-11 10:44:26 +01:00 committed by Rob Bradford
parent 4bfd51cc42
commit 64c5e3d8cb
3 changed files with 25 additions and 12 deletions

View File

@ -324,6 +324,9 @@ components:
queue_size:
type: integer
default: 1024
dax:
type: boolean
default: true
cache_size:
type: integer
format: int64

View File

@ -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<u64>,
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<u64> {
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<u64> = 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,
})
}

View File

@ -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,