vmm: Implement VM pause

In order to pause a VM, we signal all the vCPU threads to get them out
of vmx non-root. Once out, the vCPU thread will check for a an atomic
pause boolean. If it's set to true, then the thread will park until
being resumed.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz
2019-10-10 17:16:58 +02:00
committed by Sebastien Boeuf
parent 80c3fd922a
commit 4ac0cb9cff
6 changed files with 88 additions and 2 deletions

View File

@@ -58,6 +58,7 @@ lazy_static! {
r.routes.insert(endpoint!("/vm.boot"), Box::new(VmActionHandler::new(VmAction::Boot)));
r.routes.insert(endpoint!("/vm.delete"), Box::new(VmActionHandler::new(VmAction::Delete)));
r.routes.insert(endpoint!("/vm.info"), Box::new(VmInfo {}));
r.routes.insert(endpoint!("/vm.pause"), Box::new(VmActionHandler::new(VmAction::Pause)));
r.routes.insert(endpoint!("/vm.shutdown"), Box::new(VmActionHandler::new(VmAction::Shutdown)));
r.routes.insert(endpoint!("/vm.reboot"), Box::new(VmActionHandler::new(VmAction::Reboot)));
r.routes.insert(endpoint!("/vmm.shutdown"), Box::new(VmmShutdown {}));

View File

@@ -5,8 +5,8 @@
use crate::api::http::EndpointHandler;
use crate::api::{
vm_boot, vm_create, vm_delete, vm_info, vm_reboot, vm_shutdown, vmm_shutdown, ApiError,
ApiRequest, ApiResult, VmAction, VmConfig,
vm_boot, vm_create, vm_delete, vm_info, vm_pause, vm_reboot, vm_shutdown, vmm_shutdown,
ApiError, ApiRequest, ApiResult, VmAction, VmConfig,
};
use micro_http::{Body, Method, Request, Response, StatusCode, Version};
use serde_json::Error as SerdeError;
@@ -29,6 +29,9 @@ pub enum HttpError {
/// Could not get the VM information
VmInfo(ApiError),
/// Could not pause the VM
VmPause(ApiError),
/// Could not shut a VM down
VmShutdown(ApiError),
@@ -103,6 +106,7 @@ impl VmActionHandler {
VmAction::Delete => vm_delete,
VmAction::Shutdown => vm_shutdown,
VmAction::Reboot => vm_reboot,
VmAction::Pause => vm_pause,
});
VmActionHandler { action_fn }
@@ -122,6 +126,7 @@ impl EndpointHandler for VmActionHandler {
ApiError::VmBoot(_) => HttpError::VmBoot(e),
ApiError::VmShutdown(_) => HttpError::VmShutdown(e),
ApiError::VmReboot(_) => HttpError::VmReboot(e),
ApiError::VmPause(_) => HttpError::VmPause(e),
_ => HttpError::VmAction(e),
}) {
Ok(_) => Response::new(Version::Http11, StatusCode::OK),

View File

@@ -76,6 +76,9 @@ pub enum ApiError {
/// The VM config is missing.
VmMissingConfig,
/// The VM could not be paused.
VmPause(VmError),
/// The VM is not booted.
VmNotBooted,
@@ -132,6 +135,9 @@ pub enum ApiRequest {
/// Request the VM information.
VmInfo(Sender<ApiResponse>),
/// Pause a VM.
VmPause(Sender<ApiResponse>),
/// Shut the previously booted virtual machine down.
/// If the VM was not previously booted or created, the VMM API server
/// will send a VmShutdown error back.
@@ -181,6 +187,9 @@ pub enum VmAction {
/// Reboot a VM
Reboot,
/// Pause a VM
Pause,
}
fn vm_action(api_evt: EventFd, api_sender: Sender<ApiRequest>, action: VmAction) -> ApiResult<()> {
@@ -191,6 +200,7 @@ fn vm_action(api_evt: EventFd, api_sender: Sender<ApiRequest>, action: VmAction)
VmAction::Delete => ApiRequest::VmDelete(response_sender),
VmAction::Shutdown => ApiRequest::VmShutdown(response_sender),
VmAction::Reboot => ApiRequest::VmReboot(response_sender),
VmAction::Pause => ApiRequest::VmPause(response_sender),
};
// Send the VM request.
@@ -218,6 +228,10 @@ pub fn vm_reboot(api_evt: EventFd, api_sender: Sender<ApiRequest>) -> ApiResult<
vm_action(api_evt, api_sender, VmAction::Reboot)
}
pub fn vm_pause(api_evt: EventFd, api_sender: Sender<ApiRequest>) -> ApiResult<()> {
vm_action(api_evt, api_sender, VmAction::Pause)
}
pub fn vm_info(api_evt: EventFd, api_sender: Sender<ApiRequest>) -> ApiResult<VmInfo> {
let (response_sender, response_receiver) = channel();

View File

@@ -80,6 +80,21 @@ paths:
description: The VM instance could not boot because it is not created yet
content: {}
/vm.pause:
put:
summary: Pause a previously booted VM instance.
operationId: pauseVM
responses:
201:
description: The VM instance successfully paused.
content: {}
404:
description: The VM instance could not pause because it is not created yet
content: {}
405:
description: The VM instance could not pause because it is not booted.
content: {}
/vm.shutdown:
put:
summary: Shut the VM instance down.