mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-25 18:53:44 +00:00
runtime: Launch QEMU with cmd.Start()
LaunchCustomQemu() currently starts QEMU with cmd.Run() which is supposed to block until the child process terminates. This assumes that QEMU daemonizes itself, otherwise LaunchCustomQemu() would block forever. The virtcontainers package indeed enables the Daemonize knob in the configuration but having such an implicit dependency on a supposedly configurable setting is ugly and fragile. cmd.Run() is : func (c *Cmd) Run() error { if err := c.Start(); err != nil { return err } return c.Wait() } Let's open-code this : govmm calls cmd.Start() and returns the cmd to virtcontainers which calls cmd.Wait(). If QEMU doesn't start, e.g. missing binary, there won't be any errors to collect from QEMU output. Just drop these lines in govmm. Similarily there won't be any log file to read from in virtcontainers. Drop that as well. Signed-off-by: Greg Kurz <groug@kaod.org>
This commit is contained in:
@@ -941,17 +941,16 @@ func (q *qemu) StartVM(ctx context.Context, timeout int) error {
|
||||
|
||||
}
|
||||
|
||||
var strErr string
|
||||
strErr, err = govmmQemu.LaunchQemu(q.qemuConfig, newQMPLogger())
|
||||
qemuCmd, err := govmmQemu.LaunchQemu(q.qemuConfig, newQMPLogger())
|
||||
if err != nil {
|
||||
if q.config.Debug && q.qemuConfig.LogFile != "" {
|
||||
b, err := os.ReadFile(q.qemuConfig.LogFile)
|
||||
if err == nil {
|
||||
strErr += string(b)
|
||||
}
|
||||
}
|
||||
q.Logger().WithError(err).Errorf("failed to launch qemu: %s", strErr)
|
||||
return fmt.Errorf("failed to launch qemu: %s, error messages from qemu log: %s", err, strErr)
|
||||
q.Logger().WithError(err).Error("failed to launch qemu")
|
||||
return fmt.Errorf("failed to launch qemu: %s", err)
|
||||
}
|
||||
if q.qemuConfig.Knobs.Daemonize {
|
||||
// LaunchQemu returns a handle on the upper QEMU process.
|
||||
// Wait for it to exit to assume that the QEMU daemon was
|
||||
// actually started.
|
||||
qemuCmd.Wait()
|
||||
}
|
||||
|
||||
err = q.waitVM(ctx, qmpConn, timeout)
|
||||
|
Reference in New Issue
Block a user