From eb26211c64ae401c356193466c2f4e032376af23 Mon Sep 17 00:00:00 2001 From: Egor Lazarchuk Date: Sat, 24 Aug 2024 15:40:42 +0100 Subject: [PATCH] refactor: remove reexport of vmm-sys-util It is better not to reexport `vmm-sys-util` as it entangles the code. Additionally, the original reason of having one place to update this dependency does not hold any more as now we rely on dependabot for updates, so specifying dependency in multiple crates is not an issue. Signed-off-by: Egor Lazarchuk --- Cargo.lock | 5 +++++ src/cpu-template-helper/Cargo.toml | 2 +- src/firecracker/Cargo.toml | 1 + src/firecracker/examples/uffd/uffd_utils.rs | 6 +++--- src/firecracker/src/api_server/mod.rs | 4 ++-- src/firecracker/src/api_server_adapter.rs | 4 ++-- src/firecracker/src/main.rs | 4 ++-- src/firecracker/src/metrics.rs | 2 +- src/firecracker/src/seccomp.rs | 2 +- src/jailer/Cargo.toml | 1 + src/jailer/src/cgroup.rs | 6 +++--- src/jailer/src/chroot.rs | 2 +- src/jailer/src/env.rs | 8 ++++---- src/jailer/src/main.rs | 4 ++-- src/jailer/src/resource_limits.rs | 2 +- src/rebase-snap/Cargo.toml | 1 + src/rebase-snap/src/main.rs | 4 ++-- src/seccompiler/Cargo.toml | 3 +++ src/seccompiler/src/seccompiler_bin.rs | 2 +- src/snapshot-editor/Cargo.toml | 1 + src/snapshot-editor/src/edit_memory.rs | 4 ++-- src/utils/Cargo.toml | 2 +- src/utils/src/lib.rs | 10 ---------- src/vmm/src/arch/aarch64/vcpu.rs | 2 +- src/vmm/src/arch/x86_64/interrupts.rs | 2 +- src/vmm/src/arch/x86_64/msr.rs | 2 +- src/vmm/src/arch/x86_64/regs.rs | 8 ++++---- src/vmm/src/builder.rs | 6 +++--- src/vmm/src/cpu_config/x86_64/cpuid/mod.rs | 2 +- src/vmm/src/device_manager/legacy.rs | 2 +- src/vmm/src/device_manager/mmio.rs | 3 ++- src/vmm/src/device_manager/persist.rs | 3 ++- src/vmm/src/devices/acpi/vmgenid.rs | 2 +- src/vmm/src/devices/legacy/i8042.rs | 2 +- src/vmm/src/devices/legacy/mod.rs | 2 +- src/vmm/src/devices/legacy/serial.rs | 7 ++++--- src/vmm/src/devices/virtio/balloon/device.rs | 2 +- .../devices/virtio/balloon/event_handler.rs | 2 +- src/vmm/src/devices/virtio/block/device.rs | 2 +- .../devices/virtio/block/vhost_user/device.rs | 17 +++++++++-------- .../virtio/block/vhost_user/event_handler.rs | 2 +- .../src/devices/virtio/block/virtio/device.rs | 7 ++++--- .../virtio/block/virtio/event_handler.rs | 2 +- .../virtio/block/virtio/io/async_io.rs | 2 +- .../src/devices/virtio/block/virtio/io/mod.rs | 7 ++++--- .../devices/virtio/block/virtio/persist.rs | 5 +++-- .../devices/virtio/block/virtio/test_utils.rs | 3 ++- src/vmm/src/devices/virtio/device.rs | 3 ++- src/vmm/src/devices/virtio/mmio.rs | 3 ++- src/vmm/src/devices/virtio/net/device.rs | 2 +- .../src/devices/virtio/net/event_handler.rs | 2 +- src/vmm/src/devices/virtio/net/tap.rs | 13 +++++++------ src/vmm/src/devices/virtio/net/test_utils.rs | 6 +++--- src/vmm/src/devices/virtio/persist.rs | 3 ++- src/vmm/src/devices/virtio/rng/device.rs | 2 +- .../src/devices/virtio/rng/event_handler.rs | 2 +- src/vmm/src/devices/virtio/test_utils.rs | 2 +- src/vmm/src/devices/virtio/vhost_user.rs | 5 +++-- .../src/devices/virtio/vhost_user_metrics.rs | 6 ++++-- .../devices/virtio/vsock/csm/connection.rs | 4 ++-- src/vmm/src/devices/virtio/vsock/device.rs | 2 +- .../src/devices/virtio/vsock/event_handler.rs | 2 +- src/vmm/src/devices/virtio/vsock/mod.rs | 2 +- .../src/devices/virtio/vsock/test_utils.rs | 5 +++-- .../src/devices/virtio/vsock/unix/muxer.rs | 5 +++-- src/vmm/src/dumbo/tcp/connection.rs | 2 +- src/vmm/src/io_uring/mod.rs | 9 ++++----- src/vmm/src/io_uring/probe.rs | 5 +++-- src/vmm/src/io_uring/queue/submission.rs | 2 +- src/vmm/src/lib.rs | 12 ++++++------ src/vmm/src/logger/logging.rs | 2 +- src/vmm/src/logger/metrics.rs | 19 ++++++++----------- src/vmm/src/logger/mod.rs | 3 ++- src/vmm/src/persist.rs | 7 ++++--- src/vmm/src/resources.rs | 2 +- src/vmm/src/rpc_interface.rs | 11 ++++++----- src/vmm/src/signal_handler.rs | 2 +- src/vmm/src/utils/mod.rs | 14 ++------------ src/vmm/src/vmm_config/boot_source.rs | 3 ++- src/vmm/src/vmm_config/drive.rs | 3 ++- src/vmm/src/vmm_config/metrics.rs | 3 ++- src/vmm/src/vmm_config/vsock.rs | 3 ++- src/vmm/src/vstate/memory.rs | 6 ++++-- src/vmm/src/vstate/vcpu/mod.rs | 12 ++++++------ src/vmm/src/vstate/vcpu/x86_64.rs | 10 +++++----- src/vmm/tests/devices.rs | 2 +- src/vmm/tests/integration_tests.rs | 2 +- src/vmm/tests/io_uring.rs | 6 +++--- 88 files changed, 199 insertions(+), 184 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ea7b5c40621..13b02fe4cfb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -618,6 +618,7 @@ dependencies = [ "userfaultfd", "utils", "vmm", + "vmm-sys-util", ] [[package]] @@ -785,6 +786,7 @@ dependencies = [ "regex", "thiserror", "utils", + "vmm-sys-util", ] [[package]] @@ -1117,6 +1119,7 @@ dependencies = [ "log-instrument", "thiserror", "utils", + "vmm-sys-util", ] [[package]] @@ -1194,6 +1197,7 @@ dependencies = [ "serde_json", "thiserror", "utils", + "vmm-sys-util", ] [[package]] @@ -1280,6 +1284,7 @@ dependencies = [ "thiserror", "utils", "vmm", + "vmm-sys-util", ] [[package]] diff --git a/src/cpu-template-helper/Cargo.toml b/src/cpu-template-helper/Cargo.toml index 72d1c7fc213..1136e7ad6bc 100644 --- a/src/cpu-template-helper/Cargo.toml +++ b/src/cpu-template-helper/Cargo.toml @@ -19,7 +19,7 @@ serde_json = "1.0.128" thiserror = "1.0.63" vmm = { path = "../vmm" } -vmm-sys-util = { version = "0.12.1", features = ["with-serde"] } +vmm-sys-util = "0.12.1" [features] tracing = ["log-instrument", "vmm/tracing"] diff --git a/src/firecracker/Cargo.toml b/src/firecracker/Cargo.toml index 16d670e81e7..828e4e7eefe 100644 --- a/src/firecracker/Cargo.toml +++ b/src/firecracker/Cargo.toml @@ -30,6 +30,7 @@ thiserror = "1.0.63" timerfd = "1.6.0" utils = { path = "../utils" } vmm = { path = "../vmm" } +vmm-sys-util = { version = "0.12.1", features = ["with-serde"] } [dev-dependencies] cargo_toml = "0.20.4" diff --git a/src/firecracker/examples/uffd/uffd_utils.rs b/src/firecracker/examples/uffd/uffd_utils.rs index a0d63e253a4..52d33765bd8 100644 --- a/src/firecracker/examples/uffd/uffd_utils.rs +++ b/src/firecracker/examples/uffd/uffd_utils.rs @@ -12,7 +12,7 @@ use std::ptr; use serde::{Deserialize, Serialize}; use userfaultfd::{Error, Event, Uffd}; -use utils::sock_ctrl_msg::ScmSocket; +use vmm_sys_util::sock_ctrl_msg::ScmSocket; // This is the same with the one used in src/vmm. /// This describes the mapping between Firecracker base virtual address and offset in the @@ -299,8 +299,8 @@ mod tests { use std::mem::MaybeUninit; use std::os::unix::net::UnixListener; - use vmm::utils::tempdir::TempDir; - use vmm::utils::tempfile::TempFile; + use vmm_sys_util::tempdir::TempDir; + use vmm_sys_util::tempfile::TempFile; use super::*; diff --git a/src/firecracker/src/api_server/mod.rs b/src/firecracker/src/api_server/mod.rs index 35b01c4cbe2..6ac2955af8f 100644 --- a/src/firecracker/src/api_server/mod.rs +++ b/src/firecracker/src/api_server/mod.rs @@ -16,13 +16,13 @@ pub use micro_http::{Body, HttpServer, Request, Response, ServerError, StatusCod use parsed_request::{ParsedRequest, RequestAction}; use seccompiler::BpfProgramRef; use serde_json::json; -use utils::eventfd::EventFd; use utils::time::{get_time_us, ClockType}; use vmm::logger::{ debug, error, info, update_metric_with_elapsed_time, warn, ProcessTimeReporter, METRICS, }; use vmm::rpc_interface::{ApiRequest, ApiResponse, VmmAction}; use vmm::vmm_config::snapshot::SnapshotType; +use vmm_sys_util::eventfd::EventFd; /// Structure associated with the API server implementation. #[derive(Debug)] @@ -204,7 +204,6 @@ mod tests { use std::thread; use micro_http::HttpConnection; - use utils::tempfile::TempFile; use utils::time::ClockType; use vmm::builder::StartMicrovmError; use vmm::logger::StoreMetric; @@ -212,6 +211,7 @@ mod tests { use vmm::seccomp_filters::get_empty_filters; use vmm::vmm_config::instance_info::InstanceInfo; use vmm::vmm_config::snapshot::CreateSnapshotParams; + use vmm_sys_util::tempfile::TempFile; use super::request::cpu_configuration::parse_put_cpu_config; use super::*; diff --git a/src/firecracker/src/api_server_adapter.rs b/src/firecracker/src/api_server_adapter.rs index e50ebd09c17..ffc4732025d 100644 --- a/src/firecracker/src/api_server_adapter.rs +++ b/src/firecracker/src/api_server_adapter.rs @@ -9,8 +9,6 @@ use std::thread; use event_manager::{EventOps, Events, MutEventSubscriber, SubscriberOps}; use seccompiler::BpfThreadMap; -use utils::epoll::EventSet; -use utils::eventfd::EventFd; use vmm::logger::{error, warn, ProcessTimeReporter}; use vmm::resources::VmResources; use vmm::rpc_interface::{ @@ -19,6 +17,8 @@ use vmm::rpc_interface::{ }; use vmm::vmm_config::instance_info::InstanceInfo; use vmm::{EventManager, FcExitCode, Vmm}; +use vmm_sys_util::epoll::EventSet; +use vmm_sys_util::eventfd::EventFd; use super::api_server::{ApiServer, HttpServer, ServerError}; diff --git a/src/firecracker/src/main.rs b/src/firecracker/src/main.rs index e2b8a3fb9e2..8fb5392afcf 100644 --- a/src/firecracker/src/main.rs +++ b/src/firecracker/src/main.rs @@ -19,7 +19,6 @@ use event_manager::SubscriberOps; use seccomp::FilterError; use seccompiler::BpfThreadMap; use utils::arg_parser::{ArgParser, Argument}; -use utils::terminal::Terminal; use utils::validators::validate_instance_id; use vmm::builder::StartMicrovmError; use vmm::logger::{ @@ -32,6 +31,7 @@ use vmm::snapshot::{Snapshot, SnapshotError}; use vmm::vmm_config::instance_info::{InstanceInfo, VmState}; use vmm::vmm_config::metrics::{init_metrics, MetricsConfig, MetricsConfigError}; use vmm::{EventManager, FcExitCode, HTTP_MAX_PAYLOAD_SIZE}; +use vmm_sys_util::terminal::Terminal; use crate::seccomp::SeccompConfig; @@ -47,7 +47,7 @@ enum MainError { /// Failed to set the logger: {0} SetLogger(vmm::logger::LoggerInitError), /// Failed to register signal handlers: {0} - RegisterSignalHandlers(#[source] utils::errno::Error), + RegisterSignalHandlers(#[source] vmm_sys_util::errno::Error), /// Arguments parsing error: {0} \n\nFor more information try --help. ParseArguments(#[from] utils::arg_parser::UtilsArgParserError), /// When printing Snapshot Data format: {0} diff --git a/src/firecracker/src/metrics.rs b/src/firecracker/src/metrics.rs index a5fdfdd351b..9eaffd47811 100644 --- a/src/firecracker/src/metrics.rs +++ b/src/firecracker/src/metrics.rs @@ -6,8 +6,8 @@ use std::time::Duration; use event_manager::{EventOps, Events, MutEventSubscriber}; use timerfd::{ClockId, SetTimeFlags, TimerFd, TimerState}; -use utils::epoll::EventSet; use vmm::logger::{error, warn, IncMetric, METRICS}; +use vmm_sys_util::epoll::EventSet; /// Metrics reporting period. pub(crate) const WRITE_METRICS_PERIOD_MS: u64 = 60000; diff --git a/src/firecracker/src/seccomp.rs b/src/firecracker/src/seccomp.rs index 5b7e5cc4695..5794d6498a8 100644 --- a/src/firecracker/src/seccomp.rs +++ b/src/firecracker/src/seccomp.rs @@ -119,7 +119,7 @@ mod tests { use std::sync::Arc; use seccompiler::BpfThreadMap; - use utils::tempfile::TempFile; + use vmm_sys_util::tempfile::TempFile; use super::*; diff --git a/src/jailer/Cargo.toml b/src/jailer/Cargo.toml index 95b02784ec7..aeda2959c13 100644 --- a/src/jailer/Cargo.toml +++ b/src/jailer/Cargo.toml @@ -17,6 +17,7 @@ log-instrument = { path = "../log-instrument", optional = true } nix = { version = "0.29.0", default-features = false, features = ["dir"] } regex = { version = "1.10.6", default-features = false, features = ["std"] } thiserror = "1.0.63" +vmm-sys-util = "0.12.1" utils = { path = "../utils" } diff --git a/src/jailer/src/cgroup.rs b/src/jailer/src/cgroup.rs index 57c5b60dda9..e49b1acb317 100644 --- a/src/jailer/src/cgroup.rs +++ b/src/jailer/src/cgroup.rs @@ -504,7 +504,7 @@ pub mod test_util { use std::io::Write; use std::path::{Path, PathBuf}; - use utils::rand; + use vmm_sys_util::rand; #[derive(Debug)] pub struct MockCgroupFs { @@ -617,8 +617,8 @@ mod tests { use std::io::{BufReader, Write}; use std::path::PathBuf; - use utils::tempdir::TempDir; - use utils::tempfile::TempFile; + use vmm_sys_util::tempdir::TempDir; + use vmm_sys_util::tempfile::TempFile; use super::*; use crate::cgroup::test_util::MockCgroupFs; diff --git a/src/jailer/src/chroot.rs b/src/jailer/src/chroot.rs index 85b072a5cf1..44386729196 100644 --- a/src/jailer/src/chroot.rs +++ b/src/jailer/src/chroot.rs @@ -6,7 +6,7 @@ use std::ffi::CStr; use std::path::Path; use std::ptr::null; -use utils::syscall::SyscallReturnCode; +use vmm_sys_util::syscall::SyscallReturnCode; use super::{to_cstring, JailerError}; diff --git a/src/jailer/src/env.rs b/src/jailer/src/env.rs index 1f0cdb7b342..a0c37eac540 100644 --- a/src/jailer/src/env.rs +++ b/src/jailer/src/env.rs @@ -12,9 +12,9 @@ use std::process::{exit, id, Command, Stdio}; use std::{fmt, io}; use utils::arg_parser::UtilsArgParserError::MissingValue; -use utils::syscall::SyscallReturnCode; use utils::time::{get_time_us, ClockType}; use utils::{arg_parser, validators}; +use vmm_sys_util::syscall::SyscallReturnCode; use crate::cgroup::{CgroupConfiguration, CgroupConfigurationBuilder}; use crate::chroot::chroot; @@ -736,9 +736,9 @@ mod tests { use std::fs::create_dir_all; use std::os::linux::fs::MetadataExt; - use utils::rand; - use utils::tempdir::TempDir; - use utils::tempfile::TempFile; + use vmm_sys_util::rand; + use vmm_sys_util::tempdir::TempDir; + use vmm_sys_util::tempfile::TempFile; use super::*; use crate::build_arg_parser; diff --git a/src/jailer/src/main.rs b/src/jailer/src/main.rs index a4132467248..4e00c14762a 100644 --- a/src/jailer/src/main.rs +++ b/src/jailer/src/main.rs @@ -8,9 +8,9 @@ use std::{env as p_env, fs, io}; use env::PROC_MOUNTS; use utils::arg_parser::{ArgParser, Argument, UtilsArgParserError as ParsingError}; -use utils::syscall::SyscallReturnCode; use utils::time::{get_time_us, ClockType}; use utils::validators; +use vmm_sys_util::syscall::SyscallReturnCode; use crate::env::Env; @@ -357,7 +357,7 @@ mod tests { use std::fs::File; use std::os::unix::io::IntoRawFd; - use utils::rand; + use vmm_sys_util::rand; use super::*; diff --git a/src/jailer/src/resource_limits.rs b/src/jailer/src/resource_limits.rs index 4c3f488b9fb..0ca4c3460db 100644 --- a/src/jailer/src/resource_limits.rs +++ b/src/jailer/src/resource_limits.rs @@ -4,7 +4,7 @@ use std::fmt; use std::fmt::{Display, Formatter}; -use utils::syscall::SyscallReturnCode; +use vmm_sys_util::syscall::SyscallReturnCode; use super::JailerError; diff --git a/src/rebase-snap/Cargo.toml b/src/rebase-snap/Cargo.toml index 80dac38f862..4058ccb7a18 100644 --- a/src/rebase-snap/Cargo.toml +++ b/src/rebase-snap/Cargo.toml @@ -14,6 +14,7 @@ displaydoc = "0.2.5" libc = "0.2.158" log-instrument = { path = "../log-instrument", optional = true } thiserror = "1.0.63" +vmm-sys-util = "0.12.1" utils = { path = "../utils" } diff --git a/src/rebase-snap/src/main.rs b/src/rebase-snap/src/main.rs index 1909d9ea9c6..20fd23c416d 100644 --- a/src/rebase-snap/src/main.rs +++ b/src/rebase-snap/src/main.rs @@ -7,7 +7,7 @@ use std::io::{Seek, SeekFrom}; use std::os::unix::io::AsRawFd; use utils::arg_parser::{ArgParser, Argument, Arguments, UtilsArgParserError as ArgError}; -use utils::seek_hole::SeekHole; +use vmm_sys_util::seek_hole::SeekHole; const REBASE_SNAP_VERSION: &str = env!("CARGO_PKG_VERSION"); const BASE_FILE: &str = "base-file"; @@ -160,7 +160,7 @@ mod tests { use std::io::{Seek, SeekFrom, Write}; use std::os::unix::fs::FileExt; - use utils::{rand, tempfile}; + use vmm_sys_util::{rand, tempfile}; use super::*; diff --git a/src/seccompiler/Cargo.toml b/src/seccompiler/Cargo.toml index 2d997696a04..19d86ddefb4 100644 --- a/src/seccompiler/Cargo.toml +++ b/src/seccompiler/Cargo.toml @@ -26,6 +26,9 @@ thiserror = "1.0.63" utils = { path = "../utils" } +[dev-dependencies] +vmm-sys-util = "0.12.1" + [features] tracing = ["log-instrument", "utils/tracing"] diff --git a/src/seccompiler/src/seccompiler_bin.rs b/src/seccompiler/src/seccompiler_bin.rs index c6c97690bf6..890a2a3ecdb 100644 --- a/src/seccompiler/src/seccompiler_bin.rs +++ b/src/seccompiler/src/seccompiler_bin.rs @@ -214,7 +214,7 @@ mod tests { use std::path::PathBuf; use bincode::Error as BincodeError; - use utils::tempfile::TempFile; + use vmm_sys_util::tempfile::TempFile; use super::compiler::CompilationError as FilterFormatError; use super::{ diff --git a/src/snapshot-editor/Cargo.toml b/src/snapshot-editor/Cargo.toml index a042b7a829f..1449e8b9f93 100644 --- a/src/snapshot-editor/Cargo.toml +++ b/src/snapshot-editor/Cargo.toml @@ -19,6 +19,7 @@ log-instrument = { path = "../log-instrument", optional = true } semver = "1.0.23" thiserror = "1.0.63" vmm = { path = "../vmm" } +vmm-sys-util = "0.12.1" [target.'cfg(target_arch = "aarch64")'.dependencies] clap-num = "1.0.2" diff --git a/src/snapshot-editor/src/edit_memory.rs b/src/snapshot-editor/src/edit_memory.rs index 667f7af0960..015354adfc0 100644 --- a/src/snapshot-editor/src/edit_memory.rs +++ b/src/snapshot-editor/src/edit_memory.rs @@ -7,8 +7,8 @@ use std::os::fd::AsRawFd; use std::path::PathBuf; use clap::Subcommand; -use fc_utils::seek_hole::SeekHole; use vmm::utils::u64_to_usize; +use vmm_sys_util::seek_hole::SeekHole; #[derive(Debug, thiserror::Error, displaydoc::Display)] pub enum EditMemoryError { @@ -108,7 +108,7 @@ mod tests { use std::io::{Seek, SeekFrom, Write}; use std::os::unix::fs::FileExt; - use fc_utils::{rand, tempfile}; + use vmm_sys_util::{rand, tempfile}; use super::*; diff --git a/src/utils/Cargo.toml b/src/utils/Cargo.toml index ce6827d0c82..72bda2503de 100644 --- a/src/utils/Cargo.toml +++ b/src/utils/Cargo.toml @@ -16,7 +16,7 @@ log-instrument = { path = "../log-instrument", optional = true } serde = { version = "1.0.210", features = ["derive"] } thiserror = "1.0.63" vm-memory = { version = "0.14.1", features = ["backend-mmap", "backend-bitmap"] } -vmm-sys-util = { version = "0.12.1", features = ["with-serde"] } +vmm-sys-util = "0.12.1" [dev-dependencies] serde_json = "1.0.128" diff --git a/src/utils/src/lib.rs b/src/utils/src/lib.rs index c6e65bd2fe1..5c0b8271b5c 100644 --- a/src/utils/src/lib.rs +++ b/src/utils/src/lib.rs @@ -1,16 +1,6 @@ // Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// We use `utils` as a wrapper over `vmm_sys_util` to control the latter -// dependency easier (i.e. update only in one place `vmm_sys_util` version). -// More specifically, we are re-exporting modules from `vmm_sys_util` as part -// of the `utils` crate. -pub use vmm_sys_util::ioctl::ioctl_expr; -pub use vmm_sys_util::{ - epoll, errno, eventfd, fam, generate_fam_struct_impl, ioctl, ioctl_ioc_nr, ioctl_iow_nr, rand, - seek_hole, sock_ctrl_msg, syscall, tempdir, tempfile, terminal, -}; - pub mod arg_parser; pub mod time; pub mod validators; diff --git a/src/vmm/src/arch/aarch64/vcpu.rs b/src/vmm/src/arch/aarch64/vcpu.rs index 66700917065..5c08f95351a 100644 --- a/src/vmm/src/arch/aarch64/vcpu.rs +++ b/src/vmm/src/arch/aarch64/vcpu.rs @@ -29,7 +29,7 @@ pub enum VcpuError { /// Failed to set multiprocessor state: {0} SetMp(kvm_ioctls::Error), /// Failed FamStructWrapper operation: {0} - Fam(crate::utils::fam::Error), + Fam(vmm_sys_util::fam::Error), /// {0} GetMidrEl1(String), } diff --git a/src/vmm/src/arch/x86_64/interrupts.rs b/src/vmm/src/arch/x86_64/interrupts.rs index 09a2dc6ec84..8b7bf8bc793 100644 --- a/src/vmm/src/arch/x86_64/interrupts.rs +++ b/src/vmm/src/arch/x86_64/interrupts.rs @@ -105,7 +105,7 @@ mod tests { #[test] fn test_apic_delivery_mode() { let mut v: Vec = (0..20) - .map(|_| crate::utils::rand::xor_pseudo_rng_u32()) + .map(|_| vmm_sys_util::rand::xor_pseudo_rng_u32()) .collect(); v.iter_mut() diff --git a/src/vmm/src/arch/x86_64/msr.rs b/src/vmm/src/arch/x86_64/msr.rs index a05fac79961..325d6ed6b29 100644 --- a/src/vmm/src/arch/x86_64/msr.rs +++ b/src/vmm/src/arch/x86_64/msr.rs @@ -16,7 +16,7 @@ use crate::cpu_config::x86_64::cpuid::common::GetCpuidError; /// MSR related errors. pub enum MsrError { /// Failed to create `vmm_sys_util::fam::FamStructWrapper` for MSRs - Fam(#[from] crate::utils::fam::Error), + Fam(#[from] vmm_sys_util::fam::Error), /// Failed to get MSR index list: {0} GetMsrIndexList(kvm_ioctls::Error), /// Invalid CPU vendor: {0} diff --git a/src/vmm/src/arch/x86_64/regs.rs b/src/vmm/src/arch/x86_64/regs.rs index 30e4bf2cc82..aec47677c4c 100644 --- a/src/vmm/src/arch/x86_64/regs.rs +++ b/src/vmm/src/arch/x86_64/regs.rs @@ -44,7 +44,7 @@ pub enum RegsError { /// Error type for [`setup_fpu`]. #[derive(Debug, derive_more::From, PartialEq, Eq, thiserror::Error)] #[error("Failed to setup FPU: {0}")] -pub struct SetupFpuError(crate::utils::errno::Error); +pub struct SetupFpuError(vmm_sys_util::errno::Error); /// Configure Floating-Point Unit (FPU) registers for a given CPU. /// @@ -68,7 +68,7 @@ pub fn setup_fpu(vcpu: &VcpuFd) -> Result<(), SetupFpuError> { /// Error type of [`setup_regs`]. #[derive(Debug, derive_more::From, PartialEq, Eq, thiserror::Error)] #[error("Failed to setup registers: {0}")] -pub struct SetupRegistersError(crate::utils::errno::Error); +pub struct SetupRegistersError(vmm_sys_util::errno::Error); /// Configure base registers for a given CPU. /// @@ -103,13 +103,13 @@ pub fn setup_regs(vcpu: &VcpuFd, boot_ip: u64) -> Result<(), SetupRegistersError #[derive(Debug, thiserror::Error, displaydoc::Display, PartialEq, Eq)] pub enum SetupSpecialRegistersError { /// Failed to get special registers: {0} - GetSpecialRegisters(crate::utils::errno::Error), + GetSpecialRegisters(vmm_sys_util::errno::Error), /// Failed to configure segments and special registers: {0} ConfigureSegmentsAndSpecialRegisters(RegsError), /// Failed to setup page tables: {0} SetupPageTables(RegsError), /// Failed to set special registers: {0} - SetSpecialRegisters(crate::utils::errno::Error), + SetSpecialRegisters(vmm_sys_util::errno::Error), } /// Configures the special registers and system page tables for a given CPU. diff --git a/src/vmm/src/builder.rs b/src/vmm/src/builder.rs index a14c55f35ab..9ef8b4f620c 100644 --- a/src/vmm/src/builder.rs +++ b/src/vmm/src/builder.rs @@ -24,6 +24,7 @@ use vm_memory::ReadVolatile; #[cfg(target_arch = "aarch64")] use vm_superio::Rtc; use vm_superio::Serial; +use vmm_sys_util::eventfd::EventFd; #[cfg(target_arch = "x86_64")] use crate::acpi; @@ -59,7 +60,6 @@ use crate::logger::{debug, error}; use crate::persist::{MicrovmState, MicrovmStateError}; use crate::resources::VmResources; use crate::snapshot::Persist; -use crate::utils::eventfd::EventFd; use crate::utils::u64_to_usize; use crate::vmm_config::boot_source::BootConfig; use crate::vmm_config::instance_info::InstanceInfo; @@ -412,7 +412,7 @@ pub enum BuildMicrovmFromSnapshotError { /// Failed to create microVM and vCPUs: {0} CreateMicrovmAndVcpus(#[from] StartMicrovmError), /// Could not access KVM: {0} - KvmAccess(#[from] crate::utils::errno::Error), + KvmAccess(#[from] vmm_sys_util::errno::Error), /// Error configuring the TSC, frequency not present in the given snapshot. TscFrequencyNotPresent, #[cfg(target_arch = "x86_64")] @@ -1022,6 +1022,7 @@ pub mod tests { use std::io::Write; use linux_loader::cmdline::Cmdline; + use vmm_sys_util::tempfile::TempFile; use super::*; use crate::arch::DeviceType; @@ -1033,7 +1034,6 @@ pub mod tests { use crate::mmds::data_store::{Mmds, MmdsVersion}; use crate::mmds::ns::MmdsNetworkStack; use crate::test_utils::{arch_mem, single_region_mem, single_region_mem_at}; - use crate::utils::tempfile::TempFile; use crate::vmm_config::balloon::{BalloonBuilder, BalloonDeviceConfig, BALLOON_DEV_ID}; use crate::vmm_config::boot_source::DEFAULT_KERNEL_CMDLINE; use crate::vmm_config::drive::{BlockBuilder, BlockDeviceConfig}; diff --git a/src/vmm/src/cpu_config/x86_64/cpuid/mod.rs b/src/vmm/src/cpu_config/x86_64/cpuid/mod.rs index f557ed2e621..2350d30479d 100644 --- a/src/vmm/src/cpu_config/x86_64/cpuid/mod.rs +++ b/src/vmm/src/cpu_config/x86_64/cpuid/mod.rs @@ -410,7 +410,7 @@ impl TryFrom for Cpuid { } impl TryFrom for kvm_bindings::CpuId { - type Error = crate::utils::fam::Error; + type Error = vmm_sys_util::fam::Error; fn try_from(cpuid: Cpuid) -> Result { let entries = cpuid diff --git a/src/vmm/src/device_manager/legacy.rs b/src/vmm/src/device_manager/legacy.rs index 035756f261e..dc46a5172d3 100644 --- a/src/vmm/src/device_manager/legacy.rs +++ b/src/vmm/src/device_manager/legacy.rs @@ -13,11 +13,11 @@ use acpi_tables::{aml, Aml}; use kvm_ioctls::VmFd; use libc::EFD_NONBLOCK; use vm_superio::Serial; +use vmm_sys_util::eventfd::EventFd; use crate::devices::bus::BusDevice; use crate::devices::legacy::serial::SerialOut; use crate::devices::legacy::{EventFdTrigger, SerialDevice, SerialEventsWrapper}; -use crate::utils::eventfd::EventFd; /// Errors corresponding to the `PortIODeviceManager`. #[derive(Debug, derive_more::From, thiserror::Error, displaydoc::Display)] diff --git a/src/vmm/src/device_manager/mmio.rs b/src/vmm/src/device_manager/mmio.rs index 91878babbb9..cba9047d564 100644 --- a/src/vmm/src/device_manager/mmio.rs +++ b/src/vmm/src/device_manager/mmio.rs @@ -529,12 +529,13 @@ mod tests { use std::sync::Arc; + use vmm_sys_util::eventfd::EventFd; + use super::*; use crate::devices::virtio::device::{IrqTrigger, VirtioDevice}; use crate::devices::virtio::queue::Queue; use crate::devices::virtio::ActivateError; use crate::test_utils::multi_region_mem; - use crate::utils::eventfd::EventFd; use crate::vstate::memory::{GuestAddress, GuestMemoryMmap}; use crate::{builder, Vm}; diff --git a/src/vmm/src/device_manager/persist.rs b/src/vmm/src/device_manager/persist.rs index 8b16a2881d6..3a2a49c4811 100644 --- a/src/vmm/src/device_manager/persist.rs +++ b/src/vmm/src/device_manager/persist.rs @@ -652,12 +652,13 @@ impl<'a> Persist<'a> for MMIODeviceManager { #[cfg(test)] mod tests { + use vmm_sys_util::tempfile::TempFile; + use super::*; use crate::builder::tests::*; use crate::devices::virtio::block::CacheType; use crate::resources::VmmConfig; use crate::snapshot::Snapshot; - use crate::utils::tempfile::TempFile; use crate::vmm_config::balloon::BalloonDeviceConfig; use crate::vmm_config::entropy::EntropyDeviceConfig; use crate::vmm_config::net::NetworkInterfaceConfig; diff --git a/src/vmm/src/devices/acpi/vmgenid.rs b/src/vmm/src/devices/acpi/vmgenid.rs index b06d088e25e..24220577ccf 100644 --- a/src/vmm/src/devices/acpi/vmgenid.rs +++ b/src/vmm/src/devices/acpi/vmgenid.rs @@ -8,11 +8,11 @@ use log::{debug, error}; use serde::{Deserialize, Serialize}; use vm_memory::{GuestAddress, GuestMemoryError}; use vm_superio::Trigger; +use vmm_sys_util::eventfd::EventFd; use super::super::legacy::EventFdTrigger; use crate::device_manager::resources::ResourceAllocator; use crate::snapshot::Persist; -use crate::utils::eventfd::EventFd; use crate::vstate::memory::{Bytes, GuestMemoryMmap}; /// Bytes of memory we allocate for VMGenID device diff --git a/src/vmm/src/devices/legacy/i8042.rs b/src/vmm/src/devices/legacy/i8042.rs index 8ab97ce3e9d..8f965cab912 100644 --- a/src/vmm/src/devices/legacy/i8042.rs +++ b/src/vmm/src/devices/legacy/i8042.rs @@ -10,9 +10,9 @@ use std::num::Wrapping; use log::warn; use serde::Serialize; +use vmm_sys_util::eventfd::EventFd; use crate::logger::{error, IncMetric, SharedIncMetric}; -use crate::utils::eventfd::EventFd; /// Errors thrown by the i8042 device. #[derive(Debug, thiserror::Error, displaydoc::Display)] diff --git a/src/vmm/src/devices/legacy/mod.rs b/src/vmm/src/devices/legacy/mod.rs index f84c39207bf..25f332b9617 100644 --- a/src/vmm/src/devices/legacy/mod.rs +++ b/src/vmm/src/devices/legacy/mod.rs @@ -17,6 +17,7 @@ use std::ops::Deref; use serde::ser::SerializeMap; use serde::Serializer; use vm_superio::Trigger; +use vmm_sys_util::eventfd::EventFd; pub use self::i8042::{I8042Device, I8042Error as I8042DeviceError}; #[cfg(target_arch = "aarch64")] @@ -24,7 +25,6 @@ pub use self::rtc_pl031::RTCDevice; pub use self::serial::{ SerialDevice, SerialEventsWrapper, SerialWrapper, IER_RDA_BIT, IER_RDA_OFFSET, }; -use crate::utils::eventfd::EventFd; /// Wrapper for implementing the trigger functionality for `EventFd`. /// diff --git a/src/vmm/src/devices/legacy/serial.rs b/src/vmm/src/devices/legacy/serial.rs index 609afe79077..cd74159dbdc 100644 --- a/src/vmm/src/devices/legacy/serial.rs +++ b/src/vmm/src/devices/legacy/serial.rs @@ -16,10 +16,10 @@ use log::{error, warn}; use serde::Serialize; use vm_superio::serial::{Error as SerialError, SerialEvents}; use vm_superio::{Serial, Trigger}; +use vmm_sys_util::epoll::EventSet; use crate::devices::legacy::EventFdTrigger; use crate::logger::{IncMetric, SharedIncMetric}; -use crate::utils::epoll::EventSet; /// Received Data Available interrupt - for letting the driver know that /// there is some pending data to be processed. @@ -365,9 +365,10 @@ impl mod tests { #![allow(clippy::undocumented_unsafe_blocks)] + use vmm_sys_util::eventfd::EventFd; + use super::*; use crate::logger::IncMetric; - use crate::utils::eventfd::EventFd; #[test] fn test_serial_bus_read() { @@ -418,7 +419,7 @@ mod tests { assert!(is_fifo(fds[1])); // Files arent fifos - let tmp_file = crate::utils::tempfile::TempFile::new().unwrap(); + let tmp_file = vmm_sys_util::tempfile::TempFile::new().unwrap(); assert!(!is_fifo(tmp_file.as_file().as_raw_fd())); } diff --git a/src/vmm/src/devices/virtio/balloon/device.rs b/src/vmm/src/devices/virtio/balloon/device.rs index f4f91e36907..697928ae9c6 100644 --- a/src/vmm/src/devices/virtio/balloon/device.rs +++ b/src/vmm/src/devices/virtio/balloon/device.rs @@ -7,6 +7,7 @@ use std::time::Duration; use log::error; use serde::Serialize; use timerfd::{ClockId, SetTimeFlags, TimerFd, TimerState}; +use vmm_sys_util::eventfd::EventFd; use super::super::device::{DeviceState, VirtioDevice}; use super::super::queue::Queue; @@ -26,7 +27,6 @@ use crate::devices::virtio::balloon::BalloonError; use crate::devices::virtio::device::{IrqTrigger, IrqType}; use crate::devices::virtio::gen::virtio_blk::VIRTIO_F_VERSION_1; use crate::logger::IncMetric; -use crate::utils::eventfd::EventFd; use crate::utils::u64_to_usize; use crate::vstate::memory::{Address, ByteValued, Bytes, GuestAddress, GuestMemoryMmap}; diff --git a/src/vmm/src/devices/virtio/balloon/event_handler.rs b/src/vmm/src/devices/virtio/balloon/event_handler.rs index d554a893e7a..3019d6877de 100644 --- a/src/vmm/src/devices/virtio/balloon/event_handler.rs +++ b/src/vmm/src/devices/virtio/balloon/event_handler.rs @@ -2,12 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 use event_manager::{EventOps, Events, MutEventSubscriber}; +use vmm_sys_util::epoll::EventSet; use super::{report_balloon_event_fail, DEFLATE_INDEX, INFLATE_INDEX, STATS_INDEX}; use crate::devices::virtio::balloon::device::Balloon; use crate::devices::virtio::device::VirtioDevice; use crate::logger::{error, warn}; -use crate::utils::epoll::EventSet; impl Balloon { const PROCESS_ACTIVATE: u32 = 0; diff --git a/src/vmm/src/devices/virtio/block/device.rs b/src/vmm/src/devices/virtio/block/device.rs index afb3c7febd0..7399fe39a0b 100644 --- a/src/vmm/src/devices/virtio/block/device.rs +++ b/src/vmm/src/devices/virtio/block/device.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 use event_manager::{EventOps, Events, MutEventSubscriber}; +use vmm_sys_util::eventfd::EventFd; use super::persist::{BlockConstructorArgs, BlockState}; use super::vhost_user::device::{VhostUserBlock, VhostUserBlockConfig}; @@ -12,7 +13,6 @@ use crate::devices::virtio::queue::Queue; use crate::devices::virtio::{ActivateError, TYPE_BLOCK}; use crate::rate_limiter::BucketUpdate; use crate::snapshot::Persist; -use crate::utils::eventfd::EventFd; use crate::vmm_config::drive::BlockDeviceConfig; use crate::vstate::memory::GuestMemoryMmap; diff --git a/src/vmm/src/devices/virtio/block/vhost_user/device.rs b/src/vmm/src/devices/virtio/block/vhost_user/device.rs index 9b6dda0bd57..62218157c8b 100644 --- a/src/vmm/src/devices/virtio/block/vhost_user/device.rs +++ b/src/vmm/src/devices/virtio/block/vhost_user/device.rs @@ -7,8 +7,10 @@ use std::sync::Arc; use log::error; +use utils::time::{get_time_us, ClockType}; use vhost::vhost_user::message::*; use vhost::vhost_user::Frontend; +use vmm_sys_util::eventfd::EventFd; use super::{VhostUserBlockError, NUM_QUEUES, QUEUE_SIZE}; use crate::devices::virtio::block::CacheType; @@ -24,7 +26,6 @@ use crate::devices::virtio::vhost_user_metrics::{ }; use crate::devices::virtio::{ActivateError, TYPE_BLOCK}; use crate::logger::{log_dev_preview_warning, IncMetric, StoreMetric}; -use crate::utils::eventfd::EventFd; use crate::utils::u64_to_usize; use crate::vmm_config::drive::BlockDeviceConfig; use crate::vstate::memory::GuestMemoryMmap; @@ -162,7 +163,7 @@ impl std::fmt::Debug for VhostUserBlockImpl { impl VhostUserBlockImpl { pub fn new(config: VhostUserBlockConfig) -> Result { log_dev_preview_warning("vhost-user-blk device", Option::None); - let start_time = utils::time::get_time_us(utils::time::ClockType::Monotonic); + let start_time = get_time_us(ClockType::Monotonic); let mut requested_features = AVAILABLE_FEATURES; if config.cache_type == CacheType::Writeback { @@ -213,7 +214,7 @@ impl VhostUserBlockImpl { let vhost_user_block_metrics_name = format!("block_{}", config.drive_id); let metrics = VhostUserMetricsPerDevice::alloc(vhost_user_block_metrics_name); - let delta_us = utils::time::get_time_us(utils::time::ClockType::Monotonic) - start_time; + let delta_us = get_time_us(ClockType::Monotonic) - start_time; metrics.init_time_us.store(delta_us); Ok(Self { @@ -255,7 +256,7 @@ impl VhostUserBlockImpl { } pub fn config_update(&mut self) -> Result<(), VhostUserBlockError> { - let start_time = utils::time::get_time_us(utils::time::ClockType::Monotonic); + let start_time = get_time_us(ClockType::Monotonic); // This buffer is used for config size check in vhost crate. let buffer = [0u8; BLOCK_CONFIG_SPACE_SIZE as usize]; @@ -274,7 +275,7 @@ impl VhostUserBlockImpl { .trigger_irq(IrqType::Config) .map_err(VhostUserBlockError::IrqTrigger)?; - let delta_us = utils::time::get_time_us(utils::time::ClockType::Monotonic) - start_time; + let delta_us = get_time_us(ClockType::Monotonic) - start_time; self.metrics.config_change_time_us.store(delta_us); Ok(()) @@ -336,7 +337,7 @@ impl VirtioDevice for VhostUserBlock .map_err(ActivateError::QueueMemoryError)?; } - let start_time = utils::time::get_time_us(utils::time::ClockType::Monotonic); + let start_time = get_time_us(ClockType::Monotonic); // Setting features again, because now we negotiated them // with guest driver as well. self.vu_handle @@ -353,7 +354,7 @@ impl VirtioDevice for VhostUserBlock ActivateError::VhostUser(err) })?; self.device_state = DeviceState::Activated(mem); - let delta_us = utils::time::get_time_us(utils::time::ClockType::Monotonic) - start_time; + let delta_us = get_time_us(ClockType::Monotonic) - start_time; self.metrics.activate_time_us.store(delta_us); Ok(()) } @@ -371,12 +372,12 @@ mod tests { use std::sync::atomic::Ordering; use vhost::{VhostUserMemoryRegionInfo, VringConfigData}; + use vmm_sys_util::tempfile::TempFile; use super::*; use crate::devices::virtio::block::virtio::device::FileEngineType; use crate::devices::virtio::mmio::VIRTIO_MMIO_INT_CONFIG; use crate::test_utils::create_tmp_socket; - use crate::utils::tempfile::TempFile; use crate::vstate::memory::{FileOffset, GuestAddress, GuestMemoryExtension}; #[test] diff --git a/src/vmm/src/devices/virtio/block/vhost_user/event_handler.rs b/src/vmm/src/devices/virtio/block/vhost_user/event_handler.rs index 8c57f6f599f..4f143995630 100644 --- a/src/vmm/src/devices/virtio/block/vhost_user/event_handler.rs +++ b/src/vmm/src/devices/virtio/block/vhost_user/event_handler.rs @@ -1,11 +1,11 @@ // Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 use event_manager::{EventOps, Events, MutEventSubscriber}; +use vmm_sys_util::epoll::EventSet; use super::VhostUserBlock; use crate::devices::virtio::device::VirtioDevice; use crate::logger::{error, warn}; -use crate::utils::epoll::EventSet; impl VhostUserBlock { const PROCESS_ACTIVATE: u32 = 0; diff --git a/src/vmm/src/devices/virtio/block/virtio/device.rs b/src/vmm/src/devices/virtio/block/virtio/device.rs index 57524157043..fd352fe2539 100644 --- a/src/vmm/src/devices/virtio/block/virtio/device.rs +++ b/src/vmm/src/devices/virtio/block/virtio/device.rs @@ -15,6 +15,7 @@ use std::sync::Arc; use block_io::FileEngine; use serde::{Deserialize, Serialize}; +use vmm_sys_util::eventfd::EventFd; use super::io::async_io; use super::request::*; @@ -33,7 +34,6 @@ use crate::devices::virtio::queue::Queue; use crate::devices::virtio::{ActivateError, TYPE_BLOCK}; use crate::logger::{error, warn, IncMetric}; use crate::rate_limiter::{BucketUpdate, RateLimiter}; -use crate::utils::eventfd::EventFd; use crate::utils::u64_to_usize; use crate::vmm_config::drive::BlockDeviceConfig; use crate::vmm_config::RateLimiterConfig; @@ -678,6 +678,8 @@ mod tests { use std::thread; use std::time::Duration; + use vmm_sys_util::tempfile::TempFile; + use super::*; use crate::check_metric_after_block; use crate::devices::virtio::block::virtio::test_utils::{ @@ -689,7 +691,6 @@ mod tests { use crate::devices::virtio::queue::{VIRTQ_DESC_F_NEXT, VIRTQ_DESC_F_WRITE}; use crate::devices::virtio::test_utils::{default_mem, VirtQueue}; use crate::rate_limiter::TokenType; - use crate::utils::tempfile::TempFile; use crate::vstate::memory::{Address, Bytes, GuestAddress}; #[test] @@ -1083,7 +1084,7 @@ mod tests { let status_addr = GuestAddress(vq.dtable[2].addr.get()); let empty_data = vec![0; 512]; - let rand_data = crate::utils::rand::rand_alphanumerics(1024) + let rand_data = vmm_sys_util::rand::rand_alphanumerics(1024) .as_bytes() .to_vec(); diff --git a/src/vmm/src/devices/virtio/block/virtio/event_handler.rs b/src/vmm/src/devices/virtio/block/virtio/event_handler.rs index 67fe519044c..8400766e06b 100644 --- a/src/vmm/src/devices/virtio/block/virtio/event_handler.rs +++ b/src/vmm/src/devices/virtio/block/virtio/event_handler.rs @@ -1,12 +1,12 @@ // Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 use event_manager::{EventOps, Events, MutEventSubscriber}; +use vmm_sys_util::epoll::EventSet; use super::io::FileEngine; use crate::devices::virtio::block::virtio::device::VirtioBlock; use crate::devices::virtio::device::VirtioDevice; use crate::logger::{error, warn}; -use crate::utils::epoll::EventSet; impl VirtioBlock { const PROCESS_ACTIVATE: u32 = 0; diff --git a/src/vmm/src/devices/virtio/block/virtio/io/async_io.rs b/src/vmm/src/devices/virtio/block/virtio/io/async_io.rs index 7ed9a9f18d1..515ff9ca32c 100644 --- a/src/vmm/src/devices/virtio/block/virtio/io/async_io.rs +++ b/src/vmm/src/devices/virtio/block/virtio/io/async_io.rs @@ -7,6 +7,7 @@ use std::os::fd::RawFd; use std::os::unix::io::AsRawFd; use vm_memory::GuestMemoryError; +use vmm_sys_util::eventfd::EventFd; use crate::devices::virtio::block::virtio::io::UserDataError; use crate::devices::virtio::block::virtio::IO_URING_NUM_ENTRIES; @@ -14,7 +15,6 @@ use crate::io_uring::operation::{Cqe, OpCode, Operation}; use crate::io_uring::restriction::Restriction; use crate::io_uring::{self, IoUring, IoUringError}; use crate::logger::log_dev_preview_warning; -use crate::utils::eventfd::EventFd; use crate::vstate::memory::{GuestAddress, GuestMemory, GuestMemoryExtension, GuestMemoryMmap}; #[derive(Debug, thiserror::Error, displaydoc::Display)] diff --git a/src/vmm/src/devices/virtio/block/virtio/io/mod.rs b/src/vmm/src/devices/virtio/block/virtio/io/mod.rs index 1cb30aeae56..de970986da2 100644 --- a/src/vmm/src/devices/virtio/block/virtio/io/mod.rs +++ b/src/vmm/src/devices/virtio/block/virtio/io/mod.rs @@ -189,9 +189,10 @@ pub mod tests { use std::os::unix::ffi::OsStrExt; use std::os::unix::io::FromRawFd; + use vmm_sys_util::tempfile::TempFile; + use super::*; use crate::devices::virtio::block::virtio::device::FileEngineType; - use crate::utils::tempfile::TempFile; use crate::utils::u64_to_usize; use crate::vmm_config::machine_config::HugePageConfig; use crate::vstate::memory::{Bitmap, Bytes, GuestMemory, GuestMemoryExtension}; @@ -279,7 +280,7 @@ pub mod tests { let file = TempFile::new().unwrap().into_file(); let mut engine = FileEngine::from_file(file, FileEngineType::Sync).unwrap(); - let data = crate::utils::rand::rand_alphanumerics(FILE_LEN as usize) + let data = vmm_sys_util::rand::rand_alphanumerics(FILE_LEN as usize) .as_bytes() .to_vec(); @@ -349,7 +350,7 @@ pub mod tests { let file = TempFile::new().unwrap().into_file(); let mut engine = FileEngine::<()>::from_file(file, FileEngineType::Async).unwrap(); - let data = crate::utils::rand::rand_alphanumerics(FILE_LEN as usize) + let data = vmm_sys_util::rand::rand_alphanumerics(FILE_LEN as usize) .as_bytes() .to_vec(); diff --git a/src/vmm/src/devices/virtio/block/virtio/persist.rs b/src/vmm/src/devices/virtio/block/virtio/persist.rs index 712a83332b2..61bffbeaa40 100644 --- a/src/vmm/src/devices/virtio/block/virtio/persist.rs +++ b/src/vmm/src/devices/virtio/block/virtio/persist.rs @@ -7,6 +7,7 @@ use std::sync::atomic::AtomicU32; use std::sync::Arc; use serde::{Deserialize, Serialize}; +use vmm_sys_util::eventfd::EventFd; use super::device::DiskProperties; use super::*; @@ -20,7 +21,6 @@ use crate::devices::virtio::TYPE_BLOCK; use crate::rate_limiter::persist::RateLimiterState; use crate::rate_limiter::RateLimiter; use crate::snapshot::Persist; -use crate::utils::eventfd::EventFd; /// Holds info about block's file engine type. Gets saved in snapshot. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] @@ -151,12 +151,13 @@ impl Persist<'_> for VirtioBlock { mod tests { use std::sync::atomic::Ordering; + use vmm_sys_util::tempfile::TempFile; + use super::*; use crate::devices::virtio::block::virtio::device::VirtioBlockConfig; use crate::devices::virtio::device::VirtioDevice; use crate::devices::virtio::test_utils::default_mem; use crate::snapshot::Snapshot; - use crate::utils::tempfile::TempFile; #[test] fn test_cache_semantic_ser() { diff --git a/src/vmm/src/devices/virtio/block/virtio/test_utils.rs b/src/vmm/src/devices/virtio/block/virtio/test_utils.rs index e92d53c05bc..106da8177cd 100644 --- a/src/vmm/src/devices/virtio/block/virtio/test_utils.rs +++ b/src/vmm/src/devices/virtio/block/virtio/test_utils.rs @@ -8,6 +8,8 @@ use std::thread; #[cfg(test)] use std::time::Duration; +use vmm_sys_util::tempfile::TempFile; + use super::device::VirtioBlockConfig; use super::RequestHeader; use crate::devices::virtio::block::virtio::device::FileEngineType; @@ -19,7 +21,6 @@ use crate::devices::virtio::device::IrqType; use crate::devices::virtio::queue::{Queue, VIRTQ_DESC_F_NEXT, VIRTQ_DESC_F_WRITE}; use crate::devices::virtio::test_utils::{VirtQueue, VirtqDesc}; use crate::rate_limiter::RateLimiter; -use crate::utils::tempfile::TempFile; use crate::vmm_config::{RateLimiterConfig, TokenBucketConfig}; use crate::vstate::memory::{Bytes, GuestAddress}; diff --git a/src/vmm/src/devices/virtio/device.rs b/src/vmm/src/devices/virtio/device.rs index 759a37a93ca..b5af6862af9 100644 --- a/src/vmm/src/devices/virtio/device.rs +++ b/src/vmm/src/devices/virtio/device.rs @@ -9,12 +9,13 @@ use std::fmt; use std::sync::atomic::{AtomicU32, Ordering}; use std::sync::Arc; +use vmm_sys_util::eventfd::EventFd; + use super::mmio::{VIRTIO_MMIO_INT_CONFIG, VIRTIO_MMIO_INT_VRING}; use super::queue::{Queue, QueueError}; use super::ActivateError; use crate::devices::virtio::AsAny; use crate::logger::{error, warn}; -use crate::utils::eventfd::EventFd; use crate::vstate::memory::GuestMemoryMmap; /// Enum that indicates if a VirtioDevice is inactive or has been activated diff --git a/src/vmm/src/devices/virtio/mmio.rs b/src/vmm/src/devices/virtio/mmio.rs index 585c3c62f33..463d11ca2e2 100644 --- a/src/vmm/src/devices/virtio/mmio.rs +++ b/src/vmm/src/devices/virtio/mmio.rs @@ -373,13 +373,14 @@ impl MmioTransport { #[cfg(test)] pub(crate) mod tests { + use vmm_sys_util::eventfd::EventFd; + use super::*; use crate::devices::virtio::device::IrqTrigger; use crate::devices::virtio::device_status::DEVICE_NEEDS_RESET; use crate::devices::virtio::ActivateError; use crate::test_utils::single_region_mem; use crate::utils::byte_order::{read_le_u32, write_le_u32}; - use crate::utils::eventfd::EventFd; use crate::utils::u64_to_usize; use crate::vstate::memory::GuestMemoryMmap; diff --git a/src/vmm/src/devices/virtio/net/device.rs b/src/vmm/src/devices/virtio/net/device.rs index 5c27ac71267..feb7488cc05 100755 --- a/src/vmm/src/devices/virtio/net/device.rs +++ b/src/vmm/src/devices/virtio/net/device.rs @@ -13,6 +13,7 @@ use std::sync::{Arc, Mutex}; use libc::EAGAIN; use log::{error, warn}; use vm_memory::GuestMemoryError; +use vmm_sys_util::eventfd::EventFd; use crate::devices::virtio::device::{DeviceState, IrqTrigger, IrqType, VirtioDevice}; use crate::devices::virtio::gen::virtio_blk::VIRTIO_F_VERSION_1; @@ -37,7 +38,6 @@ use crate::logger::{IncMetric, METRICS}; use crate::mmds::data_store::Mmds; use crate::mmds::ns::MmdsNetworkStack; use crate::rate_limiter::{BucketUpdate, RateLimiter, TokenType}; -use crate::utils::eventfd::EventFd; use crate::utils::net::mac::MacAddr; use crate::utils::u64_to_usize; use crate::vstate::memory::{ByteValued, Bytes, GuestMemoryMmap}; diff --git a/src/vmm/src/devices/virtio/net/event_handler.rs b/src/vmm/src/devices/virtio/net/event_handler.rs index 7f0eae195d3..1d8805e93fe 100644 --- a/src/vmm/src/devices/virtio/net/event_handler.rs +++ b/src/vmm/src/devices/virtio/net/event_handler.rs @@ -2,12 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 use event_manager::{EventOps, Events, MutEventSubscriber}; +use vmm_sys_util::epoll::EventSet; use crate::devices::virtio::device::VirtioDevice; use crate::devices::virtio::net::device::Net; use crate::devices::virtio::net::{RX_INDEX, TX_INDEX}; use crate::logger::{error, warn, IncMetric}; -use crate::utils::epoll::EventSet; impl Net { const PROCESS_ACTIVATE: u32 = 0; diff --git a/src/vmm/src/devices/virtio/net/tap.rs b/src/vmm/src/devices/virtio/net/tap.rs index 056a615833c..20024a1ae8e 100644 --- a/src/vmm/src/devices/virtio/net/tap.rs +++ b/src/vmm/src/devices/virtio/net/tap.rs @@ -11,10 +11,11 @@ use std::io::{Error as IoError, Read}; use std::os::raw::*; use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; +use vmm_sys_util::ioctl::{ioctl_with_mut_ref, ioctl_with_ref, ioctl_with_val}; +use vmm_sys_util::{ioctl_ioc_nr, ioctl_iow_nr}; + use crate::devices::virtio::iovec::IoVecBuffer; use crate::devices::virtio::net::gen; -use crate::utils::ioctl::{ioctl_with_mut_ref, ioctl_with_ref, ioctl_with_val}; -use crate::utils::{ioctl_ioc_nr, ioctl_iow_nr}; // As defined in the Linux UAPI: // https://elixir.bootlin.com/linux/v4.17/source/include/uapi/linux/if.h#L33 @@ -292,7 +293,7 @@ pub mod tests { enable(&tap); let tap_traffic_simulator = TapTrafficSimulator::new(if_index(&tap)); - let packet = crate::utils::rand::rand_alphanumerics(PAYLOAD_SIZE); + let packet = vmm_sys_util::rand::rand_alphanumerics(PAYLOAD_SIZE); tap_traffic_simulator.push_tx_packet(packet.as_bytes()); let mut buf = [0u8; PACKET_SIZE]; @@ -309,11 +310,11 @@ pub mod tests { enable(&tap); let tap_traffic_simulator = TapTrafficSimulator::new(if_index(&tap)); - let mut fragment1 = crate::utils::rand::rand_bytes(PAYLOAD_SIZE); + let mut fragment1 = vmm_sys_util::rand::rand_bytes(PAYLOAD_SIZE); fragment1.as_mut_slice()[..gen::ETH_HLEN as usize] .copy_from_slice(&[0; gen::ETH_HLEN as usize]); - let fragment2 = crate::utils::rand::rand_bytes(PAYLOAD_SIZE); - let fragment3 = crate::utils::rand::rand_bytes(PAYLOAD_SIZE); + let fragment2 = vmm_sys_util::rand::rand_bytes(PAYLOAD_SIZE); + let fragment3 = vmm_sys_util::rand::rand_bytes(PAYLOAD_SIZE); let scattered = IoVecBuffer::from(vec![ fragment1.as_slice(), diff --git a/src/vmm/src/devices/virtio/net/test_utils.rs b/src/vmm/src/devices/virtio/net/test_utils.rs index 04a00ecb2ba..07808bbb44b 100644 --- a/src/vmm/src/devices/virtio/net/test_utils.rs +++ b/src/vmm/src/devices/virtio/net/test_utils.rs @@ -250,7 +250,7 @@ pub(crate) fn inject_tap_tx_frame(net: &Net, len: usize) -> Vec { assert!(len >= vnet_hdr_len()); let tap_traffic_simulator = TapTrafficSimulator::new(if_index(&net.tap)); - let mut frame = crate::utils::rand::rand_alphanumerics(len - vnet_hdr_len()) + let mut frame = vmm_sys_util::rand::rand_alphanumerics(len - vnet_hdr_len()) .as_bytes() .to_vec(); tap_traffic_simulator.push_tx_packet(&frame); @@ -418,7 +418,7 @@ pub mod test { addr += u64::from(len); // Add small random gaps between descriptor addresses in order to make sure we // don't blindly read contiguous memory. - addr += u64::from(crate::utils::rand::xor_pseudo_rng_u32()) % 10; + addr += u64::from(vmm_sys_util::rand::xor_pseudo_rng_u32()) % 10; } // Mark the chain as available. @@ -480,7 +480,7 @@ pub mod test { // Generates a frame of `frame_len` and writes it to the provided descriptor chain. // Doesn't generate an error if the descriptor chain is longer than `frame_len`. pub fn write_tx_frame(&self, desc_list: &[(u16, u32, u16)], frame_len: usize) -> Vec { - let mut frame = crate::utils::rand::rand_alphanumerics(frame_len) + let mut frame = vmm_sys_util::rand::rand_alphanumerics(frame_len) .as_bytes() .to_vec(); let prefix_len = vnet_hdr_len() + ETH_HLEN as usize; diff --git a/src/vmm/src/devices/virtio/persist.rs b/src/vmm/src/devices/virtio/persist.rs index abf39739fd3..23293a25eab 100644 --- a/src/vmm/src/devices/virtio/persist.rs +++ b/src/vmm/src/devices/virtio/persist.rs @@ -255,6 +255,8 @@ impl Persist<'_> for MmioTransport { #[cfg(test)] mod tests { + use vmm_sys_util::tempfile::TempFile; + use super::*; use crate::devices::virtio::block::virtio::device::FileEngineType; use crate::devices::virtio::block::virtio::test_utils::default_block_with_path; @@ -265,7 +267,6 @@ mod tests { use crate::devices::virtio::test_utils::default_mem; use crate::devices::virtio::vsock::{Vsock, VsockUnixBackend}; use crate::snapshot::Snapshot; - use crate::utils::tempfile::TempFile; const DEFAULT_QUEUE_MAX_SIZE: u16 = 256; impl Default for QueueState { diff --git a/src/vmm/src/devices/virtio/rng/device.rs b/src/vmm/src/devices/virtio/rng/device.rs index 5adadd60b25..4bdea1c40f6 100644 --- a/src/vmm/src/devices/virtio/rng/device.rs +++ b/src/vmm/src/devices/virtio/rng/device.rs @@ -7,6 +7,7 @@ use std::sync::Arc; use aws_lc_rs::rand; use vm_memory::GuestMemoryError; +use vmm_sys_util::eventfd::EventFd; use super::metrics::METRICS; use super::{RNG_NUM_QUEUES, RNG_QUEUE}; @@ -18,7 +19,6 @@ use crate::devices::virtio::{ActivateError, TYPE_RNG}; use crate::devices::DeviceError; use crate::logger::{debug, error, IncMetric}; use crate::rate_limiter::{RateLimiter, TokenType}; -use crate::utils::eventfd::EventFd; use crate::vstate::memory::GuestMemoryMmap; pub const ENTROPY_DEV_ID: &str = "rng"; diff --git a/src/vmm/src/devices/virtio/rng/event_handler.rs b/src/vmm/src/devices/virtio/rng/event_handler.rs index 0d3c6061955..dffda5d8845 100644 --- a/src/vmm/src/devices/virtio/rng/event_handler.rs +++ b/src/vmm/src/devices/virtio/rng/event_handler.rs @@ -2,11 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 use event_manager::{EventOps, Events, MutEventSubscriber}; +use vmm_sys_util::epoll::EventSet; use super::{Entropy, RNG_QUEUE}; use crate::devices::virtio::device::VirtioDevice; use crate::logger::{error, warn}; -use crate::utils::epoll::EventSet; impl Entropy { const PROCESS_ACTIVATE: u32 = 0; diff --git a/src/vmm/src/devices/virtio/test_utils.rs b/src/vmm/src/devices/virtio/test_utils.rs index 031ecf84427..9bb66db82ae 100644 --- a/src/vmm/src/devices/virtio/test_utils.rs +++ b/src/vmm/src/devices/virtio/test_utils.rs @@ -469,7 +469,7 @@ pub(crate) mod test { addr += u64::from(len); // Add small random gaps between descriptor addresses in order to make sure we // don't blindly read contiguous memory. - addr += u64::from(crate::utils::rand::xor_pseudo_rng_u32()) % 10; + addr += u64::from(vmm_sys_util::rand::xor_pseudo_rng_u32()) % 10; } // Mark the chain as available. diff --git a/src/vmm/src/devices/virtio/vhost_user.rs b/src/vmm/src/devices/virtio/vhost_user.rs index a63eed50c57..ad86c9942af 100644 --- a/src/vmm/src/devices/virtio/vhost_user.rs +++ b/src/vmm/src/devices/virtio/vhost_user.rs @@ -11,10 +11,10 @@ use vhost::vhost_user::message::*; use vhost::vhost_user::{Frontend, VhostUserFrontend}; use vhost::{Error as VhostError, VhostBackend, VhostUserMemoryRegionInfo, VringConfigData}; use vm_memory::{Address, Error as MmapError, GuestMemory, GuestMemoryError, GuestMemoryRegion}; +use vmm_sys_util::eventfd::EventFd; use crate::devices::virtio::device::IrqTrigger; use crate::devices::virtio::queue::Queue; -use crate::utils::eventfd::EventFd; use crate::vstate::memory::GuestMemoryMmap; /// vhost-user error. @@ -462,9 +462,10 @@ impl VhostUserHandleImpl { mod tests { #![allow(clippy::undocumented_unsafe_blocks)] + use vmm_sys_util::tempfile::TempFile; + use super::*; use crate::test_utils::create_tmp_socket; - use crate::utils::tempfile::TempFile; use crate::vstate::memory::{FileOffset, GuestAddress, GuestMemoryExtension}; #[test] diff --git a/src/vmm/src/devices/virtio/vhost_user_metrics.rs b/src/vmm/src/devices/virtio/vhost_user_metrics.rs index 87c86e847fb..73b41e6a86c 100644 --- a/src/vmm/src/devices/virtio/vhost_user_metrics.rs +++ b/src/vmm/src/devices/virtio/vhost_user_metrics.rs @@ -143,6 +143,8 @@ pub struct VhostUserDeviceMetrics { #[cfg(test)] pub mod tests { + use utils::time::{get_time_us, ClockType}; + use super::*; use crate::logger::{IncMetric, StoreMetric}; @@ -158,10 +160,10 @@ pub mod tests { #[test] fn test_vhost_user_basic_metrics() { let vhost_user_dev_name: String = String::from("vhost_user_block_drvN"); - let start_time = utils::time::get_time_us(utils::time::ClockType::Monotonic); + let start_time = get_time_us(ClockType::Monotonic); let vhost_user_metrics: Arc = VhostUserMetricsPerDevice::alloc(vhost_user_dev_name.clone()); - let delta_us = utils::time::get_time_us(utils::time::ClockType::Monotonic) - start_time; + let delta_us = get_time_us(ClockType::Monotonic) - start_time; vhost_user_metrics.activate_fails.inc(); assert_eq!(vhost_user_metrics.activate_fails.count(), 1); diff --git a/src/vmm/src/devices/virtio/vsock/csm/connection.rs b/src/vmm/src/devices/virtio/vsock/csm/connection.rs index e43d80eff72..32bb220c3fc 100644 --- a/src/vmm/src/devices/virtio/vsock/csm/connection.rs +++ b/src/vmm/src/devices/virtio/vsock/csm/connection.rs @@ -85,6 +85,7 @@ use std::time::{Duration, Instant}; use log::{debug, error, info, warn}; use vm_memory::io::{ReadVolatile, WriteVolatile}; use vm_memory::GuestMemoryError; +use vmm_sys_util::epoll::EventSet; use super::super::defs::uapi; use super::super::packet::VsockPacket; @@ -93,7 +94,6 @@ use super::txbuf::TxBuf; use super::{defs, ConnState, PendingRx, PendingRxSet, VsockCsmError}; use crate::devices::virtio::vsock::metrics::METRICS; use crate::logger::IncMetric; -use crate::utils::epoll::EventSet; use crate::utils::wrap_usize_to_u32; /// Trait that vsock connection backends need to implement. @@ -685,6 +685,7 @@ mod tests { use std::time::{Duration, Instant}; use vm_memory::{VolatileMemoryError, VolatileSlice}; + use vmm_sys_util::eventfd::EventFd; use super::super::super::defs::uapi; use super::super::defs as csm_defs; @@ -692,7 +693,6 @@ mod tests { use crate::devices::virtio::vsock::device::{RXQ_INDEX, TXQ_INDEX}; use crate::devices::virtio::vsock::test_utils; use crate::devices::virtio::vsock::test_utils::TestContext; - use crate::utils::eventfd::EventFd; use crate::vstate::memory::BitmapSlice; const LOCAL_CID: u64 = 2; diff --git a/src/vmm/src/devices/virtio/vsock/device.rs b/src/vmm/src/devices/virtio/vsock/device.rs index 47b5f5861f6..afd1d8348d4 100644 --- a/src/vmm/src/devices/virtio/vsock/device.rs +++ b/src/vmm/src/devices/virtio/vsock/device.rs @@ -23,6 +23,7 @@ use std::fmt::Debug; use log::{error, warn}; +use vmm_sys_util::eventfd::EventFd; use super::super::super::DeviceError; use super::defs::uapi; @@ -35,7 +36,6 @@ use crate::devices::virtio::vsock::VsockError; use crate::devices::virtio::ActivateError; use crate::logger::IncMetric; use crate::utils::byte_order; -use crate::utils::eventfd::EventFd; use crate::vstate::memory::{Bytes, GuestMemoryMmap}; pub(crate) const RXQ_INDEX: usize = 0; diff --git a/src/vmm/src/devices/virtio/vsock/event_handler.rs b/src/vmm/src/devices/virtio/vsock/event_handler.rs index 03df6a195d6..c35fa1ba77c 100755 --- a/src/vmm/src/devices/virtio/vsock/event_handler.rs +++ b/src/vmm/src/devices/virtio/vsock/event_handler.rs @@ -28,13 +28,13 @@ use std::fmt::Debug; /// buffers. use event_manager::{EventOps, Events, MutEventSubscriber}; use log::{error, warn}; +use vmm_sys_util::epoll::EventSet; use super::device::{Vsock, EVQ_INDEX, RXQ_INDEX, TXQ_INDEX}; use super::VsockBackend; use crate::devices::virtio::device::VirtioDevice; use crate::devices::virtio::vsock::metrics::METRICS; use crate::logger::IncMetric; -use crate::utils::epoll::EventSet; impl Vsock where diff --git a/src/vmm/src/devices/virtio/vsock/mod.rs b/src/vmm/src/devices/virtio/vsock/mod.rs index b3b384c9c0b..7fdc86aed2e 100644 --- a/src/vmm/src/devices/virtio/vsock/mod.rs +++ b/src/vmm/src/devices/virtio/vsock/mod.rs @@ -24,6 +24,7 @@ use std::os::unix::io::AsRawFd; use packet::VsockPacket; use vm_memory::GuestMemoryError; +use vmm_sys_util::epoll::EventSet; pub use self::defs::uapi::VIRTIO_ID_VSOCK as TYPE_VSOCK; pub use self::defs::VSOCK_DEV_ID; @@ -31,7 +32,6 @@ pub use self::device::Vsock; pub use self::unix::{VsockUnixBackend, VsockUnixBackendError}; use crate::devices::virtio::iovec::IoVecError; use crate::devices::virtio::persist::PersistError as VirtioStateError; -use crate::utils::epoll::EventSet; mod defs { use crate::devices::virtio::queue::FIRECRACKER_MAX_QUEUE_SIZE; diff --git a/src/vmm/src/devices/virtio/vsock/test_utils.rs b/src/vmm/src/devices/virtio/vsock/test_utils.rs index 87821f0de17..1e240bcf268 100644 --- a/src/vmm/src/devices/virtio/vsock/test_utils.rs +++ b/src/vmm/src/devices/virtio/vsock/test_utils.rs @@ -6,6 +6,9 @@ use std::os::unix::io::{AsRawFd, RawFd}; +use vmm_sys_util::epoll::EventSet; +use vmm_sys_util::eventfd::EventFd; + use crate::devices::virtio::device::VirtioDevice; use crate::devices::virtio::queue::{VIRTQ_DESC_F_NEXT, VIRTQ_DESC_F_WRITE}; use crate::devices::virtio::test_utils::VirtQueue as GuestQ; @@ -15,8 +18,6 @@ use crate::devices::virtio::vsock::{ Vsock, VsockBackend, VsockChannel, VsockEpollListener, VsockError, }; use crate::test_utils::single_region_mem; -use crate::utils::epoll::EventSet; -use crate::utils::eventfd::EventFd; use crate::vstate::memory::{GuestAddress, GuestMemoryMmap}; #[derive(Debug)] diff --git a/src/vmm/src/devices/virtio/vsock/unix/muxer.rs b/src/vmm/src/devices/virtio/vsock/unix/muxer.rs index 1dfb3a5296f..b9403a83eea 100644 --- a/src/vmm/src/devices/virtio/vsock/unix/muxer.rs +++ b/src/vmm/src/devices/virtio/vsock/unix/muxer.rs @@ -36,6 +36,7 @@ use std::os::unix::io::{AsRawFd, RawFd}; use std::os::unix::net::{UnixListener, UnixStream}; use log::{debug, error, info, warn}; +use vmm_sys_util::epoll::{ControlOperation, Epoll, EpollEvent, EventSet}; use super::super::csm::ConnState; use super::super::defs::uapi; @@ -46,7 +47,6 @@ use super::muxer_rxq::MuxerRxQ; use super::{defs, MuxerConnection, VsockUnixBackendError}; use crate::devices::virtio::vsock::metrics::METRICS; use crate::logger::IncMetric; -use crate::utils::epoll::{ControlOperation, Epoll, EpollEvent, EventSet}; /// A unique identifier of a `MuxerConnection` object. Connections are stored in a hash map, /// keyed by a `ConnMapKey` object. @@ -791,12 +791,13 @@ mod tests { use std::os::unix::net::{UnixListener, UnixStream}; use std::path::{Path, PathBuf}; + use vmm_sys_util::tempfile::TempFile; + use super::super::super::csm::defs as csm_defs; use super::*; use crate::devices::virtio::vsock::device::{RXQ_INDEX, TXQ_INDEX}; use crate::devices::virtio::vsock::test_utils; use crate::devices::virtio::vsock::test_utils::TestContext as VsockTestContext; - use crate::utils::tempfile::TempFile; const PEER_CID: u64 = 3; const PEER_BUF_ALLOC: u32 = 64 * 1024; diff --git a/src/vmm/src/dumbo/tcp/connection.rs b/src/vmm/src/dumbo/tcp/connection.rs index c0c8bf36d4e..8036f428318 100644 --- a/src/vmm/src/dumbo/tcp/connection.rs +++ b/src/vmm/src/dumbo/tcp/connection.rs @@ -10,6 +10,7 @@ use std::fmt::Debug; use std::num::{NonZeroU16, NonZeroU64, NonZeroUsize, Wrapping}; use bitflags::bitflags; +use vmm_sys_util::rand::xor_pseudo_rng_u32; use crate::dumbo::pdu::bytes::NetworkBytes; use crate::dumbo::pdu::tcp::{Flags as TcpFlags, TcpError as TcpSegmentError, TcpSegment}; @@ -18,7 +19,6 @@ use crate::dumbo::tcp::{ seq_after, seq_at_or_after, NextSegmentStatus, RstConfig, MAX_WINDOW_SIZE, MSS_DEFAULT, }; use crate::dumbo::ByteBuffer; -use crate::utils::rand::xor_pseudo_rng_u32; bitflags! { // We use a set of flags, instead of a state machine, to represent the connection status. Some diff --git a/src/vmm/src/io_uring/mod.rs b/src/vmm/src/io_uring/mod.rs index 89e44c45166..3466fd01aa5 100644 --- a/src/vmm/src/io_uring/mod.rs +++ b/src/vmm/src/io_uring/mod.rs @@ -22,8 +22,7 @@ use queue::completion::CompletionQueue; pub use queue::submission::SQueueError; use queue::submission::SubmissionQueue; use restriction::Restriction; - -use crate::utils::syscall::SyscallReturnCode; +use vmm_sys_util::syscall::SyscallReturnCode; // IO_uring operations that we require to be supported by the host kernel. const REQUIRED_OPS: [OpCode; 2] = [OpCode::Read, OpCode::Write]; @@ -38,7 +37,7 @@ pub enum IoUringError { /// Could not enable the ring: {0} Enable(IOError), /// A FamStructWrapper operation has failed: {0} - Fam(crate::utils::fam::Error), + Fam(vmm_sys_util::fam::Error), /// The number of ops in the ring is >= CQ::count FullCQueue, /// Fd was not registered: {0} @@ -389,12 +388,12 @@ mod tests { use proptest::strategy::Strategy; use proptest::test_runner::{Config, TestRunner}; use vm_memory::VolatileMemory; + use vmm_sys_util::syscall::SyscallReturnCode; + use vmm_sys_util::tempfile::TempFile; /// ------------------------------------- /// BEGIN PROPERTY BASED TESTING use super::*; - use crate::utils::syscall::SyscallReturnCode; - use crate::utils::tempfile::TempFile; use crate::vstate::memory::{Bytes, MmapRegion}; fn drain_cqueue(ring: &mut IoUring) { diff --git a/src/vmm/src/io_uring/probe.rs b/src/vmm/src/io_uring/probe.rs index 12f6fb03608..a1f74385815 100644 --- a/src/vmm/src/io_uring/probe.rs +++ b/src/vmm/src/io_uring/probe.rs @@ -1,9 +1,10 @@ // Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +use vmm_sys_util::fam::{FamStruct, FamStructWrapper}; +use vmm_sys_util::generate_fam_struct_impl; + use crate::io_uring::gen::{io_uring_probe, io_uring_probe_op}; -use crate::utils::fam::{FamStruct, FamStructWrapper}; -use crate::utils::generate_fam_struct_impl; // There is no max for the number of operations returned by probing. So we fallback to using the // number of values representable in a u8; diff --git a/src/vmm/src/io_uring/queue/submission.rs b/src/vmm/src/io_uring/queue/submission.rs index d9956b9583d..c8306b40d26 100644 --- a/src/vmm/src/io_uring/queue/submission.rs +++ b/src/vmm/src/io_uring/queue/submission.rs @@ -9,11 +9,11 @@ use std::os::unix::io::RawFd; use std::sync::atomic::Ordering; use vm_memory::{VolatileMemory, VolatileMemoryError}; +use vmm_sys_util::syscall::SyscallReturnCode; use super::mmap::{mmap, MmapError}; use crate::io_uring::gen; use crate::io_uring::operation::Sqe; -use crate::utils::syscall::SyscallReturnCode; use crate::vstate::memory::{Bytes, MmapRegion}; #[derive(Debug, thiserror::Error, displaydoc::Display)] diff --git a/src/vmm/src/lib.rs b/src/vmm/src/lib.rs index 075fb45d173..94dfcfbf409 100644 --- a/src/vmm/src/lib.rs +++ b/src/vmm/src/lib.rs @@ -121,6 +121,9 @@ use devices::acpi::vmgenid::VmGenIdError; use event_manager::{EventManager as BaseEventManager, EventOps, Events, MutEventSubscriber}; use seccompiler::BpfProgram; use userfaultfd::Uffd; +use vmm_sys_util::epoll::EventSet; +use vmm_sys_util::eventfd::EventFd; +use vmm_sys_util::terminal::Terminal; use vstate::vcpu::{self, KvmVcpuConfigureError, StartThreadedError, VcpuSendEventError}; use crate::arch::DeviceType; @@ -139,9 +142,6 @@ use crate::logger::{error, info, warn, MetricsError, METRICS}; use crate::persist::{MicrovmState, MicrovmStateError, VmInfo}; use crate::rate_limiter::BucketUpdate; use crate::snapshot::Persist; -use crate::utils::epoll::EventSet; -use crate::utils::eventfd::EventFd; -use crate::utils::terminal::Terminal; use crate::utils::u64_to_usize; use crate::vmm_config::instance_info::{InstanceInfo, VmState}; use crate::vstate::memory::{ @@ -253,9 +253,9 @@ pub enum VmmError { /// Vm error: {0} Vm(vstate::vm::VmError), /// Error thrown by observer object on Vmm initialization: {0} - VmmObserverInit(crate::utils::errno::Error), + VmmObserverInit(vmm_sys_util::errno::Error), /// Error thrown by observer object on Vmm teardown: {0} - VmmObserverTeardown(crate::utils::errno::Error), + VmmObserverTeardown(vmm_sys_util::errno::Error), /// VMGenID error: {0} VMGenID(#[from] VmGenIdError), } @@ -277,7 +277,7 @@ pub struct EmulateSerialInitError(#[from] std::io::Error); #[derive(Debug, thiserror::Error, displaydoc::Display)] pub enum StartVcpusError { /// VMM observer init error: {0} - VmmObserverInit(#[from] crate::utils::errno::Error), + VmmObserverInit(#[from] vmm_sys_util::errno::Error), /// Vcpu handle error: {0} VcpuHandle(#[from] StartThreadedError), } diff --git a/src/vmm/src/logger/logging.rs b/src/vmm/src/logger/logging.rs index 9a2c2fecdd9..45e8f94d1b0 100644 --- a/src/vmm/src/logger/logging.rs +++ b/src/vmm/src/logger/logging.rs @@ -351,7 +351,7 @@ mod tests { #[test] fn logger() { // Get temp file path. - let file = crate::utils::tempfile::TempFile::new().unwrap(); + let file = vmm_sys_util::tempfile::TempFile::new().unwrap(); let path = file.as_path().to_str().unwrap().to_string(); drop(file); diff --git a/src/vmm/src/logger/metrics.rs b/src/vmm/src/logger/metrics.rs index b07f391ef56..083881645a5 100644 --- a/src/vmm/src/logger/metrics.rs +++ b/src/vmm/src/logger/metrics.rs @@ -68,6 +68,7 @@ use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::{Mutex, OnceLock}; use serde::{Serialize, Serializer}; +use utils::time::{get_time_ns, get_time_us, ClockType}; use super::FcLineWriter; use crate::devices::legacy; @@ -324,7 +325,7 @@ impl ProcessTimeReporter { /// Obtain process start time in microseconds. pub fn report_start_time(&self) { if let Some(start_time) = self.start_time_us { - let delta_us = utils::time::get_time_us(utils::time::ClockType::Monotonic) - start_time; + let delta_us = get_time_us(ClockType::Monotonic) - start_time; METRICS.api_server.process_startup_time_us.store(delta_us); } } @@ -332,8 +333,7 @@ impl ProcessTimeReporter { /// Obtain process CPU start time in microseconds. pub fn report_cpu_start_time(&self) { if let Some(cpu_start_time) = self.start_time_cpu_us { - let delta_us = utils::time::get_time_us(utils::time::ClockType::ProcessCpu) - - cpu_start_time + let delta_us = get_time_us(ClockType::ProcessCpu) - cpu_start_time + self.parent_cpu_time_us.unwrap_or_default(); METRICS .api_server @@ -701,7 +701,7 @@ impl<'a> LatencyMetricsRecorder<'a> { /// Const default construction. fn new(metric: &'a LatencyAggregateMetrics) -> Self { Self { - start_time: utils::time::get_time_us(utils::time::ClockType::Monotonic), + start_time: get_time_us(ClockType::Monotonic), metric, } } @@ -712,8 +712,7 @@ impl<'a> Drop for LatencyMetricsRecorder<'a> { /// and updates min/max/sum metrics. /// self.start_time is recorded in new() and metrics are updated in drop fn drop(&mut self) { - let delta_us = - utils::time::get_time_us(utils::time::ClockType::Monotonic) - self.start_time; + let delta_us = get_time_us(ClockType::Monotonic) - self.start_time; self.metric.sum_us.add(delta_us); let min_us = self.metric.min_us.fetch(); let max_us = self.metric.max_us.fetch(); @@ -836,10 +835,7 @@ impl SerializeToUtcTimestampMs { impl Serialize for SerializeToUtcTimestampMs { fn serialize(&self, serializer: S) -> Result { - serializer.serialize_i64( - i64::try_from(utils::time::get_time_ns(utils::time::ClockType::Real) / 1_000_000) - .unwrap(), - ) + serializer.serialize_i64(i64::try_from(get_time_ns(ClockType::Real) / 1_000_000).unwrap()) } } @@ -956,8 +952,9 @@ mod tests { use std::sync::Arc; use std::thread; + use vmm_sys_util::tempfile::TempFile; + use super::*; - use crate::utils::tempfile::TempFile; #[test] fn test_init() { diff --git a/src/vmm/src/logger/mod.rs b/src/vmm/src/logger/mod.rs index 2c5144e5033..49d765b597b 100644 --- a/src/vmm/src/logger/mod.rs +++ b/src/vmm/src/logger/mod.rs @@ -16,6 +16,7 @@ pub use metrics::{ IncMetric, LatencyAggregateMetrics, MetricsError, ProcessTimeReporter, SharedIncMetric, SharedStoreMetric, StoreMetric, METRICS, }; +use utils::time::{get_time_us, ClockType}; /// Alias for `std::io::LineWriter`. pub type FcLineWriter = std::io::LineWriter; @@ -38,7 +39,7 @@ pub fn log_dev_preview_warning(feature_name: &str, msg_opt: Option) { /// Helper function for updating the value of a store metric with elapsed time since some time in a /// past. pub fn update_metric_with_elapsed_time(metric: &SharedStoreMetric, start_time_us: u64) -> u64 { - let delta_us = utils::time::get_time_us(utils::time::ClockType::Monotonic) - start_time_us; + let delta_us = get_time_us(ClockType::Monotonic) - start_time_us; metric.store(delta_us); delta_us } diff --git a/src/vmm/src/persist.rs b/src/vmm/src/persist.rs index 0c5c5f49037..6410e4d6c9b 100644 --- a/src/vmm/src/persist.rs +++ b/src/vmm/src/persist.rs @@ -15,6 +15,7 @@ use seccompiler::BpfThreadMap; use semver::Version; use serde::{Deserialize, Serialize}; use userfaultfd::{FeatureFlags, Uffd, UffdBuilder}; +use vmm_sys_util::sock_ctrl_msg::ScmSocket; #[cfg(target_arch = "aarch64")] use crate::arch::aarch64::vcpu::{get_manufacturer_id_from_host, get_manufacturer_id_from_state}; @@ -28,7 +29,6 @@ use crate::device_manager::persist::{ACPIDeviceManagerState, DevicePersistError, use crate::logger::{info, warn}; use crate::resources::VmResources; use crate::snapshot::Snapshot; -use crate::utils::sock_ctrl_msg::ScmSocket; use crate::utils::u64_to_usize; use crate::vmm_config::boot_source::BootSourceConfig; use crate::vmm_config::instance_info::InstanceInfo; @@ -534,7 +534,7 @@ pub enum GuestMemoryFromUffdError { /// Failed to connect to UDS Unix stream: {0} Connect(#[from] std::io::Error), /// Failed to sends file descriptor: {0} - Send(#[from] crate::utils::errno::Error), + Send(#[from] vmm_sys_util::errno::Error), } fn guest_memory_from_uffd( @@ -643,6 +643,8 @@ fn send_uffd_handshake( mod tests { use std::os::unix::net::UnixListener; + use vmm_sys_util::tempfile::TempFile; + use super::*; #[cfg(target_arch = "x86_64")] use crate::builder::tests::insert_vmgenid_device; @@ -654,7 +656,6 @@ mod tests { use crate::construct_kvm_mpidrs; use crate::devices::virtio::block::CacheType; use crate::snapshot::Persist; - use crate::utils::tempfile::TempFile; use crate::vmm_config::balloon::BalloonDeviceConfig; use crate::vmm_config::net::NetworkInterfaceConfig; use crate::vmm_config::vsock::tests::default_config; diff --git a/src/vmm/src/resources.rs b/src/vmm/src/resources.rs index d1ac27ee199..c2d2b1c7a9e 100644 --- a/src/vmm/src/resources.rs +++ b/src/vmm/src/resources.rs @@ -501,6 +501,7 @@ mod tests { use std::str::FromStr; use serde_json::{Map, Value}; + use vmm_sys_util::tempfile::TempFile; use super::*; use crate::cpu_config::templates::{CpuTemplateType, StaticCpuTemplate}; @@ -510,7 +511,6 @@ mod tests { use crate::devices::virtio::vsock::VSOCK_DEV_ID; use crate::resources::VmResources; use crate::utils::net::mac::MacAddr; - use crate::utils::tempfile::TempFile; use crate::vmm_config::boot_source::{ BootConfig, BootSource, BootSourceConfig, DEFAULT_KERNEL_CMDLINE, }; diff --git a/src/vmm/src/rpc_interface.rs b/src/vmm/src/rpc_interface.rs index 0a2c6257faa..68fd1a7c37b 100644 --- a/src/vmm/src/rpc_interface.rs +++ b/src/vmm/src/rpc_interface.rs @@ -6,6 +6,7 @@ use std::sync::{Arc, Mutex, MutexGuard}; use seccompiler::BpfThreadMap; use serde_json::Value; +use utils::time::{get_time_us, ClockType}; use super::builder::build_and_boot_microvm; use super::persist::{create_snapshot, restore_from_snapshot}; @@ -324,7 +325,7 @@ impl<'a> PrebootApiController<'a> { instance_info: InstanceInfo, from_api: &std::sync::mpsc::Receiver, to_api: &std::sync::mpsc::Sender, - api_event_fd: &crate::utils::eventfd::EventFd, + api_event_fd: &vmm_sys_util::eventfd::EventFd, boot_timer_enabled: bool, mmds_size_limit: usize, metadata_json: Option<&str>, @@ -555,7 +556,7 @@ impl<'a> PrebootApiController<'a> { ) -> Result { log_dev_preview_warning("Virtual machine snapshots", Option::None); - let load_start_us = utils::time::get_time_us(utils::time::ClockType::Monotonic); + let load_start_us = get_time_us(ClockType::Monotonic); if self.boot_path { let err = LoadSnapshotError::LoadSnapshotNotAllowed; @@ -698,7 +699,7 @@ impl RuntimeApiController { /// Pauses the microVM by pausing the vCPUs. pub fn pause(&mut self) -> Result { - let pause_start_us = utils::time::get_time_us(utils::time::ClockType::Monotonic); + let pause_start_us = get_time_us(ClockType::Monotonic); self.vmm.lock().expect("Poisoned lock").pause_vm()?; @@ -711,7 +712,7 @@ impl RuntimeApiController { /// Resumes the microVM by resuming the vCPUs. pub fn resume(&mut self) -> Result { - let resume_start_us = utils::time::get_time_us(utils::time::ClockType::Monotonic); + let resume_start_us = get_time_us(ClockType::Monotonic); self.vmm.lock().expect("Poisoned lock").resume_vm()?; @@ -764,7 +765,7 @@ impl RuntimeApiController { let mut locked_vmm = self.vmm.lock().unwrap(); let vm_info = VmInfo::from(&self.vm_resources); - let create_start_us = utils::time::get_time_us(utils::time::ClockType::Monotonic); + let create_start_us = get_time_us(ClockType::Monotonic); create_snapshot(&mut locked_vmm, &vm_info, create_params)?; diff --git a/src/vmm/src/signal_handler.rs b/src/vmm/src/signal_handler.rs index 139fb4828ed..5bcfd41fd06 100644 --- a/src/vmm/src/signal_handler.rs +++ b/src/vmm/src/signal_handler.rs @@ -155,7 +155,7 @@ extern "C" fn sigpipe_handler(num: c_int, info: *mut siginfo_t, _unused: *mut c_ /// /// Custom handlers are installed for: `SIGBUS`, `SIGSEGV`, `SIGSYS` /// `SIGXFSZ` `SIGXCPU` `SIGPIPE` `SIGHUP` and `SIGILL`. -pub fn register_signal_handlers() -> crate::utils::errno::Result<()> { +pub fn register_signal_handlers() -> vmm_sys_util::errno::Result<()> { // Call to unsafe register_signal_handler which is considered unsafe because it will // register a signal handler which will be called in the current thread and will interrupt // whatever work is done on the current thread, so we have to keep in mind that the registered diff --git a/src/vmm/src/utils/mod.rs b/src/vmm/src/utils/mod.rs index 447a7260774..a0ee2e90b6b 100644 --- a/src/vmm/src/utils/mod.rs +++ b/src/vmm/src/utils/mod.rs @@ -1,16 +1,6 @@ // Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// We use `utils` as a wrapper over `vmm_sys_util` to control the latter -// dependency easier (i.e. update only in one place `vmm_sys_util` version). -// More specifically, we are re-exporting modules from `vmm_sys_util` as part -// of the `utils` crate. -pub use vmm_sys_util::ioctl::ioctl_expr; -pub use vmm_sys_util::{ - epoll, errno, eventfd, fam, generate_fam_struct_impl, ioctl, ioctl_ioc_nr, ioctl_iow_nr, rand, - seek_hole, sock_ctrl_msg, syscall, tempdir, tempfile, terminal, -}; - /// Module with helpers to read/write bytes into slices pub mod byte_order; /// Module with network related helpers @@ -24,10 +14,10 @@ use std::num::Wrapping; use std::result::Result; /// Return the default page size of the platform, in bytes. -pub fn get_page_size() -> Result { +pub fn get_page_size() -> Result { // SAFETY: Safe because the parameters are valid. match unsafe { libc::sysconf(libc::_SC_PAGESIZE) } { - -1 => Err(errno::Error::last()), + -1 => Err(vmm_sys_util::errno::Error::last()), ps => Ok(usize::try_from(ps).unwrap()), } } diff --git a/src/vmm/src/vmm_config/boot_source.rs b/src/vmm/src/vmm_config/boot_source.rs index 37c9a32ed79..c40a0fde014 100644 --- a/src/vmm/src/vmm_config/boot_source.rs +++ b/src/vmm/src/vmm_config/boot_source.rs @@ -99,9 +99,10 @@ impl BootConfig { #[cfg(test)] pub(crate) mod tests { + use vmm_sys_util::tempfile::TempFile; + use super::*; use crate::snapshot::Snapshot; - use crate::utils::tempfile::TempFile; #[test] fn test_boot_config() { diff --git a/src/vmm/src/vmm_config/drive.rs b/src/vmm/src/vmm_config/drive.rs index 83c4ef5d066..cdfc732d48b 100644 --- a/src/vmm/src/vmm_config/drive.rs +++ b/src/vmm/src/vmm_config/drive.rs @@ -177,9 +177,10 @@ impl BlockBuilder { #[cfg(test)] mod tests { + use vmm_sys_util::tempfile::TempFile; + use super::*; use crate::devices::virtio::block::virtio::VirtioBlockError; - use crate::utils::tempfile::TempFile; impl PartialEq for DriveError { fn eq(&self, other: &DriveError) -> bool { diff --git a/src/vmm/src/vmm_config/metrics.rs b/src/vmm/src/vmm_config/metrics.rs index abe6ede92db..604c30e07b3 100644 --- a/src/vmm/src/vmm_config/metrics.rs +++ b/src/vmm/src/vmm_config/metrics.rs @@ -36,8 +36,9 @@ pub fn init_metrics(metrics_cfg: MetricsConfig) -> Result<(), MetricsConfigError #[cfg(test)] mod tests { + use vmm_sys_util::tempfile::TempFile; + use super::*; - use crate::utils::tempfile::TempFile; #[test] fn test_init_metrics() { diff --git a/src/vmm/src/vmm_config/vsock.rs b/src/vmm/src/vmm_config/vsock.rs index ed38b1e8de3..920e4a4d217 100644 --- a/src/vmm/src/vmm_config/vsock.rs +++ b/src/vmm/src/vmm_config/vsock.rs @@ -112,9 +112,10 @@ impl VsockBuilder { #[cfg(test)] pub(crate) mod tests { + use vmm_sys_util::tempfile::TempFile; + use super::*; use crate::devices::virtio::vsock::VSOCK_DEV_ID; - use crate::utils::tempfile::TempFile; pub(crate) fn default_config(tmp_sock_file: &TempFile) -> VsockDeviceConfig { VsockDeviceConfig { diff --git a/src/vmm/src/vstate/memory.rs b/src/vmm/src/vstate/memory.rs index f2f1bf8445a..a84fd6c4be4 100644 --- a/src/vmm/src/vstate/memory.rs +++ b/src/vmm/src/vstate/memory.rs @@ -17,8 +17,9 @@ pub use vm_memory::{ GuestUsize, MemoryRegionAddress, MmapRegion, }; use vm_memory::{Error as VmMemoryError, GuestMemoryError, WriteVolatile}; +use vmm_sys_util::errno; -use crate::utils::{errno, get_page_size, u64_to_usize}; +use crate::utils::{get_page_size, u64_to_usize}; use crate::vmm_config::machine_config::HugePageConfig; use crate::DirtyBitmap; @@ -425,10 +426,11 @@ mod tests { use std::collections::HashMap; use std::io::{Read, Seek}; + use vmm_sys_util::tempfile::TempFile; + use super::*; use crate::snapshot::Snapshot; use crate::utils::get_page_size; - use crate::utils::tempfile::TempFile; #[test] fn test_from_raw_regions() { diff --git a/src/vmm/src/vstate/vcpu/mod.rs b/src/vmm/src/vstate/vcpu/mod.rs index cd56eb66ce0..89b167bbd5b 100644 --- a/src/vmm/src/vstate/vcpu/mod.rs +++ b/src/vmm/src/vstate/vcpu/mod.rs @@ -16,11 +16,11 @@ use kvm_ioctls::VcpuExit; use libc::{c_int, c_void, siginfo_t}; use log::{error, info, warn}; use seccompiler::{BpfProgram, BpfProgramRef}; +use vmm_sys_util::errno; +use vmm_sys_util::eventfd::EventFd; use crate::cpu_config::templates::{CpuConfiguration, GuestConfigError}; use crate::logger::{IncMetric, METRICS}; -use crate::utils::errno; -use crate::utils::eventfd::EventFd; use crate::utils::signal::{register_signal_handler, sigrtmin, Killable}; use crate::utils::sm::StateMachine; use crate::vstate::vm::Vm; @@ -49,7 +49,7 @@ pub enum VcpuError { /// Received error signaling kvm exit: {0} FaultyKvmExit(String), /// Failed to signal vcpu: {0} - SignalVcpu(crate::utils::errno::Error), + SignalVcpu(vmm_sys_util::errno::Error), /// Unexpected kvm exit received: {0} UnhandledKvmExit(String), /// Failed to run action on vcpu: {0} @@ -620,7 +620,7 @@ pub struct VcpuHandle { /// Error type for [`VcpuHandle::send_event`]. #[derive(Debug, derive_more::From, thiserror::Error)] #[error("Failed to signal vCPU: {0}")] -pub struct VcpuSendEventError(pub crate::utils::errno::Error); +pub struct VcpuSendEventError(pub vmm_sys_util::errno::Error); impl VcpuHandle { /// Creates a new [`VcpuHandle`]. @@ -699,13 +699,13 @@ pub mod tests { use std::sync::{Arc, Barrier, Mutex}; use linux_loader::loader::KernelLoader; + use vmm_sys_util::errno; use super::*; use crate::builder::StartMicrovmError; use crate::devices::bus::DummyDevice; use crate::devices::BusDevice; use crate::seccomp_filters::get_empty_filters; - use crate::utils::errno; use crate::utils::signal::validate_signal_num; use crate::vstate::memory::{GuestAddress, GuestMemoryMmap}; use crate::vstate::vcpu::VcpuError as EmulationError; @@ -898,7 +898,7 @@ pub mod tests { entry_addr.unwrap().kernel_load } - fn vcpu_configured_for_boot() -> (VcpuHandle, crate::utils::eventfd::EventFd) { + fn vcpu_configured_for_boot() -> (VcpuHandle, vmm_sys_util::eventfd::EventFd) { Vcpu::register_kick_signal_handler(); // Need enough mem to boot linux. let mem_size = 64 << 20; diff --git a/src/vmm/src/vstate/vcpu/x86_64.rs b/src/vmm/src/vstate/vcpu/x86_64.rs index bf8b13bf268..6fee3933435 100644 --- a/src/vmm/src/vstate/vcpu/x86_64.rs +++ b/src/vmm/src/vstate/vcpu/x86_64.rs @@ -15,6 +15,7 @@ use kvm_bindings::{ use kvm_ioctls::{VcpuExit, VcpuFd}; use log::{error, warn}; use serde::{Deserialize, Serialize}; +use vmm_sys_util::fam; use crate::arch::x86_64::gen::msr_index::{MSR_IA32_TSC, MSR_IA32_TSC_DEADLINE}; use crate::arch::x86_64::interrupts; @@ -22,7 +23,6 @@ use crate::arch::x86_64::msr::{create_boot_msr_entries, MsrError}; use crate::arch::x86_64::regs::{SetupFpuError, SetupRegistersError, SetupSpecialRegistersError}; use crate::cpu_config::x86_64::{cpuid, CpuConfiguration}; use crate::logger::{IncMetric, METRICS}; -use crate::utils::fam; use crate::vstate::memory::{Address, GuestAddress, GuestMemoryMmap}; use crate::vstate::vcpu::{VcpuConfig, VcpuEmulation}; use crate::vstate::vm::Vm; @@ -50,7 +50,7 @@ pub enum KvmVcpuError { /// Failed to convert `kvm_bindings::CpuId` to `Cpuid`: {0} ConvertCpuidType(#[from] cpuid::CpuidTryFromKvmCpuid), /// Failed FamStructWrapper operation: {0} - Fam(#[from] crate::utils::fam::Error), + Fam(#[from] vmm_sys_util::fam::Error), /// Failed to get dumpable MSR index list: {0} GetMsrsToDump(#[from] crate::arch::x86_64::msr::MsrError), /// Cannot open the VCPU file descriptor: {0} @@ -106,7 +106,7 @@ pub enum KvmVcpuError { /// Error type for [`KvmVcpu::get_tsc_khz`] and [`KvmVcpu::is_tsc_scaling_required`]. #[derive(Debug, thiserror::Error, derive_more::From, Eq, PartialEq)] #[error("{0}")] -pub struct GetTscError(crate::utils::errno::Error); +pub struct GetTscError(vmm_sys_util::errno::Error); /// Error type for [`KvmVcpu::set_tsc_khz`]. #[derive(Debug, thiserror::Error, Eq, PartialEq)] @@ -117,11 +117,11 @@ pub struct SetTscError(#[from] kvm_ioctls::Error); #[derive(Debug, thiserror::Error, displaydoc::Display, Eq, PartialEq)] pub enum KvmVcpuConfigureError { /// Failed to convert `Cpuid` to `kvm_bindings::CpuId`: {0} - ConvertCpuidType(#[from] crate::utils::fam::Error), + ConvertCpuidType(#[from] vmm_sys_util::fam::Error), /// Failed to apply modifications to CPUID: {0} NormalizeCpuidError(#[from] cpuid::NormalizeCpuidError), /// Failed to set CPUID: {0} - SetCpuid(#[from] crate::utils::errno::Error), + SetCpuid(#[from] vmm_sys_util::errno::Error), /// Failed to set MSRs: {0} SetMsrs(#[from] MsrError), /// Failed to setup registers: {0} diff --git a/src/vmm/tests/devices.rs b/src/vmm/tests/devices.rs index 28f5b1ed040..1850bf540b0 100644 --- a/src/vmm/tests/devices.rs +++ b/src/vmm/tests/devices.rs @@ -11,7 +11,7 @@ use libc::EFD_NONBLOCK; use vm_superio::Serial; use vmm::devices::legacy::serial::SerialOut; use vmm::devices::legacy::{EventFdTrigger, SerialEventsWrapper, SerialWrapper}; -use vmm::utils::eventfd::EventFd; +use vmm_sys_util::eventfd::EventFd; fn create_serial( pipe: c_int, diff --git a/src/vmm/tests/integration_tests.rs b/src/vmm/tests/integration_tests.rs index 40e230496c4..4312c6345db 100644 --- a/src/vmm/tests/integration_tests.rs +++ b/src/vmm/tests/integration_tests.rs @@ -5,7 +5,6 @@ use std::io::{Seek, SeekFrom}; use std::thread; use std::time::Duration; -use utils::tempfile::TempFile; use vmm::builder::build_and_boot_microvm; use vmm::devices::virtio::block::CacheType; use vmm::persist::{snapshot_state_sanity_check, MicrovmState, MicrovmStateError, VmInfo}; @@ -30,6 +29,7 @@ use vmm::vmm_config::snapshot::{ }; use vmm::vmm_config::vsock::VsockDeviceConfig; use vmm::{DumpCpuConfigError, EventManager, FcExitCode}; +use vmm_sys_util::tempfile::TempFile; #[test] fn test_build_and_boot_microvm() { diff --git a/src/vmm/tests/io_uring.rs b/src/vmm/tests/io_uring.rs index 5ee5a389d35..0a4ba2301d1 100644 --- a/src/vmm/tests/io_uring.rs +++ b/src/vmm/tests/io_uring.rs @@ -7,10 +7,10 @@ use std::thread; use std::time::Duration; use vm_memory::VolatileMemory; -use vmm::utils::epoll::{ControlOperation, Epoll, EpollEvent, EventSet}; -use vmm::utils::eventfd::EventFd; -use vmm::utils::tempfile::TempFile; use vmm::vstate::memory::{Bytes, MmapRegion}; +use vmm_sys_util::epoll::{ControlOperation, Epoll, EpollEvent, EventSet}; +use vmm_sys_util::eventfd::EventFd; +use vmm_sys_util::tempfile::TempFile; mod test_utils { use vm_memory::VolatileMemory;