From 74225ab5b3278edab657c04f627d2ff90e868f69 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Mon, 5 Aug 2019 12:45:58 -0700 Subject: [PATCH] config: Add option dax and cache_size to virtio-fs In order to support the more performant version of virtio-fs, that is the one relying on a shared memory region between host and guest, we introduce two new parameters to the --fs device. The "dax" parameter allows the user to choose if he wants to use the shared memory region with virtio-fs. By default, this parameter is "on". The "cache_size" parameter allows the user to specify the amount of memory that should be shared between host and guest. By default, the value of this parameter is 8Gib as advised by virtio-fs maintainers. Note that dax=off and cache_size are incompatible. Signed-off-by: Sebastien Boeuf --- src/main.rs | 3 ++- vmm/src/config.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index c392dcd52..089bf77bb 100755 --- a/src/main.rs +++ b/src/main.rs @@ -119,7 +119,8 @@ fn main() { .help( "virtio-fs parameters \"tag=,\ sock=,num_queues=,\ - queue_size=\"", + queue_size=,dax=on|off,\ + cache_size=\"", ) .takes_value(true) .min_values(1), diff --git a/vmm/src/config.rs b/vmm/src/config.rs index eb07647ab..c7337ccd3 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -46,6 +46,10 @@ pub enum Error<'a> { ParseFsNumQueuesParam(std::num::ParseIntError), /// Failed parsing fs queue size parameter. ParseFsQueueSizeParam(std::num::ParseIntError), + /// Failed parsing fs dax parameter. + ParseFsDax, + /// Cannot have dax=off along with cache_size parameter. + InvalidCacheSizeWithDaxOff, /// Failed parsing persitent memory file parameter. ParsePmemFileParam, /// Failed parsing size parameter. @@ -260,6 +264,7 @@ pub struct FsConfig<'a> { pub sock: &'a Path, pub num_queues: usize, pub queue_size: u16, + pub cache_size: Option, } impl<'a> FsConfig<'a> { @@ -271,6 +276,8 @@ impl<'a> FsConfig<'a> { let mut sock: &str = ""; let mut num_queues_str: &str = ""; let mut queue_size_str: &str = ""; + let mut dax_str: &str = ""; + let mut cache_size_str: &str = ""; for param in params_list.iter() { if param.starts_with("tag=") { @@ -281,11 +288,18 @@ impl<'a> FsConfig<'a> { num_queues_str = ¶m[11..]; } else if param.starts_with("queue_size=") { queue_size_str = ¶m[11..]; + } else if param.starts_with("dax=") { + dax_str = ¶m[4..]; + } else if param.starts_with("cache_size=") { + cache_size_str = ¶m[11..]; } } let mut num_queues: usize = 1; let mut queue_size: u16 = 1024; + let mut dax: bool = true; + // Default cache size set to 8Gib. + let mut cache_size: Option = Some(0x0002_0000_0000); if tag.is_empty() { return Err(Error::ParseFsTagParam); @@ -303,12 +317,31 @@ impl<'a> FsConfig<'a> { .parse() .map_err(Error::ParseFsQueueSizeParam)?; } + if !dax_str.is_empty() { + match dax_str { + "on" => dax = true, + "off" => dax = false, + _ => return Err(Error::ParseFsDax), + } + } + + // Take appropriate decision about cache_size based on DAX being + // enabled or disabled. + if !dax { + if !cache_size_str.is_empty() { + return Err(Error::InvalidCacheSizeWithDaxOff); + } + cache_size = None; + } else if !cache_size_str.is_empty() { + cache_size = Some(parse_size(cache_size_str)?); + } Ok(FsConfig { tag, sock: Path::new(sock), num_queues, queue_size, + cache_size, }) } }