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 <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2022-08-25 10:26:59 +02:00
parent 63462fd8ab
commit a940f525a8
7 changed files with 16 additions and 4 deletions

6
Cargo.lock generated
View File

@ -1011,6 +1011,10 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "serial_buffer"
version = "0.1.0"
[[package]] [[package]]
name = "signal-hook" name = "signal-hook"
version = "0.3.14" version = "0.3.14"
@ -1344,6 +1348,7 @@ dependencies = [
"seccompiler", "seccompiler",
"serde", "serde",
"serde_json", "serde_json",
"serial_buffer",
"thiserror", "thiserror",
"versionize", "versionize",
"versionize_derive", "versionize_derive",
@ -1459,6 +1464,7 @@ dependencies = [
"seccompiler", "seccompiler",
"serde", "serde",
"serde_json", "serde_json",
"serial_buffer",
"signal-hook", "signal-hook",
"thiserror", "thiserror",
"uuid", "uuid",

View File

@ -79,6 +79,7 @@ members = [
"performance-metrics", "performance-metrics",
"qcow", "qcow",
"rate_limiter", "rate_limiter",
"serial_buffer",
"test_infra", "test_infra",
"vfio_user", "vfio_user",
"vhdx", "vhdx",

5
serial_buffer/Cargo.toml Normal file
View File

@ -0,0 +1,5 @@
[package]
name = "serial_buffer"
version = "0.1.0"
authors = ["The Cloud Hypervisor Authors"]
edition = "2021"

View File

@ -16,14 +16,14 @@ const MAX_BUFFER_SIZE: usize = 1 << 20;
// Circular buffer implementation for serial output. // Circular buffer implementation for serial output.
// Read from head; push to tail // Read from head; push to tail
pub(crate) struct SerialBuffer { pub struct SerialBuffer {
buffer: VecDeque<u8>, buffer: VecDeque<u8>,
out: Box<dyn Write + Send>, out: Box<dyn Write + Send>,
write_out: Arc<AtomicBool>, write_out: Arc<AtomicBool>,
} }
impl SerialBuffer { impl SerialBuffer {
pub(crate) fn new(out: Box<dyn Write + Send>, write_out: Arc<AtomicBool>) -> Self { pub fn new(out: Box<dyn Write + Send>, write_out: Arc<AtomicBool>) -> Self {
Self { Self {
buffer: VecDeque::new(), buffer: VecDeque::new(),
out, out,

View File

@ -41,6 +41,7 @@ qcow = { path = "../qcow" }
seccompiler = "0.2.0" seccompiler = "0.2.0"
serde = { version = "1.0.144", features = ["rc", "derive"] } serde = { version = "1.0.144", features = ["rc", "derive"] }
serde_json = "1.0.85" serde_json = "1.0.85"
serial_buffer = { path = "../serial_buffer" }
signal-hook = "0.3.14" signal-hook = "0.3.14"
thiserror = "1.0.32" thiserror = "1.0.32"
uuid = "1.1.2" uuid = "1.1.2"

View File

@ -70,7 +70,6 @@ pub mod memory_manager;
pub mod migration; pub mod migration;
mod pci_segment; mod pci_segment;
pub mod seccomp_filters; pub mod seccomp_filters;
mod serial_buffer;
mod serial_manager; mod serial_manager;
mod sigwinch_listener; mod sigwinch_listener;
pub mod vm; pub mod vm;

View File

@ -5,12 +5,12 @@
use crate::config::ConsoleOutputMode; use crate::config::ConsoleOutputMode;
use crate::device_manager::PtyPair; use crate::device_manager::PtyPair;
use crate::serial_buffer::SerialBuffer;
#[cfg(target_arch = "aarch64")] #[cfg(target_arch = "aarch64")]
use devices::legacy::Pl011; use devices::legacy::Pl011;
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
use devices::legacy::Serial; use devices::legacy::Serial;
use libc::EFD_NONBLOCK; use libc::EFD_NONBLOCK;
use serial_buffer::SerialBuffer;
use std::fs::File; use std::fs::File;
use std::io::Read; use std::io::Read;
use std::os::unix::io::{AsRawFd, FromRawFd}; use std::os::unix::io::{AsRawFd, FromRawFd};