Skip to content

Commit 7b3b1a2

Browse files
committed
Always allocate an emulated and a virtio console
I want to build on this in higher level things because we can rely on `hvc0` always being used. Signed-off-by: Colin Walters <walters@verbum.org>
1 parent 346ac16 commit 7b3b1a2

3 files changed

Lines changed: 40 additions & 35 deletions

File tree

crates/kit/src/libvirt/domain.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,13 +353,14 @@ impl DomainBuilder {
353353
}
354354
}
355355

356-
// Serial console
357-
writer.start_element("serial", &[("type", "pty")])?;
358-
writer.write_empty_element("target", &[("port", "0")])?;
359-
writer.end_element("serial")?;
360-
356+
// Serial console, see https://libvirt.org/formatdomain.html#relationship-between-serial-ports-and-consoles
357+
// We allocate a platform-specific default for early console stuff like bootloaders,
358+
// and a platform-independent `hvc0` that can be referenced independently.
359+
writer.start_element("console", &[("type", "pty")])?;
360+
writer.write_empty_element("target", &[("type", "serial")])?;
361+
writer.end_element("console")?;
361362
writer.start_element("console", &[("type", "pty")])?;
362-
writer.write_empty_element("target", &[("type", "serial"), ("port", "0")])?;
363+
writer.write_empty_element("target", &[("type", "virtio")])?;
363364
writer.end_element("console")?;
364365

365366
// VNC graphics if enabled

crates/kit/src/qemu.rs

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -561,33 +561,31 @@ fn spawn(
561561
]);
562562
}
563563

564+
// Add virtio-serial controller - always needed for console
565+
cmd.args(["-device", "virtio-serial"]);
566+
564567
// Add virtio-serial devices
565-
if !config.virtio_serial_devices.is_empty() {
566-
// Add the virtio-serial controller
567-
cmd.args(["-device", "virtio-serial"]);
568-
569-
for (idx, serial_device) in config.virtio_serial_devices.iter().enumerate() {
570-
let char_id = format!("serial_char{}", idx);
571-
// Build chardev args with optional append
572-
let chardev_args = if serial_device.append {
573-
format!(
574-
"file,id={},path={},append=on",
575-
char_id, serial_device.output_file
576-
)
577-
} else {
578-
format!("file,id={},path={}", char_id, serial_device.output_file)
579-
};
568+
for (idx, serial_device) in config.virtio_serial_devices.iter().enumerate() {
569+
let char_id = format!("serial_char{}", idx);
570+
// Build chardev args with optional append
571+
let chardev_args = if serial_device.append {
572+
format!(
573+
"file,id={},path={},append=on",
574+
char_id, serial_device.output_file
575+
)
576+
} else {
577+
format!("file,id={},path={}", char_id, serial_device.output_file)
578+
};
580579

581-
cmd.args([
582-
"-chardev",
583-
&chardev_args,
584-
"-device",
585-
&format!(
586-
"virtserialport,chardev={},name={}",
587-
char_id, serial_device.name
588-
),
589-
]);
590-
}
580+
cmd.args([
581+
"-chardev",
582+
&chardev_args,
583+
"-device",
584+
&format!(
585+
"virtserialport,chardev={},name={}",
586+
char_id, serial_device.name
587+
),
588+
]);
591589
}
592590

593591
// Configure network (only User mode supported now)
@@ -612,13 +610,19 @@ fn spawn(
612610
}
613611
}
614612

615-
// Configure display and console (only None and Console modes supported now)
613+
// No GUI, and no emulated serial ports by default.
614+
cmd.args(["-serial", "none", "-nographic", "-display", "none"]);
615+
616616
match &config.display_mode {
617617
DisplayMode::None => {
618-
cmd.args(["-nographic"]);
618+
// Disable monitor in non-console mode
619+
cmd.args(["-monitor", "none"]);
619620
}
620621
DisplayMode::Console => {
621-
cmd.args(["-serial", "stdio", "-display", "none"]);
622+
cmd.args(["-device", "virtconsole,chardev=console0"]);
623+
cmd.args(["-chardev", "stdio,id=console0,mux=on"]);
624+
// Use monitor on the same muxed chardev
625+
cmd.args(["-monitor", "chardev:console0"]);
622626
}
623627
}
624628

crates/kit/src/run_ephemeral.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ StandardOutput=file:/dev/virtio-ports/executestatus
973973
];
974974

975975
if opts.common.console {
976-
kernel_cmdline.push("console=ttyS0".to_string());
976+
kernel_cmdline.push("console=hvc0".to_string());
977977
}
978978
if cloudinit {
979979
// We don't provide any cloud-init datasource right now,

0 commit comments

Comments
 (0)