2019-09-20 18:21:54 +00:00
|
|
|
// Copyright 2019 Intel Corporation. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Portions Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Portions Copyright 2017 The Chromium OS Authors. All rights reserved.
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: (Apache-2.0 AND BSD-3-Clause)
|
|
|
|
|
|
|
|
#[macro_use(crate_version, crate_authors)]
|
|
|
|
extern crate clap;
|
|
|
|
extern crate log;
|
|
|
|
extern crate vhost_user_backend;
|
2020-01-20 16:10:21 +00:00
|
|
|
extern crate vhost_user_net;
|
2019-09-20 18:21:54 +00:00
|
|
|
|
|
|
|
use clap::{App, Arg};
|
|
|
|
use epoll;
|
|
|
|
use std::process;
|
|
|
|
use std::sync::{Arc, RwLock};
|
2020-01-20 16:10:21 +00:00
|
|
|
use vhost_user_backend::VhostUserDaemon;
|
|
|
|
use vhost_user_net::{VhostUserNetBackend, VhostUserNetBackendConfig};
|
2019-09-20 18:21:54 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let cmd_arguments = App::new("vhost-user-net backend")
|
|
|
|
.version(crate_version!())
|
|
|
|
.author(crate_authors!())
|
|
|
|
.about("Launch a vhost-user-net backend.")
|
|
|
|
.arg(
|
2020-01-20 14:28:06 +00:00
|
|
|
Arg::with_name("net-backend")
|
|
|
|
.long("net-backend")
|
2019-09-20 18:21:54 +00:00
|
|
|
.help(
|
2020-01-20 14:28:06 +00:00
|
|
|
"vhost-user-net backend parameters \"ip=<ip_addr>,\
|
2020-01-09 17:29:00 +00:00
|
|
|
mask=<net_mask>,sock=<socket_path>,\
|
|
|
|
num_queues=<number_of_queues>,\
|
|
|
|
queue_size=<size_of_each_queue>\"",
|
2019-09-20 18:21:54 +00:00
|
|
|
)
|
|
|
|
.takes_value(true)
|
|
|
|
.min_values(1),
|
|
|
|
)
|
|
|
|
.get_matches();
|
|
|
|
|
2020-01-20 14:28:06 +00:00
|
|
|
let vhost_user_net_backend = cmd_arguments.value_of("net-backend").unwrap();
|
2019-09-20 18:21:54 +00:00
|
|
|
|
|
|
|
let backend_config = match VhostUserNetBackendConfig::parse(vhost_user_net_backend) {
|
|
|
|
Ok(config) => config,
|
|
|
|
Err(e) => {
|
|
|
|
println!("Failed parsing parameters {:?}", e);
|
|
|
|
process::exit(1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let net_backend = Arc::new(RwLock::new(
|
2020-01-09 17:29:00 +00:00
|
|
|
VhostUserNetBackend::new(
|
|
|
|
backend_config.ip,
|
|
|
|
backend_config.mask,
|
|
|
|
backend_config.num_queues,
|
|
|
|
backend_config.queue_size,
|
|
|
|
)
|
|
|
|
.unwrap(),
|
2019-09-20 18:21:54 +00:00
|
|
|
));
|
2020-01-20 16:10:21 +00:00
|
|
|
|
2019-09-20 18:21:54 +00:00
|
|
|
let mut net_daemon = VhostUserDaemon::new(
|
2020-01-20 16:10:21 +00:00
|
|
|
"vhost-user-net-backend".to_string(),
|
2019-09-20 18:21:54 +00:00
|
|
|
backend_config.sock.to_string(),
|
|
|
|
net_backend.clone(),
|
|
|
|
)
|
|
|
|
.unwrap();
|
2020-01-20 16:10:21 +00:00
|
|
|
|
|
|
|
let (kill_index, kill_evt_fd) = net_backend.read().unwrap().get_kill_event();
|
2019-09-20 18:21:54 +00:00
|
|
|
let vring_worker = net_daemon.get_vring_worker();
|
|
|
|
|
2020-01-20 16:10:21 +00:00
|
|
|
if let Err(e) =
|
|
|
|
vring_worker.register_listener(kill_evt_fd, epoll::Events::EPOLLIN, u64::from(kill_index))
|
|
|
|
{
|
2019-10-15 15:34:47 +00:00
|
|
|
println!("failed to register listener for kill event: {:?}", e);
|
|
|
|
process::exit(1);
|
2019-09-20 18:21:54 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 16:10:21 +00:00
|
|
|
net_backend
|
|
|
|
.write()
|
|
|
|
.unwrap()
|
|
|
|
.set_vring_worker(Some(vring_worker));
|
2019-09-20 18:21:54 +00:00
|
|
|
|
|
|
|
if let Err(e) = net_daemon.start() {
|
|
|
|
println!(
|
2019-10-15 15:34:47 +00:00
|
|
|
"failed to start daemon for vhost-user-net with error: {:?}",
|
2019-09-20 18:21:54 +00:00
|
|
|
e
|
|
|
|
);
|
|
|
|
process::exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
net_daemon.wait().unwrap();
|
|
|
|
}
|