From: Alyssa Ross <hi@alyssa.is>
To: devel@spectrum-os.org
Subject: [RFC PATCH 4/4] crosvm: use vhost-user-net instead of virtio-net
Date: Wed, 12 May 2021 17:08:12 +0000 [thread overview]
Message-ID: <20210512170812.192540-5-hi@alyssa.is> (raw)
In-Reply-To: <20210512170812.192540-1-hi@alyssa.is>
This is a hack that just assumes vhost-user-net is desired if a MAC
address is given, but not a host IP or netmask. No sandbox is created
for this device.
It'll do for a proof of concept.
---
src/linux.rs | 32 ++++++++++++++++++++++++++++----
src/main.rs | 2 +-
2 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/src/linux.rs b/src/linux.rs
index 31b9d325..3b040a87 100644
--- a/src/linux.rs
+++ b/src/linux.rs
@@ -507,6 +507,28 @@ fn create_balloon_device(cfg: &Config, socket: BalloonControlResponseSocket) ->
})
}
+fn create_vhost_user_net_device(mac_address: MacAddress) -> DeviceResult {
+ use virtio::vhost_user::cloud_hypervisor::net_util::MacAddr;
+ use virtio::vhost_user::{self, VhostUserConfig};
+
+ let xdg_runtime_dir = std::env::var("XDG_RUNTIME_DIR").expect("XDG_RUNTIME_DIR is not set");
+
+ let dev = vhost_user::Net::new(
+ MacAddr::from_bytes(&mac_address.octets()).unwrap(),
+ VhostUserConfig {
+ sock: &format!("{}/vhost-user0.sock", xdg_runtime_dir),
+ num_queues: 2,
+ queue_size: 256,
+ },
+ )
+ .expect("vhost_user::Net::new");
+
+ Ok(VirtioDeviceStub {
+ dev: Box::new(dev),
+ jail: None,
+ })
+}
+
fn create_tap_net_device(cfg: &Config, tap_fd: RawFd) -> DeviceResult {
// Safe because we ensure that we get a unique handle to the fd.
let tap = unsafe {
@@ -872,10 +894,12 @@ fn create_virtio_devices(
devs.push(create_tap_net_device(cfg, *tap_fd)?);
}
- if let (Some(host_ip), Some(netmask), Some(mac_address)) =
- (cfg.host_ip, cfg.netmask, cfg.mac_address)
- {
- devs.push(create_net_device(cfg, host_ip, netmask, mac_address, mem)?);
+ if let Some(mac_address) = cfg.mac_address {
+ if let (Some(host_ip), Some(netmask)) = (cfg.host_ip, cfg.netmask) {
+ devs.push(create_net_device(cfg, host_ip, netmask, mac_address, mem)?);
+ } else {
+ devs.push(create_vhost_user_net_device(mac_address)?);
+ }
}
#[cfg_attr(not(feature = "gpu"), allow(unused_mut))]
diff --git a/src/main.rs b/src/main.rs
index a864833c..d19def4a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -803,7 +803,7 @@ fn run_vm(args: std::env::Args) -> std::result::Result<(), ()> {
if cfg.executable_path.is_none() {
return Err(argument::Error::ExpectedArgument("`KERNEL`".to_owned()));
}
- if cfg.host_ip.is_some() || cfg.netmask.is_some() || cfg.mac_address.is_some() {
+ if cfg.host_ip.is_some() || cfg.netmask.is_some() {
if cfg.host_ip.is_none() {
return Err(argument::Error::ExpectedArgument(
"`host_ip` missing from network config".to_owned(),
--
2.31.0
prev parent reply other threads:[~2021-05-13 0:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-12 17:08 [RFC PATCH crosvm 0/4] Implement vhost-user-net Alyssa Ross
2021-05-12 17:08 ` [RFC PATCH 1/4] devices: port vhost-user-net from cloud-hypervisor Alyssa Ross
2021-05-12 17:08 ` [RFC PATCH 2/4] vhost_rs: vhost_user: Add missing protocol features Alyssa Ross
2021-05-12 17:08 ` [RFC PATCH 3/4] devices: vhost-user: Vring should be enabled after initialization Alyssa Ross
2021-05-12 17:08 ` Alyssa Ross [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210512170812.192540-5-hi@alyssa.is \
--to=hi@alyssa.is \
--cc=devel@spectrum-os.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://spectrum-os.org/git/crosvm
https://spectrum-os.org/git/doc
https://spectrum-os.org/git/mktuntap
https://spectrum-os.org/git/nixpkgs
https://spectrum-os.org/git/spectrum
https://spectrum-os.org/git/ucspi-vsock
https://spectrum-os.org/git/www
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).