mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Add support for hotplugging user devices
Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
+24
-1
@@ -20,7 +20,8 @@ use crate::api::{
|
||||
VmSendMigrationData, VmmPingResponse,
|
||||
};
|
||||
use crate::config::{
|
||||
DeviceConfig, DiskConfig, FsConfig, NetConfig, PmemConfig, RestoreConfig, VmConfig, VsockConfig,
|
||||
DeviceConfig, DiskConfig, FsConfig, NetConfig, PmemConfig, RestoreConfig, UserDeviceConfig,
|
||||
VmConfig, VsockConfig,
|
||||
};
|
||||
use crate::migration::{get_vm_snapshot, recv_vm_snapshot};
|
||||
use crate::seccomp_filters::{get_seccomp_filter, Thread};
|
||||
@@ -645,6 +646,21 @@ impl Vmm {
|
||||
}
|
||||
}
|
||||
|
||||
fn vm_add_user_device(
|
||||
&mut self,
|
||||
device_cfg: UserDeviceConfig,
|
||||
) -> result::Result<Vec<u8>, VmError> {
|
||||
if let Some(ref mut vm) = self.vm {
|
||||
let info = vm.add_user_device(device_cfg).map_err(|e| {
|
||||
error!("Error when adding new user device to the VM: {:?}", e);
|
||||
e
|
||||
})?;
|
||||
serde_json::to_vec(&info).map_err(VmError::SerializeJson)
|
||||
} else {
|
||||
Err(VmError::VmNotRunning)
|
||||
}
|
||||
}
|
||||
|
||||
fn vm_remove_device(&mut self, id: String) -> result::Result<(), VmError> {
|
||||
if let Some(ref mut vm) = self.vm {
|
||||
if let Err(e) = vm.remove_device(id) {
|
||||
@@ -1414,6 +1430,13 @@ impl Vmm {
|
||||
.map(ApiResponsePayload::VmAction);
|
||||
sender.send(response).map_err(Error::ApiResponseSend)?;
|
||||
}
|
||||
ApiRequest::VmAddUserDevice(add_device_data, sender) => {
|
||||
let response = self
|
||||
.vm_add_user_device(add_device_data.as_ref().clone())
|
||||
.map_err(ApiError::VmAddUserDevice)
|
||||
.map(ApiResponsePayload::VmAction);
|
||||
sender.send(response).map_err(Error::ApiResponseSend)?;
|
||||
}
|
||||
ApiRequest::VmRemoveDevice(remove_device_data, sender) => {
|
||||
let response = self
|
||||
.vm_remove_device(remove_device_data.id.clone())
|
||||
|
||||
Reference in New Issue
Block a user