diff --git a/vhost-device-spi/src/linux_spi.rs b/vhost-device-spi/src/linux_spi.rs index 56cbad9..e003f7d 100644 --- a/vhost-device-spi/src/linux_spi.rs +++ b/vhost-device-spi/src/linux_spi.rs @@ -39,7 +39,8 @@ pub struct SpiIocTransfer { } /// Linux SPI definitions -/// IOCTL commands, refer Linux's Documentation/spi/spidev.rst for further details. +/// IOCTL commands, refer Linux's Documentation/spi/spidev.rst for further +/// details. const _IOC_SIZEBITS: u32 = 14; const _IOC_SIZESHIFT: u32 = 16; const SPI_IOC_MESSAGE_BASE: u32 = 0x40006b00; diff --git a/vhost-device-spi/src/main.rs b/vhost-device-spi/src/main.rs index ebd510f..8548d10 100644 --- a/vhost-device-spi/src/main.rs +++ b/vhost-device-spi/src/main.rs @@ -22,12 +22,11 @@ use std::{ use clap::Parser; use log::error; +use spi::{PhysDevice, SpiController, SpiDevice}; use thiserror::Error as ThisError; use vhost_user_backend::VhostUserDaemon; -use vm_memory::{GuestMemoryAtomic, GuestMemoryMmap}; - -use spi::{PhysDevice, SpiController, SpiDevice}; use vhu_spi::VhostUserSpiBackend; +use vm_memory::{GuestMemoryAtomic, GuestMemoryMmap}; type Result = std::result::Result; @@ -49,7 +48,8 @@ enum Error { #[derive(Parser, Debug)] #[clap(author, version, about, long_about = None)] struct SpiArgs { - /// Location of vhost-user Unix domain socket. This is suffixed by 0,1,2..socket_count-1. + /// Location of vhost-user Unix domain socket. This is suffixed by + /// 0,1,2..socket_count-1. #[clap(short, long)] socket_path: PathBuf, @@ -176,9 +176,10 @@ fn main() { #[cfg(test)] pub(crate) mod tests { - use assert_matches::assert_matches; use std::path::Path; + use assert_matches::assert_matches; + use super::*; use crate::spi::tests::DummyDevice; diff --git a/vhost-device-spi/src/spi.rs b/vhost-device-spi/src/spi.rs index 3fd3095..e661657 100644 --- a/vhost-device-spi/src/spi.rs +++ b/vhost-device-spi/src/spi.rs @@ -13,8 +13,10 @@ use std::{ }; use thiserror::Error as ThisError; -use vmm_sys_util::errno::Error as IoError; -use vmm_sys_util::ioctl::{ioctl_with_mut_ptr, ioctl_with_mut_ref, ioctl_with_ref}; +use vmm_sys_util::{ + errno::Error as IoError, + ioctl::{ioctl_with_mut_ptr, ioctl_with_mut_ref, ioctl_with_ref}, +}; use crate::{linux_spi::*, vhu_spi::VirtioSpiConfig, virtio_spi::*}; @@ -676,10 +678,12 @@ impl SpiController { #[cfg(test)] pub(crate) mod tests { - use super::*; use std::path::PathBuf; + use vmm_sys_util::tempfile::TempFile; + use super::*; + // Update read-buffer of each write-buffer with index + 1 value. pub fn update_rdwr_buf(buf: u64, len: u32) { let buf_ptr = buf as *mut u8; diff --git a/vhost-device-spi/src/vhu_spi.rs b/vhost-device-spi/src/vhu_spi.rs index ead3d1a..66caa8a 100644 --- a/vhost-device-spi/src/vhu_spi.rs +++ b/vhost-device-spi/src/vhu_spi.rs @@ -17,17 +17,18 @@ use log::warn; use thiserror::Error as ThisError; use vhost::vhost_user::message::{VhostUserProtocolFeatures, VhostUserVirtioFeatures}; use vhost_user_backend::{VhostUserBackendMut, VringRwLock, VringT}; -use virtio_bindings::bindings::virtio_config::{VIRTIO_F_NOTIFY_ON_EMPTY, VIRTIO_F_VERSION_1}; -use virtio_bindings::bindings::virtio_ring::{ - VIRTIO_RING_F_EVENT_IDX, VIRTIO_RING_F_INDIRECT_DESC, +use virtio_bindings::bindings::{ + virtio_config::{VIRTIO_F_NOTIFY_ON_EMPTY, VIRTIO_F_VERSION_1}, + virtio_ring::{VIRTIO_RING_F_EVENT_IDX, VIRTIO_RING_F_INDIRECT_DESC}, }; -use virtio_queue::DescriptorChain; -use virtio_queue::QueueOwnedT; +use virtio_queue::{DescriptorChain, QueueOwnedT}; use vm_memory::{ ByteValued, GuestAddressSpace, GuestMemoryAtomic, GuestMemoryLoadGuard, GuestMemoryMmap, Le32, }; -use vmm_sys_util::epoll::EventSet; -use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK}; +use vmm_sys_util::{ + epoll::EventSet, + eventfd::{EventFd, EFD_NONBLOCK}, +}; use crate::spi::*; @@ -488,8 +489,8 @@ impl VhostUserBackendMut for VhostUserSpiB #[cfg(test)] mod tests { - use std::path::PathBuf; - use std::slice::from_raw_parts; + use std::{path::PathBuf, slice::from_raw_parts}; + use virtio_bindings::bindings::virtio_ring::{VRING_DESC_F_NEXT, VRING_DESC_F_WRITE}; use virtio_queue::{ desc::{split::Descriptor as SplitDescriptor, RawDescriptor}, @@ -497,8 +498,7 @@ mod tests { }; use vm_memory::{Bytes, GuestAddress, GuestMemoryAtomic, GuestMemoryMmap}; - use super::Error; - use super::*; + use super::{Error, *}; use crate::spi::tests::{verify_rdwr_buf, DummyDevice}; // Prepares descriptor chains