mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-02-22 11:22:26 +00:00
vm-virtio: console: Expect an identifier upon device creation
This identifier is chosen from the DeviceManager so that it will manage all identifiers across the VM, which will ensure uniqueness. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
354c2a4b3d
commit
052eff1ca7
@ -372,6 +372,7 @@ impl VirtioConsoleConfig {
|
|||||||
|
|
||||||
/// Virtio device for exposing console to the guest OS through virtio.
|
/// Virtio device for exposing console to the guest OS through virtio.
|
||||||
pub struct Console {
|
pub struct Console {
|
||||||
|
id: String,
|
||||||
kill_evt: Option<EventFd>,
|
kill_evt: Option<EventFd>,
|
||||||
pause_evt: Option<EventFd>,
|
pause_evt: Option<EventFd>,
|
||||||
avail_features: u64,
|
avail_features: u64,
|
||||||
@ -396,6 +397,7 @@ pub struct ConsoleState {
|
|||||||
impl Console {
|
impl Console {
|
||||||
/// Create a new virtio console device that gets random data from /dev/urandom.
|
/// Create a new virtio console device that gets random data from /dev/urandom.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
id: String,
|
||||||
out: Box<dyn io::Write + Send + Sync + 'static>,
|
out: Box<dyn io::Write + Send + Sync + 'static>,
|
||||||
cols: u16,
|
cols: u16,
|
||||||
rows: u16,
|
rows: u16,
|
||||||
@ -420,6 +422,7 @@ impl Console {
|
|||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
Console {
|
Console {
|
||||||
|
id,
|
||||||
kill_evt: None,
|
kill_evt: None,
|
||||||
pause_evt: None,
|
pause_evt: None,
|
||||||
avail_features,
|
avail_features,
|
||||||
@ -618,19 +621,18 @@ impl VirtioDevice for Console {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtio_pausable!(Console);
|
virtio_pausable!(Console);
|
||||||
const CONSOLE_SNAPSHOT_ID: &str = "virtio-console";
|
|
||||||
impl Snapshottable for Console {
|
impl Snapshottable for Console {
|
||||||
fn id(&self) -> String {
|
fn id(&self) -> String {
|
||||||
CONSOLE_SNAPSHOT_ID.to_string()
|
self.id.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn snapshot(&self) -> std::result::Result<Snapshot, MigratableError> {
|
fn snapshot(&self) -> std::result::Result<Snapshot, MigratableError> {
|
||||||
let snapshot =
|
let snapshot =
|
||||||
serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?;
|
serde_json::to_vec(&self.state()).map_err(|e| MigratableError::Snapshot(e.into()))?;
|
||||||
|
|
||||||
let mut console_snapshot = Snapshot::new(CONSOLE_SNAPSHOT_ID);
|
let mut console_snapshot = Snapshot::new(self.id.as_str());
|
||||||
console_snapshot.add_data_section(SnapshotDataSection {
|
console_snapshot.add_data_section(SnapshotDataSection {
|
||||||
id: format!("{}-section", CONSOLE_SNAPSHOT_ID),
|
id: format!("{}-section", self.id),
|
||||||
snapshot,
|
snapshot,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -638,10 +640,7 @@ impl Snapshottable for Console {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn restore(&mut self, snapshot: Snapshot) -> std::result::Result<(), MigratableError> {
|
fn restore(&mut self, snapshot: Snapshot) -> std::result::Result<(), MigratableError> {
|
||||||
if let Some(console_section) = snapshot
|
if let Some(console_section) = snapshot.snapshot_data.get(&format!("{}-section", self.id)) {
|
||||||
.snapshot_data
|
|
||||||
.get(&format!("{}-section", CONSOLE_SNAPSHOT_ID))
|
|
||||||
{
|
|
||||||
let console_state = match serde_json::from_slice(&console_section.snapshot) {
|
let console_state = match serde_json::from_slice(&console_section.snapshot) {
|
||||||
Ok(state) => state,
|
Ok(state) => state,
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
|
@ -1099,13 +1099,14 @@ impl DeviceManager {
|
|||||||
};
|
};
|
||||||
let (col, row) = get_win_size();
|
let (col, row) = get_win_size();
|
||||||
let console_input = if let Some(writer) = console_writer {
|
let console_input = if let Some(writer) = console_writer {
|
||||||
|
let id = String::from(CONSOLE_DEVICE_NAME);
|
||||||
let (virtio_console_device, console_input) =
|
let (virtio_console_device, console_input) =
|
||||||
vm_virtio::Console::new(writer, col, row, console_config.iommu)
|
vm_virtio::Console::new(id.clone(), writer, col, row, console_config.iommu)
|
||||||
.map_err(DeviceManagerError::CreateVirtioConsole)?;
|
.map_err(DeviceManagerError::CreateVirtioConsole)?;
|
||||||
virtio_devices.push((
|
virtio_devices.push((
|
||||||
Arc::new(Mutex::new(virtio_console_device)) as VirtioDeviceArc,
|
Arc::new(Mutex::new(virtio_console_device)) as VirtioDeviceArc,
|
||||||
console_config.iommu,
|
console_config.iommu,
|
||||||
Some(String::from(CONSOLE_DEVICE_NAME)),
|
Some(id),
|
||||||
));
|
));
|
||||||
Some(console_input)
|
Some(console_input)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user