Skip to content

Commit

Permalink
misc: Further improve imports styling
Browse files Browse the repository at this point in the history
By introducing `imports_granularity="Module"` format strategy,
effectively groups imports from the same module into one line or block,
improving maintainability and readability.

Signed-off-by: Ruoqing He <[email protected]>
  • Loading branch information
RuoqingHe authored and rbradford committed Sep 29, 2024
1 parent 9013d8b commit 61e57e1
Show file tree
Hide file tree
Showing 99 changed files with 360 additions and 515 deletions.
2 changes: 2 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
edition = "2021"
group_imports="StdExternalCrate"
imports_granularity="Module"

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

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 std::{cmp, fs, result, str};

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::super::{DeviceType, GuestMemoryMmap, 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,
Expand Down
3 changes: 1 addition & 2 deletions arch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
extern crate log;

use std::collections::BTreeMap;
use std::fmt;
use std::result;
use std::sync::Arc;
use std::{fmt, result};

use serde::{Deserialize, Serialize};
use thiserror::Error;
Expand Down
4 changes: 1 addition & 3 deletions arch/src/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ use vm_memory::{
GuestMemoryRegion, GuestUsize,
};

use crate::GuestMemoryMmap;
use crate::InitramfsConfig;
use crate::RegionType;
use crate::{GuestMemoryMmap, InitramfsConfig, RegionType};
mod smbios;
use std::arch::x86_64;
#[cfg(feature = "tdx")]
Expand Down
9 changes: 3 additions & 6 deletions arch/src/x86_64/mptable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE-BSD-3-Clause file.

use std::mem;
use std::result;
use std::slice;
use std::{mem, result, slice};

use libc::c_uchar;
use thiserror::Error;
Expand Down Expand Up @@ -306,9 +304,8 @@ pub fn setup_mptable(

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

use super::*;
use crate::layout::MPTABLE_START;
Expand Down
7 changes: 2 additions & 5 deletions arch/src/x86_64/smbios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@
//
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause

use std::mem;
use std::result;
use std::slice;
use std::{mem, result, slice};

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

use crate::layout::SMBIOS_START;
use crate::GuestMemoryMmap;
Expand Down
13 changes: 5 additions & 8 deletions block/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,16 @@ pub mod vhdx;
pub mod vhdx_sync;

use std::alloc::{alloc_zeroed, dealloc, Layout};
use std::cmp;
use std::collections::VecDeque;
use std::fmt::Debug;
use std::fs::File;
use std::io::{self, IoSlice, IoSliceMut, Read, Seek, SeekFrom, Write};
use std::os::linux::fs::MetadataExt;
use std::os::unix::io::AsRawFd;
use std::path::Path;
use std::result;
use std::sync::Arc;
use std::sync::MutexGuard;
use std::sync::{Arc, MutexGuard};
use std::time::Instant;
use std::{cmp, result};

#[cfg(feature = "io_uring")]
use io_uring::{opcode, IoUring, Probe};
Expand All @@ -52,14 +50,13 @@ use smallvec::SmallVec;
use thiserror::Error;
use virtio_bindings::virtio_blk::*;
use virtio_queue::DescriptorChain;
use vm_memory::bitmap::Bitmap;
use vm_memory::{
bitmap::Bitmap, ByteValued, Bytes, GuestAddress, GuestMemory, GuestMemoryError,
GuestMemoryLoadGuard,
ByteValued, Bytes, GuestAddress, GuestMemory, GuestMemoryError, GuestMemoryLoadGuard,
};
use vm_virtio::{AccessPlatform, Translatable};
use vmm_sys_util::aio;
use vmm_sys_util::eventfd::EventFd;
use vmm_sys_util::{ioctl_io_nr, ioctl_ioc_nr};
use vmm_sys_util::{aio, ioctl_io_nr, ioctl_ioc_nr};

use crate::async_io::{AsyncIo, AsyncIoError, AsyncIoResult};
use crate::fixed_vhd::FixedVhd;
Expand Down
15 changes: 6 additions & 9 deletions block/src/qcow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@ use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use libc::{EINVAL, ENOSPC, ENOTSUP};
use remain::sorted;
use thiserror::Error;
use vmm_sys_util::{
file_traits::FileSetLen, file_traits::FileSync, seek_hole::SeekHole, write_zeroes::PunchHole,
write_zeroes::WriteZeroesAt,
};
use vmm_sys_util::file_traits::{FileSetLen, FileSync};
use vmm_sys_util::seek_hole::SeekHole;
use vmm_sys_util::write_zeroes::{PunchHole, WriteZeroesAt};

use crate::qcow::qcow_raw_file::QcowRawFile;
pub use crate::qcow::raw_file::RawFile;
use crate::qcow::{
qcow_raw_file::QcowRawFile,
refcount::RefCount,
vec_cache::{CacheMap, Cacheable, VecCache},
};
use crate::qcow::refcount::RefCount;
use crate::qcow::vec_cache::{CacheMap, Cacheable, VecCache};
use crate::BlockBackend;

/// Nesting depth limit for disk formats that can open other disk files.
Expand Down
3 changes: 2 additions & 1 deletion block/src/qcow/raw_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use std::os::unix::io::{AsRawFd, RawFd};
use std::slice;

use libc::c_void;
use vmm_sys_util::{seek_hole::SeekHole, write_zeroes::PunchHole, write_zeroes::WriteZeroesAt};
use vmm_sys_util::seek_hole::SeekHole;
use vmm_sys_util::write_zeroes::{PunchHole, WriteZeroesAt};

use crate::BlockBackend;

Expand Down
6 changes: 2 additions & 4 deletions block/src/qcow/refcount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ use std::io;
use libc::EINVAL;
use thiserror::Error;

use crate::qcow::{
qcow_raw_file::QcowRawFile,
vec_cache::{CacheMap, Cacheable, VecCache},
};
use crate::qcow::qcow_raw_file::QcowRawFile;
use crate::qcow::vec_cache::{CacheMap, Cacheable, VecCache};

#[derive(Debug, Error)]
pub enum Error {
Expand Down
10 changes: 4 additions & 6 deletions block/src/vhdx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ use remain::sorted;
use thiserror::Error;
use uuid::Uuid;

use crate::vhdx::{
vhdx_bat::{BatEntry, VhdxBatError},
vhdx_header::{RegionInfo, RegionTableEntry, VhdxHeader, VhdxHeaderError},
vhdx_io::VhdxIoError,
vhdx_metadata::{DiskSpec, VhdxMetadataError},
};
use crate::vhdx::vhdx_bat::{BatEntry, VhdxBatError};
use crate::vhdx::vhdx_header::{RegionInfo, RegionTableEntry, VhdxHeader, VhdxHeaderError};
use crate::vhdx::vhdx_io::VhdxIoError;
use crate::vhdx::vhdx_metadata::{DiskSpec, VhdxMetadataError};
use crate::BlockBackend;

macro_rules! div_round_up {
Expand Down
3 changes: 2 additions & 1 deletion block/src/vhdx/vhdx_bat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use remain::sorted;
use thiserror::Error;

use crate::vhdx::{vhdx_header::RegionTableEntry, vhdx_metadata::DiskSpec};
use crate::vhdx::vhdx_header::RegionTableEntry;
use crate::vhdx::vhdx_metadata::DiskSpec;

// Payload BAT Entry States
pub const PAYLOAD_BLOCK_NOT_PRESENT: u64 = 0;
Expand Down
6 changes: 2 additions & 4 deletions block/src/vhdx/vhdx_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ use std::io::{self, Read, Seek, SeekFrom, Write};
use remain::sorted;
use thiserror::Error;

use crate::vhdx::{
vhdx_bat::{self, BatEntry, VhdxBatError},
vhdx_metadata::{self, DiskSpec},
};
use crate::vhdx::vhdx_bat::{self, BatEntry, VhdxBatError};
use crate::vhdx::vhdx_metadata::{self, DiskSpec};

const SECTOR_SIZE: u64 = 512;

Expand Down
6 changes: 2 additions & 4 deletions devices/src/gic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ use std::sync::{Arc, Mutex};

use anyhow::anyhow;
use arch::layout;
use hypervisor::{
arch::aarch64::gic::{Vgic, VgicConfig},
CpuState, GicState,
};
use hypervisor::arch::aarch64::gic::{Vgic, VgicConfig};
use hypervisor::{CpuState, GicState};
use vm_device::interrupt::{
InterruptIndex, InterruptManager, InterruptSourceConfig, InterruptSourceGroup,
LegacyIrqSourceConfig, MsiIrqGroupConfig,
Expand Down
3 changes: 1 addition & 2 deletions devices/src/interrupt_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
//
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause

use std::io;
use std::result;
use std::{io, result};

use thiserror::Error;
use vmm_sys_util::eventfd::EventFd;
Expand Down
3 changes: 1 addition & 2 deletions devices/src/legacy/cmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause

use std::cmp::min;
use std::mem;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Barrier};
use std::thread;
use std::{mem, thread};

// https://github.com/rust-lang/libc/issues/1848
#[cfg_attr(target_env = "musl", allow(deprecated))]
Expand Down
3 changes: 1 addition & 2 deletions devices/src/legacy/gpio_pl061.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
//! This module implements an ARM PrimeCell General Purpose Input/Output(PL061) to support gracefully poweroff microvm from external.
//!
use std::io;
use std::result;
use std::sync::{Arc, Barrier};
use std::{io, result};

use serde::{Deserialize, Serialize};
use thiserror::Error;
Expand Down
6 changes: 2 additions & 4 deletions devices/src/legacy/i8042.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
//
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause

use std::sync::{
atomic::{AtomicBool, Ordering},
Arc, Barrier,
};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Barrier};
use std::thread;

use vm_device::BusDevice;
Expand Down
18 changes: 9 additions & 9 deletions devices/src/pvmemcontrol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
// SPDX-License-Identifier: Apache-2.0
//

use std::{
collections::HashMap,
ffi::CString,
io, result,
sync::{Arc, Barrier, Mutex, RwLock},
};
use std::collections::HashMap;
use std::ffi::CString;
use std::sync::{Arc, Barrier, Mutex, RwLock};
use std::{io, result};

use num_enum::TryFromPrimitive;
use pci::{
BarReprogrammingParams, PciBarConfiguration, PciBarPrefetchable, PciBarRegionType,
PciClassCode, PciConfiguration, PciDevice, PciDeviceError, PciHeaderType, PciSubclass,
};
use thiserror::Error;
use vm_allocator::{page_size::get_page_size, AddressAllocator, SystemAllocator};
use vm_allocator::page_size::get_page_size;
use vm_allocator::{AddressAllocator, SystemAllocator};
use vm_device::{BusDeviceSync, Resource};
use vm_memory::bitmap::AtomicBitmap;
use vm_memory::{
bitmap::AtomicBitmap, Address, ByteValued, Bytes, GuestAddress, GuestAddressSpace, GuestMemory,
GuestMemoryAtomic, GuestMemoryError, GuestMemoryMmap, Le32, Le64,
Address, ByteValued, Bytes, GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryAtomic,
GuestMemoryError, GuestMemoryMmap, Le32, Le64,
};
use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};

Expand Down
3 changes: 2 additions & 1 deletion fuzz/fuzz_targets/balloon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use libfuzzer_sys::fuzz_target;
use seccompiler::SeccompAction;
use virtio_devices::{VirtioDevice, VirtioInterrupt, VirtioInterruptType};
use virtio_queue::{Queue, QueueT};
use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic};
use vm_memory::bitmap::AtomicBitmap;
use vm_memory::{Bytes, GuestAddress, GuestMemoryAtomic};
use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK};

type GuestMemoryMmap = vm_memory::GuestMemoryMmap<AtomicBitmap>;
Expand Down
9 changes: 5 additions & 4 deletions fuzz/fuzz_targets/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@
#![no_main]

use std::collections::BTreeMap;
use std::ffi;
use std::fs::File;
use std::io;
use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
use std::path::PathBuf;
use std::sync::Arc;
use std::{ffi, io};

use block::{async_io::DiskFile, raw_sync::RawFileDiskSync};
use block::async_io::DiskFile;
use block::raw_sync::RawFileDiskSync;
use libfuzzer_sys::fuzz_target;
use seccompiler::SeccompAction;
use virtio_devices::{Block, VirtioDevice, VirtioInterrupt, VirtioInterruptType};
use virtio_queue::{Queue, QueueT};
use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic};
use vm_memory::bitmap::AtomicBitmap;
use vm_memory::{Bytes, GuestAddress, GuestMemoryAtomic};
use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK};

type GuestMemoryMmap = vm_memory::GuestMemoryMmap<AtomicBitmap>;
Expand Down
3 changes: 2 additions & 1 deletion fuzz/fuzz_targets/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use libfuzzer_sys::fuzz_target;
use seccompiler::SeccompAction;
use virtio_devices::{VirtioDevice, VirtioInterrupt, VirtioInterruptType};
use virtio_queue::{Queue, QueueT};
use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic};
use vm_memory::bitmap::AtomicBitmap;
use vm_memory::{Bytes, GuestAddress, GuestMemoryAtomic};
use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK};

type GuestMemoryMmap = vm_memory::GuestMemoryMmap<AtomicBitmap>;
Expand Down
5 changes: 3 additions & 2 deletions fuzz/fuzz_targets/http_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ use libfuzzer_sys::fuzz_target;
use micro_http::Request;
use once_cell::sync::Lazy;
use vm_migration::MigratableError;
use vmm::api::http::*;
use vmm::api::{
http::*, ApiRequest, RequestHandler, VmInfoResponse, VmReceiveMigrationData,
VmSendMigrationData, VmmPingResponse,
ApiRequest, RequestHandler, VmInfoResponse, VmReceiveMigrationData, VmSendMigrationData,
VmmPingResponse,
};
use vmm::config::RestoreConfig;
use vmm::vm::{Error as VmError, VmState};
Expand Down
3 changes: 2 additions & 1 deletion fuzz/fuzz_targets/iommu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use libfuzzer_sys::fuzz_target;
use seccompiler::SeccompAction;
use virtio_devices::{VirtioDevice, VirtioInterrupt, VirtioInterruptType};
use virtio_queue::{Queue, QueueT};
use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic};
use vm_memory::bitmap::AtomicBitmap;
use vm_memory::{Bytes, GuestAddress, GuestMemoryAtomic};
use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK};

type GuestMemoryMmap = vm_memory::GuestMemoryMmap<AtomicBitmap>;
Expand Down
Loading

0 comments on commit 61e57e1

Please sign in to comment.