-
Notifications
You must be signed in to change notification settings - Fork 22
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
PHD: add Windows Server 2016 adapter & improve WS2016/2019 reliability #646
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4cb4bfa
PHD: add Windows Server 2016 adapter
gjcolombo 9147815
PHD: make GuestOs generate shell command sequences
gjcolombo 9ade09d
PHD: only apply debounce on repeated characters
gjcolombo 1c73c8c
PHD: wait for entire command to be typed before starting serial timeout
gjcolombo 73f52ee
whoa we're half way there / whoa clippy on a prayer
gjcolombo bb39823
PHD: make callers consume serial buffer by hand
gjcolombo 2689f98
PR feedback: clean up CommandSequenceEntry & comments
gjcolombo b5b8d81
PR feedback & comment cleanup
gjcolombo 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
//! Common helper functions for issuing shell commands to guests and handling | ||
//! their outputs. | ||
|
||
use std::borrow::Cow; | ||
|
||
use super::{CommandSequence, CommandSequenceEntry}; | ||
|
||
/// Produces the shell command sequence necessary to execute `cmd` in a guest's | ||
/// shell, given that the guest is using the supplied serial console buffering | ||
/// discipline. | ||
/// | ||
/// This routine assumes that multi-line commands will be echoed with `> ` at | ||
/// the start of each line in the command. This is technically shell-dependent | ||
/// but is true for all the shell types in PHD's currently-supported guests. | ||
pub(super) fn shell_command_sequence( | ||
cmd: Cow<'_, str>, | ||
buffer_kind: crate::serial::BufferKind, | ||
) -> CommandSequence { | ||
let echo = cmd.trim_end().replace('\n', "\n> "); | ||
match buffer_kind { | ||
crate::serial::BufferKind::Raw => CommandSequence(vec![ | ||
CommandSequenceEntry::write_str(cmd), | ||
CommandSequenceEntry::wait_for(echo), | ||
CommandSequenceEntry::ClearBuffer, | ||
CommandSequenceEntry::write_str("\n"), | ||
]), | ||
|
||
crate::serial::BufferKind::Vt80x24 => { | ||
// In 80x24 mode, it's simplest to issue multi-line operations one | ||
// line at a time and wait for each line to be echoed before | ||
// starting the next. For very long commands (more than 24 lines), | ||
// this avoids having to deal with lines scrolling off the buffer | ||
// before they can be waited for. | ||
let cmd_lines = cmd.trim_end().lines(); | ||
let echo_lines = echo.lines(); | ||
let mut seq = vec![]; | ||
|
||
let mut iter = cmd_lines.zip(echo_lines).peekable(); | ||
while let Some((cmd, echo)) = iter.next() { | ||
seq.push(CommandSequenceEntry::write_str(cmd.to_owned())); | ||
seq.push(CommandSequenceEntry::wait_for(echo.to_owned())); | ||
|
||
if iter.peek().is_some() { | ||
seq.push(CommandSequenceEntry::write_str("\n")); | ||
} | ||
} | ||
|
||
// Before issuing the command, clear any stale echoed characters | ||
// from the serial console buffer. This ensures that the next prompt | ||
// is preceded in the buffer only by the output of the issued | ||
// command. | ||
seq.push(CommandSequenceEntry::ClearBuffer); | ||
seq.push(CommandSequenceEntry::write_str("\n")); | ||
CommandSequence(seq) | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
//! Guest OS adaptations for Windows Server 2016 images. See [the general | ||
//! Windows module](mod@super::windows) documentation for more information. | ||
|
||
use std::borrow::Cow; | ||
|
||
use super::{CommandSequence, GuestOs, GuestOsKind}; | ||
|
||
/// The guest adapter for Windows Server 2016 images. See [the general | ||
/// Windows module](mod@super::windows) documentation for more information about | ||
/// the configuration this adapter requires. | ||
pub(super) struct WindowsServer2016; | ||
|
||
impl GuestOs for WindowsServer2016 { | ||
fn get_login_sequence(&self) -> CommandSequence { | ||
super::windows::get_login_sequence_for(GuestOsKind::WindowsServer2016) | ||
} | ||
|
||
fn get_shell_prompt(&self) -> &'static str { | ||
"Administrator@PHD-WINDOWS:$ " | ||
} | ||
|
||
fn read_only_fs(&self) -> bool { | ||
false | ||
} | ||
|
||
fn shell_command_sequence<'a>(&self, cmd: &'a str) -> CommandSequence<'a> { | ||
// `reset` the command prompt before issuing the command to try to force | ||
// Windows to redraw the subsequent command prompt. Without this, | ||
// Windows may not draw the prompt if the post-command state happens to | ||
// place a prompt at a location that already had one pre-command. | ||
let cmd = format!("reset && {cmd}"); | ||
super::shell_commands::shell_command_sequence( | ||
Cow::Owned(cmd), | ||
crate::serial::BufferKind::Vt80x24, | ||
) | ||
} | ||
} |
Oops, something went wrong.
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.
This feels like it might be the wrong tool for the job, but maybe not?
Previously this was only used for the string literals that appear in guest OSes' boot sequences, but now a command might be an owned string, e.g. if
shell_command_sequence
had to amend it. It seemed silly to make all the literals into ownedString
s just to accommodate this case, but I'm not sure ifCow
is the best (or even an appropriate) way for this code to have its&'static str
cake and eatString
s too.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.
Cow
is absolutely an appropriate way to have something that's "either a&'static str
or aString
" --- honestly, I think I see it used for that purpose far more than for use-cases that actually use copy-on-write...