mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Add transport.BoundSocketFD interface.
This is beneficial for 2 reasons: - transport package should not depend on lisafs, which is a user of that package. - This allows users other than lisafs client to use transport.HostBoundEndpoint. PiperOrigin-RevId: 475326947
This commit is contained in:
@@ -573,7 +573,8 @@ func (f *ClientFD) RemoveXattr(ctx context.Context, name string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// ClientBoundSocketFD corresponds to a bound socket on the server.
|
||||
// ClientBoundSocketFD corresponds to a bound socket on the server. It
|
||||
// implements transport.BoundSocketFD.
|
||||
//
|
||||
// All fields are immutable.
|
||||
type ClientBoundSocketFD struct {
|
||||
@@ -587,19 +588,18 @@ type ClientBoundSocketFD struct {
|
||||
client *Client
|
||||
}
|
||||
|
||||
// Close closes the host and gofer-backed FDs associated to this bound socket.
|
||||
// Close implements transport.BoundSocketFD.Close.
|
||||
func (f *ClientBoundSocketFD) Close(ctx context.Context) {
|
||||
_ = unix.Close(int(f.notificationFD))
|
||||
f.client.CloseFD(ctx, f.fd, true /* flush */)
|
||||
}
|
||||
|
||||
// NotificationFD is a host FD that can be used to notify when new clients
|
||||
// connect to the socket.
|
||||
// NotificationFD implements transport.BoundSocketFD.NotificationFD.
|
||||
func (f *ClientBoundSocketFD) NotificationFD() int32 {
|
||||
return f.notificationFD
|
||||
}
|
||||
|
||||
// Listen makes a Listen RPC.
|
||||
// Listen implements transport.BoundSocketFD.Listen.
|
||||
func (f *ClientBoundSocketFD) Listen(ctx context.Context, backlog int32) error {
|
||||
req := ListenReq{
|
||||
FD: f.fd,
|
||||
@@ -612,7 +612,7 @@ func (f *ClientBoundSocketFD) Listen(ctx context.Context, backlog int32) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Accept makes an Accept RPC.
|
||||
// Accept implements transport.BoundSocketFD.Accept.
|
||||
func (f *ClientBoundSocketFD) Accept(ctx context.Context) (int, error) {
|
||||
req := AcceptReq{
|
||||
FD: f.fd,
|
||||
|
||||
@@ -99,7 +99,6 @@ go_library(
|
||||
"//pkg/errors/linuxerr",
|
||||
"//pkg/fdnotifier",
|
||||
"//pkg/ilist",
|
||||
"//pkg/lisafs",
|
||||
"//pkg/log",
|
||||
"//pkg/refs",
|
||||
"//pkg/refsvfs2",
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
"gvisor.dev/gvisor/pkg/abi/linux"
|
||||
"gvisor.dev/gvisor/pkg/context"
|
||||
"gvisor.dev/gvisor/pkg/fdnotifier"
|
||||
"gvisor.dev/gvisor/pkg/lisafs"
|
||||
"gvisor.dev/gvisor/pkg/sentry/uniqueid"
|
||||
"gvisor.dev/gvisor/pkg/syserr"
|
||||
"gvisor.dev/gvisor/pkg/tcpip"
|
||||
@@ -120,7 +119,7 @@ type connectionedEndpoint struct {
|
||||
// that may listen and accept incoming connections.
|
||||
//
|
||||
// boundSocketFD is protected by baseEndpoint.mu.
|
||||
boundSocketFD *lisafs.ClientBoundSocketFD
|
||||
boundSocketFD BoundSocketFD
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -604,7 +603,7 @@ func (e *connectionedEndpoint) OnSetSendBufferSize(v int64) (newSz int64) {
|
||||
func (e *connectionedEndpoint) WakeupWriters() {}
|
||||
|
||||
// SetBoundSocketFD implement HostBountEndpoint.SetBoundSocketFD.
|
||||
func (e *connectionedEndpoint) SetBoundSocketFD(bsFD *lisafs.ClientBoundSocketFD) {
|
||||
func (e *connectionedEndpoint) SetBoundSocketFD(bsFD BoundSocketFD) {
|
||||
e.Lock()
|
||||
defer e.Unlock()
|
||||
if e.boundSocketFD != nil {
|
||||
|
||||
@@ -18,7 +18,6 @@ package transport
|
||||
import (
|
||||
"gvisor.dev/gvisor/pkg/abi/linux"
|
||||
"gvisor.dev/gvisor/pkg/context"
|
||||
"gvisor.dev/gvisor/pkg/lisafs"
|
||||
"gvisor.dev/gvisor/pkg/log"
|
||||
"gvisor.dev/gvisor/pkg/syserr"
|
||||
"gvisor.dev/gvisor/pkg/tcpip"
|
||||
@@ -269,9 +268,26 @@ type BoundEndpoint interface {
|
||||
// on the host.
|
||||
type HostBoundEndpoint interface {
|
||||
// SetBoundSocketFD will be called on supporting endpoints after
|
||||
// binding a socket on the host filesystem. Implementations should use
|
||||
// delegate Listen and Accept calls to the ClientBoundSocketFD.
|
||||
SetBoundSocketFD(*lisafs.ClientBoundSocketFD)
|
||||
// binding a socket on the host filesystem. Implementations should
|
||||
// delegate Listen and Accept calls to the BoundSocketFD.
|
||||
SetBoundSocketFD(bsFD BoundSocketFD)
|
||||
}
|
||||
|
||||
// BoundSocketFD is an interface that wraps a socket FD that was bind(2)-ed.
|
||||
// It allows to listen and accept on that socket.
|
||||
type BoundSocketFD interface {
|
||||
// Close closes the socket FD.
|
||||
Close(ctx context.Context)
|
||||
|
||||
// NotificationFD is a host FD that can be used to notify when new clients
|
||||
// connect to the socket.
|
||||
NotificationFD() int32
|
||||
|
||||
// Listen is analogous to listen(2).
|
||||
Listen(ctx context.Context, backlog int32) error
|
||||
|
||||
// Accept is analogous to accept(2).
|
||||
Accept(ctx context.Context) (int, error)
|
||||
}
|
||||
|
||||
// message represents a message passed over a Unix domain socket.
|
||||
|
||||
Reference in New Issue
Block a user