diff --git a/pkg/abi/linux/fuse.go b/pkg/abi/linux/fuse.go index 6f7edde35..3cfdf2e59 100644 --- a/pkg/abi/linux/fuse.go +++ b/pkg/abi/linux/fuse.go @@ -1124,3 +1124,14 @@ type FUSEFallocateIn struct { // padding _ uint32 } + +// FUSEFlushIn is the request sent by the kernel to the daemon after a file is +// closed. +// +// +marshal +type FUSEFlushIn struct { + Fh uint64 + _ uint32 // unused + _ uint32 // padding + LockOwner uint64 +} diff --git a/pkg/sentry/fsimpl/fuse/file.go b/pkg/sentry/fsimpl/fuse/file.go index 333b00556..81de93d27 100644 --- a/pkg/sentry/fsimpl/fuse/file.go +++ b/pkg/sentry/fsimpl/fuse/file.go @@ -92,6 +92,21 @@ func (fd *fileDescription) Release(ctx context.Context) { conn.CallAsync(ctx, req) } +// OnClose implements vfs.FileDescriptionImpl.OnClose. +func (fd *fileDescription) OnClose(ctx context.Context) error { + inode := fd.inode() + conn := inode.fs.conn + inode.attrMu.Lock() + defer inode.attrMu.Unlock() + + in := linux.FUSEFlushIn{ + Fh: fd.Fh, + LockOwner: 0, // TODO(gvisor.dev/issue/3245): file lock + } + req := conn.NewRequest(auth.CredentialsFromContext(ctx), pidFromContext(ctx), inode.nodeID, linux.FUSE_FLUSH, &in) + return conn.CallAsync(ctx, req) +} + // PRead implements vfs.FileDescriptionImpl.PRead. func (fd *fileDescription) PRead(ctx context.Context, dst usermem.IOSequence, offset int64, opts vfs.ReadOptions) (int64, error) { return 0, nil