mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Add support for hotplugging a vDPA device
Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
@@ -102,6 +102,9 @@ pub enum HttpError {
|
||||
/// Could not add a network device to a VM
|
||||
VmAddNet(ApiError),
|
||||
|
||||
/// Could not add a vDPA device to a VM
|
||||
VmAddVdpa(ApiError),
|
||||
|
||||
/// Could not add a vsock device to a VM
|
||||
VmAddVsock(ApiError),
|
||||
|
||||
@@ -220,6 +223,7 @@ lazy_static! {
|
||||
r.routes.insert(endpoint!("/vm.add-fs"), Box::new(VmActionHandler::new(VmAction::AddFs(Arc::default()))));
|
||||
r.routes.insert(endpoint!("/vm.add-net"), Box::new(VmActionHandler::new(VmAction::AddNet(Arc::default()))));
|
||||
r.routes.insert(endpoint!("/vm.add-pmem"), Box::new(VmActionHandler::new(VmAction::AddPmem(Arc::default()))));
|
||||
r.routes.insert(endpoint!("/vm.add-vdpa"), Box::new(VmActionHandler::new(VmAction::AddVdpa(Arc::default()))));
|
||||
r.routes.insert(endpoint!("/vm.add-vsock"), Box::new(VmActionHandler::new(VmAction::AddVsock(Arc::default()))));
|
||||
r.routes.insert(endpoint!("/vm.boot"), Box::new(VmActionHandler::new(VmAction::Boot)));
|
||||
r.routes.insert(endpoint!("/vm.counters"), Box::new(VmActionHandler::new(VmAction::Counters)));
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
use crate::api::http::{error_response, EndpointHandler, HttpError};
|
||||
use crate::api::{
|
||||
vm_add_device, vm_add_disk, vm_add_fs, vm_add_net, vm_add_pmem, vm_add_user_device,
|
||||
vm_add_vsock, vm_boot, vm_counters, vm_create, vm_delete, vm_info, vm_pause, vm_power_button,
|
||||
vm_reboot, vm_receive_migration, vm_remove_device, vm_resize, vm_resize_zone, vm_restore,
|
||||
vm_resume, vm_send_migration, vm_shutdown, vm_snapshot, vmm_ping, vmm_shutdown, ApiRequest,
|
||||
VmAction, VmConfig,
|
||||
vm_add_vdpa, vm_add_vsock, vm_boot, vm_counters, vm_create, vm_delete, vm_info, vm_pause,
|
||||
vm_power_button, vm_reboot, vm_receive_migration, vm_remove_device, vm_resize, vm_resize_zone,
|
||||
vm_restore, vm_resume, vm_send_migration, vm_shutdown, vm_snapshot, vmm_ping, vmm_shutdown,
|
||||
ApiRequest, VmAction, VmConfig,
|
||||
};
|
||||
use crate::config::NetConfig;
|
||||
use micro_http::{Body, Method, Request, Response, StatusCode, Version};
|
||||
@@ -121,6 +121,13 @@ impl EndpointHandler for VmActionHandler {
|
||||
.map_err(HttpError::VmAddNet)
|
||||
}
|
||||
|
||||
AddVdpa(_) => vm_add_vdpa(
|
||||
api_notifier,
|
||||
api_sender,
|
||||
Arc::new(serde_json::from_slice(body.raw())?),
|
||||
)
|
||||
.map_err(HttpError::VmAddVdpa),
|
||||
|
||||
AddVsock(_) => vm_add_vsock(
|
||||
api_notifier,
|
||||
api_sender,
|
||||
|
||||
@@ -34,9 +34,9 @@ pub use self::http::start_http_path_thread;
|
||||
pub mod http;
|
||||
pub mod http_endpoint;
|
||||
|
||||
use crate::config::UserDeviceConfig;
|
||||
use crate::config::{
|
||||
DeviceConfig, DiskConfig, FsConfig, NetConfig, PmemConfig, RestoreConfig, VmConfig, VsockConfig,
|
||||
DeviceConfig, DiskConfig, FsConfig, NetConfig, PmemConfig, RestoreConfig, UserDeviceConfig,
|
||||
VdpaConfig, VmConfig, VsockConfig,
|
||||
};
|
||||
use crate::device_tree::DeviceTree;
|
||||
use crate::vm::{Error as VmError, VmState};
|
||||
@@ -134,6 +134,9 @@ pub enum ApiError {
|
||||
/// The network device could not be added to the VM.
|
||||
VmAddNet(VmError),
|
||||
|
||||
/// The vDPA device could not be added to the VM.
|
||||
VmAddVdpa(VmError),
|
||||
|
||||
/// The vsock device could not be added to the VM.
|
||||
VmAddVsock(VmError),
|
||||
|
||||
@@ -294,6 +297,9 @@ pub enum ApiRequest {
|
||||
/// Add a network device to the VM.
|
||||
VmAddNet(Arc<NetConfig>, Sender<ApiResponse>),
|
||||
|
||||
/// Add a vDPA device to the VM.
|
||||
VmAddVdpa(Arc<VdpaConfig>, Sender<ApiResponse>),
|
||||
|
||||
/// Add a vsock device to the VM.
|
||||
VmAddVsock(Arc<VsockConfig>, Sender<ApiResponse>),
|
||||
|
||||
@@ -371,6 +377,9 @@ pub enum VmAction {
|
||||
/// Add network
|
||||
AddNet(Arc<NetConfig>),
|
||||
|
||||
/// Add vdpa
|
||||
AddVdpa(Arc<VdpaConfig>),
|
||||
|
||||
/// Add vsock
|
||||
AddVsock(Arc<VsockConfig>),
|
||||
|
||||
@@ -423,6 +432,7 @@ fn vm_action(
|
||||
AddFs(v) => ApiRequest::VmAddFs(v, response_sender),
|
||||
AddPmem(v) => ApiRequest::VmAddPmem(v, response_sender),
|
||||
AddNet(v) => ApiRequest::VmAddNet(v, response_sender),
|
||||
AddVdpa(v) => ApiRequest::VmAddVdpa(v, response_sender),
|
||||
AddVsock(v) => ApiRequest::VmAddVsock(v, response_sender),
|
||||
AddUserDevice(v) => ApiRequest::VmAddUserDevice(v, response_sender),
|
||||
RemoveDevice(v) => ApiRequest::VmRemoveDevice(v, response_sender),
|
||||
@@ -634,6 +644,14 @@ pub fn vm_add_net(
|
||||
vm_action(api_evt, api_sender, VmAction::AddNet(data))
|
||||
}
|
||||
|
||||
pub fn vm_add_vdpa(
|
||||
api_evt: EventFd,
|
||||
api_sender: Sender<ApiRequest>,
|
||||
data: Arc<VdpaConfig>,
|
||||
) -> ApiResult<Option<Body>> {
|
||||
vm_action(api_evt, api_sender, VmAction::AddVdpa(data))
|
||||
}
|
||||
|
||||
pub fn vm_add_vsock(
|
||||
api_evt: EventFd,
|
||||
api_sender: Sender<ApiRequest>,
|
||||
|
||||
@@ -325,7 +325,28 @@ paths:
|
||||
description: The new device was successfully (cold) added to the VM instance.
|
||||
500:
|
||||
description: The new device could not be added to the VM instance.
|
||||
|
||||
|
||||
/vm.add-vdpa:
|
||||
put:
|
||||
summary: Add a new vDPA device to the VM
|
||||
requestBody:
|
||||
description: The details of the new vDPA device
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/VdpaConfig'
|
||||
required: true
|
||||
responses:
|
||||
200:
|
||||
description: The new vDPA device was successfully added to the VM instance.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/PciDeviceInfo'
|
||||
204:
|
||||
description: The new vDPA device was successfully (cold) added to the VM instance.
|
||||
500:
|
||||
description: The new vDPA device could not be added to the VM instance.
|
||||
|
||||
/vm.snapshot:
|
||||
put:
|
||||
|
||||
Reference in New Issue
Block a user