From 6c24ab8dd80d7351834758b13a5a5349d301e1ba Mon Sep 17 00:00:00 2001 From: Lucas Manning Date: Thu, 5 Oct 2023 17:25:37 -0700 Subject: [PATCH] Issue FUSE_FLUSH request during file close. PiperOrigin-RevId: 571178563 --- pkg/abi/linux/fuse.go | 11 +++++++++++ pkg/sentry/fsimpl/fuse/file.go | 15 +++++++++++++++ 2 files changed, 26 insertions(+) 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