Skip to content

Commit dd6693c

Browse files
committed
server: support for read-only serial clients
1 parent 6f85e92 commit dd6693c

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

bin/propolis-server/src/lib/serial/history_buffer.rs

+2
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ impl TryFrom<&api::InstanceSerialConsoleStreamRequest> for SerialHistoryOffset {
5353
api::InstanceSerialConsoleStreamRequest {
5454
from_start: Some(offset),
5555
most_recent: None,
56+
..
5657
} => Ok(SerialHistoryOffset::FromStart(*offset as usize)),
5758
api::InstanceSerialConsoleStreamRequest {
5859
from_start: None,
5960
most_recent: Some(offset),
61+
..
6062
} => Ok(SerialHistoryOffset::MostRecent(*offset as usize)),
6163
_ => Err(()),
6264
}

bin/propolis-server/src/lib/server.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ async fn instance_serial(
425425
let ctx = rqctx.context();
426426
let vm = ctx.vm.active_vm().await.ok_or_else(not_created_error)?;
427427
let serial = vm.objects().lock_shared().await.com1().clone();
428+
let query = query.into_inner();
428429

429430
// Use the default buffering paramters for the websocket configuration
430431
//
@@ -440,7 +441,7 @@ async fn instance_serial(
440441
)
441442
.await;
442443

443-
let byte_offset = SerialHistoryOffset::try_from(&query.into_inner()).ok();
444+
let byte_offset = SerialHistoryOffset::try_from(&query).ok();
444445
if let Some(mut byte_offset) = byte_offset {
445446
loop {
446447
let (data, offset) = serial.history_vec(byte_offset, None)?;
@@ -459,7 +460,14 @@ async fn instance_serial(
459460
serial_mgr
460461
.as_ref()
461462
.ok_or("Instance has no serial console manager")?
462-
.connect(ws_stream, crate::serial::ClientKind::ReadWrite)
463+
.connect(
464+
ws_stream,
465+
if query.writable {
466+
crate::serial::ClientKind::ReadWrite
467+
} else {
468+
crate::serial::ClientKind::ReadOnly
469+
},
470+
)
463471
.await;
464472

465473
Ok(())

crates/propolis-api-types/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,11 @@ pub struct InstanceSerialConsoleStreamRequest {
325325
/// recently buffered data retrieved from the instance. (See note on `from_start` about mutual
326326
/// exclusivity)
327327
pub most_recent: Option<u64>,
328+
/// True if the connection should allow writing. If this option is set, any
329+
/// existing writer to the serial console will be disconnected when this
330+
/// client connects.
331+
#[serde(default)]
332+
pub writable: bool,
328333
}
329334

330335
/// Control message(s) sent through the websocket to serial console clients.

openapi/propolis-server.json

+8
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,14 @@
265265
"format": "uint64",
266266
"minimum": 0
267267
}
268+
},
269+
{
270+
"in": "query",
271+
"name": "writable",
272+
"description": "True if the connection should allow writing. If this option is set, any existing writer to the serial console will be disconnected when this client connects.",
273+
"schema": {
274+
"type": "boolean"
275+
}
268276
}
269277
],
270278
"responses": {

0 commit comments

Comments
 (0)