mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-02-22 11:22:26 +00:00
vmm: Add support for adding disks to the VM
The disk will be hotplugged via DeviceManager and saved in the config for later use. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
b3082c1984
commit
164ec2b8e6
@ -26,7 +26,7 @@ extern crate vm_allocator;
|
||||
extern crate vm_memory;
|
||||
extern crate vm_virtio;
|
||||
|
||||
use crate::config::{DeviceConfig, VmConfig};
|
||||
use crate::config::{DeviceConfig, DiskConfig, 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};
|
||||
@ -644,6 +644,39 @@ impl Vm {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_disk(&mut self, mut _disk_cfg: DiskConfig) -> Result<()> {
|
||||
if cfg!(feature = "pci_support") {
|
||||
#[cfg(feature = "pci_support")]
|
||||
{
|
||||
self.device_manager
|
||||
.lock()
|
||||
.unwrap()
|
||||
.add_disk(&mut _disk_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(disks) = config.disks.as_mut() {
|
||||
disks.push(_disk_cfg);
|
||||
} else {
|
||||
config.disks = Some(vec![_disk_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<Console>, on_tty: bool) {
|
||||
for signal in signals.forever() {
|
||||
match signal {
|
||||
|
Loading…
x
Reference in New Issue
Block a user