Skip to content

Commit

Permalink
refactor: moved block to virtio_block
Browse files Browse the repository at this point in the history
Now virtio_block is named similar to vhost_user_block

Signed-off-by: Egor Lazarchuk <[email protected]>
  • Loading branch information
ShadowCurse committed Nov 8, 2023
1 parent 3de96a9 commit e113916
Show file tree
Hide file tree
Showing 19 changed files with 43 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/vmm/src/device_manager/mmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ use crate::arch::DeviceType::Virtio;
use crate::devices::legacy::RTCDevice;
use crate::devices::pseudo::BootTimer;
use crate::devices::virtio::balloon::Balloon;
use crate::devices::virtio::block::VirtioBlock;
use crate::devices::virtio::device::VirtioDevice;
use crate::devices::virtio::mmio::MmioTransport;
use crate::devices::virtio::net::Net;
use crate::devices::virtio::rng::Entropy;
use crate::devices::virtio::virtio_block::VirtioBlock;
use crate::devices::virtio::vsock::TYPE_VSOCK;
use crate::devices::virtio::{TYPE_BALLOON, TYPE_BLOCK, TYPE_NET, TYPE_RNG};
use crate::devices::BusDevice;
Expand Down
4 changes: 2 additions & 2 deletions src/vmm/src/device_manager/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ use super::mmio::*;
use crate::arch::DeviceType;
use crate::devices::virtio::balloon::persist::{BalloonConstructorArgs, BalloonState};
use crate::devices::virtio::balloon::{Balloon, BalloonError};
use crate::devices::virtio::block::persist::{VirtioBlockConstructorArgs, VirtioBlockState};
use crate::devices::virtio::block::{VirtioBlock, VirtioBlockError};
use crate::devices::virtio::device::VirtioDevice;
use crate::devices::virtio::mmio::MmioTransport;
use crate::devices::virtio::net::persist::{
Expand All @@ -37,6 +35,8 @@ use crate::devices::virtio::vhost_user_block::persist::{
VhostUserBlockConstructorArgs, VhostUserBlockState,
};
use crate::devices::virtio::vhost_user_block::VhostUserBlockError;
use crate::devices::virtio::virtio_block::persist::{VirtioBlockConstructorArgs, VirtioBlockState};
use crate::devices::virtio::virtio_block::{VirtioBlock, VirtioBlockError};
use crate::devices::virtio::vsock::persist::{
VsockConstructorArgs, VsockState, VsockUdsConstructorArgs,
};
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/devices/virtio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::any::Any;
use std::io::Error as IOError;

pub mod balloon;
pub mod block;
pub mod block_common;
pub mod device;
pub mod gen;
Expand All @@ -24,6 +23,7 @@ pub mod rng;
pub mod test_utils;
pub mod vhost_user;
pub mod vhost_user_block;
pub mod virtio_block;
pub mod vsock;

/// When the driver initializes the device, it lets the device know about the
Expand Down
6 changes: 3 additions & 3 deletions src/vmm/src/devices/virtio/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,13 @@ mod tests {
use utils::tempfile::TempFile;

use super::*;
use crate::devices::virtio::block::device::FileEngineType;
use crate::devices::virtio::block::test_utils::default_block_with_path;
use crate::devices::virtio::block::VirtioBlock;
use crate::devices::virtio::mmio::tests::DummyDevice;
use crate::devices::virtio::net::test_utils::default_net;
use crate::devices::virtio::net::Net;
use crate::devices::virtio::test_utils::default_mem;
use crate::devices::virtio::virtio_block::device::FileEngineType;
use crate::devices::virtio::virtio_block::test_utils::default_block_with_path;
use crate::devices::virtio::virtio_block::VirtioBlock;
use crate::devices::virtio::vsock::{Vsock, VsockUnixBackend};

const DEFAULT_QUEUE_MAX_SIZE: u16 = 256;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ use super::{
io as block_io, VirtioBlockError, BLOCK_CONFIG_SPACE_SIZE, BLOCK_QUEUE_SIZES, SECTOR_SHIFT,
SECTOR_SIZE,
};
use crate::devices::virtio::block::block_metrics::{BlockDeviceMetrics, BlockMetricsPerDevice};
use crate::devices::virtio::block_common::CacheType;
use crate::devices::virtio::device::{DeviceState, IrqTrigger, IrqType, VirtioDevice};
use crate::devices::virtio::gen::virtio_blk::{
VIRTIO_BLK_F_FLUSH, VIRTIO_BLK_F_RO, VIRTIO_BLK_ID_BYTES, VIRTIO_F_VERSION_1,
};
use crate::devices::virtio::gen::virtio_ring::VIRTIO_RING_F_EVENT_IDX;
use crate::devices::virtio::queue::Queue;
use crate::devices::virtio::virtio_block::block_metrics::{
BlockDeviceMetrics, BlockMetricsPerDevice,
};
use crate::devices::virtio::{ActivateError, TYPE_BLOCK};
use crate::logger::{error, warn, IncMetric};
use crate::rate_limiter::{BucketUpdate, RateLimiter};
Expand Down Expand Up @@ -668,14 +670,14 @@ mod tests {

use super::*;
use crate::check_metric_after_block;
use crate::devices::virtio::block::test_utils::{
use crate::devices::virtio::queue::{VIRTQ_DESC_F_NEXT, VIRTQ_DESC_F_WRITE};
use crate::devices::virtio::test_utils::{default_mem, VirtQueue};
use crate::devices::virtio::virtio_block::test_utils::{
default_block, default_engine_type_for_kv, read_blk_req_descriptors, set_queue,
set_rate_limiter, simulate_async_completion_event,
simulate_queue_and_async_completion_events, simulate_queue_event,
};
use crate::devices::virtio::block::IO_URING_NUM_ENTRIES;
use crate::devices::virtio::queue::{VIRTQ_DESC_F_NEXT, VIRTQ_DESC_F_WRITE};
use crate::devices::virtio::test_utils::{default_mem, VirtQueue};
use crate::devices::virtio::virtio_block::IO_URING_NUM_ENTRIES;
use crate::rate_limiter::TokenType;
use crate::vstate::memory::{Address, Bytes, GuestAddress};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use event_manager::{EventOps, Events, MutEventSubscriber};
use utils::epoll::EventSet;

use super::io::FileEngine;
use crate::devices::virtio::block::device::VirtioBlock;
use crate::devices::virtio::device::VirtioDevice;
use crate::devices::virtio::virtio_block::device::VirtioBlock;
use crate::logger::{debug, error, warn};

impl VirtioBlock {
Expand Down Expand Up @@ -105,13 +105,13 @@ mod tests {
use event_manager::{EventManager, SubscriberOps};

use super::*;
use crate::devices::virtio::block::device::FileEngineType;
use crate::devices::virtio::block::test_utils::{
default_block, read_blk_req_descriptors, set_queue, simulate_async_completion_event,
};
use crate::devices::virtio::block::{VIRTIO_BLK_S_OK, VIRTIO_BLK_T_OUT};
use crate::devices::virtio::queue::VIRTQ_DESC_F_NEXT;
use crate::devices::virtio::test_utils::{default_mem, VirtQueue};
use crate::devices::virtio::virtio_block::device::FileEngineType;
use crate::devices::virtio::virtio_block::test_utils::{
default_block, read_blk_req_descriptors, set_queue, simulate_async_completion_event,
};
use crate::devices::virtio::virtio_block::{VIRTIO_BLK_S_OK, VIRTIO_BLK_T_OUT};
use crate::vstate::memory::{Bytes, GuestAddress};

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use std::os::unix::io::AsRawFd;
use utils::eventfd::EventFd;
use vm_memory::GuestMemoryError;

use crate::devices::virtio::block::io::UserDataError;
use crate::devices::virtio::block::IO_URING_NUM_ENTRIES;
use crate::devices::virtio::virtio_block::io::UserDataError;
use crate::devices::virtio::virtio_block::IO_URING_NUM_ENTRIES;
use crate::io_uring::operation::{Cqe, OpCode, Operation};
use crate::io_uring::restriction::Restriction;
use crate::io_uring::{IoUring, IoUringError};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::fs::File;

pub use self::async_io::{AsyncFileEngine, AsyncIoError};
pub use self::sync_io::{SyncFileEngine, SyncIoError};
use crate::devices::virtio::block::device::FileEngineType;
use crate::devices::virtio::virtio_block::device::FileEngineType;
use crate::vstate::memory::{GuestAddress, GuestMemoryMmap};

#[derive(Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -191,8 +191,8 @@ pub mod tests {
use utils::{skip_if_io_uring_supported, skip_if_io_uring_unsupported, u64_to_usize};

use super::*;
use crate::devices::virtio::block::device::FileEngineType;
use crate::devices::virtio::block::request::PendingRequest;
use crate::devices::virtio::virtio_block::device::FileEngineType;
use crate::devices::virtio::virtio_block::request::PendingRequest;
use crate::vstate::memory::{Bitmap, Bytes, GuestMemory, GuestMemoryExtension};

const FILE_LEN: u32 = 1024;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ use versionize_derive::Versionize;

use super::device::DiskProperties;
use super::*;
use crate::devices::virtio::block::block_metrics::BlockMetricsPerDevice;
use crate::devices::virtio::block::device::FileEngineType;
use crate::devices::virtio::device::{DeviceState, IrqTrigger};
use crate::devices::virtio::gen::virtio_blk::VIRTIO_BLK_F_RO;
use crate::devices::virtio::persist::VirtioDeviceState;
use crate::devices::virtio::virtio_block::block_metrics::BlockMetricsPerDevice;
use crate::devices::virtio::virtio_block::device::FileEngineType;
use crate::devices::virtio::TYPE_BLOCK;
use crate::logger::warn;
use crate::rate_limiter::persist::RateLimiterState;
Expand Down Expand Up @@ -187,9 +187,9 @@ mod tests {
use utils::tempfile::TempFile;

use super::*;
use crate::devices::virtio::block::device::VirtioBlockConfig;
use crate::devices::virtio::device::VirtioDevice;
use crate::devices::virtio::test_utils::default_mem;
use crate::devices::virtio::virtio_block::device::VirtioBlockConfig;

#[test]
fn test_cache_semantic_ser() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ use std::convert::From;
use vm_memory::GuestMemoryError;

use super::{io as block_io, VirtioBlockError, SECTOR_SHIFT, SECTOR_SIZE};
use crate::devices::virtio::block::block_metrics::BlockDeviceMetrics;
use crate::devices::virtio::block::device::DiskProperties;
pub use crate::devices::virtio::gen::virtio_blk::{
VIRTIO_BLK_ID_BYTES, VIRTIO_BLK_S_IOERR, VIRTIO_BLK_S_OK, VIRTIO_BLK_S_UNSUPP,
VIRTIO_BLK_T_FLUSH, VIRTIO_BLK_T_GET_ID, VIRTIO_BLK_T_IN, VIRTIO_BLK_T_OUT,
};
use crate::devices::virtio::queue::DescriptorChain;
use crate::devices::virtio::virtio_block::block_metrics::BlockDeviceMetrics;
use crate::devices::virtio::virtio_block::device::DiskProperties;
use crate::logger::{error, IncMetric};
use crate::rate_limiter::{RateLimiter, TokenType};
use crate::vstate::memory::{ByteValued, Bytes, GuestAddress, GuestMemoryMmap};
Expand Down Expand Up @@ -665,7 +665,7 @@ mod tests {
use proptest::prelude::*;
use proptest::strategy::{Map, Strategy, TupleUnion};

use crate::devices::virtio::block::test_utils::RequestDescriptorChain;
use crate::devices::virtio::virtio_block::test_utils::RequestDescriptorChain;

// Implements a "strategy" for producing arbitrary values of RequestType.
// This can also be generated by a derive macro from `proptest_derive`, but the crate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ use utils::tempfile::TempFile;

use super::device::VirtioBlockConfig;
use super::RequestHeader;
use crate::devices::virtio::block::device::FileEngineType;
#[cfg(test)]
use crate::devices::virtio::block::io::FileEngine;
use crate::devices::virtio::block::{CacheType, VirtioBlock};
#[cfg(test)]
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::devices::virtio::virtio_block::device::FileEngineType;
#[cfg(test)]
use crate::devices::virtio::virtio_block::io::FileEngine;
use crate::devices::virtio::virtio_block::{CacheType, VirtioBlock};
use crate::rate_limiter::RateLimiter;
use crate::vmm_config::{RateLimiterConfig, TokenBucketConfig};
use crate::vstate::memory::{Bytes, GuestAddress};
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ use crate::devices::legacy::{IER_RDA_BIT, IER_RDA_OFFSET};
use crate::devices::virtio::balloon::{
Balloon, BalloonConfig, BalloonError, BalloonStats, BALLOON_DEV_ID,
};
use crate::devices::virtio::block::VirtioBlock;
use crate::devices::virtio::net::Net;
use crate::devices::virtio::virtio_block::VirtioBlock;
use crate::devices::virtio::{TYPE_BALLOON, TYPE_BLOCK, TYPE_NET};
use crate::logger::{error, info, warn, MetricsError, METRICS};
use crate::persist::{MicrovmState, MicrovmStateError, VmInfo};
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/logger/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ use serde::{Serialize, Serializer};
use vm_superio::rtc_pl031::RtcEvents;

use super::FcLineWriter;
use crate::devices::virtio::block::block_metrics;
use crate::devices::virtio::net::metrics as net_metrics;
use crate::devices::virtio::virtio_block::block_metrics;
#[cfg(target_arch = "aarch64")]
use crate::warn;

Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ mod tests {

use super::*;
use crate::cpu_config::templates::{CpuTemplateType, StaticCpuTemplate};
use crate::devices::virtio::block::VirtioBlockError;
use crate::devices::virtio::block_common::CacheType;
use crate::devices::virtio::virtio_block::VirtioBlockError;
use crate::devices::virtio::vsock::VSOCK_DEV_ID;
use crate::resources::VmResources;
use crate::vmm_config::boot_source::{
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/version_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use semver::Version;
use versionize::{VersionMap, Versionize};

use crate::device_manager::persist::DeviceStates;
use crate::devices::virtio::block::persist::VirtioBlockState;
use crate::devices::virtio::net::persist::NetConfigSpaceState;
use crate::devices::virtio::persist::{QueueState, VirtioDeviceState};
use crate::devices::virtio::virtio_block::persist::VirtioBlockState;
use crate::persist::VmInfo;
use crate::vstate::vcpu::VcpuState;
use crate::vstate::vm::VmState;
Expand Down
8 changes: 4 additions & 4 deletions src/vmm/src/vmm_config/drive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use std::sync::{Arc, Mutex};
use serde::{Deserialize, Serialize};

use super::RateLimiterConfig;
pub use crate::devices::virtio::block::device::FileEngineType;
use crate::devices::virtio::block::device::VirtioBlockConfig;
use crate::devices::virtio::block::{VirtioBlock, VirtioBlockError};
use crate::devices::virtio::block_common::CacheType;
use crate::devices::virtio::vhost_user_block::device::{VhostUserBlock, VhostUserBlockConfig};
use crate::devices::virtio::vhost_user_block::VhostUserBlockError;
pub use crate::devices::virtio::virtio_block::device::FileEngineType;
use crate::devices::virtio::virtio_block::device::VirtioBlockConfig;
use crate::devices::virtio::virtio_block::{VirtioBlock, VirtioBlockError};
use crate::VmmError;

/// Errors associated with the operations allowed on a drive.
Expand Down Expand Up @@ -223,7 +223,7 @@ mod tests {
use utils::tempfile::TempFile;

use super::*;
use crate::devices::virtio::block::device::VirtioBlockConfig;
use crate::devices::virtio::virtio_block::device::VirtioBlockConfig;

impl PartialEq for DriveError {
fn eq(&self, other: &DriveError) -> bool {
Expand Down

0 comments on commit e113916

Please sign in to comment.