diff options
author | Ayush Ranjan <ayushranjan@google.com> | 2019-08-16 10:18:58 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2019-08-16 10:20:11 -0700 |
commit | 4bab7d7f084c4ce4a8bf5860b71df6aee757cd5c (patch) | |
tree | 1af2f9e4fa26b6f6987354967d534d34f063d304 /pkg/sentry/vfs | |
parent | ef045b914bc8d9795f9184aed4b13351be70a3cf (diff) |
vfs: Remove vfs.DefaultDirectoryFD from embedding vfs.DefaultFD.
This fixes the implementation ambiguity issues when a filesystem
implementation embeds vfs.DefaultDirectoryFD to its directory FD along
with an internal common fileDescription utility.
For similar reasons also removes FileDescriptionDefaultImpl from
DynamicBytesFileDescriptionImpl.
PiperOrigin-RevId: 263795513
Diffstat (limited to 'pkg/sentry/vfs')
-rw-r--r-- | pkg/sentry/vfs/file_description_impl_util.go | 19 | ||||
-rw-r--r-- | pkg/sentry/vfs/file_description_impl_util_test.go | 9 |
2 files changed, 20 insertions, 8 deletions
diff --git a/pkg/sentry/vfs/file_description_impl_util.go b/pkg/sentry/vfs/file_description_impl_util.go index 4d1d447ed..ba230da72 100644 --- a/pkg/sentry/vfs/file_description_impl_util.go +++ b/pkg/sentry/vfs/file_description_impl_util.go @@ -28,6 +28,16 @@ import ( "gvisor.dev/gvisor/pkg/waiter" ) +// The following design pattern is strongly recommended for filesystem +// implementations to adapt: +// - Have a local fileDescription struct (containing FileDescription) which +// embeds FileDescriptionDefaultImpl and overrides the default methods +// which are common to all fd implementations for that for that filesystem +// like StatusFlags, SetStatusFlags, Stat, SetStat, StatFS, etc. +// - This should be embedded in all file description implementations as the +// first field by value. +// - Directory FDs would also embed DirectoryFileDescriptionDefaultImpl. + // FileDescriptionDefaultImpl may be embedded by implementations of // FileDescriptionImpl to obtain implementations of many FileDescriptionImpl // methods with default behavior analogous to Linux's. @@ -119,11 +129,8 @@ func (FileDescriptionDefaultImpl) Ioctl(ctx context.Context, uio usermem.IO, arg // DirectoryFileDescriptionDefaultImpl may be embedded by implementations of // FileDescriptionImpl that always represent directories to obtain -// implementations of non-directory I/O methods that return EISDIR, and -// implementations of other methods consistent with FileDescriptionDefaultImpl. -type DirectoryFileDescriptionDefaultImpl struct { - FileDescriptionDefaultImpl -} +// implementations of non-directory I/O methods that return EISDIR. +type DirectoryFileDescriptionDefaultImpl struct{} // PRead implements FileDescriptionImpl.PRead. func (DirectoryFileDescriptionDefaultImpl) PRead(ctx context.Context, dst usermem.IOSequence, offset int64, opts ReadOptions) (int64, error) { @@ -153,8 +160,6 @@ func (DirectoryFileDescriptionDefaultImpl) Write(ctx context.Context, src userme // DynamicBytesFileDescriptionImpl.SetDataSource() must be called before first // use. type DynamicBytesFileDescriptionImpl struct { - FileDescriptionDefaultImpl - data DynamicBytesSource // immutable mu sync.Mutex // protects the following fields buf bytes.Buffer diff --git a/pkg/sentry/vfs/file_description_impl_util_test.go b/pkg/sentry/vfs/file_description_impl_util_test.go index cef7e3ce5..511b829fc 100644 --- a/pkg/sentry/vfs/file_description_impl_util_test.go +++ b/pkg/sentry/vfs/file_description_impl_util_test.go @@ -29,11 +29,18 @@ import ( "gvisor.dev/gvisor/pkg/syserror" ) +// fileDescription is the common fd struct which a filesystem implementation +// embeds in all of its file description implementations as required. +type fileDescription struct { + vfsfd FileDescription + FileDescriptionDefaultImpl +} + // genCountFD is a read-only FileDescriptionImpl representing a regular file // that contains the number of times its DynamicBytesSource.Generate() // implementation has been called. type genCountFD struct { - vfsfd FileDescription + fileDescription DynamicBytesFileDescriptionImpl count uint64 // accessed using atomic memory ops |