mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-02-22 03:12:27 +00:00
vmm: vm: Add "add_vsock()"
Add the vsock device to the device manager and patch the config to add the new vsock device. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
1d61c476a1
commit
99422324a7
@ -27,7 +27,7 @@ extern crate vm_virtio;
|
||||
|
||||
use crate::config::{
|
||||
DeviceConfig, DiskConfig, FsConfig, HotplugMethod, NetConfig, PmemConfig, ValidationError,
|
||||
VmConfig,
|
||||
VmConfig, VsockConfig,
|
||||
};
|
||||
use crate::cpu;
|
||||
use crate::device_manager::{get_win_size, Console, DeviceManager, DeviceManagerError};
|
||||
@ -197,6 +197,9 @@ pub enum Error {
|
||||
|
||||
/// Failed to validate config
|
||||
ConfigValidation(ValidationError),
|
||||
|
||||
/// No more that one virtio-vsock device
|
||||
TooManyVsockDevices,
|
||||
}
|
||||
pub type Result<T> = result::Result<T, Error>;
|
||||
|
||||
@ -884,6 +887,39 @@ impl Vm {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_vsock(&mut self, mut _vsock_cfg: VsockConfig) -> Result<()> {
|
||||
if cfg!(feature = "pci_support") {
|
||||
#[cfg(feature = "pci_support")]
|
||||
{
|
||||
if self.config.lock().unwrap().vsock.is_some() {
|
||||
return Err(Error::TooManyVsockDevices);
|
||||
}
|
||||
|
||||
self.device_manager
|
||||
.lock()
|
||||
.unwrap()
|
||||
.add_vsock(&mut _vsock_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();
|
||||
config.vsock = Some(_vsock_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