summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fs/ashmem
diff options
context:
space:
mode:
authorNicolas Lacasse <nlacasse@google.com>2019-01-14 20:33:29 -0800
committerShentubot <shentubot@google.com>2019-01-14 20:34:28 -0800
commitdc8450b5676d4c4ac9bcfa23cabd862e0060527d (patch)
treea4ef1ad59764f46f674b7003221ba8ae399b9e65 /pkg/sentry/fs/ashmem
parent343ebe9789087b099ea7feae19879f5c24e59bf1 (diff)
Remove fs.Handle, ramfs.Entry, and all the DeprecatedFileOperations.
More helper structs have been added to the fsutil package to make it easier to implement fs.InodeOperations and fs.FileOperations. PiperOrigin-RevId: 229305982 Change-Id: Ib6f8d3862f4216745116857913dbfa351530223b
Diffstat (limited to 'pkg/sentry/fs/ashmem')
-rw-r--r--pkg/sentry/fs/ashmem/BUILD1
-rw-r--r--pkg/sentry/fs/ashmem/area.go16
-rw-r--r--pkg/sentry/fs/ashmem/device.go133
3 files changed, 18 insertions, 132 deletions
diff --git a/pkg/sentry/fs/ashmem/BUILD b/pkg/sentry/fs/ashmem/BUILD
index 44ef82e64..2463111a8 100644
--- a/pkg/sentry/fs/ashmem/BUILD
+++ b/pkg/sentry/fs/ashmem/BUILD
@@ -28,6 +28,7 @@ go_library(
"//pkg/sentry/usage",
"//pkg/sentry/usermem",
"//pkg/syserror",
+ "//pkg/waiter",
],
)
diff --git a/pkg/sentry/fs/ashmem/area.go b/pkg/sentry/fs/ashmem/area.go
index d7dd2c084..7c1b11464 100644
--- a/pkg/sentry/fs/ashmem/area.go
+++ b/pkg/sentry/fs/ashmem/area.go
@@ -28,6 +28,7 @@ import (
"gvisor.googlesource.com/gvisor/pkg/sentry/usage"
"gvisor.googlesource.com/gvisor/pkg/sentry/usermem"
"gvisor.googlesource.com/gvisor/pkg/syserror"
+ "gvisor.googlesource.com/gvisor/pkg/waiter"
)
const (
@@ -42,9 +43,10 @@ const (
//
// +stateify savable
type Area struct {
- fsutil.NoFsync `state:"nosave"`
- fsutil.DeprecatedFileOperations `state:"nosave"`
- fsutil.NotDirReaddir `state:"nosave"`
+ waiter.AlwaysReady `state:"nosave"`
+ fsutil.FileNoFsync `state:"nosave"`
+ fsutil.FileNoopFlush `state:"nosave"`
+ fsutil.FileNotDirReaddir `state:"nosave"`
ad *Device
@@ -98,11 +100,6 @@ func (a *Area) Write(ctx context.Context, file *fs.File, src usermem.IOSequence,
return 0, syserror.ENOSYS
}
-// Flush implements fs.FileOperations.Flush.
-func (a *Area) Flush(ctx context.Context, file *fs.File) error {
- return nil
-}
-
// ConfigureMMap implements fs.FileOperations.ConfigureMMap.
func (a *Area) ConfigureMMap(ctx context.Context, file *fs.File, opts *memmap.MMapOpts) error {
a.mu.Lock()
@@ -122,8 +119,7 @@ func (a *Area) ConfigureMMap(ctx context.Context, file *fs.File, opts *memmap.MM
return syserror.ENOMEM
}
tmpfsInodeOps := tmpfs.NewInMemoryFile(ctx, usage.Tmpfs, fs.UnstableAttr{}, k)
- // This is not backed by a real filesystem, so we pass in nil.
- tmpfsInode := fs.NewInode(tmpfsInodeOps, fs.NewNonCachingMountSource(nil, fs.MountSourceFlags{}), fs.StableAttr{})
+ tmpfsInode := fs.NewInode(tmpfsInodeOps, fs.NewPseudoMountSource(), fs.StableAttr{})
dirent := fs.NewDirent(tmpfsInode, namePrefix+"/"+a.name)
tmpfsFile, err := tmpfsInode.GetFile(ctx, dirent, fs.FileFlags{Read: true, Write: true})
// Drop the extra reference on the Dirent.
diff --git a/pkg/sentry/fs/ashmem/device.go b/pkg/sentry/fs/ashmem/device.go
index 962da141b..5369d1b0d 100644
--- a/pkg/sentry/fs/ashmem/device.go
+++ b/pkg/sentry/fs/ashmem/device.go
@@ -16,49 +16,40 @@
package ashmem
import (
- "sync"
-
+ "gvisor.googlesource.com/gvisor/pkg/abi/linux"
"gvisor.googlesource.com/gvisor/pkg/sentry/context"
"gvisor.googlesource.com/gvisor/pkg/sentry/fs"
"gvisor.googlesource.com/gvisor/pkg/sentry/fs/fsutil"
- "gvisor.googlesource.com/gvisor/pkg/sentry/kernel/time"
"gvisor.googlesource.com/gvisor/pkg/sentry/usermem"
- "gvisor.googlesource.com/gvisor/pkg/syserror"
)
// Device implements fs.InodeOperations.
//
// +stateify savable
type Device struct {
- fsutil.DeprecatedFileOperations `state:"nosave"`
+ fsutil.InodeGenericChecker `state:"nosave"`
fsutil.InodeNoExtendedAttributes `state:"nosave"`
+ fsutil.InodeNoopRelease `state:"nosave"`
+ fsutil.InodeNoopTruncate `state:"nosave"`
+ fsutil.InodeNoopWriteOut `state:"nosave"`
fsutil.InodeNotDirectory `state:"nosave"`
- fsutil.InodeNotRenameable `state:"nosave"`
+ fsutil.InodeNotMappable `state:"nosave"`
fsutil.InodeNotSocket `state:"nosave"`
fsutil.InodeNotSymlink `state:"nosave"`
- fsutil.NoFsync `state:"nosave"`
- fsutil.NoMappable `state:"nosave"`
- fsutil.NoopWriteOut `state:"nosave"`
- fsutil.NotDirReaddir `state:"nosave"`
+ fsutil.InodeVirtual `state:"nosave"`
- mu sync.Mutex `state:"nosave"`
- unstable fs.UnstableAttr
+ fsutil.InodeSimpleAttributes
}
+var _ fs.InodeOperations = (*Device)(nil)
+
// NewDevice creates and intializes a Device structure.
func NewDevice(ctx context.Context, owner fs.FileOwner, fp fs.FilePermissions) *Device {
return &Device{
- unstable: fs.WithCurrentTime(ctx, fs.UnstableAttr{
- Owner: owner,
- Perms: fp,
- Links: 1,
- }),
+ InodeSimpleAttributes: fsutil.NewInodeSimpleAttributes(ctx, owner, fp, linux.ANON_INODE_FS_MAGIC),
}
}
-// Release implements fs.InodeOperations.Release.
-func (ad *Device) Release(context.Context) {}
-
// GetFile implements fs.InodeOperations.GetFile.
func (ad *Device) GetFile(ctx context.Context, d *fs.Dirent, flags fs.FileFlags) (*fs.File, error) {
return fs.NewFile(ctx, d, flags, &Area{
@@ -67,105 +58,3 @@ func (ad *Device) GetFile(ctx context.Context, d *fs.Dirent, flags fs.FileFlags)
perms: usermem.AnyAccess,
}), nil
}
-
-// UnstableAttr implements fs.InodeOperations.UnstableAttr.
-func (ad *Device) UnstableAttr(ctx context.Context, inode *fs.Inode) (fs.UnstableAttr, error) {
- ad.mu.Lock()
- defer ad.mu.Unlock()
- return ad.unstable, nil
-}
-
-// Check implements fs.InodeOperations.Check.
-func (ad *Device) Check(ctx context.Context, inode *fs.Inode, p fs.PermMask) bool {
- return fs.ContextCanAccessFile(ctx, inode, p)
-}
-
-// SetPermissions implements fs.InodeOperations.SetPermissions.
-func (ad *Device) SetPermissions(ctx context.Context, inode *fs.Inode, fp fs.FilePermissions) bool {
- ad.mu.Lock()
- defer ad.mu.Unlock()
- ad.unstable.Perms = fp
- ad.unstable.StatusChangeTime = time.NowFromContext(ctx)
- return true
-}
-
-// SetOwner implements fs.InodeOperations.SetOwner.
-func (ad *Device) SetOwner(ctx context.Context, inode *fs.Inode, owner fs.FileOwner) error {
- ad.mu.Lock()
- defer ad.mu.Unlock()
- if owner.UID.Ok() {
- ad.unstable.Owner.UID = owner.UID
- }
- if owner.GID.Ok() {
- ad.unstable.Owner.GID = owner.GID
- }
- return nil
-}
-
-// SetTimestamps implements fs.InodeOperations.SetTimestamps.
-func (ad *Device) SetTimestamps(ctx context.Context, inode *fs.Inode, ts fs.TimeSpec) error {
- if ts.ATimeOmit && ts.MTimeOmit {
- return nil
- }
-
- ad.mu.Lock()
- defer ad.mu.Unlock()
-
- now := time.NowFromContext(ctx)
- if !ts.ATimeOmit {
- if ts.ATimeSetSystemTime {
- ad.unstable.AccessTime = now
- } else {
- ad.unstable.AccessTime = ts.ATime
- }
- }
- if !ts.MTimeOmit {
- if ts.MTimeSetSystemTime {
- ad.unstable.ModificationTime = now
- } else {
- ad.unstable.ModificationTime = ts.MTime
- }
- }
- ad.unstable.StatusChangeTime = now
- return nil
-}
-
-// Truncate implements fs.InodeOperations.WriteOut.
-//
-// Ignored by ashmem.
-func (ad *Device) Truncate(ctx context.Context, inode *fs.Inode, size int64) error {
- return nil
-}
-
-// AddLink implements fs.InodeOperations.AddLink.
-//
-// Ashmem doesn't support links, no-op.
-func (ad *Device) AddLink() {}
-
-// DropLink implements fs.InodeOperations.DropLink.
-//
-// Ashmem doesn't support links, no-op.
-func (ad *Device) DropLink() {}
-
-// NotifyStatusChange implements fs.InodeOperations.NotifyStatusChange.
-func (ad *Device) NotifyStatusChange(ctx context.Context) {
- ad.mu.Lock()
- defer ad.mu.Unlock()
- now := time.NowFromContext(ctx)
- ad.unstable.ModificationTime = now
- ad.unstable.StatusChangeTime = now
-}
-
-// IsVirtual implements fs.InodeOperations.IsVirtual.
-//
-// Ashmem is virtual.
-func (ad *Device) IsVirtual() bool {
- return true
-}
-
-// StatFS implements fs.InodeOperations.StatFS.
-//
-// Ashmem doesn't support querying for filesystem info.
-func (ad *Device) StatFS(context.Context) (fs.Info, error) {
- return fs.Info{}, syserror.ENOSYS
-}