Skip to content

Commit

Permalink
control_plane_agent: detach stale faux-mgs clients on new attach
Browse files Browse the repository at this point in the history
requests

Factors out existing check that was used when sending new packets to
also detach stale clients in serial_console_attach()

As suggested in oxidecomputer#1796.

Signed-off-by: Andriy Sultanov <[email protected]>
  • Loading branch information
last-genius committed Nov 19, 2024
1 parent a842b3c commit f35d547
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions task/control-plane-agent/src/mgs_compute_sled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,25 @@ impl MgsHandler {
id
}

fn get_attached_nonidle_client(
&mut self,
) -> &Option<AttachedSerialConsoleMgs> {
if let Some(attached) = &self.attached_serial_console_mgs {
// Check whether we think this client has disappeared
let client_age_ms = sys_get_timer()
.now
.saturating_sub(attached.last_keepalive_received);
if Duration::from_millis(client_age_ms)
> SERIAL_CONSOLE_IDLE_TIMEOUT
{
self.usart.clear_rx_data();
self.attached_serial_console_mgs = None;
}
}

return &self.attached_serial_console_mgs;
}

pub(crate) fn packet_to_mgs(
&mut self,
tx_buf: &mut [u8; gateway_messages::MAX_SERIALIZED_SIZE],
Expand All @@ -279,21 +298,8 @@ impl MgsHandler {
}

// Do we have an attached MGS instance that hasn't gone stale?
let sender = match &self.attached_serial_console_mgs {
Some(attached) => {
// Check whether we think this client has disappeared
let client_age_ms = sys_get_timer()
.now
.saturating_sub(attached.last_keepalive_received);
if Duration::from_millis(client_age_ms)
> SERIAL_CONSOLE_IDLE_TIMEOUT
{
self.usart.clear_rx_data();
self.attached_serial_console_mgs = None;
return None;
}
attached.sender
}
let sender = match &self.get_attached_nonidle_client() {
Some(attached) => attached.sender,
None => {
// Discard any buffered data and reset any usart-related timers.
self.usart.clear_rx_data();
Expand Down Expand Up @@ -746,7 +752,7 @@ impl SpHandler for MgsHandler {
return Err(SpError::RequestUnsupportedForComponent);
}

if self.attached_serial_console_mgs.is_some() {
if self.get_attached_nonidle_client().is_some() {
return Err(SpError::SerialConsoleAlreadyAttached);
}

Expand Down

0 comments on commit f35d547

Please sign in to comment.