vhost_user_net: Provide tap option for vhost_user_net backend

Provide vhost_user_net backend with the tap option, it allows to
use the existing tap interface.

Signed-off-by: Cathy Zhang <cathy.zhang@intel.com>
This commit is contained in:
Cathy Zhang 2020-03-03 14:40:55 +08:00 committed by Rob Bradford
parent e0419e988b
commit 6341736286
3 changed files with 17 additions and 4 deletions

View File

@ -25,7 +25,8 @@ fn main() {
"vhost-user-net backend parameters \"ip=<ip_addr>,\ "vhost-user-net backend parameters \"ip=<ip_addr>,\
mask=<net_mask>,sock=<socket_path>,\ mask=<net_mask>,sock=<socket_path>,\
num_queues=<number_of_queues>,\ num_queues=<number_of_queues>,\
queue_size=<size_of_each_queue>\"", queue_size=<size_of_each_queue>,\
tap=<if_name>\"",
) )
.takes_value(true) .takes_value(true)
.min_values(1), .min_values(1),

View File

@ -264,7 +264,8 @@ fn create_app<'a, 'b>(
"vhost-user-net backend parameters \"ip=<ip_addr>,\ "vhost-user-net backend parameters \"ip=<ip_addr>,\
mask=<net_mask>,sock=<socket_path>,\ mask=<net_mask>,sock=<socket_path>,\
num_queues=<number_of_queues>,\ num_queues=<number_of_queues>,\
queue_size=<size_of_each_queue>\"", queue_size=<size_of_each_queue>,\
tap=<if_name>\"",
) )
.takes_value(true) .takes_value(true)
.conflicts_with_all(&["block-backend", "kernel"]) .conflicts_with_all(&["block-backend", "kernel"])

View File

@ -144,9 +144,10 @@ impl VhostUserNetBackend {
netmask: Ipv4Addr, netmask: Ipv4Addr,
num_queues: usize, num_queues: usize,
queue_size: u16, queue_size: u16,
ifname: Option<&str>,
) -> Result<Self> { ) -> Result<Self> {
let taps = let taps = open_tap(ifname, Some(ip_addr), Some(netmask), num_queues / 2)
open_tap(None, Some(ip_addr), Some(netmask), num_queues / 2).map_err(Error::OpenTap)?; .map_err(Error::OpenTap)?;
Self::new_with_tap(taps, num_queues, queue_size) Self::new_with_tap(taps, num_queues, queue_size)
} }
@ -352,6 +353,7 @@ pub struct VhostUserNetBackendConfig<'a> {
pub sock: &'a str, pub sock: &'a str,
pub num_queues: usize, pub num_queues: usize,
pub queue_size: u16, pub queue_size: u16,
pub tap: Option<&'a str>,
} }
impl<'a> VhostUserNetBackendConfig<'a> { impl<'a> VhostUserNetBackendConfig<'a> {
@ -363,6 +365,7 @@ impl<'a> VhostUserNetBackendConfig<'a> {
let mut sock: &str = ""; let mut sock: &str = "";
let mut num_queues_str: &str = ""; let mut num_queues_str: &str = "";
let mut queue_size_str: &str = ""; let mut queue_size_str: &str = "";
let mut tap_str: &str = "";
for param in params_list.iter() { for param in params_list.iter() {
if param.starts_with("ip=") { if param.starts_with("ip=") {
@ -375,6 +378,8 @@ impl<'a> VhostUserNetBackendConfig<'a> {
num_queues_str = &param[11..]; num_queues_str = &param[11..];
} else if param.starts_with("queue_size=") { } else if param.starts_with("queue_size=") {
queue_size_str = &param[11..]; queue_size_str = &param[11..];
} else if param.starts_with("tap=") {
tap_str = &param[4..];
} }
} }
@ -382,6 +387,7 @@ impl<'a> VhostUserNetBackendConfig<'a> {
let mut mask: Ipv4Addr = Ipv4Addr::new(255, 255, 255, 0); let mut mask: Ipv4Addr = Ipv4Addr::new(255, 255, 255, 0);
let mut num_queues: usize = 2; let mut num_queues: usize = 2;
let mut queue_size: u16 = 256; let mut queue_size: u16 = 256;
let mut tap: Option<&str> = None;
if sock.is_empty() { if sock.is_empty() {
return Err(Error::ParseSockParam); return Err(Error::ParseSockParam);
@ -398,6 +404,9 @@ impl<'a> VhostUserNetBackendConfig<'a> {
if !queue_size_str.is_empty() { if !queue_size_str.is_empty() {
queue_size = queue_size_str.parse().map_err(Error::ParseQueueSizeParam)?; queue_size = queue_size_str.parse().map_err(Error::ParseQueueSizeParam)?;
} }
if !tap_str.is_empty() {
tap = Some(tap_str);
}
Ok(VhostUserNetBackendConfig { Ok(VhostUserNetBackendConfig {
ip, ip,
@ -405,6 +414,7 @@ impl<'a> VhostUserNetBackendConfig<'a> {
sock, sock,
num_queues, num_queues,
queue_size, queue_size,
tap,
}) })
} }
} }
@ -424,6 +434,7 @@ pub fn start_net_backend(backend_command: &str) {
backend_config.mask, backend_config.mask,
backend_config.num_queues, backend_config.num_queues,
backend_config.queue_size, backend_config.queue_size,
backend_config.tap,
) )
.unwrap(), .unwrap(),
)); ));