Skip to content

console: VM serial consoles ​

For Go code, follow the repository Go anti-pattern rules.

Metal specification · overview: Metal daemon and API

Purpose ​

The console package keeps recent VM serial output and replays it to new viewers. It also handles SSH session PTYs, whose IDs start with ssh-. firecracker owns their lifecycle.

Types ​

TypeResponsibility
SerialBrokerMaps VM and SSH session IDs to consoles.
DescriptorStoreKeeps PTY masters open across a metald restart.
consoleOwns one PTY master, its scrollback, and its viewers.
ringBufferHolds recent output for replay.
WinsizeCarries a viewer terminal size.

PTY model ​

Flow diagram
Loading diagram...
MethodAction
OpenAllocates the master and starts the drain. Keeps it out of the store.
PersistAdds the master to the store after the unit holds the slave.
AttachAdds a viewer. The viewer follows the VM to its next console after a restart.
CloseReleases the master.
ShutdownReleases local masters.
AdoptRestores stored masters, removes stale masters and links.

Do not close a master while its VM runs. Linux then sends SIGHUP to Firecracker and stops the VM.

  • The unit needs NotifyAccess, FileDescriptorStoreMax, and FileDescriptorStorePreserve=yes.
  • systemd closes a stored master that reports EPOLLHUP, which happens while no slave is open.
  • A master is non-blocking. One drain at a time reads a PTY.
  • The drain treats EIO as idle until the console is closed.

Backpressure ​

  • Output must never block the guest.
  • A viewer that would block is dropped and disconnected.
  • A new viewer gets the bounded scrollback first, then live output.

Lifecycle ​

A VM console lives from VM launch to VM stop. An SSH session console lives from session start to session end. The runtime calls Open, Persist, and Close. metald calls Adopt and Shutdown.

A viewer lives until it disconnects or is dropped. Attach owns its input goroutine, so input goes to the current console and a restart does not leave a second reader on the viewer.

AGPL-3.0