vmm: Add id option to VFIO hotplug

Add a new id option to the VFIO hotplug command so that it matches the
VFIO coldplug semantic.

This is done by refactoring the existing code for VFIO hotplug, where
VmAddDeviceData structure is replaced by DeviceConfig. This structure is
the one used whenever a VFIO device is coldplugged, which is why it
makes sense to reuse it for the hotplug codepath.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2020-03-11 16:17:51 +01:00
parent 18dc916380
commit 34412c9b41
6 changed files with 21 additions and 35 deletions

View File

@@ -16,7 +16,7 @@ extern crate tempfile;
extern crate vmm_sys_util;
use crate::api::{ApiError, ApiRequest, ApiResponse, ApiResponsePayload, VmInfo, VmmPingResponse};
use crate::config::VmConfig;
use crate::config::{DeviceConfig, VmConfig};
use crate::vm::{Error as VmError, Vm, VmState};
use libc::EFD_NONBLOCK;
use std::io;
@@ -372,9 +372,9 @@ impl Vmm {
}
}
fn vm_add_device(&mut self, path: String) -> result::Result<(), VmError> {
fn vm_add_device(&mut self, device_cfg: DeviceConfig) -> result::Result<(), VmError> {
if let Some(ref mut vm) = self.vm {
if let Err(e) = vm.add_device(path) {
if let Err(e) = vm.add_device(device_cfg) {
error!("Error when adding new device to the VM: {:?}", e);
Err(e)
} else {
@@ -555,7 +555,7 @@ impl Vmm {
}
ApiRequest::VmAddDevice(add_device_data, sender) => {
let response = self
.vm_add_device(add_device_data.path.clone())
.vm_add_device(add_device_data.as_ref().clone())
.map_err(ApiError::VmAddDevice)
.map(|_| ApiResponsePayload::Empty);
sender.send(response).map_err(Error::ApiResponseSend)?;