Skip to content

Commit

Permalink
Support for fallback guest agent
Browse files Browse the repository at this point in the history
Signed-off-by: Balaji Vijayakumar <[email protected]>
  • Loading branch information
balajiv113 committed Nov 22, 2023
1 parent 9d20fbf commit 4640684
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cmd/lima-guestagent/daemon_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ var (
vSockPort = 0

virtioPort = "/dev/virtio-ports/" + filenames.VirtioPort

socket = "/run/lima-guestagent.sock"
)

func daemonAction(cmd *cobra.Command, _ []string) error {
Expand Down Expand Up @@ -88,6 +90,16 @@ func daemonAction(cmd *cobra.Command, _ []string) error {
}
l = vsockL
logrus.Infof("serving the guest agent on vsock port: %d", vSockPort)
} else {
socketL, err := net.Listen("unix", socket)
if err != nil {
return err
}
if err := os.Chmod(socket, 0o777); err != nil {
return err
}
l = socketL
logrus.Infof("serving the guest agent on %q", socket)
}
return srv.Serve(l)
}
23 changes: 23 additions & 0 deletions pkg/hostagent/hostagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,29 @@ func (a *HostAgent) createClient(_ context.Context) (guestagentclient.GuestAgent
return guestagentclient.NewGuestAgentClient(a.driver.GuestAgentConn)
}

func (a *HostAgent) getDriverConnOrFallback(ctx context.Context) (net.Conn, error) {
conn, err := a.driver.GuestAgentConn(ctx)
if err != nil {
retry := 0
for retry < 2 {
var d net.Dialer
conn, err = d.DialContext(ctx, "unix", filepath.Join(a.instDir, filenames.GuestAgentSock))
if err != nil {
//Forward ssh sock and create connection
localUnix := filepath.Join(a.instDir, filenames.GuestAgentSock)
remoteUnix := "/run/lima-guestagent.sock"
if err := forwardSSH(context.Background(), a.sshConfig, a.sshLocalPort, localUnix, remoteUnix, verbCancel, false); err != nil {
return nil, err
}
retry = retry + 1
}
return conn, err
}
return nil, errors.New("unable to create guestagent fallback connection")
}
return conn, nil
}

func (a *HostAgent) processGuestAgentEvents(ctx context.Context, client guestagentclient.GuestAgentClient) error {
info, err := client.Info(ctx)
if err != nil {
Expand Down

0 comments on commit 4640684

Please sign in to comment.