mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Move the VM creation and startup helpers to the api module
They're API wrappers, not VMM ones. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
@@ -29,24 +29,27 @@
|
||||
//! 5. The thread handles the response and forwards potential errors.
|
||||
|
||||
extern crate micro_http;
|
||||
extern crate vmm_sys_util;
|
||||
|
||||
pub use self::http::start_http_thread;
|
||||
|
||||
pub mod http;
|
||||
|
||||
use crate::config::VmConfig;
|
||||
use crate::vm::Error;
|
||||
use std::sync::mpsc::Sender;
|
||||
use crate::vm::Error as VmError;
|
||||
use crate::{Error, Result};
|
||||
use std::sync::mpsc::{channel, Sender};
|
||||
use std::sync::Arc;
|
||||
use vmm_sys_util::eventfd::EventFd;
|
||||
|
||||
/// API errors are sent back from the VMM API server through the ApiResponse.
|
||||
#[derive(Debug)]
|
||||
pub enum ApiError {
|
||||
/// The VM could not be created.
|
||||
VmCreate(Error),
|
||||
VmCreate(VmError),
|
||||
|
||||
/// The VM could not start.
|
||||
VmStart(Error),
|
||||
VmStart(VmError),
|
||||
}
|
||||
|
||||
pub enum ApiResponsePayload {
|
||||
@@ -70,3 +73,41 @@ pub enum ApiRequest {
|
||||
/// VmStart error back.
|
||||
VmStart(Sender<ApiResponse>),
|
||||
}
|
||||
|
||||
pub fn vm_create(
|
||||
api_evt: EventFd,
|
||||
api_sender: Sender<ApiRequest>,
|
||||
config: Arc<VmConfig>,
|
||||
) -> Result<()> {
|
||||
let (response_sender, response_receiver) = channel();
|
||||
|
||||
// Send the VM creation request.
|
||||
api_sender
|
||||
.send(ApiRequest::VmCreate(config, response_sender))
|
||||
.map_err(Error::ApiRequestSend)?;
|
||||
api_evt.write(1).map_err(Error::EventFdWrite)?;
|
||||
|
||||
response_receiver
|
||||
.recv()
|
||||
.map_err(Error::ApiResponseRecv)?
|
||||
.map_err(Error::ApiVmCreate)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn vm_start(api_evt: EventFd, api_sender: Sender<ApiRequest>) -> Result<()> {
|
||||
let (response_sender, response_receiver) = channel();
|
||||
|
||||
// Send the VM start request.
|
||||
api_sender
|
||||
.send(ApiRequest::VmStart(response_sender))
|
||||
.map_err(Error::ApiRequestSend)?;
|
||||
api_evt.write(1).map_err(Error::EventFdWrite)?;
|
||||
|
||||
response_receiver
|
||||
.recv()
|
||||
.map_err(Error::ApiResponseRecv)?
|
||||
.map_err(Error::ApiVmStart)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user