summaryrefslogtreecommitdiffstats
path: root/meta-egvirt/recipes-extended/vhost-device-console/vhost-device-console-0.1.0/src/main.rs
diff options
context:
space:
mode:
authorTimos Ampelikiotis <t.ampelikiotis@virtualopensystems.com>2024-10-03 11:09:37 +0300
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>2024-10-22 12:21:45 +0000
commitd9b03f2d9b945805f56dfe3eb526264c68747d6f (patch)
tree6fcf0d51d76cdcdd602b8bc2c51d1a7441319d1e /meta-egvirt/recipes-extended/vhost-device-console/vhost-device-console-0.1.0/src/main.rs
parent7dd141f96eb0d7992365e74d34cba80ea5bde3a4 (diff)
Update vhost-device-console
Bug-AGL: SPEC-4966 Change-Id: I41cbe30549ebe923f8e3000ece072aa66c5e90a9 Signed-off-by: Timos Ampelikiotis <t.ampelikiotis@virtualopensystems.com>
Diffstat (limited to 'meta-egvirt/recipes-extended/vhost-device-console/vhost-device-console-0.1.0/src/main.rs')
-rwxr-xr-x[-rw-r--r--]meta-egvirt/recipes-extended/vhost-device-console/vhost-device-console-0.1.0/src/main.rs63
1 files changed, 57 insertions, 6 deletions
diff --git a/meta-egvirt/recipes-extended/vhost-device-console/vhost-device-console-0.1.0/src/main.rs b/meta-egvirt/recipes-extended/vhost-device-console/vhost-device-console-0.1.0/src/main.rs
index cceafb4f..216a01e6 100644..100755
--- a/meta-egvirt/recipes-extended/vhost-device-console/vhost-device-console-0.1.0/src/main.rs
+++ b/meta-egvirt/recipes-extended/vhost-device-console/vhost-device-console-0.1.0/src/main.rs
@@ -1,18 +1,69 @@
// VIRTIO CONSOLE Emulation via vhost-user
//
-// Copyright 2023 VIRTUAL OPEN SYSTEMS SAS. All Rights Reserved.
+// Copyright 2023-2024 VIRTUAL OPEN SYSTEMS SAS. All Rights Reserved.
// Timos Ampelikiotis <t.ampelikiotis@virtualopensystems.com>
//
// SPDX-License-Identifier: Apache-2.0 or BSD-3-Clause
-#[cfg(target_env = "gnu")]
mod backend;
-#[cfg(target_env = "gnu")]
mod console;
-#[cfg(target_env = "gnu")]
mod vhu_console;
+mod virtio_console;
+use crate::console::BackendType;
+use clap::Parser;
+use log::error;
+use std::path::PathBuf;
+use std::process::exit;
+
+pub(crate) type Result<T> = std::result::Result<T, Error>;
+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.
+ #[clap(short = 's', long, value_name = "SOCKET")]
+ socket_path: PathBuf,
+
+ /// Number of guests (sockets) to connect to.
+ #[clap(short = 'c', long, default_value_t = 1)]
+ socket_count: u32,
+
+ /// Console backend (Network, Nested) to be used.
+ #[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).
+ #[clap(short = 'p', long, value_name = "PORT", default_value = "12345")]
+ tcp_port: String,
+}
+
+impl TryFrom<ConsoleArgs> for VuConsoleConfig {
+ type Error = Error;
+
+ fn try_from(args: ConsoleArgs) -> Result<Self> {
+ if args.socket_count == 0 {
+ return Err(Error::SocketCountInvalid(0));
+ }
+
+ if (args.backend == BackendType::Nested) && (args.socket_count != 1) {
+ return Err(Error::WrongBackendSocket);
+ }
+
+ Ok(VuConsoleConfig {
+ socket_path: args.socket_path,
+ backend: args.backend,
+ tcp_port: args.tcp_port,
+ socket_count: args.socket_count,
+ })
+ }
+}
-#[cfg(target_env = "gnu")]
fn main() {
- backend::console_init()
+ env_logger::init();
+ if let Err(e) = VuConsoleConfig::try_from(ConsoleArgs::parse()).and_then(start_backend) {
+ error!("{e}");
+ exit(1);
+ }
}