mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-23 06:05:21 +00:00
vmm: api: Return an optional response from vm_action()
Any action that relies on vm_action() can now return a response body. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
038180269e
commit
0bc2b08d3a
@ -28,7 +28,6 @@
|
|||||||
//! response channel Receiver.
|
//! response channel Receiver.
|
||||||
//! 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 vm_device;
|
extern crate vm_device;
|
||||||
extern crate vmm_sys_util;
|
extern crate vmm_sys_util;
|
||||||
|
|
||||||
@ -41,6 +40,7 @@ use crate::config::{
|
|||||||
DeviceConfig, DiskConfig, FsConfig, NetConfig, PmemConfig, RestoreConfig, VmConfig, VsockConfig,
|
DeviceConfig, DiskConfig, FsConfig, NetConfig, PmemConfig, RestoreConfig, VmConfig, VsockConfig,
|
||||||
};
|
};
|
||||||
use crate::vm::{Error as VmError, VmState};
|
use crate::vm::{Error as VmError, VmState};
|
||||||
|
use micro_http::Body;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::sync::mpsc::{channel, RecvError, SendError, Sender};
|
use std::sync::mpsc::{channel, RecvError, SendError, Sender};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
@ -175,6 +175,9 @@ pub enum ApiResponsePayload {
|
|||||||
|
|
||||||
/// Vmm ping response
|
/// Vmm ping response
|
||||||
VmmPing(VmmPingResponse),
|
VmmPing(VmmPingResponse),
|
||||||
|
|
||||||
|
/// Vm action response
|
||||||
|
VmAction(Vec<u8>),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is the response sent by the VMM API server through the mpsc channel.
|
/// This is the response sent by the VMM API server through the mpsc channel.
|
||||||
@ -328,7 +331,11 @@ pub enum VmAction {
|
|||||||
Snapshot(Arc<VmSnapshotConfig>),
|
Snapshot(Arc<VmSnapshotConfig>),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn vm_action(api_evt: EventFd, api_sender: Sender<ApiRequest>, action: VmAction) -> ApiResult<()> {
|
fn vm_action(
|
||||||
|
api_evt: EventFd,
|
||||||
|
api_sender: Sender<ApiRequest>,
|
||||||
|
action: VmAction,
|
||||||
|
) -> ApiResult<Option<Body>> {
|
||||||
let (response_sender, response_receiver) = channel();
|
let (response_sender, response_receiver) = channel();
|
||||||
|
|
||||||
use VmAction::*;
|
use VmAction::*;
|
||||||
@ -355,32 +362,36 @@ fn vm_action(api_evt: EventFd, api_sender: Sender<ApiRequest>, action: VmAction)
|
|||||||
api_sender.send(request).map_err(ApiError::RequestSend)?;
|
api_sender.send(request).map_err(ApiError::RequestSend)?;
|
||||||
api_evt.write(1).map_err(ApiError::EventFdWrite)?;
|
api_evt.write(1).map_err(ApiError::EventFdWrite)?;
|
||||||
|
|
||||||
response_receiver.recv().map_err(ApiError::ResponseRecv)??;
|
let body = match response_receiver.recv().map_err(ApiError::ResponseRecv)?? {
|
||||||
|
ApiResponsePayload::VmAction(response) => Some(Body::new(response)),
|
||||||
|
ApiResponsePayload::Empty => None,
|
||||||
|
_ => return Err(ApiError::ResponsePayloadType),
|
||||||
|
};
|
||||||
|
|
||||||
Ok(())
|
Ok(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn vm_boot(api_evt: EventFd, api_sender: Sender<ApiRequest>) -> ApiResult<()> {
|
pub fn vm_boot(api_evt: EventFd, api_sender: Sender<ApiRequest>) -> ApiResult<Option<Body>> {
|
||||||
vm_action(api_evt, api_sender, VmAction::Boot)
|
vm_action(api_evt, api_sender, VmAction::Boot)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn vm_delete(api_evt: EventFd, api_sender: Sender<ApiRequest>) -> ApiResult<()> {
|
pub fn vm_delete(api_evt: EventFd, api_sender: Sender<ApiRequest>) -> ApiResult<Option<Body>> {
|
||||||
vm_action(api_evt, api_sender, VmAction::Delete)
|
vm_action(api_evt, api_sender, VmAction::Delete)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn vm_shutdown(api_evt: EventFd, api_sender: Sender<ApiRequest>) -> ApiResult<()> {
|
pub fn vm_shutdown(api_evt: EventFd, api_sender: Sender<ApiRequest>) -> ApiResult<Option<Body>> {
|
||||||
vm_action(api_evt, api_sender, VmAction::Shutdown)
|
vm_action(api_evt, api_sender, VmAction::Shutdown)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn vm_reboot(api_evt: EventFd, api_sender: Sender<ApiRequest>) -> ApiResult<()> {
|
pub fn vm_reboot(api_evt: EventFd, api_sender: Sender<ApiRequest>) -> ApiResult<Option<Body>> {
|
||||||
vm_action(api_evt, api_sender, VmAction::Reboot)
|
vm_action(api_evt, api_sender, VmAction::Reboot)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn vm_pause(api_evt: EventFd, api_sender: Sender<ApiRequest>) -> ApiResult<()> {
|
pub fn vm_pause(api_evt: EventFd, api_sender: Sender<ApiRequest>) -> ApiResult<Option<Body>> {
|
||||||
vm_action(api_evt, api_sender, VmAction::Pause)
|
vm_action(api_evt, api_sender, VmAction::Pause)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn vm_resume(api_evt: EventFd, api_sender: Sender<ApiRequest>) -> ApiResult<()> {
|
pub fn vm_resume(api_evt: EventFd, api_sender: Sender<ApiRequest>) -> ApiResult<Option<Body>> {
|
||||||
vm_action(api_evt, api_sender, VmAction::Resume)
|
vm_action(api_evt, api_sender, VmAction::Resume)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,7 +399,7 @@ pub fn vm_snapshot(
|
|||||||
api_evt: EventFd,
|
api_evt: EventFd,
|
||||||
api_sender: Sender<ApiRequest>,
|
api_sender: Sender<ApiRequest>,
|
||||||
data: Arc<VmSnapshotConfig>,
|
data: Arc<VmSnapshotConfig>,
|
||||||
) -> ApiResult<()> {
|
) -> ApiResult<Option<Body>> {
|
||||||
vm_action(api_evt, api_sender, VmAction::Snapshot(data))
|
vm_action(api_evt, api_sender, VmAction::Snapshot(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -396,7 +407,7 @@ pub fn vm_restore(
|
|||||||
api_evt: EventFd,
|
api_evt: EventFd,
|
||||||
api_sender: Sender<ApiRequest>,
|
api_sender: Sender<ApiRequest>,
|
||||||
data: Arc<RestoreConfig>,
|
data: Arc<RestoreConfig>,
|
||||||
) -> ApiResult<()> {
|
) -> ApiResult<Option<Body>> {
|
||||||
vm_action(api_evt, api_sender, VmAction::Restore(data))
|
vm_action(api_evt, api_sender, VmAction::Restore(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -451,7 +462,7 @@ pub fn vm_resize(
|
|||||||
api_evt: EventFd,
|
api_evt: EventFd,
|
||||||
api_sender: Sender<ApiRequest>,
|
api_sender: Sender<ApiRequest>,
|
||||||
data: Arc<VmResizeData>,
|
data: Arc<VmResizeData>,
|
||||||
) -> ApiResult<()> {
|
) -> ApiResult<Option<Body>> {
|
||||||
vm_action(api_evt, api_sender, VmAction::Resize(data))
|
vm_action(api_evt, api_sender, VmAction::Resize(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -459,7 +470,7 @@ pub fn vm_add_device(
|
|||||||
api_evt: EventFd,
|
api_evt: EventFd,
|
||||||
api_sender: Sender<ApiRequest>,
|
api_sender: Sender<ApiRequest>,
|
||||||
data: Arc<DeviceConfig>,
|
data: Arc<DeviceConfig>,
|
||||||
) -> ApiResult<()> {
|
) -> ApiResult<Option<Body>> {
|
||||||
vm_action(api_evt, api_sender, VmAction::AddDevice(data))
|
vm_action(api_evt, api_sender, VmAction::AddDevice(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -467,7 +478,7 @@ pub fn vm_remove_device(
|
|||||||
api_evt: EventFd,
|
api_evt: EventFd,
|
||||||
api_sender: Sender<ApiRequest>,
|
api_sender: Sender<ApiRequest>,
|
||||||
data: Arc<VmRemoveDeviceData>,
|
data: Arc<VmRemoveDeviceData>,
|
||||||
) -> ApiResult<()> {
|
) -> ApiResult<Option<Body>> {
|
||||||
vm_action(api_evt, api_sender, VmAction::RemoveDevice(data))
|
vm_action(api_evt, api_sender, VmAction::RemoveDevice(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -475,7 +486,7 @@ pub fn vm_add_disk(
|
|||||||
api_evt: EventFd,
|
api_evt: EventFd,
|
||||||
api_sender: Sender<ApiRequest>,
|
api_sender: Sender<ApiRequest>,
|
||||||
data: Arc<DiskConfig>,
|
data: Arc<DiskConfig>,
|
||||||
) -> ApiResult<()> {
|
) -> ApiResult<Option<Body>> {
|
||||||
vm_action(api_evt, api_sender, VmAction::AddDisk(data))
|
vm_action(api_evt, api_sender, VmAction::AddDisk(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -483,7 +494,7 @@ pub fn vm_add_fs(
|
|||||||
api_evt: EventFd,
|
api_evt: EventFd,
|
||||||
api_sender: Sender<ApiRequest>,
|
api_sender: Sender<ApiRequest>,
|
||||||
data: Arc<FsConfig>,
|
data: Arc<FsConfig>,
|
||||||
) -> ApiResult<()> {
|
) -> ApiResult<Option<Body>> {
|
||||||
vm_action(api_evt, api_sender, VmAction::AddFs(data))
|
vm_action(api_evt, api_sender, VmAction::AddFs(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -491,7 +502,7 @@ pub fn vm_add_pmem(
|
|||||||
api_evt: EventFd,
|
api_evt: EventFd,
|
||||||
api_sender: Sender<ApiRequest>,
|
api_sender: Sender<ApiRequest>,
|
||||||
data: Arc<PmemConfig>,
|
data: Arc<PmemConfig>,
|
||||||
) -> ApiResult<()> {
|
) -> ApiResult<Option<Body>> {
|
||||||
vm_action(api_evt, api_sender, VmAction::AddPmem(data))
|
vm_action(api_evt, api_sender, VmAction::AddPmem(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -499,7 +510,7 @@ pub fn vm_add_net(
|
|||||||
api_evt: EventFd,
|
api_evt: EventFd,
|
||||||
api_sender: Sender<ApiRequest>,
|
api_sender: Sender<ApiRequest>,
|
||||||
data: Arc<NetConfig>,
|
data: Arc<NetConfig>,
|
||||||
) -> ApiResult<()> {
|
) -> ApiResult<Option<Body>> {
|
||||||
vm_action(api_evt, api_sender, VmAction::AddNet(data))
|
vm_action(api_evt, api_sender, VmAction::AddNet(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -507,6 +518,6 @@ pub fn vm_add_vsock(
|
|||||||
api_evt: EventFd,
|
api_evt: EventFd,
|
||||||
api_sender: Sender<ApiRequest>,
|
api_sender: Sender<ApiRequest>,
|
||||||
data: Arc<VsockConfig>,
|
data: Arc<VsockConfig>,
|
||||||
) -> ApiResult<()> {
|
) -> ApiResult<Option<Body>> {
|
||||||
vm_action(api_evt, api_sender, VmAction::AddVsock(data))
|
vm_action(api_evt, api_sender, VmAction::AddVsock(data))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user