vmm: Add ability to add virtio-fs device post-boot

Adds DeviceManager method `make_virtio_fs_device` which creates a single
device, and modifies `make_virtio_fs_devices` to use this method.

Implements the new `vm.add-fs route`.

Signed-off-by: Dean Sheather <dean@coder.com>
This commit is contained in:
Dean Sheather
2020-04-14 19:21:24 +10:00
committed by Sebastien Boeuf
parent bb2139a408
commit c2abadc293
5 changed files with 213 additions and 94 deletions

View File

@@ -26,7 +26,8 @@ extern crate vm_memory;
extern crate vm_virtio;
use crate::config::{
DeviceConfig, DiskConfig, HotplugMethod, NetConfig, PmemConfig, ValidationError, VmConfig,
DeviceConfig, DiskConfig, FsConfig, HotplugMethod, NetConfig, PmemConfig, ValidationError,
VmConfig,
};
use crate::cpu;
use crate::device_manager::{get_win_size, Console, DeviceManager, DeviceManagerError};
@@ -777,6 +778,39 @@ impl Vm {
}
}
pub fn add_fs(&mut self, mut _fs_cfg: FsConfig) -> Result<()> {
if cfg!(feature = "pci_support") {
#[cfg(feature = "pci_support")]
{
self.device_manager
.lock()
.unwrap()
.add_fs(&mut _fs_cfg)
.map_err(Error::DeviceManager)?;
// Update VmConfig by adding the new device. This is important to
// ensure the device would be created in case of a reboot.
{
let mut config = self.config.lock().unwrap();
if let Some(fs_config) = config.fs.as_mut() {
fs_config.push(_fs_cfg);
} else {
config.fs = Some(vec![_fs_cfg]);
}
}
self.device_manager
.lock()
.unwrap()
.notify_hotplug(HotPlugNotificationFlags::PCI_DEVICES_CHANGED)
.map_err(Error::DeviceManager)?;
}
Ok(())
} else {
Err(Error::NoPciSupport)
}
}
pub fn add_pmem(&mut self, mut _pmem_cfg: PmemConfig) -> Result<()> {
if cfg!(feature = "pci_support") {
#[cfg(feature = "pci_support")]