mirror of
https://github.com/rust-vmm/vhost-device.git
synced 2025-12-31 19:45:41 +00:00
vsock: clean up comments and fix log messages
Remove old comments, useless code, and code commented. Avoid println!() to print messages and replaced with dbg!(), info!(), or error!(). Also init `env_logger` like other daemons in the main(). Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
This commit is contained in:
parent
8fa597e941
commit
d6775cd90d
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -675,6 +675,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"clap 3.2.22",
|
||||
"env_logger",
|
||||
"epoll",
|
||||
"futures",
|
||||
"log",
|
||||
|
||||
@ -12,6 +12,7 @@ edition = "2018"
|
||||
[dependencies]
|
||||
byteorder = "1"
|
||||
clap = { version = ">=3.0", features = ["derive"] }
|
||||
env_logger = ">=0.9"
|
||||
epoll = "4.3.1"
|
||||
futures = { version = "0.3", features = ["thread-pool"] }
|
||||
log = ">=0.4.6"
|
||||
|
||||
@ -9,9 +9,9 @@ mod vhu_vsock_thread;
|
||||
mod vsock_conn;
|
||||
|
||||
use clap::Parser;
|
||||
use log::{info, warn};
|
||||
use std::{
|
||||
convert::TryFrom,
|
||||
process,
|
||||
sync::{Arc, RwLock},
|
||||
};
|
||||
use vhost::{vhost_user, vhost_user::Listener};
|
||||
@ -38,48 +38,35 @@ pub(crate) fn start_backend_server(vsock_config: VsockConfig) {
|
||||
|
||||
let mut vring_workers = vsock_daemon.get_epoll_handlers();
|
||||
|
||||
if vring_workers.len() != vsock_backend.read().unwrap().threads.len() {
|
||||
println!("Number of vring workers must be identical to number of backend threads");
|
||||
}
|
||||
|
||||
for thread in vsock_backend.read().unwrap().threads.iter() {
|
||||
thread
|
||||
.lock()
|
||||
.unwrap()
|
||||
.set_vring_worker(Some(vring_workers.remove(0)));
|
||||
}
|
||||
if let Err(e) = vsock_daemon.start(listener) {
|
||||
dbg!("Failed to start vsock daemon: {:?}", e);
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
vsock_daemon.start(listener).unwrap();
|
||||
|
||||
match vsock_daemon.wait() {
|
||||
Ok(()) => {
|
||||
println!("Stopping cleanly");
|
||||
process::exit(0);
|
||||
info!("Stopping cleanly");
|
||||
}
|
||||
Err(vhost_user_backend::Error::HandleRequest(vhost_user::Error::PartialMessage)) => {
|
||||
println!("vhost-user connection closed with partial message. If the VM is shutting down, this is expected behavior; otherwise, it might be a bug.");
|
||||
continue;
|
||||
info!("vhost-user connection closed with partial message. If the VM is shutting down, this is expected behavior; otherwise, it might be a bug.");
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Error running daemon: {:?}", e);
|
||||
warn!("Error running daemon: {:?}", e);
|
||||
}
|
||||
}
|
||||
|
||||
vsock_backend
|
||||
.read()
|
||||
.unwrap()
|
||||
.exit_event
|
||||
.write(1)
|
||||
.expect("Shutting down worker thread");
|
||||
|
||||
println!("Vsock daemon is finished");
|
||||
// No matter the result, we need to shut down the worker thread.
|
||||
vsock_backend.read().unwrap().exit_event.write(1).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let vsock_config = VsockConfig::try_from(VsockArgs::parse()).unwrap();
|
||||
env_logger::init();
|
||||
|
||||
let vsock_config = VsockConfig::try_from(VsockArgs::parse()).unwrap();
|
||||
start_backend_server(vsock_config);
|
||||
}
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
// SPDX-License-Identifier: Apache-2.0 or BSD-3-Clause
|
||||
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use super::{
|
||||
rxops::*,
|
||||
vhu_vsock::{
|
||||
@ -22,7 +20,6 @@ use std::{
|
||||
use virtio_vsock::packet::VsockPacket;
|
||||
use vm_memory::bitmap::BitmapSlice;
|
||||
|
||||
// TODO: convert UnixStream to Arc<Mutex<UnixStream>>
|
||||
pub struct VsockThreadBackend {
|
||||
/// Map of ConnMapKey objects indexed by raw file descriptors.
|
||||
pub listener_map: HashMap<RawFd, ConnMapKey>,
|
||||
|
||||
@ -278,10 +278,6 @@ impl VhostUserBackendMut<VringRwLock, ()> for VhostUserVsockBackend {
|
||||
let vring_rx = &vrings[0];
|
||||
let vring_tx = &vrings[1];
|
||||
|
||||
if evset == EventSet::OUT {
|
||||
dbg!("received epollout");
|
||||
}
|
||||
|
||||
if evset != EventSet::IN {
|
||||
return Err(Error::HandleEventNotEpollIn.into());
|
||||
}
|
||||
|
||||
@ -365,7 +365,6 @@ impl VhostUserVsockThread {
|
||||
epoll::Events::EPOLLIN,
|
||||
)?;
|
||||
|
||||
// self.register_listener(stream_fd, BACKEND_EVENT);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -461,11 +460,6 @@ impl VhostUserVsockThread {
|
||||
if !vring.enable_notification().unwrap() {
|
||||
break;
|
||||
}
|
||||
// TODO: This may not be required because of
|
||||
// previous pending_rx check
|
||||
// if !work {
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
} else {
|
||||
self.process_rx_queue(vring)?;
|
||||
|
||||
@ -290,12 +290,12 @@ impl<S: AsRawFd + Read + Write> VsockConnection<S> {
|
||||
if e.kind() == ErrorKind::WouldBlock {
|
||||
0
|
||||
} else {
|
||||
println!("send_bytes error: {:?}", e);
|
||||
dbg!("send_bytes error: {:?}", e);
|
||||
return Err(Error::UnixWrite);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
println!("send_bytes error: {:?}", e);
|
||||
dbg!("send_bytes error: {:?}", e);
|
||||
return Err(Error::UnixWrite);
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user