mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Make HostBountEndpoint.SetBoundSocketFD take ownership of bound socket FD.
Earlier SetBoundSocketFD() was taking ownership of bound socket FD only on success. Having it take ownership unconditionally is cleaner. PiperOrigin-RevId: 516903597
This commit is contained in:
@@ -476,8 +476,7 @@ func (d *directfsDentry) bindAt(ctx context.Context, name string, creds *auth.Cr
|
||||
}
|
||||
bsFD := &boundSocketFD{sockFD}
|
||||
hbep := opts.Endpoint.(transport.HostBoundEndpoint)
|
||||
if err := hbep.SetBoundSocketFD(bsFD); err != nil {
|
||||
bsFD.Close(ctx)
|
||||
if err := hbep.SetBoundSocketFD(ctx, bsFD); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -406,8 +406,7 @@ func (d *lisafsDentry) mknod(ctx context.Context, name string, creds *auth.Crede
|
||||
return nil, err
|
||||
}
|
||||
hbep := opts.Endpoint.(transport.HostBoundEndpoint)
|
||||
if err := hbep.SetBoundSocketFD(boundSocketFD); err != nil {
|
||||
boundSocketFD.Close(ctx)
|
||||
if err := hbep.SetBoundSocketFD(ctx, boundSocketFD); err != nil {
|
||||
if err := d.controlFD.UnlinkAt(ctx, name, 0 /* flags */); err != nil {
|
||||
log.Warningf("failed to clean up socket which was created by BindAt RPC: %v", err)
|
||||
}
|
||||
|
||||
@@ -595,10 +595,11 @@ func (e *connectionedEndpoint) OnSetSendBufferSize(v int64) (newSz int64) {
|
||||
func (e *connectionedEndpoint) WakeupWriters() {}
|
||||
|
||||
// SetBoundSocketFD implement HostBountEndpoint.SetBoundSocketFD.
|
||||
func (e *connectionedEndpoint) SetBoundSocketFD(bsFD BoundSocketFD) error {
|
||||
func (e *connectionedEndpoint) SetBoundSocketFD(ctx context.Context, bsFD BoundSocketFD) error {
|
||||
e.Lock()
|
||||
defer e.Unlock()
|
||||
if e.path != "" || e.boundSocketFD != nil {
|
||||
bsFD.Close(ctx)
|
||||
return syserr.ErrAlreadyBound.ToError()
|
||||
}
|
||||
e.boundSocketFD = bsFD
|
||||
|
||||
@@ -269,9 +269,9 @@ type BoundEndpoint interface {
|
||||
type HostBoundEndpoint interface {
|
||||
// SetBoundSocketFD will be called on supporting endpoints after
|
||||
// binding a socket on the host filesystem. Implementations should
|
||||
// delegate Listen and Accept calls to the BoundSocketFD. On success,
|
||||
// the ownership of bsFD is transferred to the endpoint.
|
||||
SetBoundSocketFD(bsFD BoundSocketFD) error
|
||||
// delegate Listen and Accept calls to the BoundSocketFD. The ownership
|
||||
// of bsFD is transferred to the endpoint.
|
||||
SetBoundSocketFD(ctx context.Context, bsFD BoundSocketFD) error
|
||||
|
||||
// ResetBoundSocketFD cleans up the BoundSocketFD set by the last successful
|
||||
// SetBoundSocketFD call.
|
||||
|
||||
Reference in New Issue
Block a user