Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions mantle/cmd/kola/qemuexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ var (

devshell bool
devshellConsole bool

consoleFile string
)

func init() {
Expand All @@ -81,6 +83,7 @@ func init() {
cmdQemuExec.Flags().StringArrayVar(&bindrw, "bind-rw", nil, "Same as above, but writable")
cmdQemuExec.Flags().BoolVarP(&forceConfigInjection, "inject-ignition", "", false, "Force injecting Ignition config using guestfs")
cmdQemuExec.Flags().BoolVar(&propagateInitramfsFailure, "propagate-initramfs-failure", false, "Error out if the system fails in the initramfs")
cmdQemuExec.Flags().StringVarP(&consoleFile, "console-to-file", "", "", "Filepath in which to save serial console logs")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Save serial console to this file" maybe? "in which" is better than ending in "in" (which ends in "in" (which...))


}

Expand Down Expand Up @@ -114,6 +117,10 @@ func runQemuExec(cmd *cobra.Command, args []string) error {

if devshellConsole {
devshell = true

if consoleFile != "" {
return fmt.Errorf("Cannot use console devshell and --console-to-file")
}
}
if devshell {
if directIgnition {
Expand Down Expand Up @@ -244,6 +251,7 @@ func runQemuExec(cmd *cobra.Command, args []string) error {
builder.EnableUsermodeNetworking(h)
}
builder.InheritConsole = true
builder.ConsoleFile = consoleFile
builder.Append(args...)

if devshell && !devshellConsole {
Expand Down
2 changes: 1 addition & 1 deletion mantle/cmd/kola/testiso.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func newQemuBuilder(outdir string) (*platform.QemuBuilder, *conf.Conf, error) {
}

if !builder.InheritConsole {
builder.ConsoleToFile(filepath.Join(outdir, "console.txt"))
builder.ConsoleFile = filepath.Join(outdir, "console.txt")
}
config, err := conf.EmptyIgnition().Render(kola.IsIgnitionV2())
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion mantle/platform/machine/qemuiso/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (qc *Cluster) NewMachineWithQemuOptions(userdata *conf.UserData, options pl
builder.Firmware = qc.flight.opts.Firmware
}
builder.Hostname = fmt.Sprintf("qemu%d", qc.BaseCluster.AllocateMachineSerial())
builder.ConsoleToFile(qm.consolePath)
builder.ConsoleFile = qm.consolePath

if qc.flight.opts.Memory != "" {
memory, err := strconv.ParseInt(qc.flight.opts.Memory, 10, 32)
Expand Down
2 changes: 1 addition & 1 deletion mantle/platform/machine/unprivqemu/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (qc *Cluster) NewMachineWithQemuOptions(userdata *conf.UserData, options pl
builder.Firmware = qc.flight.opts.Firmware
builder.Swtpm = qc.flight.opts.Swtpm
builder.Hostname = fmt.Sprintf("qemu%d", qc.BaseCluster.AllocateMachineSerial())
builder.ConsoleToFile(qm.consolePath)
builder.ConsoleFile = qm.consolePath

if qc.flight.opts.Memory != "" {
memory, err := strconv.ParseInt(qc.flight.opts.Memory, 10, 32)
Expand Down
14 changes: 9 additions & 5 deletions mantle/platform/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ type QemuBuilder struct {
ForceConfigInjection bool
configInjected bool

// File to which to redirect the serial console
ConsoleFile string

// Memory defaults to 1024 on most architectures, others it may be 2048
Memory int
// Processors < 0 means to use host count, unset means 1, values > 1 are directly used
Expand Down Expand Up @@ -436,11 +439,6 @@ func virtio(device, args string) string {
return fmt.Sprintf("virtio-%s-%s,%s", device, suffix, args)
}

// ConsoleToFile configures the instance to have a serial console, logging to `path`.
func (builder *QemuBuilder) ConsoleToFile(path string) {
builder.Append("-display", "none", "-chardev", "file,id=log,path="+path, "-serial", "chardev:log")
}

// EnableUsermodeNetworking configure forwarding for all requested ports,
// via usermode network helpers.
func (builder *QemuBuilder) EnableUsermodeNetworking(h []HostForwardPort) {
Expand Down Expand Up @@ -1307,6 +1305,12 @@ func (builder *QemuBuilder) Exec() (*QemuInstance, error) {
fdnum++
}

if builder.ConsoleFile != "" {
builder.Append("-display", "none", "-chardev", "file,id=log,path="+builder.ConsoleFile, "-serial", "chardev:log")
} else {
builder.Append("-serial", "mon:stdio")
}

// And the custom arguments
argv = append(argv, builder.Argv...)

Expand Down
4 changes: 2 additions & 2 deletions src/cmdlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,8 @@ EOF
echo "$@" > "${tmp_builddir}"/cmd.sh

touch "${runvm_console}"
kola_args=(kola qemuexec -m 2048 --auto-cpus -U --workdir none)
kola_args=(kola qemuexec -m 2048 --auto-cpus -U --workdir none \
--console-to-file "${runvm_console}")
base_qemu_args=(-drive 'if=none,id=root,format=raw,snapshot=on,file='"${vmbuilddir}"'/root,index=1' \
-device 'virtio-blk,drive=root'
-kernel "${vmbuilddir}/kernel" -initrd "${vmbuilddir}/initrd" \
Expand All @@ -518,7 +519,6 @@ EOF

if [ -z "${RUNVM_SHELL:-}" ]; then
if ! "${kola_args[@]}" -- "${base_qemu_args[@]}" \
-serial file:"${runvm_console}" \
-device virtserialport,chardev=virtioserial0,name=cosa-cmdout \
-chardev stdio,id=virtioserial0 \
"${qemu_args[@]}" <&-; then # the <&- here closes stdin otherwise qemu waits forever
Expand Down