From a940f525a8aa92a87c3f4159510d73f1baa2e0b2 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Thu, 25 Aug 2022 10:26:59 +0200 Subject: [PATCH] vmm: Move SerialBuffer to its own crate We want to be able to reuse the SerialBuffer from the virtio-devices crate, particularly from the virtio-console implementation. That's why we move the SerialBuffer definition to its own crate so that it can be accessed from both vmm and virtio-devices crates, without creating any cyclic dependency. Signed-off-by: Sebastien Boeuf --- Cargo.lock | 6 ++++++ Cargo.toml | 1 + serial_buffer/Cargo.toml | 5 +++++ vmm/src/serial_buffer.rs => serial_buffer/src/lib.rs | 4 ++-- vmm/Cargo.toml | 1 + vmm/src/lib.rs | 1 - vmm/src/serial_manager.rs | 2 +- 7 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 serial_buffer/Cargo.toml rename vmm/src/serial_buffer.rs => serial_buffer/src/lib.rs (96%) diff --git a/Cargo.lock b/Cargo.lock index 8ce8491de..b3f199fc0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1011,6 +1011,10 @@ dependencies = [ "syn", ] +[[package]] +name = "serial_buffer" +version = "0.1.0" + [[package]] name = "signal-hook" version = "0.3.14" @@ -1344,6 +1348,7 @@ dependencies = [ "seccompiler", "serde", "serde_json", + "serial_buffer", "thiserror", "versionize", "versionize_derive", @@ -1459,6 +1464,7 @@ dependencies = [ "seccompiler", "serde", "serde_json", + "serial_buffer", "signal-hook", "thiserror", "uuid", diff --git a/Cargo.toml b/Cargo.toml index c4fede0cd..948f09dae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -79,6 +79,7 @@ members = [ "performance-metrics", "qcow", "rate_limiter", + "serial_buffer", "test_infra", "vfio_user", "vhdx", diff --git a/serial_buffer/Cargo.toml b/serial_buffer/Cargo.toml new file mode 100644 index 000000000..f5329eb2d --- /dev/null +++ b/serial_buffer/Cargo.toml @@ -0,0 +1,5 @@ +[package] +name = "serial_buffer" +version = "0.1.0" +authors = ["The Cloud Hypervisor Authors"] +edition = "2021" \ No newline at end of file diff --git a/vmm/src/serial_buffer.rs b/serial_buffer/src/lib.rs similarity index 96% rename from vmm/src/serial_buffer.rs rename to serial_buffer/src/lib.rs index fbf7cb753..f01f31aa7 100644 --- a/vmm/src/serial_buffer.rs +++ b/serial_buffer/src/lib.rs @@ -16,14 +16,14 @@ const MAX_BUFFER_SIZE: usize = 1 << 20; // Circular buffer implementation for serial output. // Read from head; push to tail -pub(crate) struct SerialBuffer { +pub struct SerialBuffer { buffer: VecDeque, out: Box, write_out: Arc, } impl SerialBuffer { - pub(crate) fn new(out: Box, write_out: Arc) -> Self { + pub fn new(out: Box, write_out: Arc) -> Self { Self { buffer: VecDeque::new(), out, diff --git a/vmm/Cargo.toml b/vmm/Cargo.toml index 068e70da7..f37534dd9 100644 --- a/vmm/Cargo.toml +++ b/vmm/Cargo.toml @@ -41,6 +41,7 @@ qcow = { path = "../qcow" } seccompiler = "0.2.0" serde = { version = "1.0.144", features = ["rc", "derive"] } serde_json = "1.0.85" +serial_buffer = { path = "../serial_buffer" } signal-hook = "0.3.14" thiserror = "1.0.32" uuid = "1.1.2" diff --git a/vmm/src/lib.rs b/vmm/src/lib.rs index 02285dfc6..9656f3bfc 100644 --- a/vmm/src/lib.rs +++ b/vmm/src/lib.rs @@ -70,7 +70,6 @@ pub mod memory_manager; pub mod migration; mod pci_segment; pub mod seccomp_filters; -mod serial_buffer; mod serial_manager; mod sigwinch_listener; pub mod vm; diff --git a/vmm/src/serial_manager.rs b/vmm/src/serial_manager.rs index d694c2eab..d5be4c725 100644 --- a/vmm/src/serial_manager.rs +++ b/vmm/src/serial_manager.rs @@ -5,12 +5,12 @@ use crate::config::ConsoleOutputMode; use crate::device_manager::PtyPair; -use crate::serial_buffer::SerialBuffer; #[cfg(target_arch = "aarch64")] use devices::legacy::Pl011; #[cfg(target_arch = "x86_64")] use devices::legacy::Serial; use libc::EFD_NONBLOCK; +use serial_buffer::SerialBuffer; use std::fs::File; use std::io::Read; use std::os::unix::io::{AsRawFd, FromRawFd};