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 <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2019-08-05 12:45:58 -07:00 committed by Samuel Ortiz
parent f30ba069b7
commit 74225ab5b3
2 changed files with 35 additions and 1 deletions

View File

@ -119,7 +119,8 @@ fn main() {
.help(
"virtio-fs parameters \"tag=<tag_name>,\
sock=<socket_path>,num_queues=<number_of_queues>,\
queue_size=<size_of_each_queue>\"",
queue_size=<size_of_each_queue>,dax=on|off,\
cache_size=<DAX cache size: default 8Gib>\"",
)
.takes_value(true)
.min_values(1),

View File

@ -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<u64>,
}
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 = &param[11..];
} else if param.starts_with("queue_size=") {
queue_size_str = &param[11..];
} else if param.starts_with("dax=") {
dax_str = &param[4..];
} else if param.starts_with("cache_size=") {
cache_size_str = &param[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<u64> = 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,
})
}
}