mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-02 11:35:46 +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:
parent
f674019ea1
commit
ce0b475ef7
@ -358,13 +358,13 @@ fn main() {
|
|||||||
if cmd_arguments.is_present("vm-config") && vm_config.valid() {
|
if cmd_arguments.is_present("vm-config") && vm_config.valid() {
|
||||||
// Create and start the VM based off the VM config we just built.
|
// Create and start the VM based off the VM config we just built.
|
||||||
let sender = api_request_sender.clone();
|
let sender = api_request_sender.clone();
|
||||||
vmm::vm_create(
|
vmm::api::vm_create(
|
||||||
api_evt.try_clone().unwrap(),
|
api_evt.try_clone().unwrap(),
|
||||||
api_request_sender,
|
api_request_sender,
|
||||||
Arc::new(vm_config),
|
Arc::new(vm_config),
|
||||||
)
|
)
|
||||||
.expect("Could not create the VM");
|
.expect("Could not create the VM");
|
||||||
vmm::vm_start(api_evt.try_clone().unwrap(), sender).expect("Could not start the VM");
|
vmm::api::vm_start(api_evt.try_clone().unwrap(), sender).expect("Could not start the VM");
|
||||||
}
|
}
|
||||||
|
|
||||||
match vmm_thread.join() {
|
match vmm_thread.join() {
|
||||||
|
@ -29,24 +29,27 @@
|
|||||||
//! 5. The thread handles the response and forwards potential errors.
|
//! 5. The thread handles the response and forwards potential errors.
|
||||||
|
|
||||||
extern crate micro_http;
|
extern crate micro_http;
|
||||||
|
extern crate vmm_sys_util;
|
||||||
|
|
||||||
pub use self::http::start_http_thread;
|
pub use self::http::start_http_thread;
|
||||||
|
|
||||||
pub mod http;
|
pub mod http;
|
||||||
|
|
||||||
use crate::config::VmConfig;
|
use crate::config::VmConfig;
|
||||||
use crate::vm::Error;
|
use crate::vm::Error as VmError;
|
||||||
use std::sync::mpsc::Sender;
|
use crate::{Error, Result};
|
||||||
|
use std::sync::mpsc::{channel, Sender};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use vmm_sys_util::eventfd::EventFd;
|
||||||
|
|
||||||
/// API errors are sent back from the VMM API server through the ApiResponse.
|
/// API errors are sent back from the VMM API server through the ApiResponse.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ApiError {
|
pub enum ApiError {
|
||||||
/// The VM could not be created.
|
/// The VM could not be created.
|
||||||
VmCreate(Error),
|
VmCreate(VmError),
|
||||||
|
|
||||||
/// The VM could not start.
|
/// The VM could not start.
|
||||||
VmStart(Error),
|
VmStart(VmError),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum ApiResponsePayload {
|
pub enum ApiResponsePayload {
|
||||||
@ -70,3 +73,41 @@ pub enum ApiRequest {
|
|||||||
/// VmStart error back.
|
/// VmStart error back.
|
||||||
VmStart(Sender<ApiResponse>),
|
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(())
|
||||||
|
}
|
||||||
|
@ -19,7 +19,7 @@ use crate::vm::{Error as VmError, ExitBehaviour, Vm};
|
|||||||
use libc::EFD_NONBLOCK;
|
use libc::EFD_NONBLOCK;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::os::unix::io::{AsRawFd, RawFd};
|
use std::os::unix::io::{AsRawFd, RawFd};
|
||||||
use std::sync::mpsc::{channel, Receiver, RecvError, SendError, Sender};
|
use std::sync::mpsc::{Receiver, RecvError, SendError, Sender};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::{result, thread};
|
use std::{result, thread};
|
||||||
use vmm_sys_util::eventfd::EventFd;
|
use vmm_sys_util::eventfd::EventFd;
|
||||||
@ -29,9 +29,6 @@ pub mod config;
|
|||||||
pub mod device_manager;
|
pub mod device_manager;
|
||||||
pub mod vm;
|
pub mod vm;
|
||||||
|
|
||||||
use self::config::VmConfig;
|
|
||||||
//use self::vm::{ExitBehaviour, Vm};
|
|
||||||
|
|
||||||
/// Errors associated with VMM management
|
/// Errors associated with VMM management
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[allow(clippy::large_enum_variant)]
|
#[allow(clippy::large_enum_variant)]
|
||||||
@ -236,44 +233,6 @@ pub fn start_vmm_thread(
|
|||||||
Ok(thread)
|
Ok(thread)
|
||||||
}
|
}
|
||||||
|
|
||||||
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(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Vmm {
|
pub struct Vmm {
|
||||||
epoll: EpollContext,
|
epoll: EpollContext,
|
||||||
exit_evt: EventFd,
|
exit_evt: EventFd,
|
||||||
|
Loading…
Reference in New Issue
Block a user