Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vhost-net: create vhost based Net backend #4461

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions src/vmm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ kvm-ioctls = "0.16.0"
lazy_static = "1.4.0"
libc = "0.2.117"
memfd = "0.6.3"
linux-loader = "0.10.0"
linux-loader = "0.11.0"
serde = { version = "1.0.136", features = ["derive", "rc"] }
semver = { version = "1.0.17", features = ["serde"] }
serde_json = "1.0.78"
timerfd = "1.5.0"
thiserror = "1.0.32"
displaydoc = "0.2.4"
userfaultfd = "0.7.0"
vhost = { version = "0.10.0", features = ["vhost-user-frontend"] }
vhost = { version = "0.10", features = ["vhost-user-frontend", "vhost-net", "vhost-user"] }
vm-allocator = "0.1.0"
vm-superio = "0.7.0"
vm-memory = { version = "0.13.1", features = ["backend-mmap", "backend-bitmap"] }
vm-memory = { version = "0.14.0", features = ["backend-mmap", "backend-bitmap"] }
log = { version = "0.4.17", features = ["std", "serde"] }
aes-gcm = { version = "0.10.1", default-features = false, features = ["aes"] }
base64 = "0.21.0"
Expand Down
14 changes: 12 additions & 2 deletions src/vmm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,9 +883,19 @@ fn attach_net_devices<'a, I: Iterator<Item = &'a Arc<Mutex<Net>>> + Debug>(
event_manager: &mut EventManager,
) -> Result<(), StartMicrovmError> {
for net_device in net_devices {
let id = net_device.lock().expect("Poisoned lock").id().clone();
let (id, is_vhost) = {
let locked = net_device.lock().expect("Poisoned lock");
(locked.id().clone(), locked.is_vhost())
};
// The device mutex mustn't be locked here otherwise it will deadlock.
attach_virtio_device(event_manager, vmm, id, net_device.clone(), cmdline, false)?;
attach_virtio_device(
event_manager,
vmm,
id,
net_device.clone(),
cmdline,
is_vhost,
)?;
}
Ok(())
}
Expand Down
41 changes: 28 additions & 13 deletions src/vmm/src/device_manager/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,19 +290,34 @@ impl<'a> Persist<'a> for MMIODeviceManager {
}
TYPE_NET => {
let net = locked_device.as_any().downcast_ref::<Net>().unwrap();
if let (Some(mmds_ns), None) =
(net.mmds_ns.as_ref(), states.mmds_version.as_ref())
{
states.mmds_version =
Some(mmds_ns.mmds.lock().expect("Poisoned lock").version().into());
if net.is_vhost() {
warn!("skipping vhost-net device. It doesn't support snapshotting yet");
} else {
match net {
Net::Virtio(virtionet) => {
if let (Some(mmds_ns), None) =
(virtionet.mmds_ns.as_ref(), states.mmds_version.as_ref())
{
states.mmds_version = Some(
mmds_ns
.mmds
.lock()
.expect("Poisoned lock")
.version()
.into(),
);
}

states.net_devices.push(ConnectedNetState {
device_id: devid.clone(),
device_state: net.save(),
transport_state,
device_info: device_info.clone(),
})
}
Net::Vhost(_) => panic!(),
}
}

states.net_devices.push(ConnectedNetState {
device_id: devid.clone(),
device_state: net.save(),
transport_state,
device_info: device_info.clone(),
});
}
TYPE_VSOCK => {
let vsock = locked_device
Expand Down Expand Up @@ -506,7 +521,7 @@ impl<'a> Persist<'a> for MMIODeviceManager {
} else if state
.net_devices
.iter()
.any(|dev| dev.device_state.mmds_ns.is_some())
.any(|dev| dev.device_state.mmds_ns().is_some())
{
// If there's at least one network device having an mmds_ns, it means
// that we are restoring from a version that did not persist the `MmdsVersionState`.
Expand Down
5 changes: 5 additions & 0 deletions src/vmm/src/devices/virtio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use std::any::Any;
use std::io::Error as IOError;

pub use ::vhost::Error as VhostError;

pub mod balloon;
pub mod block;
pub mod device;
Expand Down Expand Up @@ -66,6 +68,9 @@ pub enum ActivateError {
BadActivate,
/// Vhost user: {0}
VhostUser(vhost_user::VhostUserError),

/// Vhost errored on one of the ioctls
Vhost(VhostError),
}

/// Trait that helps in upcasting an object to Any
Expand Down
Loading