mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Add a 'resize-zone' action to the API actions
Implement a new VM action called 'resize-zone' allowing the user to resize one specific memory zone at a time. This relies on all the preliminary work from the previous commits to resize each virtio-mem device independently from each others. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
@@ -68,6 +68,9 @@ pub enum HttpError {
|
||||
/// Could not resize a VM
|
||||
VmResize(ApiError),
|
||||
|
||||
/// Could not resize a memory zone
|
||||
VmResizeZone(ApiError),
|
||||
|
||||
/// Could not add a device to a VM
|
||||
VmAddDevice(ApiError),
|
||||
|
||||
@@ -204,6 +207,7 @@ lazy_static! {
|
||||
r.routes.insert(endpoint!("/vm.reboot"), Box::new(VmActionHandler::new(VmAction::Reboot)));
|
||||
r.routes.insert(endpoint!("/vm.remove-device"), Box::new(VmActionHandler::new(VmAction::RemoveDevice(Arc::default()))));
|
||||
r.routes.insert(endpoint!("/vm.resize"), Box::new(VmActionHandler::new(VmAction::Resize(Arc::default()))));
|
||||
r.routes.insert(endpoint!("/vm.resize-zone"), Box::new(VmActionHandler::new(VmAction::ResizeZone(Arc::default()))));
|
||||
r.routes.insert(endpoint!("/vm.restore"), Box::new(VmActionHandler::new(VmAction::Restore(Arc::default()))));
|
||||
r.routes.insert(endpoint!("/vm.resume"), Box::new(VmActionHandler::new(VmAction::Resume)));
|
||||
r.routes.insert(endpoint!("/vm.shutdown"), Box::new(VmActionHandler::new(VmAction::Shutdown)));
|
||||
|
||||
@@ -7,8 +7,8 @@ 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_vsock, vm_boot,
|
||||
vm_counters, vm_create, vm_delete, vm_info, vm_pause, vm_reboot, vm_remove_device, vm_resize,
|
||||
vm_restore, vm_resume, vm_shutdown, vm_snapshot, vmm_ping, vmm_shutdown, ApiRequest, VmAction,
|
||||
VmConfig,
|
||||
vm_resize_zone, vm_restore, vm_resume, vm_shutdown, vm_snapshot, vmm_ping, vmm_shutdown,
|
||||
ApiRequest, VmAction, VmConfig,
|
||||
};
|
||||
use micro_http::{Body, Method, Request, Response, StatusCode, Version};
|
||||
use std::sync::mpsc::Sender;
|
||||
@@ -132,6 +132,13 @@ impl EndpointHandler for VmActionHandler {
|
||||
)
|
||||
.map_err(HttpError::VmResize),
|
||||
|
||||
ResizeZone(_) => vm_resize_zone(
|
||||
api_notifier,
|
||||
api_sender,
|
||||
Arc::new(serde_json::from_slice(body.raw())?),
|
||||
)
|
||||
.map_err(HttpError::VmResizeZone),
|
||||
|
||||
Restore(_) => vm_restore(
|
||||
api_notifier,
|
||||
api_sender,
|
||||
|
||||
@@ -109,6 +109,9 @@ pub enum ApiError {
|
||||
/// The VM could not be resized
|
||||
VmResize(VmError),
|
||||
|
||||
/// The memory zone could not be resized.
|
||||
VmResizeZone(VmError),
|
||||
|
||||
/// The device could not be added to the VM.
|
||||
VmAddDevice(VmError),
|
||||
|
||||
@@ -156,6 +159,12 @@ pub struct VmResizeData {
|
||||
pub desired_ram_w_balloon: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize, Serialize, Default)]
|
||||
pub struct VmResizeZoneData {
|
||||
pub id: String,
|
||||
pub desired_ram: u64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize, Serialize, Default)]
|
||||
pub struct VmRemoveDeviceData {
|
||||
pub id: String,
|
||||
@@ -236,6 +245,9 @@ pub enum ApiRequest {
|
||||
/// Resize the VM.
|
||||
VmResize(Arc<VmResizeData>, Sender<ApiResponse>),
|
||||
|
||||
/// Resize the memory zone.
|
||||
VmResizeZone(Arc<VmResizeZoneData>, Sender<ApiResponse>),
|
||||
|
||||
/// Add a device to the VM.
|
||||
VmAddDevice(Arc<DeviceConfig>, Sender<ApiResponse>),
|
||||
|
||||
@@ -331,6 +343,9 @@ pub enum VmAction {
|
||||
/// Resize VM
|
||||
Resize(Arc<VmResizeData>),
|
||||
|
||||
/// Resize memory zone
|
||||
ResizeZone(Arc<VmResizeZoneData>),
|
||||
|
||||
/// Restore VM
|
||||
Restore(Arc<RestoreConfig>),
|
||||
|
||||
@@ -362,6 +377,7 @@ fn vm_action(
|
||||
AddVsock(v) => ApiRequest::VmAddVsock(v, response_sender),
|
||||
RemoveDevice(v) => ApiRequest::VmRemoveDevice(v, response_sender),
|
||||
Resize(v) => ApiRequest::VmResize(v, response_sender),
|
||||
ResizeZone(v) => ApiRequest::VmResizeZone(v, response_sender),
|
||||
Restore(v) => ApiRequest::VmRestore(v, response_sender),
|
||||
Snapshot(v) => ApiRequest::VmSnapshot(v, response_sender),
|
||||
};
|
||||
@@ -478,6 +494,14 @@ pub fn vm_resize(
|
||||
vm_action(api_evt, api_sender, VmAction::Resize(data))
|
||||
}
|
||||
|
||||
pub fn vm_resize_zone(
|
||||
api_evt: EventFd,
|
||||
api_sender: Sender<ApiRequest>,
|
||||
data: Arc<VmResizeZoneData>,
|
||||
) -> ApiResult<Option<Body>> {
|
||||
vm_action(api_evt, api_sender, VmAction::ResizeZone(data))
|
||||
}
|
||||
|
||||
pub fn vm_add_device(
|
||||
api_evt: EventFd,
|
||||
api_sender: Sender<ApiRequest>,
|
||||
|
||||
@@ -150,6 +150,22 @@ paths:
|
||||
404:
|
||||
description: The VM instance could not be resized because it is not created.
|
||||
|
||||
/vm.resize-zone:
|
||||
put:
|
||||
summary: Resize a memory zone
|
||||
requestBody:
|
||||
description: The target size for the memory zone
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/VmResizeZone'
|
||||
required: true
|
||||
responses:
|
||||
204:
|
||||
description: The memory zone was successfully resized.
|
||||
500:
|
||||
description: The memory zone could not be resized.
|
||||
|
||||
/vm.add-device:
|
||||
put:
|
||||
summary: Add a new device to the VM
|
||||
@@ -774,6 +790,16 @@ components:
|
||||
type: integer
|
||||
format: int64
|
||||
|
||||
VmResizeZone:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
desired_ram:
|
||||
description: desired memory zone size in bytes
|
||||
type: integer
|
||||
format: int64
|
||||
|
||||
VmAddDevice:
|
||||
type: object
|
||||
properties:
|
||||
|
||||
Reference in New Issue
Block a user