mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-07-07 10:15:45 +00:00
vhost_user_net: Add client mode
Relying on latest changes from vhost_user_backend crate, this patch enables the client mode support for vhost-user-net backend. In this mode, the backend behaves as a client instead of the default mode where it behaves as the server. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
a4a0751051
commit
8f9ffe5417
@ -16,6 +16,7 @@ use log::*;
|
|||||||
use net_util::{
|
use net_util::{
|
||||||
open_tap, MacAddr, NetCounters, NetQueuePair, OpenTapError, RxVirtio, Tap, TxVirtio,
|
open_tap, MacAddr, NetCounters, NetQueuePair, OpenTapError, RxVirtio, Tap, TxVirtio,
|
||||||
};
|
};
|
||||||
|
use option_parser::Toggle;
|
||||||
use option_parser::{OptionParser, OptionParserError};
|
use option_parser::{OptionParser, OptionParserError};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io::{self};
|
use std::io::{self};
|
||||||
@ -75,7 +76,7 @@ pub enum Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub const SYNTAX: &str = "vhost-user-net backend parameters \
|
pub const SYNTAX: &str = "vhost-user-net backend parameters \
|
||||||
\"ip=<ip_addr>,mask=<net_mask>,socket=<socket_path>,\
|
\"ip=<ip_addr>,mask=<net_mask>,socket=<socket_path>,client=on|off,\
|
||||||
num_queues=<number_of_queues>,queue_size=<size_of_each_queue>,tap=<if_name>\"";
|
num_queues=<number_of_queues>,queue_size=<size_of_each_queue>,tap=<if_name>\"";
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
@ -278,6 +279,7 @@ pub struct VhostUserNetBackendConfig {
|
|||||||
pub num_queues: usize,
|
pub num_queues: usize,
|
||||||
pub queue_size: u16,
|
pub queue_size: u16,
|
||||||
pub tap: Option<String>,
|
pub tap: Option<String>,
|
||||||
|
pub client: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VhostUserNetBackendConfig {
|
impl VhostUserNetBackendConfig {
|
||||||
@ -291,7 +293,8 @@ impl VhostUserNetBackendConfig {
|
|||||||
.add("mask")
|
.add("mask")
|
||||||
.add("queue_size")
|
.add("queue_size")
|
||||||
.add("num_queues")
|
.add("num_queues")
|
||||||
.add("socket");
|
.add("socket")
|
||||||
|
.add("client");
|
||||||
|
|
||||||
parser.parse(backend).map_err(Error::FailedConfigParse)?;
|
parser.parse(backend).map_err(Error::FailedConfigParse)?;
|
||||||
|
|
||||||
@ -317,6 +320,11 @@ impl VhostUserNetBackendConfig {
|
|||||||
.map_err(Error::FailedConfigParse)?
|
.map_err(Error::FailedConfigParse)?
|
||||||
.unwrap_or(2);
|
.unwrap_or(2);
|
||||||
let socket = parser.get("socket").ok_or(Error::SocketParameterMissing)?;
|
let socket = parser.get("socket").ok_or(Error::SocketParameterMissing)?;
|
||||||
|
let client = parser
|
||||||
|
.convert::<Toggle>("client")
|
||||||
|
.map_err(Error::FailedConfigParse)?
|
||||||
|
.unwrap_or(Toggle(false))
|
||||||
|
.0;
|
||||||
|
|
||||||
Ok(VhostUserNetBackendConfig {
|
Ok(VhostUserNetBackendConfig {
|
||||||
ip,
|
ip,
|
||||||
@ -326,6 +334,7 @@ impl VhostUserNetBackendConfig {
|
|||||||
num_queues,
|
num_queues,
|
||||||
queue_size,
|
queue_size,
|
||||||
tap,
|
tap,
|
||||||
|
client,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -353,8 +362,6 @@ pub fn start_net_backend(backend_command: &str) {
|
|||||||
.unwrap(),
|
.unwrap(),
|
||||||
));
|
));
|
||||||
|
|
||||||
let listener = Listener::new(&backend_config.socket, true).unwrap();
|
|
||||||
|
|
||||||
let mut net_daemon =
|
let mut net_daemon =
|
||||||
VhostUserDaemon::new("vhost-user-net-backend".to_string(), net_backend.clone()).unwrap();
|
VhostUserDaemon::new("vhost-user-net-backend".to_string(), net_backend.clone()).unwrap();
|
||||||
|
|
||||||
@ -372,7 +379,11 @@ pub fn start_net_backend(backend_command: &str) {
|
|||||||
.set_vring_worker(Some(vring_workers.remove(0)));
|
.set_vring_worker(Some(vring_workers.remove(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = net_daemon.start_server(listener) {
|
if let Err(e) = if backend_config.client {
|
||||||
|
net_daemon.start_client(&backend_config.socket)
|
||||||
|
} else {
|
||||||
|
net_daemon.start_server(Listener::new(&backend_config.socket, true).unwrap())
|
||||||
|
} {
|
||||||
error!(
|
error!(
|
||||||
"failed to start daemon for vhost-user-net with error: {:?}",
|
"failed to start daemon for vhost-user-net with error: {:?}",
|
||||||
e
|
e
|
||||||
|
Loading…
Reference in New Issue
Block a user