vmm: api: Add "add-vsock" API entry point

This allows the hotplugging of vsock devices.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford
2020-04-28 16:21:22 +01:00
parent bf09a1e695
commit 8de7448d44
6 changed files with 114 additions and 9 deletions

View File

@@ -38,7 +38,7 @@ pub mod http;
pub mod http_endpoint;
use crate::config::{
DeviceConfig, DiskConfig, FsConfig, NetConfig, PmemConfig, RestoreConfig, VmConfig,
DeviceConfig, DiskConfig, FsConfig, NetConfig, PmemConfig, RestoreConfig, VmConfig, VsockConfig,
};
use crate::vm::{Error as VmError, VmState};
use std::io;
@@ -132,6 +132,9 @@ pub enum ApiError {
/// The network device could not be added to the VM.
VmAddNet(VmError),
/// The vsock device could not be added to the VM.
VmAddVsock(VmError),
}
pub type ApiResult<T> = std::result::Result<T, ApiError>;
@@ -244,6 +247,9 @@ pub enum ApiRequest {
/// Add a network device to the VM.
VmAddNet(Arc<NetConfig>, Sender<ApiResponse>),
/// Add a vsock device to the VM.
VmAddVsock(Arc<VsockConfig>, Sender<ApiResponse>),
/// Take a VM snapshot
VmSnapshot(Arc<VmSnapshotConfig>, Sender<ApiResponse>),
@@ -545,3 +551,21 @@ pub fn vm_add_net(
Ok(())
}
pub fn vm_add_vsock(
api_evt: EventFd,
api_sender: Sender<ApiRequest>,
data: Arc<VsockConfig>,
) -> ApiResult<()> {
let (response_sender, response_receiver) = channel();
// Send the VM add-vsock request.
api_sender
.send(ApiRequest::VmAddVsock(data, response_sender))
.map_err(ApiError::RequestSend)?;
api_evt.write(1).map_err(ApiError::EventFdWrite)?;
response_receiver.recv().map_err(ApiError::ResponseRecv)??;
Ok(())
}