-
Notifications
You must be signed in to change notification settings - Fork 602
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
Support for native driver specific guest agent connection #1998
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ name="lima-guestagent" | |
description="Forward ports to the lima-hostagent" | ||
|
||
command=${LIMA_CIDATA_GUEST_INSTALL_PREFIX}/bin/lima-guestagent | ||
command_args="daemon" | ||
command_args="daemon --vsock-port "${LIMA_CIDATA_VSOCK_PORT}"" | ||
command_background=true | ||
pidfile="/run/lima-guestagent.pid" | ||
EOF | ||
|
@@ -40,9 +40,5 @@ else | |
# Remove legacy systemd service | ||
rm -f "${LIMA_CIDATA_HOME}/.config/systemd/user/lima-guestagent.service" | ||
|
||
if [ "$LIMA_CIDATA_VMTYPE" = "wsl2" ]; then | ||
sudo "${LIMA_CIDATA_GUEST_INSTALL_PREFIX}"/bin/lima-guestagent install-systemd --vsock-port "${LIMA_CIDATA_VSOCK_PORT}" | ||
else | ||
sudo "${LIMA_CIDATA_GUEST_INSTALL_PREFIX}"/bin/lima-guestagent install-systemd | ||
fi | ||
sudo "${LIMA_CIDATA_GUEST_INSTALL_PREFIX}"/bin/lima-guestagent install-systemd --vsock-port "${LIMA_CIDATA_VSOCK_PORT}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True but by default the port will be 0 for qemu so either way it will be ignored |
||
fi |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package serialport | ||
|
||
import ( | ||
"net" | ||
"time" | ||
) | ||
|
||
type SerialConn struct { | ||
serialDevice string | ||
port *Port | ||
} | ||
|
||
var _ net.Conn = (*SerialConn)(nil) | ||
|
||
func DialSerial(serialDevice string) (*SerialConn, error) { | ||
s, err := openPort(serialDevice) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &SerialConn{port: s, serialDevice: serialDevice}, nil | ||
} | ||
|
||
func (c *SerialConn) Read(b []byte) (n int, err error) { | ||
return c.port.Read(b) | ||
} | ||
|
||
func (c *SerialConn) Write(b []byte) (n int, err error) { | ||
return c.port.Write(b) | ||
} | ||
|
||
func (c *SerialConn) Close() error { | ||
// There is no need to close the serial port every time. | ||
// So just do nothing. | ||
return nil | ||
} | ||
|
||
func (c *SerialConn) LocalAddr() net.Addr { | ||
return &net.UnixAddr{Name: "virtio-port:" + c.serialDevice, Net: "virtio"} | ||
} | ||
|
||
func (c *SerialConn) RemoteAddr() net.Addr { | ||
return &net.UnixAddr{Name: "qemu-host", Net: "virtio"} | ||
} | ||
|
||
func (c *SerialConn) SetDeadline(_ time.Time) error { | ||
return nil | ||
} | ||
|
||
func (c *SerialConn) SetReadDeadline(_ time.Time) error { | ||
return nil | ||
} | ||
|
||
func (c *SerialConn) SetWriteDeadline(_ time.Time) error { | ||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package serialport | ||
|
||
import ( | ||
"net" | ||
"sync" | ||
"syscall" | ||
|
||
"golang.org/x/net/netutil" | ||
) | ||
|
||
type SerialListener struct { | ||
mu sync.Mutex | ||
conn *SerialConn | ||
closed bool | ||
} | ||
|
||
func Listen(serialDevice string) (net.Listener, error) { | ||
c, err := DialSerial(serialDevice) | ||
if err != nil { | ||
return nil, &net.OpError{Op: "dial", Net: "virtio", Source: c.LocalAddr(), Addr: nil, Err: err} | ||
} | ||
|
||
return netutil.LimitListener(&SerialListener{conn: c}, 1), nil | ||
} | ||
|
||
func (ln *SerialListener) ok() bool { | ||
return ln != nil && ln.conn != nil && !ln.closed | ||
} | ||
|
||
func (ln *SerialListener) Accept() (net.Conn, error) { | ||
ln.mu.Lock() | ||
defer ln.mu.Unlock() | ||
|
||
if !ln.ok() { | ||
return nil, syscall.EINVAL | ||
} | ||
|
||
return ln.conn, nil | ||
} | ||
|
||
func (ln *SerialListener) Close() error { | ||
ln.mu.Lock() | ||
defer ln.mu.Unlock() | ||
|
||
if !ln.ok() { | ||
return syscall.EINVAL | ||
} | ||
|
||
if ln.closed { | ||
return nil | ||
} | ||
ln.closed = true | ||
|
||
return nil | ||
} | ||
|
||
func (ln *SerialListener) Addr() net.Addr { | ||
if ln.ok() { | ||
return ln.conn.LocalAddr() | ||
} | ||
|
||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package serialport | ||
|
||
import ( | ||
"os" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func openPort(name string) (p *Port, err error) { | ||
f, err := os.OpenFile(name, unix.O_RDWR|unix.O_NOCTTY|unix.O_NONBLOCK, 0o666) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
defer func() { | ||
if err != nil && f != nil { | ||
f.Close() | ||
} | ||
}() | ||
|
||
fd := f.Fd() | ||
if err = unix.SetNonblock(int(fd), false); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &Port{f: f}, nil | ||
} | ||
|
||
type Port struct { | ||
f *os.File | ||
} | ||
|
||
func (p *Port) Read(b []byte) (n int, err error) { | ||
return p.f.Read(b) | ||
} | ||
|
||
func (p *Port) Write(b []byte) (n int, err error) { | ||
return p.f.Write(b) | ||
} | ||
|
||
func (p *Port) Close() (err error) { | ||
return p.f.Close() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was needed to properly upgrade on first start.
Without this, the below case was failing
lima 0.15 create and start -> stop -> lima 1 start -> guest is updated but not restarted to pick up latest one -> This will be taken only after second restart