Skip to content

Commit

Permalink
Merge pull request #8632 from adamqqqplay/support-vhost-user-blk
Browse files Browse the repository at this point in the history
dragonball: introduce vhost-user-blk device
  • Loading branch information
justxuewei committed Dec 27, 2023
2 parents a4ad12a + 81ab174 commit 43a627c
Show file tree
Hide file tree
Showing 11 changed files with 908 additions and 33 deletions.
21 changes: 16 additions & 5 deletions src/dragonball/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ edition = "2018"
anyhow = "1.0.32"
arc-swap = "1.5.0"
bytes = "1.1.0"
dbs-address-space = { path = "./src/dbs_address_space" }
dbs-address-space = { path = "./src/dbs_address_space" }
dbs-allocator = { path = "./src/dbs_allocator" }
dbs-arch = { path = "./src/dbs_arch" }
dbs-boot = { path = "./src/dbs_boot" }
dbs-device = { path = "./src/dbs_device" }
dbs-interrupt = { path = "./src/dbs_interrupt", features = ["kvm-irq"] }
dbs-legacy-devices = { path = "./src/dbs_legacy_devices" }
dbs-upcall = { path = "./src/dbs_upcall" , optional = true }
dbs-upcall = { path = "./src/dbs_upcall", optional = true }
dbs-utils = { path = "./src/dbs_utils" }
dbs-virtio-devices = { path = "./src/dbs_virtio_devices", optional = true, features = ["virtio-mmio"] }
dbs-virtio-devices = { path = "./src/dbs_virtio_devices", optional = true, features = [
"virtio-mmio",
] }
derivative = "2.2.0"
kvm-bindings = "0.6.0"
kvm-ioctls = "0.12.0"
Expand Down Expand Up @@ -60,9 +62,18 @@ virtio-vsock = ["dbs-virtio-devices/virtio-vsock", "virtio-queue"]
virtio-blk = ["dbs-virtio-devices/virtio-blk", "virtio-queue"]
virtio-net = ["dbs-virtio-devices/virtio-net", "virtio-queue"]
# virtio-fs only work on atomic-guest-memory
virtio-fs = ["dbs-virtio-devices/virtio-fs-pro", "virtio-queue", "atomic-guest-memory"]
virtio-mem = ["dbs-virtio-devices/virtio-mem", "virtio-queue", "atomic-guest-memory"]
virtio-fs = [
"dbs-virtio-devices/virtio-fs-pro",
"virtio-queue",
"atomic-guest-memory",
]
virtio-mem = [
"dbs-virtio-devices/virtio-mem",
"virtio-queue",
"atomic-guest-memory",
]
virtio-balloon = ["dbs-virtio-devices/virtio-balloon", "virtio-queue"]
vhost-net = ["dbs-virtio-devices/vhost-net"]
vhost-user-fs = ["dbs-virtio-devices/vhost-user-fs"]
vhost-user-net = ["dbs-virtio-devices/vhost-user-net"]
vhost-user-blk = ["dbs-virtio-devices/vhost-user-blk"]
28 changes: 14 additions & 14 deletions src/dragonball/src/api/v1/vmm_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use self::VmmActionError::MachineConfig;

#[cfg(feature = "virtio-balloon")]
pub use crate::device_manager::balloon_dev_mgr::{BalloonDeviceConfigInfo, BalloonDeviceError};
#[cfg(feature = "virtio-blk")]
#[cfg(any(feature = "virtio-blk", feature = "vhost-user-blk"))]
pub use crate::device_manager::blk_dev_mgr::{
BlockDeviceConfigInfo, BlockDeviceConfigUpdateInfo, BlockDeviceError, BlockDeviceMgr,
};
Expand Down Expand Up @@ -99,7 +99,7 @@ pub enum VmmActionError {
#[error("failed to add virtio-vsock device: {0}")]
Vsock(#[source] VsockDeviceError),

#[cfg(feature = "virtio-blk")]
#[cfg(any(feature = "virtio-blk", feature = "vhost-user-blk"))]
/// Block device related errors.
#[error("virtio-blk device error: {0}")]
Block(#[source] BlockDeviceError),
Expand Down Expand Up @@ -186,16 +186,16 @@ pub enum VmmAction {
/// booted. The response is sent using the `OutcomeSender`.
InsertVsockDevice(VsockDeviceConfigInfo),

#[cfg(feature = "virtio-blk")]
#[cfg(any(feature = "virtio-blk", feature = "vhost-user-blk"))]
/// Add a new block device or update one that already exists using the `BlockDeviceConfig` as
/// input. This action can only be called before the microVM has booted.
InsertBlockDevice(BlockDeviceConfigInfo),

#[cfg(feature = "virtio-blk")]
#[cfg(any(feature = "virtio-blk", feature = "vhost-user-blk"))]
/// Remove a new block device for according to given drive_id
RemoveBlockDevice(String),

#[cfg(feature = "virtio-blk")]
#[cfg(any(feature = "virtio-blk", feature = "vhost-user-blk"))]
/// Update a block device, after microVM start. Currently, the only updatable properties
/// are the RX and TX rate limiters.
UpdateBlockDevice(BlockDeviceConfigUpdateInfo),
Expand Down Expand Up @@ -321,15 +321,15 @@ impl VmmService {
VmmAction::EndHypervisorTracing => self.end_tracing(),
#[cfg(feature = "virtio-vsock")]
VmmAction::InsertVsockDevice(vsock_cfg) => self.add_vsock_device(vmm, vsock_cfg),
#[cfg(feature = "virtio-blk")]
#[cfg(any(feature = "virtio-blk", feature = "vhost-user-blk"))]
VmmAction::InsertBlockDevice(block_device_config) => {
self.add_block_device(vmm, event_mgr, block_device_config)
}
#[cfg(feature = "virtio-blk")]
#[cfg(any(feature = "virtio-blk", feature = "vhost-user-blk"))]
VmmAction::UpdateBlockDevice(blk_update) => {
self.update_blk_rate_limiters(vmm, blk_update)
}
#[cfg(feature = "virtio-blk")]
#[cfg(any(feature = "virtio-blk", feature = "vhost-user-blk"))]
VmmAction::RemoveBlockDevice(drive_id) => {
self.remove_block_device(vmm, event_mgr, &drive_id)
}
Expand Down Expand Up @@ -602,7 +602,7 @@ impl VmmService {
.map_err(VmmActionError::Vsock)
}

#[cfg(feature = "virtio-blk")]
#[cfg(any(feature = "virtio-blk", feature = "vhost-user-blk"))]
// Only call this function as part of the API.
// If the drive_id does not exist, a new Block Device Config is added to the list.
#[instrument(skip(self, event_mgr))]
Expand All @@ -629,7 +629,7 @@ impl VmmService {
.map_err(VmmActionError::Block)
}

#[cfg(feature = "virtio-blk")]
#[cfg(any(feature = "virtio-blk", feature = "vhost-user-blk"))]
/// Updates configuration for an emulated net device as described in `config`.
#[instrument(skip(self))]
fn update_blk_rate_limiters(
Expand All @@ -646,7 +646,7 @@ impl VmmService {
.map_err(VmmActionError::Block)
}

#[cfg(feature = "virtio-blk")]
#[cfg(any(feature = "virtio-blk", feature = "vhost-user-blk"))]
// Remove the device
#[instrument(skip(self, event_mgr))]
fn remove_block_device(
Expand Down Expand Up @@ -1342,7 +1342,7 @@ mod tests {
}
}

#[cfg(feature = "virtio-blk")]
#[cfg(any(feature = "virtio-blk", feature = "vhost-user-blk"))]
#[test]
fn test_vmm_action_insert_block_device() {
skip_if_not_root!();
Expand Down Expand Up @@ -1399,7 +1399,7 @@ mod tests {
}
}

#[cfg(feature = "virtio-blk")]
#[cfg(any(feature = "virtio-blk", feature = "vhost-user-blk"))]
#[test]
fn test_vmm_action_update_block_device() {
skip_if_not_root!();
Expand Down Expand Up @@ -1432,7 +1432,7 @@ mod tests {
}
}

#[cfg(feature = "virtio-blk")]
#[cfg(any(feature = "virtio-blk", feature = "vhost-user-blk"))]
#[test]
fn test_vmm_action_remove_block_device() {
skip_if_not_root!();
Expand Down
20 changes: 16 additions & 4 deletions src/dragonball/src/dbs_virtio_devices/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ readme = "README.md"
byteorder = "1.4.3"
caps = "0.5.3"
dbs-device = { path = "../dbs_device" }
dbs-interrupt = { path = "../dbs_interrupt", features = ["kvm-legacy-irq", "kvm-msi-irq"] }
dbs-interrupt = { path = "../dbs_interrupt", features = [
"kvm-legacy-irq",
"kvm-msi-irq",
] }
dbs-utils = { path = "../dbs_utils" }
dbs-address-space = { path = "../dbs_address_space" }
dbs-boot = { path = "../dbs_boot" }
Expand All @@ -37,24 +40,33 @@ threadpool = "1"
virtio-bindings = "0.1.0"
virtio-queue = "0.7.0"
vmm-sys-util = "0.11.0"
vm-memory = { version = "0.10.0", features = [ "backend-mmap" ] }
vm-memory = { version = "0.10.0", features = ["backend-mmap"] }
sendfd = "0.4.3"
vhost-rs = { version = "0.6.1", package = "vhost", optional = true }
timerfd = "1.0"

[dev-dependencies]
vm-memory = { version = "0.10.0", features = [ "backend-mmap", "backend-atomic" ] }
vm-memory = { version = "0.10.0", features = [
"backend-mmap",
"backend-atomic",
] }

[features]
virtio-mmio = []
virtio-vsock = ["virtio-mmio"]
virtio-net = ["virtio-mmio"]
virtio-blk = ["virtio-mmio"]
virtio-fs = ["virtio-mmio", "fuse-backend-rs/virtiofs", "nydus-rafs/virtio-fs"]
virtio-fs-pro = ["virtio-fs", "nydus-storage/backend-registry", "nydus-storage/backend-oss"]
virtio-fs-pro = [
"virtio-fs",
"nydus-storage/backend-registry",
"nydus-storage/backend-oss",
]
virtio-mem = ["virtio-mmio"]
virtio-balloon = ["virtio-mmio"]
vhost = ["virtio-mmio", "vhost-rs/vhost-user-master", "vhost-rs/vhost-kern"]
vhost-net = ["vhost", "vhost-rs/vhost-net"]
vhost-user = ["vhost"]
vhost-user-fs = ["vhost-user"]
vhost-user-net = ["vhost-user"]
vhost-user-blk = ["vhost-user"]
4 changes: 4 additions & 0 deletions src/dragonball/src/dbs_virtio_devices/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub mod balloon;
pub mod vhost;

use std::io::Error as IOError;
use std::num::ParseIntError;

#[cfg(any(feature = "virtio-net", feature = "vhost-net"))]
use dbs_utils::metric::SharedIncMetric;
Expand Down Expand Up @@ -205,6 +206,9 @@ pub enum Error {
/// Generic IO error
#[error("IO: {0}.")]
IOError(#[from] IOError),
/// Error from ParseInt
#[error("ParseIntError")]
ParseIntError(ParseIntError),
/// Error from virtio_queue
#[error("virtio queue error: {0}")]
VirtioQueueError(#[from] VqError),
Expand Down

0 comments on commit 43a627c

Please sign in to comment.