console: run nightly rustfmt to group imports

Nightly rustfmt groups imports neatly, so run it to make things
prettier.

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
This commit is contained in:
Manos Pitsidianakis 2024-11-11 06:33:59 +02:00 committed by Manos Pitsidianakis
parent c3a346c63a
commit 8a2a11d877
5 changed files with 64 additions and 35 deletions

View File

@ -0,0 +1,7 @@
edition = "2018"
format_generated_files = false
format_code_in_doc_comments = true
format_strings = true
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
wrap_comments = true

View File

@ -5,19 +5,23 @@
//
// SPDX-License-Identifier: Apache-2.0 or BSD-3-Clause
use log::{error, info};
use std::any::Any;
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::{Arc, RwLock};
use std::thread::Builder;
use std::{
any::Any,
collections::HashMap,
path::PathBuf,
sync::{Arc, RwLock},
thread::Builder,
};
use log::{error, info};
use thiserror::Error as ThisError;
use vhost_user_backend::VhostUserDaemon;
use vm_memory::{GuestMemoryAtomic, GuestMemoryMmap};
use crate::console::{BackendType, ConsoleController};
use crate::vhu_console::VhostUserConsoleBackend;
use crate::{
console::{BackendType, ConsoleController},
vhu_console::VhostUserConsoleBackend,
};
pub(crate) type Result<T> = std::result::Result<T, Error>;
@ -170,9 +174,10 @@ pub fn start_backend(config: VuConsoleConfig) -> Result<()> {
#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use super::*;
use crate::ConsoleArgs;
use assert_matches::assert_matches;
#[test]
fn test_console_valid_configuration_nested() {

View File

@ -5,10 +5,11 @@
//
// SPDX-License-Identifier: Apache-2.0 or BSD-3-Clause
use crate::virtio_console::VirtioConsoleConfig;
use clap::ValueEnum;
use log::trace;
use crate::virtio_console::VirtioConsoleConfig;
#[derive(ValueEnum, Clone, Copy, Default, Debug, Eq, PartialEq)]
pub enum BackendType {
#[default]

View File

@ -9,11 +9,12 @@ mod backend;
mod console;
mod vhu_console;
mod virtio_console;
use crate::console::BackendType;
use std::{path::PathBuf, process::exit};
use clap::Parser;
use log::error;
use std::path::PathBuf;
use std::process::exit;
use crate::console::BackendType;
pub(crate) type Result<T> = std::result::Result<T, Error>;
use crate::backend::{start_backend, Error, VuConsoleConfig};
@ -21,7 +22,8 @@ use crate::backend::{start_backend, Error, VuConsoleConfig};
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
struct ConsoleArgs {
/// Location of vhost-user Unix domain socket. This is suffixed by 0,1,2..socket_count-1.
/// Location of vhost-user Unix domain socket. This is suffixed by
/// `0,1,2..(socket_count-1)`.
#[clap(short = 's', long, value_name = "SOCKET")]
socket_path: PathBuf,
@ -33,8 +35,9 @@ struct ConsoleArgs {
#[clap(short = 'b', long, value_enum, default_value = "nested")]
backend: BackendType,
/// Initial tcp port to be used with "network" backend. If socket_count is N then
/// the following tcp ports will be created: tcp_port, tcp_port + 1, ..., tcp_port + (N - 1).
/// Initial tcp port to be used with `network` backend. If socket_count is
/// `N` then the following tcp ports will be created: `tcp_port`,
/// `tcp_port + 1`, ... , `tcp_port + (N - 1)`.
#[clap(short = 'p', long, value_name = "PORT", default_value = "12345")]
tcp_port: String,
}

View File

@ -5,33 +5,41 @@
//
// SPDX-License-Identifier: Apache-2.0 or BSD-3-Clause
use crate::console::{BackendType, ConsoleController};
use crate::virtio_console::{
VirtioConsoleControl, VIRTIO_CONSOLE_CONSOLE_PORT, VIRTIO_CONSOLE_DEVICE_READY,
VIRTIO_CONSOLE_F_MULTIPORT, VIRTIO_CONSOLE_PORT_ADD, VIRTIO_CONSOLE_PORT_NAME,
VIRTIO_CONSOLE_PORT_OPEN, VIRTIO_CONSOLE_PORT_READY,
use std::{
io::{self, Read, Result as IoResult, Write},
net::TcpListener,
os::fd::{AsRawFd, RawFd},
slice::from_raw_parts,
sync::{Arc, RwLock},
};
use crossterm::terminal::{disable_raw_mode, enable_raw_mode};
use log::{error, trace, warn};
use queues::{IsQueue, Queue};
use std::io::{self, Read, Result as IoResult, Write};
use std::net::TcpListener;
use std::os::fd::{AsRawFd, RawFd};
use std::slice::from_raw_parts;
use std::sync::{Arc, RwLock};
use thiserror::Error as ThisError;
use vhost::vhost_user::message::{VhostUserProtocolFeatures, VhostUserVirtioFeatures};
use vhost_user_backend::{VhostUserBackendMut, VringEpollHandler, VringRwLock, VringT};
use virtio_bindings::bindings::virtio_config::{VIRTIO_F_NOTIFY_ON_EMPTY, VIRTIO_F_VERSION_1};
use virtio_bindings::bindings::virtio_ring::{
VIRTIO_RING_F_EVENT_IDX, VIRTIO_RING_F_INDIRECT_DESC,
use virtio_bindings::bindings::{
virtio_config::{VIRTIO_F_NOTIFY_ON_EMPTY, VIRTIO_F_VERSION_1},
virtio_ring::{VIRTIO_RING_F_EVENT_IDX, VIRTIO_RING_F_INDIRECT_DESC},
};
use virtio_queue::{DescriptorChain, QueueOwnedT};
use vm_memory::{
ByteValued, GuestAddressSpace, GuestMemoryAtomic, GuestMemoryLoadGuard, GuestMemoryMmap,
};
use vmm_sys_util::epoll::EventSet;
use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK};
use vmm_sys_util::{
epoll::EventSet,
eventfd::{EventFd, EFD_NONBLOCK},
};
use crate::{
console::{BackendType, ConsoleController},
virtio_console::{
VirtioConsoleControl, VIRTIO_CONSOLE_CONSOLE_PORT, VIRTIO_CONSOLE_DEVICE_READY,
VIRTIO_CONSOLE_F_MULTIPORT, VIRTIO_CONSOLE_PORT_ADD, VIRTIO_CONSOLE_PORT_NAME,
VIRTIO_CONSOLE_PORT_OPEN, VIRTIO_CONSOLE_PORT_READY,
},
};
type Result<T> = std::result::Result<T, Error>;
@ -75,9 +83,11 @@ enum QueueEvents {
TxQueue = 1,
CtrlRxQueue = 2,
CtrlTxQueue = 3,
/// `BACKEND_RX_EFD` is being triggered when the backend has new data to send to the RX queue.
/// `BACKEND_RX_EFD` is being triggered when the backend has new data to
/// send to the RX queue.
BackendRxEfd = (VhostUserConsoleBackend::NUM_QUEUES + 1),
/// `BACKEND_CTRL_RX_EFD` event is used when the backend needs to write to the RX control queue.
/// `BACKEND_CTRL_RX_EFD` event is used when the backend needs to write to
/// the RX control queue.
BackendCtrlRxEfd = (VhostUserConsoleBackend::NUM_QUEUES + 2),
KeyEfd = (VhostUserConsoleBackend::NUM_QUEUES + 3),
ListenerEfd = (VhostUserConsoleBackend::NUM_QUEUES + 4),
@ -100,7 +110,8 @@ impl QueueEvents {
/// Port name
///
/// Need to be updated when `MULTIPORT` feature is supported for more than one devices.
/// Need to be updated when `MULTIPORT` feature is supported for more than one
/// devices.
const PORT_NAME: &[u8] = b"org.test.foo!";
// Define a new trait that combines Read and Write
@ -842,12 +853,14 @@ impl VhostUserBackendMut for VhostUserConsoleBackend {
#[cfg(test)]
mod tests {
use super::*;
use std::io::Cursor;
use virtio_bindings::virtio_ring::{VRING_DESC_F_NEXT, VRING_DESC_F_WRITE};
use virtio_queue::{mock::MockSplitQueue, Descriptor, Queue};
use vm_memory::{Bytes, GuestAddress, GuestMemoryAtomic, GuestMemoryMmap};
use super::*;
#[test]
fn test_vhost_user_console_backend_creation() {
let console_controller = Arc::new(RwLock::new(ConsoleController::new(BackendType::Nested)));