mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: trim qualified paths
Import the modules used in the crate instead of spelling the full paths at every use site, and drop the now-unnecessary crate-level Signed-off-by: Henry Hrvoje Tonkovac <htonkovac@gmail.com> Assisted-by: Claude:Opus-4.8
This commit is contained in:
committed by
Sebastien Boeuf
parent
0caa3ee73f
commit
025e782e50
@@ -5,17 +5,17 @@
|
||||
use std::panic::AssertUnwindSafe;
|
||||
use std::sync::Arc;
|
||||
use std::sync::mpsc::Sender;
|
||||
use std::thread;
|
||||
use std::{fmt, panic, thread};
|
||||
|
||||
use futures::channel::oneshot;
|
||||
use futures::{FutureExt, executor};
|
||||
use futures::{FutureExt, executor, future, lock};
|
||||
use log::{error, warn};
|
||||
use seccompiler::{SeccompAction, apply_filter};
|
||||
use vmm_sys_util::eventfd::EventFd;
|
||||
use zbus::connection::Builder;
|
||||
use zbus::fdo::{self, Result};
|
||||
use zbus::interface;
|
||||
use zbus::zvariant::Optional;
|
||||
use zbus::{interface, object_server};
|
||||
|
||||
use super::{ApiAction, ApiRequest};
|
||||
#[cfg(all(target_arch = "x86_64", feature = "guest_debug"))]
|
||||
@@ -40,10 +40,10 @@ pub struct DBusApiOptions {
|
||||
|
||||
pub struct DBusApi {
|
||||
api_notifier: EventFd,
|
||||
api_sender: futures::lock::Mutex<Sender<ApiRequest>>,
|
||||
api_sender: lock::Mutex<Sender<ApiRequest>>,
|
||||
}
|
||||
|
||||
fn api_error(error: impl std::fmt::Debug + std::fmt::Display) -> fdo::Error {
|
||||
fn api_error(error: impl fmt::Debug + fmt::Display) -> fdo::Error {
|
||||
fdo::Error::Failed(format!("{error}"))
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ impl DBusApi {
|
||||
pub fn new(api_notifier: EventFd, api_sender: Sender<ApiRequest>) -> Self {
|
||||
Self {
|
||||
api_notifier,
|
||||
api_sender: futures::lock::Mutex::new(api_sender),
|
||||
api_sender: lock::Mutex::new(api_sender),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,10 +313,8 @@ impl DBusApi {
|
||||
|
||||
// implementation of this function is provided by the `#[zbus(signal)]` macro call
|
||||
#[zbus(signal)]
|
||||
async fn event(
|
||||
ctxt: &zbus::object_server::SignalEmitter<'_>,
|
||||
event: Arc<String>,
|
||||
) -> zbus::Result<()>;
|
||||
async fn event(ctxt: &object_server::SignalEmitter<'_>, event: Arc<String>)
|
||||
-> zbus::Result<()>;
|
||||
}
|
||||
|
||||
pub fn start_dbus_thread(
|
||||
@@ -371,10 +369,10 @@ pub fn start_dbus_thread(
|
||||
})?;
|
||||
}
|
||||
|
||||
std::panic::catch_unwind(AssertUnwindSafe(move || {
|
||||
panic::catch_unwind(AssertUnwindSafe(move || {
|
||||
executor::block_on(async move {
|
||||
let recv_shutdown = recv_shutdown.fuse();
|
||||
let executor_tick = futures::future::Fuse::terminated();
|
||||
let executor_tick = future::Fuse::terminated();
|
||||
futures::pin_mut!(recv_shutdown, executor_tick);
|
||||
executor_tick.set(connection.executor().tick().fuse());
|
||||
|
||||
|
||||
@@ -35,11 +35,13 @@
|
||||
//! [special HTTP library]: https://github.com/firecracker-microvm/micro-http
|
||||
|
||||
use std::fs::File;
|
||||
use std::result;
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
use micro_http::{Body, Method, Request, Response, StatusCode, Version};
|
||||
use vmm_sys_util::eventfd::EventFd;
|
||||
|
||||
use crate::api;
|
||||
#[cfg(all(target_arch = "x86_64", feature = "guest_debug"))]
|
||||
use crate::api::VmCoredump;
|
||||
use crate::api::http::http_endpoint::fds_helper::{attach_fds_to_cfg, attach_fds_to_cfgs};
|
||||
@@ -327,7 +329,7 @@ impl EndpointHandler for VmCreate {
|
||||
}
|
||||
}
|
||||
|
||||
match crate::api::VmCreate
|
||||
match api::VmCreate
|
||||
.send(api_notifier, api_sender, vm_config)
|
||||
.map_err(HttpError::ApiError)
|
||||
{
|
||||
@@ -350,7 +352,7 @@ pub trait GetHandler {
|
||||
&'static self,
|
||||
_api_notifier: EventFd,
|
||||
_api_sender: Sender<ApiRequest>,
|
||||
) -> std::result::Result<Option<Body>, HttpError> {
|
||||
) -> result::Result<Option<Body>, HttpError> {
|
||||
Err(HttpError::BadRequest)
|
||||
}
|
||||
}
|
||||
@@ -362,7 +364,7 @@ pub trait PutHandler {
|
||||
_api_sender: Sender<ApiRequest>,
|
||||
_body: &Option<Body>,
|
||||
_files: Vec<File>,
|
||||
) -> std::result::Result<Option<Body>, HttpError> {
|
||||
) -> result::Result<Option<Body>, HttpError> {
|
||||
Err(HttpError::BadRequest)
|
||||
}
|
||||
}
|
||||
@@ -503,7 +505,7 @@ impl PutHandler for VmAddNet {
|
||||
api_sender: Sender<ApiRequest>,
|
||||
body: &Option<Body>,
|
||||
files: Vec<File>,
|
||||
) -> std::result::Result<Option<Body>, HttpError> {
|
||||
) -> result::Result<Option<Body>, HttpError> {
|
||||
if let Some(body) = body {
|
||||
let mut net_cfg: NetConfig = serde_json::from_slice(body.raw())?;
|
||||
attach_fds_to_cfg(files, &mut net_cfg)?;
|
||||
@@ -525,7 +527,7 @@ impl PutHandler for VmResize {
|
||||
api_sender: Sender<ApiRequest>,
|
||||
body: &Option<Body>,
|
||||
_files: Vec<File>,
|
||||
) -> std::result::Result<Option<Body>, HttpError> {
|
||||
) -> result::Result<Option<Body>, HttpError> {
|
||||
if let Some(body) = body {
|
||||
self.send(
|
||||
api_notifier,
|
||||
@@ -555,7 +557,7 @@ impl PutHandler for VmRestore {
|
||||
api_sender: Sender<ApiRequest>,
|
||||
body: &Option<Body>,
|
||||
files: Vec<File>,
|
||||
) -> std::result::Result<Option<Body>, HttpError> {
|
||||
) -> result::Result<Option<Body>, HttpError> {
|
||||
if let Some(body) = body {
|
||||
let mut restore_cfg: RestoreConfig = serde_json::from_slice(body.raw())?;
|
||||
|
||||
@@ -593,7 +595,7 @@ impl EndpointHandler for VmActionHandler {
|
||||
api_sender: Sender<ApiRequest>,
|
||||
body: &Option<Body>,
|
||||
files: Vec<File>,
|
||||
) -> std::result::Result<Option<Body>, HttpError> {
|
||||
) -> result::Result<Option<Body>, HttpError> {
|
||||
PutHandler::handle_request(self.action, api_notifier, api_sender, body, files)
|
||||
}
|
||||
|
||||
@@ -602,7 +604,7 @@ impl EndpointHandler for VmActionHandler {
|
||||
api_notifier: EventFd,
|
||||
api_sender: Sender<ApiRequest>,
|
||||
_body: &Option<Body>,
|
||||
) -> std::result::Result<Option<Body>, HttpError> {
|
||||
) -> result::Result<Option<Body>, HttpError> {
|
||||
GetHandler::handle_request(self.action, api_notifier, api_sender)
|
||||
}
|
||||
}
|
||||
@@ -618,7 +620,7 @@ impl EndpointHandler for VmInfo {
|
||||
api_sender: Sender<ApiRequest>,
|
||||
) -> Response {
|
||||
match req.method() {
|
||||
Method::Get => match crate::api::VmInfo
|
||||
Method::Get => match api::VmInfo
|
||||
.send(api_notifier, api_sender, ())
|
||||
.map_err(HttpError::ApiError)
|
||||
{
|
||||
@@ -647,7 +649,7 @@ impl EndpointHandler for VmmPing {
|
||||
api_sender: Sender<ApiRequest>,
|
||||
) -> Response {
|
||||
match req.method() {
|
||||
Method::Get => match crate::api::VmmPing
|
||||
Method::Get => match api::VmmPing
|
||||
.send(api_notifier, api_sender, ())
|
||||
.map_err(HttpError::ApiError)
|
||||
{
|
||||
@@ -678,7 +680,7 @@ impl EndpointHandler for VmmShutdown {
|
||||
) -> Response {
|
||||
match req.method() {
|
||||
Method::Put => {
|
||||
match crate::api::VmmShutdown
|
||||
match api::VmmShutdown
|
||||
.send(api_notifier, api_sender, ())
|
||||
.map_err(HttpError::ApiError)
|
||||
{
|
||||
|
||||
@@ -12,7 +12,7 @@ use std::panic::AssertUnwindSafe;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::LazyLock;
|
||||
use std::sync::mpsc::Sender;
|
||||
use std::thread;
|
||||
use std::{fs, iter, panic, result, thread};
|
||||
|
||||
use block::fcntl::{LockError, LockGranularity, LockType, try_acquire_lock};
|
||||
use log::{error, info};
|
||||
@@ -104,7 +104,7 @@ pub fn error_response(error: HttpError) -> Response {
|
||||
|
||||
let error: &dyn Error = &error;
|
||||
// Write the Display::display() output all errors (from top to root).
|
||||
let error_messages = std::iter::successors(Some(error), |sub_error| {
|
||||
let error_messages = iter::successors(Some(error), |sub_error| {
|
||||
// Dereference necessary to mitigate rustc compiler bug.
|
||||
// See <https://github.com/rust-lang/rust/issues/141673>
|
||||
(*sub_error).source()
|
||||
@@ -167,7 +167,7 @@ pub trait EndpointHandler {
|
||||
_api_sender: Sender<ApiRequest>,
|
||||
_body: &Option<Body>,
|
||||
_files: Vec<File>,
|
||||
) -> std::result::Result<Option<Body>, HttpError> {
|
||||
) -> result::Result<Option<Body>, HttpError> {
|
||||
Err(HttpError::BadRequest)
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ pub trait EndpointHandler {
|
||||
_api_notifier: EventFd,
|
||||
_api_sender: Sender<ApiRequest>,
|
||||
_body: &Option<Body>,
|
||||
) -> std::result::Result<Option<Body>, HttpError> {
|
||||
) -> result::Result<Option<Body>, HttpError> {
|
||||
Err(HttpError::BadRequest)
|
||||
}
|
||||
}
|
||||
@@ -385,7 +385,7 @@ fn start_http_thread(
|
||||
})?;
|
||||
}
|
||||
|
||||
std::panic::catch_unwind(AssertUnwindSafe(move || {
|
||||
panic::catch_unwind(AssertUnwindSafe(move || {
|
||||
server.start_server().unwrap();
|
||||
loop {
|
||||
match server.requests() {
|
||||
@@ -456,7 +456,7 @@ pub fn start_http_path_thread(
|
||||
let lock = acquire_api_socket_lock(&socket_path)?;
|
||||
// We hold the lock, so any socket at this path is stale from a crashed
|
||||
// run: remove it before bind. Ignore errors (it is usually not present).
|
||||
let _ = std::fs::remove_file(&socket_path);
|
||||
let _ = fs::remove_file(&socket_path);
|
||||
|
||||
let socket_fd = UnixListener::bind(socket_path).map_err(VmmError::CreateApiServerSocket)?;
|
||||
// SAFETY: Valid FD just opened
|
||||
|
||||
@@ -1925,7 +1925,7 @@ impl ApiAction for VmNmi {
|
||||
mod unit_tests {
|
||||
use std::path::PathBuf;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use std::{fs, process};
|
||||
use std::{env, fs, process};
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -1939,7 +1939,7 @@ mod unit_tests {
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_nanos();
|
||||
let path = std::env::temp_dir().join(format!(
|
||||
let path = env::temp_dir().join(format!(
|
||||
"cloud-hypervisor-api-{name}-{}-{unique}",
|
||||
process::id()
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user