mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
ch-remote: support live disk resizing
Support disk resizing via ch-remote and REST api. On-behalf-of: SAP thomas.prescher@sap.com Signed-off-by: Thomas Prescher <thomas.prescher@cyberus-technology.de>
This commit is contained in:
committed by
Rob Bradford
parent
aac240d076
commit
5fb078305a
@@ -47,8 +47,8 @@ use crate::api::http::{EndpointHandler, HttpError, error_response};
|
||||
use crate::api::{
|
||||
AddDisk, ApiAction, ApiError, ApiRequest, NetConfig, VmAddDevice, VmAddFs, VmAddNet, VmAddPmem,
|
||||
VmAddUserDevice, VmAddVdpa, VmAddVsock, VmBoot, VmConfig, VmCounters, VmDelete, VmNmi, VmPause,
|
||||
VmPowerButton, VmReboot, VmReceiveMigration, VmRemoveDevice, VmResize, VmResizeZone, VmRestore,
|
||||
VmResume, VmSendMigration, VmShutdown, VmSnapshot,
|
||||
VmPowerButton, VmReboot, VmReceiveMigration, VmRemoveDevice, VmResize, VmResizeDisk,
|
||||
VmResizeZone, VmRestore, VmResume, VmSendMigration, VmShutdown, VmSnapshot,
|
||||
};
|
||||
use crate::config::RestoreConfig;
|
||||
use crate::cpu::Error as CpuError;
|
||||
@@ -424,6 +424,7 @@ vm_action_put_handler_body!(VmAddVdpa);
|
||||
vm_action_put_handler_body!(VmAddVsock);
|
||||
vm_action_put_handler_body!(VmAddUserDevice);
|
||||
vm_action_put_handler_body!(VmRemoveDevice);
|
||||
vm_action_put_handler_body!(VmResizeDisk);
|
||||
vm_action_put_handler_body!(VmResizeZone);
|
||||
vm_action_put_handler_body!(VmSnapshot);
|
||||
vm_action_put_handler_body!(VmReceiveMigration);
|
||||
|
||||
@@ -30,7 +30,7 @@ use crate::api::VmCoredump;
|
||||
use crate::api::{
|
||||
AddDisk, ApiError, ApiRequest, VmAddDevice, VmAddFs, VmAddNet, VmAddPmem, VmAddUserDevice,
|
||||
VmAddVdpa, VmAddVsock, VmBoot, VmCounters, VmDelete, VmNmi, VmPause, VmPowerButton, VmReboot,
|
||||
VmReceiveMigration, VmRemoveDevice, VmResize, VmResizeZone, VmRestore, VmResume,
|
||||
VmReceiveMigration, VmRemoveDevice, VmResize, VmResizeDisk, VmResizeZone, VmRestore, VmResume,
|
||||
VmSendMigration, VmShutdown, VmSnapshot,
|
||||
};
|
||||
use crate::landlock::Landlock;
|
||||
@@ -251,6 +251,10 @@ pub static HTTP_ROUTES: LazyLock<HttpRoutes> = LazyLock::new(|| {
|
||||
endpoint!("/vm.resize"),
|
||||
Box::new(VmActionHandler::new(&VmResize)),
|
||||
);
|
||||
r.routes.insert(
|
||||
endpoint!("/vm.resize-disk"),
|
||||
Box::new(VmActionHandler::new(&VmResizeDisk)),
|
||||
);
|
||||
r.routes.insert(
|
||||
endpoint!("/vm.resize-zone"),
|
||||
Box::new(VmActionHandler::new(&VmResizeZone)),
|
||||
|
||||
@@ -134,6 +134,10 @@ pub enum ApiError {
|
||||
#[error("The VM could not be resized")]
|
||||
VmResize(#[source] VmError),
|
||||
|
||||
/// The disk could not be resized.
|
||||
#[error("The disk could not be resized")]
|
||||
VmResizeDisk(#[source] VmError),
|
||||
|
||||
/// The memory zone could not be resized.
|
||||
#[error("The memory zone could not be resized")]
|
||||
VmResizeZone(#[source] VmError),
|
||||
@@ -223,6 +227,12 @@ pub struct VmResizeData {
|
||||
pub desired_balloon: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize, Serialize, Default, Debug)]
|
||||
pub struct VmResizeDiskData {
|
||||
pub id: String,
|
||||
pub desired_size: u64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize, Serialize, Default, Debug)]
|
||||
pub struct VmResizeZoneData {
|
||||
pub id: String,
|
||||
@@ -1139,6 +1149,41 @@ impl ApiAction for VmResize {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct VmResizeDisk;
|
||||
|
||||
impl ApiAction for VmResizeDisk {
|
||||
type RequestBody = VmResizeDiskData;
|
||||
type ResponseBody = Option<Body>;
|
||||
|
||||
fn request(
|
||||
&self,
|
||||
resize_disk_data: Self::RequestBody,
|
||||
response_sender: Sender<ApiResponse>,
|
||||
) -> ApiRequest {
|
||||
Box::new(move |vmm| {
|
||||
let response = vmm
|
||||
.vm_resize_disk(resize_disk_data.id, resize_disk_data.desired_size)
|
||||
.map_err(ApiError::VmResizeDisk)
|
||||
.map(|_| ApiResponsePayload::Empty);
|
||||
|
||||
response_sender
|
||||
.send(response)
|
||||
.map_err(VmmError::ApiResponseSend)?;
|
||||
|
||||
Ok(false)
|
||||
})
|
||||
}
|
||||
|
||||
fn send(
|
||||
&self,
|
||||
api_evt: EventFd,
|
||||
api_sender: Sender<ApiRequest>,
|
||||
data: Self::RequestBody,
|
||||
) -> ApiResult<Self::ResponseBody> {
|
||||
get_response_body(self, api_evt, api_sender, data)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct VmResizeZone;
|
||||
|
||||
impl ApiAction for VmResizeZone {
|
||||
|
||||
Reference in New Issue
Block a user