Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve VM shutdown/reboot experience #362

Merged
merged 2 commits into from
Jan 4, 2024
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 cmd/incusd/instance_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/lxc/incus/internal/server/cluster"
"github.com/lxc/incus/internal/server/db/operationtype"
"github.com/lxc/incus/internal/server/instance"
"github.com/lxc/incus/internal/server/instance/drivers"
"github.com/lxc/incus/internal/server/instance/instancetype"
"github.com/lxc/incus/internal/server/operations"
"github.com/lxc/incus/internal/server/request"
Expand Down Expand Up @@ -286,7 +287,14 @@ func (s *execWs) Do(op *operations.Operation) error {
_ = pty.Close()
}

// Make VM disconnections (shutdown/reboot) match containers.
if cmdErr == drivers.ErrExecDisconnected {
cmdResult = 129
cmdErr = nil
}

metadata := jmap.Map{"return": cmdResult}

err = op.ExtendMetadata(metadata)
if err != nil {
return err
Expand Down
5 changes: 4 additions & 1 deletion internal/server/instance/drivers/driver_qemu_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import (
"github.com/lxc/incus/shared/logger"
)

// ErrExecDisconnected is returned when the guest disconnects the exec session.
var ErrExecDisconnected = fmt.Errorf("Disconnected")

// Cmd represents a running command for an Qemu VM.
type qemuCmd struct {
attachedChildPid int
Expand Down Expand Up @@ -78,7 +81,7 @@ func (c *qemuCmd) Wait() (int, error) {
// so we inform the client of the disconnection with a more
// descriptive message.
if errors.Is(err, io.EOF) {
return exitStatus, fmt.Errorf("Disconnected")
return exitStatus, ErrExecDisconnected
}

return exitStatus, err
Expand Down
Loading