From fa7aa5b4e2e5d958dff4f8acb3b783c96878efe0 Mon Sep 17 00:00:00 2001 From: Ayush Ranjan Date: Thu, 23 Mar 2023 00:06:44 -0700 Subject: [PATCH] Decouple file_handle_sharing and cache settings in the gofer client. Earlier, both these settings were controlled by the cache= option. Only cache_none was able to disable file handle sharing. But there can be cases where we want the FS cache but disable file handle sharing. Instead of adding yet another cache enum, decouple these settings so they can be set independently. As a result, we don't need cache_none anymore, get rid of it. PiperOrigin-RevId: 518780704 --- pkg/sentry/fsimpl/gofer/filesystem.go | 9 ++++----- pkg/sentry/fsimpl/gofer/gofer.go | 29 ++++++++++++++------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/pkg/sentry/fsimpl/gofer/filesystem.go b/pkg/sentry/fsimpl/gofer/filesystem.go index 97cbdde45..fc9dec077 100644 --- a/pkg/sentry/fsimpl/gofer/filesystem.go +++ b/pkg/sentry/fsimpl/gofer/filesystem.go @@ -1736,11 +1736,10 @@ func (fs *filesystem) MountOptions() string { case InteropModeWritethrough: optsKV = append(optsKV, mopt{moptCache, cacheFSCacheWritethrough}) case InteropModeShared: - if fs.opts.regularFilesUseSpecialFileFD { - optsKV = append(optsKV, mopt{moptCache, cacheNone}) - } else { - optsKV = append(optsKV, mopt{moptCache, cacheRemoteRevalidating}) - } + optsKV = append(optsKV, mopt{moptCache, cacheRemoteRevalidating}) + } + if fs.opts.regularFilesUseSpecialFileFD { + optsKV = append(optsKV, mopt{moptDisableFileHandleSharing, nil}) } if fs.opts.forcePageCache { optsKV = append(optsKV, mopt{moptForcePageCache, nil}) diff --git a/pkg/sentry/fsimpl/gofer/gofer.go b/pkg/sentry/fsimpl/gofer/gofer.go index 73825ddbb..ea807e86c 100644 --- a/pkg/sentry/fsimpl/gofer/gofer.go +++ b/pkg/sentry/fsimpl/gofer/gofer.go @@ -73,16 +73,17 @@ const Name = "9p" // Mount option names for goferfs. const ( - moptTransport = "trans" - moptReadFD = "rfdno" - moptWriteFD = "wfdno" - moptAname = "aname" - moptDfltUID = "dfltuid" - moptDfltGID = "dfltgid" - moptCache = "cache" - moptForcePageCache = "force_page_cache" - moptLimitHostFDTranslation = "limit_host_fd_translation" - moptOverlayfsStaleRead = "overlayfs_stale_read" + moptTransport = "trans" + moptReadFD = "rfdno" + moptWriteFD = "wfdno" + moptAname = "aname" + moptDfltUID = "dfltuid" + moptDfltGID = "dfltgid" + moptCache = "cache" + moptForcePageCache = "force_page_cache" + moptLimitHostFDTranslation = "limit_host_fd_translation" + moptOverlayfsStaleRead = "overlayfs_stale_read" + moptDisableFileHandleSharing = "disable_file_handle_sharing" // Directfs options. moptDirectfs = "directfs" @@ -90,7 +91,6 @@ const ( // Valid values for the "cache" mount option. const ( - cacheNone = "none" cacheFSCache = "fscache" cacheFSCacheWritethrough = "fscache_writethrough" cacheRemoteRevalidating = "remote_revalidating" @@ -422,9 +422,6 @@ func (fstype FilesystemType) GetFilesystem(ctx context.Context, vfsObj *vfs.Virt fsopts.interop = InteropModeExclusive case cacheFSCacheWritethrough: fsopts.interop = InteropModeWritethrough - case cacheNone: - fsopts.regularFilesUseSpecialFileFD = true - fallthrough case cacheRemoteRevalidating: fsopts.interop = InteropModeShared default: @@ -459,6 +456,10 @@ func (fstype FilesystemType) GetFilesystem(ctx context.Context, vfsObj *vfs.Virt } // Handle simple flags. + if _, ok := mopts[moptDisableFileHandleSharing]; ok { + delete(mopts, moptDisableFileHandleSharing) + fsopts.regularFilesUseSpecialFileFD = true + } if _, ok := mopts[moptForcePageCache]; ok { delete(mopts, moptForcePageCache) fsopts.forcePageCache = true