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",
]
[[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",

View File

@ -79,6 +79,7 @@ members = [
"performance-metrics",
"qcow",
"rate_limiter",
"serial_buffer",
"test_infra",
"vfio_user",
"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.
// Read from head; push to tail
pub(crate) struct SerialBuffer {
pub struct SerialBuffer {
buffer: VecDeque<u8>,
out: Box<dyn Write + Send>,
write_out: Arc<AtomicBool>,
}
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 {
buffer: VecDeque::new(),
out,

View File

@ -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"

View File

@ -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;

View File

@ -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};