Skip to content

Commit 3c3c15b

Browse files
committed
refactor(vmm): copy part of utils to vmm/utils
Most modules in `utils` are `vmm` specific, so copy them into `vmm/utils`. The actual removal of those files from `utils` will happen in later commit. Signed-off-by: Egor Lazarchuk <[email protected]>
1 parent 1bbe0a0 commit 3c3c15b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+732
-180
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/vmm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ vhost = { version = "0.11.0", features = ["vhost-user-frontend"] }
4343
vm-allocator = "0.1.0"
4444
vm-memory = { version = "0.14.1", features = ["backend-mmap", "backend-bitmap"] }
4545
vm-superio = "0.8.0"
46+
vmm-sys-util = { version = "0.12.1", features = ["with-serde"] }
4647
zerocopy = { version = "0.7.35" }
4748

4849
[target.'cfg(target_arch = "aarch64")'.dependencies]

src/vmm/src/arch/aarch64/vcpu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub enum VcpuError {
2929
/// Failed to set multiprocessor state: {0}
3030
SetMp(kvm_ioctls::Error),
3131
/// Failed FamStructWrapper operation: {0}
32-
Fam(utils::fam::Error),
32+
Fam(crate::utils::fam::Error),
3333
/// {0}
3434
GetMidrEl1(String),
3535
}

src/vmm/src/arch/x86_64/interrupts.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
use kvm_bindings::kvm_lapic_state;
99
use kvm_ioctls::VcpuFd;
10-
use utils::byte_order;
10+
11+
use crate::utils::byte_order;
1112

1213
/// Errors thrown while configuring the LAPIC.
1314
#[derive(Debug, thiserror::Error, displaydoc::Display, PartialEq, Eq)]
@@ -103,7 +104,9 @@ mod tests {
103104

104105
#[test]
105106
fn test_apic_delivery_mode() {
106-
let mut v: Vec<u32> = (0..20).map(|_| utils::rand::xor_pseudo_rng_u32()).collect();
107+
let mut v: Vec<u32> = (0..20)
108+
.map(|_| crate::utils::rand::xor_pseudo_rng_u32())
109+
.collect();
107110

108111
v.iter_mut()
109112
.for_each(|x| *x = set_apic_delivery_mode(*x, 2));

src/vmm/src/arch/x86_64/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ pub mod gen;
2424
use linux_loader::configurator::linux::LinuxBootConfigurator;
2525
use linux_loader::configurator::{BootConfigurator, BootParams};
2626
use linux_loader::loader::bootparam::boot_params;
27-
use utils::u64_to_usize;
2827

2928
use crate::arch::InitrdConfig;
3029
use crate::device_manager::resources::ResourceAllocator;
30+
use crate::utils::u64_to_usize;
3131
use crate::vstate::memory::{
3232
Address, GuestAddress, GuestMemory, GuestMemoryMmap, GuestMemoryRegion,
3333
};

src/vmm/src/arch/x86_64/msr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::cpu_config::x86_64::cpuid::common::GetCpuidError;
1616
/// MSR related errors.
1717
pub enum MsrError {
1818
/// Failed to create `vmm_sys_util::fam::FamStructWrapper` for MSRs
19-
Fam(#[from] utils::fam::Error),
19+
Fam(#[from] crate::utils::fam::Error),
2020
/// Failed to get MSR index list: {0}
2121
GetMsrIndexList(kvm_ioctls::Error),
2222
/// Invalid CPU vendor: {0}

src/vmm/src/arch/x86_64/regs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub enum RegsError {
4444
/// Error type for [`setup_fpu`].
4545
#[derive(Debug, derive_more::From, PartialEq, Eq, thiserror::Error)]
4646
#[error("Failed to setup FPU: {0}")]
47-
pub struct SetupFpuError(utils::errno::Error);
47+
pub struct SetupFpuError(crate::utils::errno::Error);
4848

4949
/// Configure Floating-Point Unit (FPU) registers for a given CPU.
5050
///
@@ -68,7 +68,7 @@ pub fn setup_fpu(vcpu: &VcpuFd) -> Result<(), SetupFpuError> {
6868
/// Error type of [`setup_regs`].
6969
#[derive(Debug, derive_more::From, PartialEq, Eq, thiserror::Error)]
7070
#[error("Failed to setup registers: {0}")]
71-
pub struct SetupRegistersError(utils::errno::Error);
71+
pub struct SetupRegistersError(crate::utils::errno::Error);
7272

7373
/// Configure base registers for a given CPU.
7474
///
@@ -103,13 +103,13 @@ pub fn setup_regs(vcpu: &VcpuFd, boot_ip: u64) -> Result<(), SetupRegistersError
103103
#[derive(Debug, thiserror::Error, displaydoc::Display, PartialEq, Eq)]
104104
pub enum SetupSpecialRegistersError {
105105
/// Failed to get special registers: {0}
106-
GetSpecialRegisters(utils::errno::Error),
106+
GetSpecialRegisters(crate::utils::errno::Error),
107107
/// Failed to configure segments and special registers: {0}
108108
ConfigureSegmentsAndSpecialRegisters(RegsError),
109109
/// Failed to setup page tables: {0}
110110
SetupPageTables(RegsError),
111111
/// Failed to set special registers: {0}
112-
SetSpecialRegisters(utils::errno::Error),
112+
SetSpecialRegisters(crate::utils::errno::Error),
113113
}
114114

115115
/// Configures the special registers and system page tables for a given CPU.

src/vmm/src/builder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ use linux_loader::loader::pe::PE as Loader;
1919
use linux_loader::loader::KernelLoader;
2020
use seccompiler::BpfThreadMap;
2121
use userfaultfd::Uffd;
22-
use utils::eventfd::EventFd;
2322
use utils::time::TimestampUs;
24-
use utils::u64_to_usize;
2523
use vm_memory::ReadVolatile;
2624
#[cfg(target_arch = "aarch64")]
2725
use vm_superio::Rtc;
@@ -61,6 +59,8 @@ use crate::logger::{debug, error};
6159
use crate::persist::{MicrovmState, MicrovmStateError};
6260
use crate::resources::VmResources;
6361
use crate::snapshot::Persist;
62+
use crate::utils::eventfd::EventFd;
63+
use crate::utils::u64_to_usize;
6464
use crate::vmm_config::boot_source::BootConfig;
6565
use crate::vmm_config::instance_info::InstanceInfo;
6666
use crate::vmm_config::machine_config::{VmConfig, VmConfigError};
@@ -412,7 +412,7 @@ pub enum BuildMicrovmFromSnapshotError {
412412
/// Failed to create microVM and vCPUs: {0}
413413
CreateMicrovmAndVcpus(#[from] StartMicrovmError),
414414
/// Could not access KVM: {0}
415-
KvmAccess(#[from] utils::errno::Error),
415+
KvmAccess(#[from] crate::utils::errno::Error),
416416
/// Error configuring the TSC, frequency not present in the given snapshot.
417417
TscFrequencyNotPresent,
418418
#[cfg(target_arch = "x86_64")]
@@ -1022,7 +1022,6 @@ pub mod tests {
10221022
use std::io::Write;
10231023

10241024
use linux_loader::cmdline::Cmdline;
1025-
use utils::tempfile::TempFile;
10261025

10271026
use super::*;
10281027
use crate::arch::DeviceType;
@@ -1034,6 +1033,7 @@ pub mod tests {
10341033
use crate::mmds::data_store::{Mmds, MmdsVersion};
10351034
use crate::mmds::ns::MmdsNetworkStack;
10361035
use crate::test_utils::{arch_mem, single_region_mem, single_region_mem_at};
1036+
use crate::utils::tempfile::TempFile;
10371037
use crate::vmm_config::balloon::{BalloonBuilder, BalloonDeviceConfig, BALLOON_DEV_ID};
10381038
use crate::vmm_config::boot_source::DEFAULT_KERNEL_CMDLINE;
10391039
use crate::vmm_config::drive::{BlockBuilder, BlockDeviceConfig};

src/vmm/src/cpu_config/x86_64/cpuid/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ impl TryFrom<kvm_bindings::CpuId> for Cpuid {
410410
}
411411

412412
impl TryFrom<Cpuid> for kvm_bindings::CpuId {
413-
type Error = utils::fam::Error;
413+
type Error = crate::utils::fam::Error;
414414

415415
fn try_from(cpuid: Cpuid) -> Result<Self, Self::Error> {
416416
let entries = cpuid

src/vmm/src/device_manager/legacy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ use std::sync::{Arc, Mutex};
1212
use acpi_tables::{aml, Aml};
1313
use kvm_ioctls::VmFd;
1414
use libc::EFD_NONBLOCK;
15-
use utils::eventfd::EventFd;
1615
use vm_superio::Serial;
1716

1817
use crate::devices::bus::BusDevice;
1918
use crate::devices::legacy::serial::SerialOut;
2019
use crate::devices::legacy::{EventFdTrigger, SerialDevice, SerialEventsWrapper};
20+
use crate::utils::eventfd::EventFd;
2121

2222
/// Errors corresponding to the `PortIODeviceManager`.
2323
#[derive(Debug, derive_more::From, thiserror::Error, displaydoc::Display)]

0 commit comments

Comments
 (0)