Skip to content

Commit

Permalink
chore: Move virtio_gen module to vmm::devices::virtio
Browse files Browse the repository at this point in the history
In our ongoing effort to eliminate our many crates, merge the virtio
bindings into the virtio modules of the vmm crate.

Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
  • Loading branch information
roypat committed Oct 13, 2023
1 parent d069b73 commit 1a54ca9
Show file tree
Hide file tree
Showing 19 changed files with 26 additions and 40 deletions.
5 changes: 0 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions src/virtio_gen/Cargo.toml

This file was deleted.

1 change: 0 additions & 1 deletion src/vmm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ micro_http = { git = "https://github.com/firecracker-microvm/micro-http" }
seccompiler = { path = "../seccompiler" }
snapshot = { path = "../snapshot"}
utils = { path = "../utils" }
virtio_gen = { path = "../virtio_gen" }

[target.'cfg(target_arch = "aarch64")'.dependencies]
vm-fdt = "0.2.0"
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/devices/virtio/balloon/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use timerfd::{ClockId, SetTimeFlags, TimerFd, TimerState};
use utils::eventfd::EventFd;
use utils::u64_to_usize;
use utils::vm_memory::{Address, ByteValued, Bytes, GuestAddress, GuestMemoryMmap};
use virtio_gen::virtio_blk::VIRTIO_F_VERSION_1;

use super::super::{ActivateError, DeviceState, Queue, VirtioDevice, TYPE_BALLOON};
use super::util::{compact_page_frame_numbers, remove_range};
Expand All @@ -27,6 +26,7 @@ use super::{
VIRTIO_BALLOON_S_SWAP_OUT,
};
use crate::devices::virtio::balloon::BalloonError;
use crate::devices::virtio::gen::virtio_blk::VIRTIO_F_VERSION_1;
use crate::devices::virtio::{IrqTrigger, IrqType};
use crate::logger::{IncMetric, METRICS};

Expand Down
8 changes: 4 additions & 4 deletions src/vmm/src/devices/virtio/block/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ use utils::eventfd::EventFd;
use utils::kernel_version::{min_kernel_version_for_io_uring, KernelVersion};
use utils::u64_to_usize;
use utils::vm_memory::GuestMemoryMmap;
use virtio_gen::virtio_blk::{
VIRTIO_BLK_F_FLUSH, VIRTIO_BLK_F_RO, VIRTIO_BLK_ID_BYTES, VIRTIO_F_VERSION_1,
};
use virtio_gen::virtio_ring::VIRTIO_RING_F_EVENT_IDX;

use super::super::{ActivateError, DeviceState, Queue, VirtioDevice, TYPE_BLOCK};
use super::io::async_io;
Expand All @@ -32,6 +28,10 @@ use super::{
io as block_io, BlockError, BLOCK_CONFIG_SPACE_SIZE, BLOCK_QUEUE_SIZES, SECTOR_SHIFT,
SECTOR_SIZE,
};
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::{IrqTrigger, IrqType};
use crate::logger::{error, warn, IncMetric, METRICS};
use crate::rate_limiter::{BucketUpdate, RateLimiter};
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/devices/virtio/block/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ mod tests {

use event_manager::{EventManager, SubscriberOps};
use utils::vm_memory::{Bytes, GuestAddress};
use virtio_gen::virtio_blk::{VIRTIO_BLK_S_OK, VIRTIO_BLK_T_OUT};

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::gen::virtio_blk::{VIRTIO_BLK_S_OK, VIRTIO_BLK_T_OUT};
use crate::devices::virtio::test_utils::{default_mem, VirtQueue};
use crate::devices::virtio::VIRTQ_DESC_F_NEXT;

Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/devices/virtio/block/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use snapshot::Persist;
use utils::vm_memory::GuestMemoryMmap;
use versionize::{VersionMap, Versionize, VersionizeError, VersionizeResult};
use versionize_derive::Versionize;
use virtio_gen::virtio_blk::VIRTIO_BLK_F_RO;

use super::*;
use crate::devices::virtio::block::device::FileEngineType;
use crate::devices::virtio::gen::virtio_blk::VIRTIO_BLK_F_RO;
use crate::devices::virtio::persist::VirtioDeviceState;
use crate::devices::virtio::{DeviceState, FIRECRACKER_MAX_QUEUE_SIZE, TYPE_BLOCK};
use crate::logger::warn;
Expand Down
8 changes: 4 additions & 4 deletions src/vmm/src/devices/virtio/block/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
use std::convert::From;

use utils::vm_memory::{ByteValued, Bytes, GuestAddress, GuestMemoryError, GuestMemoryMmap};
pub use 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 super::super::DescriptorChain;
use super::{io as block_io, BlockError, SECTOR_SHIFT};
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::SECTOR_SIZE;
use crate::logger::{error, IncMetric, METRICS};
use crate::rate_limiter::{RateLimiter, TokenType};
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions src/vmm/src/devices/virtio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::io::Error as IOError;
pub mod balloon;
pub mod block;
pub mod device;
pub(crate) mod gen;
mod iovec;
mod mmio;
pub mod net;
Expand Down
14 changes: 7 additions & 7 deletions src/vmm/src/devices/virtio/net/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ use utils::eventfd::EventFd;
use utils::net::mac::MacAddr;
use utils::u64_to_usize;
use utils::vm_memory::{ByteValued, Bytes, GuestMemoryError, GuestMemoryMmap};
use virtio_gen::virtio_net::{

use crate::devices::virtio::gen::virtio_net::{
virtio_net_hdr_v1, VIRTIO_F_VERSION_1, VIRTIO_NET_F_CSUM, VIRTIO_NET_F_GUEST_CSUM,
VIRTIO_NET_F_GUEST_TSO4, VIRTIO_NET_F_GUEST_UFO, VIRTIO_NET_F_HOST_TSO4, VIRTIO_NET_F_HOST_UFO,
VIRTIO_NET_F_MAC,
};
use virtio_gen::virtio_ring::VIRTIO_RING_F_EVENT_IDX;

use crate::devices::virtio::gen::virtio_ring::VIRTIO_RING_F_EVENT_IDX;
use crate::dumbo::pdu::arp::ETH_IPV4_FRAME_LEN;
use crate::dumbo::pdu::ethernet::{EthernetFrame, PAYLOAD_OFFSET};
use crate::logger::{IncMetric, METRICS};
Expand Down Expand Up @@ -857,14 +857,14 @@ pub mod tests {

use utils::net::mac::MAC_ADDR_LEN;
use utils::vm_memory::{Address, GuestMemory};
use virtio_gen::virtio_net::{

use super::*;
use crate::check_metric_after_block;
use crate::devices::virtio::gen::virtio_net::{
virtio_net_hdr_v1, VIRTIO_F_VERSION_1, VIRTIO_NET_F_CSUM, VIRTIO_NET_F_GUEST_CSUM,
VIRTIO_NET_F_GUEST_TSO4, VIRTIO_NET_F_GUEST_UFO, VIRTIO_NET_F_HOST_TSO4,
VIRTIO_NET_F_HOST_UFO, VIRTIO_NET_F_MAC,
};

use super::*;
use crate::check_metric_after_block;
use crate::devices::virtio::net::device::{
frame_bytes_from_buf, frame_bytes_from_buf_mut, init_vnet_hdr, vnet_hdr_len,
};
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/devices/virtio/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use utils::vm_memory::address::Address;
use utils::vm_memory::{GuestAddress, GuestMemoryMmap};
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use virtio_gen::virtio_ring::VIRTIO_RING_F_EVENT_IDX;

use super::device::*;
use super::queue::*;
use crate::devices::virtio::gen::virtio_ring::VIRTIO_RING_F_EVENT_IDX;
use crate::devices::virtio::MmioTransport;

/// Errors thrown during restoring virtio state.
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/devices/virtio/rng/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use std::sync::Arc;
use aws_lc_rs::rand;
use utils::eventfd::EventFd;
use utils::vm_memory::{GuestMemoryError, GuestMemoryMmap};
use virtio_gen::virtio_rng::VIRTIO_F_VERSION_1;

use super::{RNG_NUM_QUEUES, RNG_QUEUE};
use crate::devices::virtio::device::{IrqTrigger, IrqType};
use crate::devices::virtio::gen::virtio_rng::VIRTIO_F_VERSION_1;
use crate::devices::virtio::iovec::IoVecBufferMut;
use crate::devices::virtio::{
ActivateError, DeviceState, Queue, VirtioDevice, FIRECRACKER_MAX_QUEUE_SIZE, TYPE_RNG,
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use utils::u64_to_usize;
use utils::vm_memory::{GuestMemory, GuestMemoryMmap};
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
use virtio_gen::virtio_ring::VIRTIO_RING_F_EVENT_IDX;

#[cfg(target_arch = "aarch64")]
use crate::arch::aarch64::vcpu::{get_manufacturer_id_from_host, get_manufacturer_id_from_state};
Expand All @@ -32,6 +31,7 @@ use crate::cpu_config::x86_64::cpuid::common::get_vendor_id_from_host;
#[cfg(target_arch = "x86_64")]
use crate::cpu_config::x86_64::cpuid::CpuidTrait;
use crate::device_manager::persist::{DevicePersistError, DeviceStates};
use crate::devices::virtio::gen::virtio_ring::VIRTIO_RING_F_EVENT_IDX;
use crate::devices::virtio::TYPE_NET;
use crate::logger::{info, warn};
use crate::memory_snapshot::{GuestMemoryState, SnapshotMemory};
Expand Down
8 changes: 4 additions & 4 deletions tools/bindgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,26 @@ fc-bindgen \
info "BINDGEN virtio_ring.h"
fc-bindgen \
--allowlist-var "VIRTIO_RING_F_EVENT_IDX" \
"$KERNEL_HEADERS_HOME/include/linux/virtio_ring.h" >src/virtio_gen/src/virtio_ring.rs
"$KERNEL_HEADERS_HOME/include/linux/virtio_ring.h" >src/vmm/src/devices/virtio/gen/virtio_ring.rs

info "BINDGEN virtio_blk.h"
fc-bindgen \
--allowlist-var "VIRTIO_BLK_.*" \
--allowlist-var "VIRTIO_F_.*" \
"$KERNEL_HEADERS_HOME/include/linux/virtio_blk.h" >src/virtio_gen/src/virtio_blk.rs
"$KERNEL_HEADERS_HOME/include/linux/virtio_blk.h" >src/vmm/src/devices/virtio/gen/virtio_blk.rs

info "BINDGEN virtio_net.h"
fc-bindgen \
--allowlist-var "VIRTIO_NET_F_.*" \
--allowlist-var "VIRTIO_F_.*" \
--allowlist-type "virtio_net_hdr_v1" \
"$KERNEL_HEADERS_HOME/include/linux/virtio_net.h" >src/virtio_gen/src/virtio_net.rs
"$KERNEL_HEADERS_HOME/include/linux/virtio_net.h" >src/vmm/src/devices/virtio/gen/virtio_net.rs

info "BINDGEN virtio_rng.h"
fc-bindgen \
--allowlist-var "VIRTIO_RNG_.*" \
--allowlist-var "VIRTIO_F_.*" \
"$KERNEL_HEADERS_HOME/include/linux/virtio_rng.h" >src/virtio_gen/src/virtio_rng.rs
"$KERNEL_HEADERS_HOME/include/linux/virtio_rng.h" >src/vmm/src/devices/virtio/gen/virtio_rng.rs

# https://www.kernel.org/doc/Documentation/kbuild/headers_install.txt
# The Linux repo is huge. Just copy what we need.
Expand Down

0 comments on commit 1a54ca9

Please sign in to comment.