From e60464fdfa1d54fe234603814450d7956f20a5bd Mon Sep 17 00:00:00 2001 From: Ayush Ranjan Date: Thu, 16 Nov 2023 11:48:52 -0800 Subject: [PATCH] Set disable_file_handle_sharing for NFS mounts. The gofer client caches remote file handles for performance reasons (to reduce Open RPCs). However, remote filesystems like NFS rely on close(2) syscall for flushing file data to the server. Due to remote file handle caching, the application's close(2) syscall is not propagated to the host and file data is not flushed. disable_file_handle_sharing prevents the remote file handle from being cached. PiperOrigin-RevId: 583116138 --- runsc/cmd/gofer.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/runsc/cmd/gofer.go b/runsc/cmd/gofer.go index 1cd937639..21300f237 100644 --- a/runsc/cmd/gofer.go +++ b/runsc/cmd/gofer.go @@ -656,7 +656,7 @@ func resolveSymlinksImpl(root, base, rel string, followCount uint) (string, erro return base, nil } -// adjustMountOptions adds 'overlayfs_stale_read' if mounting over overlayfs. +// adjustMountOptions adds filesystem-specific gofer mount options. func adjustMountOptions(conf *config.Config, path string, opts []string) ([]string, error) { rv := make([]string, len(opts)) copy(rv, opts) @@ -665,8 +665,16 @@ func adjustMountOptions(conf *config.Config, path string, opts []string) ([]stri if err := unix.Statfs(path, &statfs); err != nil { return nil, err } - if statfs.Type == unix.OVERLAYFS_SUPER_MAGIC { + switch statfs.Type { + case unix.OVERLAYFS_SUPER_MAGIC: rv = append(rv, "overlayfs_stale_read") + case unix.NFS_SUPER_MAGIC: + // The gofer client implements remote file handle sharing for performance. + // However, remote filesystems like NFS rely on close(2) syscall for + // flushing file data to the server. Such handle sharing prevents the + // application's close(2) syscall from being propagated to the host. Hence + // disable file handle sharing, so NFS files are flushed correctly. + rv = append(rv, "disable_file_handle_sharing") } return rv, nil }