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

@@ -7,7 +7,7 @@ use crate::api::http::EndpointHandler;
use crate::api::{
vm_add_device, vm_boot, vm_create, vm_delete, vm_info, vm_pause, vm_reboot, vm_remove_device,
vm_resize, vm_resume, vm_shutdown, vmm_ping, vmm_shutdown, ApiError, ApiRequest, ApiResult,
VmAction, VmAddDeviceData, VmConfig, VmRemoveDeviceData, VmResizeData,
DeviceConfig, VmAction, VmConfig, VmRemoveDeviceData, VmResizeData,
};
use micro_http::{Body, Method, Request, Response, StatusCode, Version};
use serde_json::Error as SerdeError;
@@ -283,8 +283,8 @@ impl EndpointHandler for VmAddDevice {
Method::Put => {
match &req.body {
Some(body) => {
// Deserialize into a VmAddDeviceData
let vm_add_device_data: VmAddDeviceData =
// Deserialize into a DeviceConfig
let vm_add_device_data: DeviceConfig =
match serde_json::from_slice(body.raw())
.map_err(HttpError::SerdeJsonDeserialize)
{

View File

@@ -36,7 +36,7 @@ pub use self::http::start_http_thread;
pub mod http;
pub mod http_endpoint;
use crate::config::VmConfig;
use crate::config::{DeviceConfig, VmConfig};
use crate::vm::{Error as VmError, VmState};
use std::io;
use std::sync::mpsc::{channel, RecvError, SendError, Sender};
@@ -125,11 +125,6 @@ pub struct VmResizeData {
pub desired_ram: Option<u64>,
}
#[derive(Clone, Deserialize, Serialize)]
pub struct VmAddDeviceData {
pub path: String,
}
#[derive(Clone, Deserialize, Serialize)]
pub struct VmRemoveDeviceData {
pub id: String,
@@ -199,7 +194,7 @@ pub enum ApiRequest {
VmResize(Arc<VmResizeData>, Sender<ApiResponse>),
/// Add a device to the VM.
VmAddDevice(Arc<VmAddDeviceData>, Sender<ApiResponse>),
VmAddDevice(Arc<DeviceConfig>, Sender<ApiResponse>),
/// Remove a device from the VM.
VmRemoveDevice(Arc<VmRemoveDeviceData>, Sender<ApiResponse>),
@@ -359,7 +354,7 @@ pub fn vm_resize(
pub fn vm_add_device(
api_evt: EventFd,
api_sender: Sender<ApiRequest>,
data: Arc<VmAddDeviceData>,
data: Arc<DeviceConfig>,
) -> ApiResult<()> {
let (response_sender, response_receiver) = channel();