From 1cb2378499107f3908bc1093e11b05d53fc4fec2 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Thu, 27 Jun 2019 09:14:11 -0700 Subject: [PATCH] vmm: Add support for multiple virtio-fs devices Until now, the VMM was only accepting a single instance of a virtio-fs device. This commit extend the virtio-fs support by allowing several devices to be created for a single VM. Signed-off-by: Sebastien Boeuf --- src/main.rs | 5 +++-- vmm/src/config.rs | 28 +++++++++++++++++----------- vmm/src/vm.rs | 35 +++++++++++++++++++++-------------- 3 files changed, 41 insertions(+), 27 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8723f29a0..5be5a4e82 100755 --- a/src/main.rs +++ b/src/main.rs @@ -74,7 +74,8 @@ fn main() { sock=,num_queues=,\ queue_size=\"", ) - .takes_value(true), + .takes_value(true) + .min_values(1), ) .get_matches(); @@ -98,7 +99,7 @@ fn main() { // This .unwrap() cannot fail as there is a default value defined let rng = cmd_arguments.value_of("rng").unwrap(); - let fs = cmd_arguments.value_of("fs"); + let fs: Option> = cmd_arguments.values_of("fs").map(|x| x.collect()); let vm_config = match config::VmConfig::parse(config::VmParams { cpus, diff --git a/vmm/src/config.rs b/vmm/src/config.rs index d7a817970..498d0e1e8 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -59,7 +59,7 @@ pub struct VmParams<'a> { pub disks: Vec<&'a str>, pub net: Option<&'a str>, pub rng: &'a str, - pub fs: Option<&'a str>, + pub fs: Option>, } pub struct CpusConfig(pub u8); @@ -232,6 +232,7 @@ impl<'a> RngConfig<'a> { } } +#[derive(Debug)] pub struct FsConfig<'a> { pub tag: &'a str, pub sock: &'a Path, @@ -240,13 +241,9 @@ pub struct FsConfig<'a> { } impl<'a> FsConfig<'a> { - pub fn parse(fs: Option<&'a str>) -> Result> { - if fs.is_none() { - return Ok(None); - } - + pub fn parse(fs: &'a str) -> Result { // Split the parameters based on the comma delimiter - let params_list: Vec<&str> = fs.unwrap().split(',').collect(); + let params_list: Vec<&str> = fs.split(',').collect(); let mut tag: &str = ""; let mut sock: &str = ""; @@ -285,12 +282,12 @@ impl<'a> FsConfig<'a> { .map_err(Error::ParseFsQueueSizeParam)?; } - Ok(Some(FsConfig { + Ok(FsConfig { tag, sock: Path::new(sock), num_queues, queue_size, - })) + }) } } @@ -302,7 +299,7 @@ pub struct VmConfig<'a> { pub disks: Vec>, pub net: Option>, pub rng: RngConfig<'a>, - pub fs: Option>, + pub fs: Option>>, } impl<'a> VmConfig<'a> { @@ -312,6 +309,15 @@ impl<'a> VmConfig<'a> { disks.push(DiskConfig::parse(disk)?); } + let mut fs: Option> = None; + if let Some(fs_list) = &vm_params.fs { + let mut fs_config_list = Vec::new(); + for item in fs_list.iter() { + fs_config_list.push(FsConfig::parse(item)?); + } + fs = Some(fs_config_list); + } + Ok(VmConfig { cpus: CpusConfig::parse(vm_params.cpus)?, memory: MemoryConfig::parse(vm_params.memory)?, @@ -320,7 +326,7 @@ impl<'a> VmConfig<'a> { disks, net: NetConfig::parse(vm_params.net)?, rng: RngConfig::parse(vm_params.rng)?, - fs: FsConfig::parse(vm_params.fs)?, + fs, }) } } diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index dafa2c3dc..af7e38675 100755 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -595,21 +595,28 @@ impl DeviceManager { } // Add virtio-fs if required - if let Some(fs_cfg) = &vm_cfg.fs { - if let Some(fs_sock) = fs_cfg.sock.to_str() { - let virtio_fs_device = - vm_virtio::Fs::new(fs_sock, fs_cfg.tag, fs_cfg.num_queues, fs_cfg.queue_size) - .map_err(DeviceManagerError::CreateVirtioFs)?; + if let Some(fs_list_cfg) = &vm_cfg.fs { + for fs_cfg in fs_list_cfg.iter() { + println!("####VIRTIO-FS config {:?}", fs_cfg); + if let Some(fs_sock) = fs_cfg.sock.to_str() { + let virtio_fs_device = vm_virtio::Fs::new( + fs_sock, + fs_cfg.tag, + fs_cfg.num_queues, + fs_cfg.queue_size, + ) + .map_err(DeviceManagerError::CreateVirtioFs)?; - DeviceManager::add_virtio_pci_device( - Box::new(virtio_fs_device), - memory.clone(), - allocator, - vm_fd, - &mut pci_root, - &mut mmio_bus, - &interrupt_info, - )?; + DeviceManager::add_virtio_pci_device( + Box::new(virtio_fs_device), + memory.clone(), + allocator, + vm_fd, + &mut pci_root, + &mut mmio_bus, + &interrupt_info, + )?; + } } }