mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: remove unused mutex in api
This patch removes locks in VmCreate request and VmInfo response since we needn't use a lock here and should ensure that internal implementation is transparent to the runtime. Signed-off-by: Songqian Li <sionli@tencent.com>
This commit is contained in:
committed by
Rob Bradford
parent
7eb70730d1
commit
cc9899e09d
@@ -20,7 +20,7 @@ use hypervisor::HypervisorType;
|
||||
use seccompiler::{apply_filter, SeccompAction};
|
||||
use std::panic::AssertUnwindSafe;
|
||||
use std::sync::mpsc::Sender;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
use vmm_sys_util::eventfd::EventFd;
|
||||
use zbus::fdo::{self, Result};
|
||||
@@ -201,7 +201,7 @@ impl DBusApi {
|
||||
let api_sender = self.clone_api_sender().await;
|
||||
let api_notifier = self.clone_api_notifier()?;
|
||||
|
||||
let mut vm_config: VmConfig = serde_json::from_str(&vm_config).map_err(api_error)?;
|
||||
let mut vm_config: Box<VmConfig> = serde_json::from_str(&vm_config).map_err(api_error)?;
|
||||
|
||||
if let Some(ref mut nets) = vm_config.net {
|
||||
if nets.iter().any(|net| net.fds.is_some()) {
|
||||
@@ -212,11 +212,9 @@ impl DBusApi {
|
||||
}
|
||||
}
|
||||
|
||||
blocking::unblock(move || {
|
||||
VmCreate.send(api_notifier, api_sender, Arc::new(Mutex::new(vm_config)))
|
||||
})
|
||||
.await
|
||||
.map_err(api_error)?;
|
||||
blocking::unblock(move || VmCreate.send(api_notifier, api_sender, vm_config))
|
||||
.await
|
||||
.map_err(api_error)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ use micro_http::{Body, Method, Request, Response, StatusCode, Version};
|
||||
use std::fs::File;
|
||||
use std::os::unix::io::IntoRawFd;
|
||||
use std::sync::mpsc::Sender;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use vmm_sys_util::eventfd::EventFd;
|
||||
|
||||
// /api/v1/vm.create handler
|
||||
@@ -36,7 +35,7 @@ impl EndpointHandler for VmCreate {
|
||||
match &req.body {
|
||||
Some(body) => {
|
||||
// Deserialize into a VmConfig
|
||||
let mut vm_config: VmConfig = match serde_json::from_slice(body.raw())
|
||||
let mut vm_config: Box<VmConfig> = match serde_json::from_slice(body.raw())
|
||||
.map_err(HttpError::SerdeJsonDeserialize)
|
||||
{
|
||||
Ok(config) => config,
|
||||
@@ -53,7 +52,7 @@ impl EndpointHandler for VmCreate {
|
||||
}
|
||||
|
||||
match crate::api::VmCreate
|
||||
.send(api_notifier, api_sender, Arc::new(Mutex::new(vm_config)))
|
||||
.send(api_notifier, api_sender, vm_config)
|
||||
.map_err(HttpError::ApiError)
|
||||
{
|
||||
Ok(_) => Response::new(Version::Http11, StatusCode::NoContent),
|
||||
|
||||
@@ -51,7 +51,6 @@ use serde::{Deserialize, Serialize};
|
||||
use std::fmt::Display;
|
||||
use std::io;
|
||||
use std::sync::mpsc::{channel, RecvError, SendError, Sender};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use vm_migration::MigratableError;
|
||||
use vmm_sys_util::eventfd::EventFd;
|
||||
|
||||
@@ -210,10 +209,10 @@ impl Display for ApiError {
|
||||
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
pub struct VmInfoResponse {
|
||||
pub config: Arc<Mutex<VmConfig>>,
|
||||
pub config: Box<VmConfig>,
|
||||
pub state: VmState,
|
||||
pub memory_actual_size: u64,
|
||||
pub device_tree: Option<Arc<Mutex<DeviceTree>>>,
|
||||
pub device_tree: Option<DeviceTree>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
@@ -287,7 +286,7 @@ pub enum ApiResponsePayload {
|
||||
pub type ApiResponse = Result<ApiResponsePayload, ApiError>;
|
||||
|
||||
pub trait RequestHandler {
|
||||
fn vm_create(&mut self, config: Arc<Mutex<VmConfig>>) -> Result<(), VmError>;
|
||||
fn vm_create(&mut self, config: Box<VmConfig>) -> Result<(), VmError>;
|
||||
|
||||
fn vm_boot(&mut self) -> Result<(), VmError>;
|
||||
|
||||
@@ -827,7 +826,7 @@ impl ApiAction for VmCounters {
|
||||
pub struct VmCreate;
|
||||
|
||||
impl ApiAction for VmCreate {
|
||||
type RequestBody = Arc<Mutex<VmConfig>>;
|
||||
type RequestBody = Box<VmConfig>;
|
||||
type ResponseBody = ();
|
||||
|
||||
fn request(
|
||||
|
||||
Reference in New Issue
Block a user