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:
Ayush Ranjan
2023-03-15 12:53:27 -07:00
committed by gVisor bot
parent 4c5803c47f
commit 6669003321
4 changed files with 7 additions and 8 deletions
+1 -2
View File
@@ -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
}
+1 -2
View File
@@ -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
+3 -3
View File
@@ -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.