Skip to content

Commit

Permalink
misc: Adapt consistent import style formatting
Browse files Browse the repository at this point in the history
Historically the Cloud Hypervisor coding style has been to ensure that
all imports are ordered and placed in a single group. Unfortunately
cargo fmt has no support for ensuring that all imports are in a single
group so if whitespace lines were added as part of the import statements
then they would only be odered correctly in the group.

By adopting "group_imports="StdExternalCrate" we can enforce a style
where imports are placed in at most three groups for std, external
crates and the crate itself. Choosing a style enforceable by the tooling
reduces the reviewer burden.

Signed-off-by: Rob Bradford <[email protected]>
  • Loading branch information
rbradford committed Sep 29, 2024
1 parent 6e4aefe commit 88a9f79
Show file tree
Hide file tree
Showing 153 changed files with 1,137 additions and 876 deletions.
3 changes: 2 additions & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
edition = "2021"
edition = "2021"
group_imports="StdExternalCrate"
1 change: 1 addition & 0 deletions api_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use std::io::{Read, Write};
use std::os::unix::io::RawFd;

use thiserror::Error;
use vmm_sys_util::sock_ctrl_msg::ScmSocket;

Expand Down
17 changes: 9 additions & 8 deletions arch/src/aarch64/fdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,30 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the THIRD-PARTY file.

use crate::{NumaNodes, PciSpaceInfo};
use byteorder::{BigEndian, ByteOrder};
use hypervisor::arch::aarch64::gic::Vgic;
use std::cmp;
use std::collections::HashMap;
use std::ffi::CStr;
use std::fmt::Debug;
use std::fs;
use std::path::Path;
use std::result;
use std::str;
use std::sync::{Arc, Mutex};

use byteorder::{BigEndian, ByteOrder};
use hypervisor::arch::aarch64::gic::Vgic;
use thiserror::Error;
use vm_fdt::{FdtWriter, FdtWriterResult};
use vm_memory::{Address, Bytes, GuestMemory, GuestMemoryError, GuestMemoryRegion};

use super::super::DeviceType;
use super::super::GuestMemoryMmap;
use super::super::InitramfsConfig;
use super::layout::{
IRQ_BASE, MEM_32BIT_DEVICES_SIZE, MEM_32BIT_DEVICES_START, MEM_PCI_IO_SIZE, MEM_PCI_IO_START,
PCI_HIGH_BASE, PCI_MMIO_CONFIG_SIZE_PER_SEGMENT,
};
use std::fs;
use std::path::Path;
use thiserror::Error;
use vm_fdt::{FdtWriter, FdtWriterResult};
use vm_memory::{Address, Bytes, GuestMemory, GuestMemoryError, GuestMemoryRegion};
use crate::{NumaNodes, PciSpaceInfo};

// This is a value for uniquely identifying the FDT node declaring the interrupt controller.
const GIC_PHANDLE: u32 = 1;
Expand Down
10 changes: 6 additions & 4 deletions arch/src/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ pub mod regs;
/// Module for loading UEFI binary.
pub mod uefi;

pub use self::fdt::DeviceInfoForFdt;
use crate::{DeviceType, GuestMemoryMmap, NumaNodes, PciSpaceInfo, RegionType};
use hypervisor::arch::aarch64::gic::Vgic;
use log::{log_enabled, Level};
use std::collections::HashMap;
use std::fmt::Debug;
use std::sync::{Arc, Mutex};

use hypervisor::arch::aarch64::gic::Vgic;
use log::{log_enabled, Level};
use thiserror::Error;
use vm_memory::{Address, GuestAddress, GuestMemory, GuestMemoryAtomic};

pub use self::fdt::DeviceInfoForFdt;
use crate::{DeviceType, GuestMemoryMmap, NumaNodes, PciSpaceInfo, RegionType};

pub const _NSIG: i32 = 65;

/// Errors thrown while configuring aarch64 system.
Expand Down
1 change: 1 addition & 0 deletions arch/src/aarch64/uefi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use std::io::{Read, Seek, SeekFrom};
use std::os::fd::AsFd;
use std::result;

use thiserror::Error;
use vm_memory::{GuestAddress, GuestMemory};

Expand Down
8 changes: 5 additions & 3 deletions arch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
#[macro_use]
extern crate log;

#[cfg(target_arch = "x86_64")]
use crate::x86_64::SgxEpcSection;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use std::fmt;
use std::result;
use std::sync::Arc;

use serde::{Deserialize, Serialize};
use thiserror::Error;

#[cfg(target_arch = "x86_64")]
use crate::x86_64::SgxEpcSection;

type GuestMemoryMmap = vm_memory::GuestMemoryMmap<vm_memory::bitmap::AtomicBitmap>;
type GuestRegionMmap = vm_memory::GuestRegionMmap<vm_memory::bitmap::AtomicBitmap>;

Expand Down
15 changes: 9 additions & 6 deletions arch/src/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,24 @@ pub mod layout;
mod mpspec;
mod mptable;
pub mod regs;
use crate::GuestMemoryMmap;
use crate::InitramfsConfig;
use crate::RegionType;
use std::collections::BTreeMap;
use std::mem;

use hypervisor::arch::x86::{CpuIdEntry, CPUID_FLAG_VALID_INDEX};
use hypervisor::{CpuVendor, HypervisorCpuError, HypervisorError};
use linux_loader::loader::bootparam::{boot_params, setup_header};
use linux_loader::loader::elf::start_info::{
hvm_memmap_table_entry, hvm_modlist_entry, hvm_start_info,
};
use std::collections::BTreeMap;
use std::mem;
use thiserror::Error;
use vm_memory::{
Address, Bytes, GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryAtomic,
GuestMemoryRegion, GuestUsize,
};

use crate::GuestMemoryMmap;
use crate::InitramfsConfig;
use crate::RegionType;
mod smbios;
use std::arch::x86_64;
#[cfg(feature = "tdx")]
Expand Down Expand Up @@ -1551,9 +1553,10 @@ fn update_cpuid_sgx(

#[cfg(test)]
mod tests {
use super::*;
use linux_loader::loader::bootparam::boot_e820_entry;

use super::*;

#[test]
fn regions_base_addr() {
let regions = arch_memory_regions();
Expand Down
15 changes: 9 additions & 6 deletions arch/src/x86_64/mptable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE-BSD-3-Clause file.

use crate::layout::{APIC_START, HIGH_RAM_START, IOAPIC_START};
use crate::x86_64::{get_x2apic_id, mpspec};
use crate::GuestMemoryMmap;
use libc::c_uchar;
use std::mem;
use std::result;
use std::slice;

use libc::c_uchar;
use thiserror::Error;
use vm_memory::{Address, ByteValued, Bytes, GuestAddress, GuestMemory, GuestMemoryError};

use crate::layout::{APIC_START, HIGH_RAM_START, IOAPIC_START};
use crate::x86_64::{get_x2apic_id, mpspec};
use crate::GuestMemoryMmap;

// This is a workaround to the Rust enforcement specifying that any implementation of a foreign
// trait (in this case `ByteValued`) where:
// * the type that is implementing the trait is foreign or
Expand Down Expand Up @@ -304,12 +306,13 @@ pub fn setup_mptable(

#[cfg(test)]
mod tests {
use super::*;
use crate::layout::MPTABLE_START;
use vm_memory::{
bitmap::BitmapSlice, GuestUsize, VolatileMemoryError, VolatileSlice, WriteVolatile,
};

use super::*;
use crate::layout::MPTABLE_START;

fn table_entry_size(type_: u8) -> usize {
match type_ as u32 {
mpspec::MP_PROCESSOR => mem::size_of::<MpcCpuWrapper>(),
Expand Down
17 changes: 10 additions & 7 deletions arch/src/x86_64/regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
// Portions Copyright 2017 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE-BSD-3-Clause file.
use crate::layout::{
BOOT_GDT_START, BOOT_IDT_START, BOOT_STACK_POINTER, PVH_INFO_START, ZERO_PAGE_START,
};
use crate::{EntryPoint, GuestMemoryMmap};
use std::sync::Arc;
use std::{mem, result};

use hypervisor::arch::x86::gdt::{gdt_entry, segment_from_gdt};
use hypervisor::arch::x86::regs::CR0_PE;
use hypervisor::arch::x86::{FpuState, SpecialRegisters};
use std::sync::Arc;
use std::{mem, result};
use thiserror::Error;
use vm_memory::{Address, Bytes, GuestMemory, GuestMemoryError};

use crate::layout::{
BOOT_GDT_START, BOOT_IDT_START, BOOT_STACK_POINTER, PVH_INFO_START, ZERO_PAGE_START,
};
use crate::{EntryPoint, GuestMemoryMmap};

#[derive(Debug, Error)]
pub enum Error {
/// Failed to get SREGs for this CPU.
Expand Down Expand Up @@ -186,9 +188,10 @@ pub fn configure_segments_and_sregs(

#[cfg(test)]
mod tests {
use super::*;
use vm_memory::GuestAddress;

use super::*;

fn create_guest_mem() -> GuestMemoryMmap {
GuestMemoryMmap::from_ranges(&[(GuestAddress(0), 0x10000)]).unwrap()
}
Expand Down
6 changes: 4 additions & 2 deletions arch/src/x86_64/smbios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
//
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause

use crate::layout::SMBIOS_START;
use crate::GuestMemoryMmap;
use std::mem;
use std::result;
use std::slice;

use thiserror::Error;
use uuid::Uuid;
use vm_memory::ByteValued;
use vm_memory::{Address, Bytes, GuestAddress};

use crate::layout::SMBIOS_START;
use crate::GuestMemoryMmap;

#[derive(Debug, Error)]
pub enum Error {
/// There was too little guest memory to store the entire SMBIOS table.
Expand Down
4 changes: 3 additions & 1 deletion arch/src/x86_64/tdx/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// Copyright © 2021 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
use crate::GuestMemoryMmap;
use std::fs::File;
use std::io::{Read, Seek, SeekFrom};
use std::str::FromStr;

use thiserror::Error;
use uuid::Uuid;
use vm_memory::{ByteValued, Bytes, GuestAddress, GuestMemoryError};

use crate::GuestMemoryMmap;

#[derive(Error, Debug)]
pub enum TdvfError {
#[error("Failed read TDVF descriptor: {0}")]
Expand Down
3 changes: 2 additions & 1 deletion block/src/async_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
//
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause

use crate::DiskTopology;
use thiserror::Error;
use vmm_sys_util::eventfd::EventFd;

use crate::DiskTopology;

#[derive(Error, Debug)]
pub enum DiskFileError {
/// Failed getting disk file size.
Expand Down
5 changes: 3 additions & 2 deletions block/src/fixed_vhd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
//
// SPDX-License-Identifier: Apache-2.0

use crate::vhd::VhdFooter;
use crate::BlockBackend;
use std::fs::File;
use std::io::{Read, Seek, SeekFrom, Write};
use std::os::unix::io::{AsRawFd, RawFd};

use crate::vhd::VhdFooter;
use crate::BlockBackend;

#[derive(Debug)]
pub struct FixedVhd {
file: File,
Expand Down
8 changes: 5 additions & 3 deletions block/src/fixed_vhd_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
//
// SPDX-License-Identifier: Apache-2.0

use std::fs::File;
use std::os::unix::io::{AsRawFd, RawFd};

use vmm_sys_util::eventfd::EventFd;

use crate::async_io::{
AsyncIo, AsyncIoError, AsyncIoResult, DiskFile, DiskFileError, DiskFileResult,
};
use crate::fixed_vhd::FixedVhd;
use crate::raw_async::RawFileAsync;
use crate::BlockBackend;
use std::fs::File;
use std::os::unix::io::{AsRawFd, RawFd};
use vmm_sys_util::eventfd::EventFd;

pub struct FixedVhdDiskAsync(FixedVhd);

Expand Down
8 changes: 5 additions & 3 deletions block/src/fixed_vhd_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
//
// SPDX-License-Identifier: Apache-2.0

use std::fs::File;
use std::os::unix::io::{AsRawFd, RawFd};

use vmm_sys_util::eventfd::EventFd;

use crate::async_io::{
AsyncIo, AsyncIoError, AsyncIoResult, DiskFile, DiskFileError, DiskFileResult,
};
use crate::fixed_vhd::FixedVhd;
use crate::raw_sync::RawFileSync;
use crate::BlockBackend;
use std::fs::File;
use std::os::unix::io::{AsRawFd, RawFd};
use vmm_sys_util::eventfd::EventFd;

pub struct FixedVhdDiskSync(FixedVhd);

Expand Down
20 changes: 11 additions & 9 deletions block/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ pub mod vhd;
pub mod vhdx;
pub mod vhdx_sync;

use crate::async_io::{AsyncIo, AsyncIoError, AsyncIoResult};
use crate::fixed_vhd::FixedVhd;
use crate::qcow::{QcowFile, RawFile};
use crate::vhdx::{Vhdx, VhdxError};
#[cfg(feature = "io_uring")]
use io_uring::{opcode, IoUring, Probe};
use libc::{ioctl, S_IFBLK, S_IFMT};
use serde::{Deserialize, Serialize};
use smallvec::SmallVec;
use std::alloc::{alloc_zeroed, dealloc, Layout};
use std::cmp;
use std::collections::VecDeque;
Expand All @@ -52,6 +43,12 @@ use std::result;
use std::sync::Arc;
use std::sync::MutexGuard;
use std::time::Instant;

#[cfg(feature = "io_uring")]
use io_uring::{opcode, IoUring, Probe};
use libc::{ioctl, S_IFBLK, S_IFMT};
use serde::{Deserialize, Serialize};
use smallvec::SmallVec;
use thiserror::Error;
use virtio_bindings::virtio_blk::*;
use virtio_queue::DescriptorChain;
Expand All @@ -64,6 +61,11 @@ use vmm_sys_util::aio;
use vmm_sys_util::eventfd::EventFd;
use vmm_sys_util::{ioctl_io_nr, ioctl_ioc_nr};

use crate::async_io::{AsyncIo, AsyncIoError, AsyncIoResult};
use crate::fixed_vhd::FixedVhd;
use crate::qcow::{QcowFile, RawFile};
use crate::vhdx::{Vhdx, VhdxError};

const SECTOR_SHIFT: u8 = 9;
pub const SECTOR_SIZE: u64 = 0x01 << SECTOR_SHIFT;

Expand Down
Loading

0 comments on commit 88a9f79

Please sign in to comment.