From 15de30f141c1a912482cc271dee7f957596a340a Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Mon, 23 Mar 2020 16:20:57 +0000 Subject: [PATCH] vmm: Add support for adding pmem devices to the VM The persistent memory will be hotplugged via DeviceManager and saved in the config for later use. Signed-off-by: Rob Bradford --- vmm/src/vm.rs | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 98b8c4fe5..629c0c3e8 100755 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -26,7 +26,7 @@ extern crate vm_allocator; extern crate vm_memory; extern crate vm_virtio; -use crate::config::{DeviceConfig, DiskConfig, VmConfig}; +use crate::config::{DeviceConfig, DiskConfig, PmemConfig, VmConfig}; use crate::cpu; use crate::device_manager::{get_win_size, Console, DeviceManager, DeviceManagerError}; use crate::memory_manager::{get_host_cpu_phys_bits, Error as MemoryManagerError, MemoryManager}; @@ -677,6 +677,39 @@ impl Vm { } } + pub fn add_pmem(&mut self, mut _pmem_cfg: PmemConfig) -> Result<()> { + if cfg!(feature = "pci_support") { + #[cfg(feature = "pci_support")] + { + self.device_manager + .lock() + .unwrap() + .add_pmem(&mut _pmem_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(pmem) = config.pmem.as_mut() { + pmem.push(_pmem_cfg); + } else { + config.pmem = Some(vec![_pmem_cfg]); + } + } + + self.device_manager + .lock() + .unwrap() + .notify_hotplug(HotPlugNotificationFlags::PCI_DEVICES_CHANGED) + .map_err(Error::DeviceManager)?; + } + Ok(()) + } else { + Err(Error::NoPciSupport) + } + } + fn os_signal_handler(signals: Signals, console_input_clone: Arc, on_tty: bool) { for signal in signals.forever() { match signal {