-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hypestv: support relaying serial ports to new windows #374
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ use hyperv::run_hvc; | |
use mesh::rpc::RpcSend; | ||
use pal_async::DefaultDriver; | ||
use rustyline_printer::Printer; | ||
use std::fmt::Display; | ||
use std::path::PathBuf; | ||
use std::sync::Arc; | ||
use vm::Vm; | ||
|
||
|
@@ -42,6 +44,10 @@ pub(crate) enum InteractiveCommand { | |
/// Detach from the active VM. | ||
Detach, | ||
|
||
/// Quit the interactive shell. | ||
#[clap(visible_alias = "q")] | ||
Quit, | ||
|
||
#[clap(flatten)] | ||
Vm(VmCommand), | ||
} | ||
|
@@ -74,12 +80,12 @@ pub(crate) enum VmCommand { | |
force: bool, | ||
}, | ||
|
||
/// Sets the serial output mode. | ||
/// Gets or sets the serial output mode. | ||
Serial { | ||
/// The serial port to configure (1 = COM1, etc.). | ||
port: u32, | ||
port: Option<u32>, | ||
/// The serial output mode. | ||
mode: SerialMode, | ||
mode: Option<SerialMode>, | ||
}, | ||
|
||
/// Inspect host or paravisor state. | ||
|
@@ -102,20 +108,28 @@ pub(crate) enum VmCommand { | |
}, | ||
} | ||
|
||
#[derive(ValueEnum, Clone)] | ||
#[derive(ValueEnum, Copy, Clone)] | ||
pub(crate) enum SerialMode { | ||
/// The serial port is disconnected. | ||
Off, | ||
/// The serial port output is connected to the host's console. | ||
Output, | ||
// TODO: add Console mode for interactive console, and Terminal mode for | ||
// launching a terminal emulator. | ||
/// The serial port output is logged to standard output. | ||
Log, | ||
/// The serial port input and output are connected to a new terminal | ||
/// emulator window. | ||
Term, | ||
// TODO: add Console mode for interactive console. | ||
} | ||
|
||
impl Display for SerialMode { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
f.pad(self.to_possible_value().unwrap().get_name()) | ||
} | ||
} | ||
|
||
pub(crate) enum Request { | ||
Prompt(mesh::rpc::Rpc<(), String>), | ||
Inspect(mesh::rpc::Rpc<(InspectTarget, String), anyhow::Result<inspect::Node>>), | ||
Command(mesh::rpc::Rpc<InteractiveCommand, anyhow::Result<()>>), | ||
Command(mesh::rpc::Rpc<InteractiveCommand, anyhow::Result<bool>>), | ||
} | ||
|
||
pub(crate) enum InspectTarget { | ||
|
@@ -130,10 +144,15 @@ pub(crate) enum InspectTarget { | |
struct CommandLine { | ||
/// The initial VM name. Use select to change the active VM. | ||
vm: Option<String>, | ||
#[clap(long, hide(true))] | ||
relay_console_path: Option<PathBuf>, | ||
} | ||
|
||
pub async fn main(driver: DefaultDriver) -> anyhow::Result<()> { | ||
let command_line = CommandLine::parse(); | ||
if let Some(relay_console_path) = command_line.relay_console_path { | ||
return console_relay::relay_console(&relay_console_path); | ||
} | ||
|
||
let mut rl = rustyline::Editor::<_, rustyline::history::FileHistory>::with_config( | ||
rustyline::Config::builder() | ||
|
@@ -215,7 +234,8 @@ pub async fn main(driver: DefaultDriver) -> anyhow::Result<()> { | |
|
||
match parse(&mut template, trimmed) { | ||
Ok(cmd) => match block_on(send.call_failable(Request::Command, cmd)) { | ||
Ok(()) => {} | ||
Ok(true) => {} | ||
Ok(false) => break, | ||
Err(err) => { | ||
eprintln!("{:#}", err); | ||
} | ||
|
@@ -275,8 +295,11 @@ pub async fn main(driver: DefaultDriver) -> anyhow::Result<()> { | |
.handle_command(cmd) | ||
.await?; | ||
} | ||
InteractiveCommand::Quit => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol, I'm surprised this wasn't here in v0. how were you quitting before this? like, via ctrl-d? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, ctrl-d. |
||
return Ok(false); | ||
} | ||
} | ||
Ok(()) | ||
Ok(true) | ||
}) | ||
.await | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another useful addition to this sort of tool: having a
.hypestv_init
file (a-la.gdbinit
) which lets you configure a set of pre-baked commands to run when doing various kinds of vm development (e.g: depending on the guest that's running, or the vm sku, etc...).the concern, of course, is that this opens up an avenue to "script" this dev tool...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking that similar to this, we'd have the concept of a workspace that could be loaded or saved by name. And maybe if you name it the same as a VM, it gets loaded automatically or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like a
.vmname
file or something like that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I could probably get behind a scheme like auto-loading
.hypestv-<vmname>
.